ctkVTKAbstractView.h 5.9 KB

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