ctkVTKAbstractView.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #if CTK_USE_QVTKOPENGLWIDGET
  20. #include <QVTKOpenGLWidget.h>
  21. #else
  22. #include <QVTKWidget.h>
  23. #endif
  24. // CTK includes
  25. #include "ctkVTKObject.h"
  26. #include "ctkVisualizationVTKWidgetsExport.h"
  27. class ctkVTKAbstractViewPrivate;
  28. class vtkCornerAnnotation;
  29. class vtkInteractorObserver;
  30. class vtkRenderWindowInteractor;
  31. class vtkRenderWindow;
  32. /// \ingroup Visualization_VTK_Widgets
  33. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKAbstractView : public QWidget
  34. {
  35. Q_OBJECT
  36. QVTK_OBJECT
  37. Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
  38. Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  39. Q_PROPERTY(QColor backgroundColor2 READ backgroundColor2 WRITE setBackgroundColor)
  40. Q_PROPERTY(bool gradientBackground READ gradientBackground WRITE setGradientBackground)
  41. Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
  42. /// This property controls whether a corner annotation is visible with the
  43. /// last frames per second (FPS) value.
  44. /// false by default.
  45. Q_PROPERTY(bool fpsVisible READ isFPSVisible WRITE setFPSVisible)
  46. /// This property controls whether the render window uses depth peeling or
  47. /// not.
  48. /// false by default.
  49. Q_PROPERTY(bool useDepthPeeling READ useDepthPeeling WRITE setUseDepthPeeling)
  50. public:
  51. typedef QWidget Superclass;
  52. explicit ctkVTKAbstractView(QWidget* parent = 0);
  53. virtual ~ctkVTKAbstractView();
  54. public Q_SLOTS:
  55. /// Notify QVTKWidget that the view needs to be rendered.
  56. /// scheduleRender() respects the desired framerate of the render window,
  57. /// it won't render the window more than what the current render window
  58. /// framerate is.
  59. virtual void scheduleRender();
  60. /// Force a render even if a render is already ocurring
  61. /// Be careful when calling forceRender() as it can slow down your
  62. /// application. It is preferable to use scheduleRender() instead.
  63. virtual void forceRender();
  64. /// Set the background color of the rendering screen.
  65. virtual void setBackgroundColor(const QColor& newBackgroundColor);
  66. /// Set the second background color of the rendering screen for gradient
  67. /// backgrounds.
  68. virtual void setBackgroundColor2(const QColor& newBackgroundColor);
  69. /// Set/Get whether this view should have a gradient background using the
  70. /// Background (top) and Background2 (bottom) colors. Default is off.
  71. virtual void setGradientBackground(bool enable);
  72. /// Enable/Disable rendering
  73. void setRenderEnabled(bool value);
  74. /// Set corner annotation \a text
  75. virtual void setCornerAnnotationText(const QString& text);
  76. /// Show/Hide the FPS annotation
  77. void setFPSVisible(bool show);
  78. /// Set the useDepthPeeling property value.
  79. /// \sa useDepthPeeling
  80. void setUseDepthPeeling(bool use);
  81. public:
  82. /// Get underlying RenderWindow
  83. Q_INVOKABLE vtkRenderWindow* renderWindow()const;
  84. /// Set/Get window interactor
  85. Q_INVOKABLE vtkRenderWindowInteractor* interactor()const;
  86. /// QVTKWidget catches all render requests, and ensure the desired framerate
  87. /// is respected.
  88. /// The interactor never calls Render() on the render window.
  89. /// TBD: can we only set a QVTKRenderWindowInteractor ?
  90. virtual void setInteractor(vtkRenderWindowInteractor* interactor);
  91. /// Get current interactor style
  92. Q_INVOKABLE vtkInteractorObserver* interactorStyle()const;
  93. /// Get corner annotation \a text
  94. QString cornerAnnotationText() const;
  95. Q_INVOKABLE vtkCornerAnnotation* cornerAnnotation()const;
  96. /// Get the underlying QVTKWidget
  97. #if CTK_USE_QVTKOPENGLWIDGET
  98. Q_INVOKABLE QVTKOpenGLWidget * VTKWidget() const;
  99. #else
  100. Q_INVOKABLE QVTKWidget * VTKWidget() const;
  101. #endif
  102. /// Get background color
  103. virtual QColor backgroundColor() const;
  104. /// Get the second background color
  105. virtual QColor backgroundColor2() const;
  106. /// Is the background a gradient
  107. virtual bool gradientBackground() const;
  108. /// Return if rendering is enabled
  109. bool renderEnabled() const;
  110. /// Return true if the FPS annotation is visible, false otherwise.
  111. bool isFPSVisible() const;
  112. /// Return the current FPS
  113. double fps()const;
  114. /// Return the useDepthPeeling property value.
  115. /// \sa useDepthPeeling
  116. bool useDepthPeeling()const;
  117. /// Set the default number of multisamples to use. Note that a negative
  118. /// value means "auto", which means the renderer will attempt to select
  119. /// the maximum number (but is not guaranteed to work).
  120. ///
  121. /// WARNING: Multisampling should be set *before* creation of the
  122. /// OpenGL context (e.g., initializing the rendering window) in order
  123. /// to have an effect. Consider using setMultisamples before
  124. /// instantiating ctkVTKAbstractView objects.
  125. /// \sa multiSamples
  126. static void setMultiSamples(int);
  127. /// Return the current multisamples default
  128. /// \sa setMultiSamples()
  129. static int multiSamples();
  130. virtual QSize minimumSizeHint()const;
  131. virtual QSize sizeHint()const;
  132. virtual bool hasHeightForWidth()const;
  133. virtual int heightForWidth(int width)const;
  134. protected Q_SLOTS:
  135. void onRender();
  136. void updateFPS();
  137. protected:
  138. QScopedPointer<ctkVTKAbstractViewPrivate> d_ptr;
  139. ctkVTKAbstractView(ctkVTKAbstractViewPrivate* pimpl, QWidget* parent);
  140. private:
  141. Q_DECLARE_PRIVATE(ctkVTKAbstractView);
  142. Q_DISABLE_COPY(ctkVTKAbstractView);
  143. };
  144. #endif