ctkVTKAbstractView.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // CTK includes
  19. #include "ctkVTKOpenGLNativeWidget.h"
  20. #include "ctkVTKObject.h"
  21. #include "ctkVisualizationVTKWidgetsExport.h"
  22. class ctkVTKAbstractViewPrivate;
  23. class vtkCornerAnnotation;
  24. class vtkInteractorObserver;
  25. class vtkRenderWindowInteractor;
  26. class vtkRenderWindow;
  27. /// \ingroup Visualization_VTK_Widgets
  28. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKAbstractView : public QWidget
  29. {
  30. Q_OBJECT
  31. QVTK_OBJECT
  32. Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
  33. Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  34. Q_PROPERTY(QColor backgroundColor2 READ backgroundColor2 WRITE setBackgroundColor)
  35. Q_PROPERTY(bool gradientBackground READ gradientBackground WRITE setGradientBackground)
  36. Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
  37. /// This property controls whether a corner annotation is visible with the
  38. /// last frames per second (FPS) value.
  39. /// false by default.
  40. Q_PROPERTY(bool fpsVisible READ isFPSVisible WRITE setFPSVisible)
  41. /// This property controls whether the render window uses depth peeling or
  42. /// not.
  43. /// false by default.
  44. Q_PROPERTY(bool useDepthPeeling READ useDepthPeeling WRITE setUseDepthPeeling)
  45. /// Set a maximum rate (in frames per second) for rendering.
  46. Q_PROPERTY(double maximumUpdateRate READ maximumUpdateRate WRITE setMaximumUpdateRate)
  47. public:
  48. typedef QWidget Superclass;
  49. explicit ctkVTKAbstractView(QWidget* parent = 0);
  50. virtual ~ctkVTKAbstractView();
  51. public Q_SLOTS:
  52. /// Notify QVTKWidget that the view needs to be rendered.
  53. /// scheduleRender() respects the maximum update rate of the view,
  54. /// it won't render the window more frequently than what the maximum
  55. /// update rate is.
  56. /// \sa setMaximumUpdateRate
  57. virtual void scheduleRender();
  58. /// Force a render even if a render is already ocurring
  59. /// Be careful when calling forceRender() as it can slow down your
  60. /// application. It is preferable to use scheduleRender() instead.
  61. /// \sa scheduleRender
  62. virtual void forceRender();
  63. /// Set maximum rate for rendering (in frames per second).
  64. /// If rendering is requested more frequently than this rate using scheduleRender,
  65. /// actual rendering will happen at this rate.
  66. /// This mechanism prevents repeated rendering caused by cluster of rendering requests.
  67. ///
  68. /// If maximum update rate is set to 0 then it indicates that rendering is done next time
  69. /// the application is idle, i.e., pending timer events are processed. This option should be used
  70. /// with caution, as policy of timer event processing may differ between operating systems.
  71. /// Specifically, on macOS, timer events may be indefinitely delayed if user interface continuously
  72. /// generates events.
  73. ///
  74. /// RenderWindow's DesiredUpdateRate property is intended for determining rendering quality settings,
  75. /// and is not suitable to be used as maximum update rate. The main reason is that VTK usually makes the
  76. /// rendering much faster and lower quality than DesiredUpdateRate would dictate, and so it would
  77. /// unnecessarily decrease the actual refresh rate.
  78. ///
  79. /// By default maximum update rate is set to 60FPS, which allows smooth updates, while effectively
  80. /// suppressing repeated update requests (after a rendering has been completed,
  81. /// repeated rendering requests will be ignored for 17 milliseconds).
  82. ///
  83. /// \sa scheduleRender
  84. void setMaximumUpdateRate(double fps);
  85. /// Set the background color of the rendering screen.
  86. virtual void setBackgroundColor(const QColor& newBackgroundColor);
  87. /// Set the second background color of the rendering screen for gradient
  88. /// backgrounds.
  89. virtual void setBackgroundColor2(const QColor& newBackgroundColor);
  90. /// Set whether this view should have a gradient background using the
  91. /// Background (top) and Background2 (bottom) colors. Default is off.
  92. virtual void setGradientBackground(bool enable);
  93. /// Enable/Disable rendering
  94. void setRenderEnabled(bool value);
  95. /// Set corner annotation \a text
  96. virtual void setCornerAnnotationText(const QString& text);
  97. /// Show/Hide the FPS annotation
  98. void setFPSVisible(bool show);
  99. /// Set the useDepthPeeling property value.
  100. /// \sa useDepthPeeling
  101. void setUseDepthPeeling(bool use);
  102. public:
  103. /// Get underlying RenderWindow
  104. Q_INVOKABLE vtkRenderWindow* renderWindow()const;
  105. /// Set/Get window interactor
  106. Q_INVOKABLE vtkRenderWindowInteractor* interactor()const;
  107. /// QVTKWidget catches all render requests, and ensure the desired framerate
  108. /// is respected.
  109. /// The interactor never calls Render() on the render window.
  110. /// TBD: can we only set a QVTKRenderWindowInteractor ?
  111. virtual void setInteractor(vtkRenderWindowInteractor* interactor);
  112. /// Get current interactor style
  113. Q_INVOKABLE vtkInteractorObserver* interactorStyle()const;
  114. /// Get corner annotation \a text
  115. QString cornerAnnotationText() const;
  116. Q_INVOKABLE vtkCornerAnnotation* cornerAnnotation()const;
  117. /// Get the underlying QVTKWidget
  118. Q_INVOKABLE ctkVTKOpenGLNativeWidget * VTKWidget() const;
  119. /// Get background color
  120. virtual QColor backgroundColor() const;
  121. /// Get the second background color
  122. virtual QColor backgroundColor2() const;
  123. /// Is the background a gradient
  124. virtual bool gradientBackground() const;
  125. /// Return if rendering is enabled
  126. bool renderEnabled() const;
  127. /// Return true if the FPS annotation is visible, false otherwise.
  128. bool isFPSVisible() const;
  129. /// Return the current FPS
  130. double fps()const;
  131. /// Returns maximum rate for rendering (in frames per second).
  132. /// \\sa setMaximumUpdateRate
  133. double maximumUpdateRate()const;
  134. /// Returns true if depth peeling is enabled.
  135. /// \sa setUseDepthPeeling
  136. bool useDepthPeeling()const;
  137. /// Set the default number of multisamples to use. Note that a negative
  138. /// value means "auto", which means the renderer will attempt to select
  139. /// the maximum number (but is not guaranteed to work).
  140. ///
  141. /// WARNING: Multisampling should be set *before* creation of the
  142. /// OpenGL context (e.g., initializing the rendering window) in order
  143. /// to have an effect. Consider using setMultisamples before
  144. /// instantiating ctkVTKAbstractView objects.
  145. /// \sa multiSamples
  146. static void setMultiSamples(int);
  147. /// Return the current multisamples default
  148. /// \sa setMultiSamples()
  149. static int multiSamples();
  150. virtual QSize minimumSizeHint()const;
  151. virtual QSize sizeHint()const;
  152. virtual bool hasHeightForWidth()const;
  153. virtual int heightForWidth(int width)const;
  154. protected Q_SLOTS:
  155. void onRender();
  156. void updateFPS();
  157. protected:
  158. QScopedPointer<ctkVTKAbstractViewPrivate> d_ptr;
  159. ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget* parent);
  160. private:
  161. Q_DECLARE_PRIVATE(ctkVTKAbstractView);
  162. Q_DISABLE_COPY(ctkVTKAbstractView);
  163. };
  164. #endif