ctkVTKAbstractView.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkVTKAbstractView_h
  15. #define __ctkVTKAbstractView_h
  16. // Qt includes
  17. #include <QWidget>
  18. // VTK includes
  19. #include <QVTKWidget.h>
  20. // CTK includes
  21. #include "ctkVTKObject.h"
  22. #include "ctkVisualizationVTKWidgetsExport.h"
  23. class ctkVTKAbstractViewPrivate;
  24. class vtkCornerAnnotation;
  25. class vtkInteractorObserver;
  26. class vtkRenderWindowInteractor;
  27. class vtkRenderWindow;
  28. /// \ingroup Visualization_VTK_Widgets
  29. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKAbstractView : public QWidget
  30. {
  31. Q_OBJECT
  32. QVTK_OBJECT
  33. Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
  34. Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  35. Q_PROPERTY(QColor backgroundColor2 READ backgroundColor2 WRITE setBackgroundColor)
  36. Q_PROPERTY(bool gradientBackground READ gradientBackground WRITE setGradientBackground)
  37. Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
  38. /// This property controls whether a corner annotation is visible with the
  39. /// last FPS value.
  40. /// false by default.
  41. Q_PROPERTY(bool fpsVisible READ isFPSVisible WRITE setFPSVisible)
  42. public:
  43. typedef QWidget Superclass;
  44. explicit ctkVTKAbstractView(QWidget* parent = 0);
  45. virtual ~ctkVTKAbstractView();
  46. public Q_SLOTS:
  47. /// Notify QVTKWidget that the view needs to be rendered.
  48. /// scheduleRender() respects the desired framerate of the render window,
  49. /// it won't render the window more than what the current render window
  50. /// framerate is.
  51. virtual void scheduleRender();
  52. /// Force a render even if a render is already ocurring
  53. /// Be careful when calling forceRender() as it can slow down your
  54. /// application. It is preferable to use scheduleRender() instead.
  55. virtual void forceRender();
  56. /// Set the background color of the rendering screen.
  57. virtual void setBackgroundColor(const QColor& newBackgroundColor);
  58. /// Set the second background color of the rendering screen for gradient
  59. /// backgrounds.
  60. virtual void setBackgroundColor2(const QColor& newBackgroundColor);
  61. /// Set/Get whether this view should have a gradient background using the
  62. /// Background (top) and Background2 (bottom) colors. Default is off.
  63. virtual void setGradientBackground(bool enable);
  64. /// Enable/Disable rendering
  65. void setRenderEnabled(bool value);
  66. /// Set corner annotation \a text
  67. virtual void setCornerAnnotationText(const QString& text);
  68. /// Show/Hide the FPS annotation
  69. void setFPSVisible(bool show);
  70. public:
  71. /// Get underlying RenderWindow
  72. Q_INVOKABLE vtkRenderWindow* renderWindow()const;
  73. /// Set/Get window interactor
  74. Q_INVOKABLE vtkRenderWindowInteractor* interactor()const;
  75. /// QVTKWidget catches all render requests, and ensure the desired framerate
  76. /// is respected.
  77. /// The interactor never calls Render() on the render window.
  78. /// TBD: can we only set a QVTKRenderWindowInteractor ?
  79. virtual void setInteractor(vtkRenderWindowInteractor* interactor);
  80. /// Get current interactor style
  81. Q_INVOKABLE vtkInteractorObserver* interactorStyle()const;
  82. /// Get corner annotation \a text
  83. QString cornerAnnotationText() const;
  84. Q_INVOKABLE vtkCornerAnnotation* cornerAnnotation()const;
  85. /// Get the underlying QVTKWidget
  86. Q_INVOKABLE QVTKWidget * VTKWidget() const;
  87. /// Get background color
  88. virtual QColor backgroundColor() const;
  89. /// Get the second background color
  90. virtual QColor backgroundColor2() const;
  91. /// Is the background a gradient
  92. virtual bool gradientBackground() const;
  93. /// Return if rendering is enabled
  94. bool renderEnabled() const;
  95. /// Return true if the FPS annotation is visible, false otherwise.
  96. bool isFPSVisible() const;
  97. /// Return the current FPS
  98. double fps()const;
  99. virtual QSize minimumSizeHint()const;
  100. virtual QSize sizeHint()const;
  101. virtual bool hasHeightForWidth()const;
  102. virtual int heightForWidth(int width)const;
  103. protected Q_SLOTS:
  104. void onRender();
  105. void updateFPS();
  106. protected:
  107. QScopedPointer<ctkVTKAbstractViewPrivate> d_ptr;
  108. ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget* parent);
  109. private:
  110. Q_DECLARE_PRIVATE(ctkVTKAbstractView);
  111. Q_DISABLE_COPY(ctkVTKAbstractView);
  112. };
  113. #endif