ctkVTKRenderView.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.commontk.org/LICENSE
  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 __ctkVTKRenderView_h
  15. #define __ctkVTKRenderView_h
  16. // Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include <ctkAxesWidget.h>
  20. #include <ctkPimpl.h>
  21. #include "ctkVisualizationVTKWidgetsExport.h"
  22. class ctkVTKRenderViewPrivate;
  23. class vtkInteractorObserver;
  24. class vtkRenderWindowInteractor;
  25. class vtkRenderWindow;
  26. class vtkRenderer;
  27. class vtkCamera;
  28. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderView : public QWidget
  29. {
  30. Q_OBJECT
  31. Q_PROPERTY(QString cornerAnnotationText READ cornerAnnotationText WRITE setCornerAnnotationText)
  32. Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor)
  33. Q_PROPERTY(bool renderEnabled READ renderEnabled WRITE setRenderEnabled)
  34. Q_PROPERTY(bool orientationWidgetVisible READ orientationWidgetVisible
  35. WRITE setOrientationWidgetVisible)
  36. Q_PROPERTY(double zoomFactor READ zoomFactor WRITE setZoomFactor)
  37. Q_PROPERTY(int pitchRollYawIncrement READ pitchRollYawIncrement WRITE setPitchRollYawIncrement)
  38. Q_ENUMS(RotateDirection)
  39. Q_PROPERTY(RotateDirection pitchDirection READ pitchDirection WRITE setPitchDirection)
  40. Q_PROPERTY(RotateDirection rollDirection READ rollDirection WRITE setRollDirection)
  41. Q_PROPERTY(RotateDirection yawDirection READ yawDirection WRITE setYawDirection)
  42. Q_PROPERTY(RotateDirection spinDirection READ spinDirection WRITE setSpinDirection)
  43. Q_PROPERTY(bool spinEnabled READ spinEnabled WRITE setSpinEnabled)
  44. Q_PROPERTY(int spinIncrement READ spinIncrement WRITE setSpinIncrement)
  45. Q_PROPERTY(int animationIntervalMs READ animationIntervalMs WRITE setAnimationIntervalMs)
  46. Q_PROPERTY(bool rockEnabled READ rockEnabled WRITE setRockEnabled)
  47. Q_PROPERTY(int rockLength READ rockLength WRITE setRockLength)
  48. public:
  49. enum RotateDirection { PitchUp, PitchDown, RollLeft, RollRight, YawLeft, YawRight };
  50. typedef QWidget Superclass;
  51. explicit ctkVTKRenderView(QWidget* parent = 0);
  52. virtual ~ctkVTKRenderView();
  53. public slots:
  54. /// If a render has already been scheduled, this called is a no-op
  55. void scheduleRender();
  56. /// Force a render even if a render is already ocurring
  57. void forceRender();
  58. /// Set background color
  59. void setBackgroundColor(const QColor& newBackgroundColor);
  60. /// Enable/Disable rendering
  61. void setRenderEnabled(bool value);
  62. /// Set corner annotation \a text
  63. void setCornerAnnotationText(const QString& text);
  64. /// Show/Hide Orientation widget
  65. void setOrientationWidgetVisible(bool visible);
  66. /// Set absolute amount degrees the view should be either pitched, rolled or yawed with.
  67. /// \sa pitch setPitchDirection roll setRollDirection yaw setYawDirection
  68. /// \note The default is 5 degrees
  69. void setPitchRollYawIncrement(int newPitchRollYawIncrement);
  70. /// Pitch view of X degrees. X been set using setPitchRollYawIncrement
  71. /// \sa setPitchRollYawIncrement setPitchDirection
  72. void pitch();
  73. /// Rool view of X degrees. X been set using setPitchRollYawIncrement
  74. /// \sa setPitchRollYawIncrement setRollDirection
  75. void roll();
  76. /// Yaw view of X degrees. X been set using setPitchRollYawIncrement
  77. /// \sa setPitchRollYawIncrement setYawDirection
  78. void yaw();
  79. /// Enable or Disbled the animated spin of the view
  80. void setSpinEnabled(bool enabled);
  81. /// Set number of degrees in spin increment
  82. /// \sa setSpinDirection setSpinIntervalMs
  83. void setSpinIncrement(int newSpinIncrement);
  84. /// Amount of wait time between spin or rock increments
  85. /// \sa setSpinIncrement setRockIncrement
  86. void setAnimationIntervalMs(int ms);
  87. /// Enable or Disbled the animated rock of the view
  88. void setRockEnabled(bool enabled);
  89. /// Set length of the rock animation
  90. void setRockLength(int newRockLength);
  91. /// Set increment of animated rock
  92. void setRockIncrement(int newRockIncrement);
  93. /// \brief Set zoom factor
  94. /// zoomFactor is a value between 0.0 and 1.0
  95. /// \note The default value is 0.05
  96. void setZoomFactor(double newZoomFactor);
  97. /// Zoom in using the \a zoomfactor
  98. /// \sa setZoomFactor
  99. void zoomIn();
  100. /// Zoom out using the \a zoomfactor
  101. /// \sa setZoomFactor
  102. void zoomOut();
  103. /// Set the focal point
  104. void setFocalPoint(int x, int y, int z);
  105. /// \brief Reset focal point
  106. /// The visible scene bbox is computed, then the camera is recentered around its centroid.
  107. void resetFocalPoint();
  108. /// \brief Change camera to look from a given axis to the focal point
  109. /// Translate/Rotate the camera to look from a given axis
  110. /// The Field of View (fov) controls how far from the focal point the
  111. /// camera must be (final_pos = focal_point + 3*fov).
  112. void lookFromAxis(const ctkAxesWidget::Axis& axis, double fov = 10.);
  113. public:
  114. /// Get underlying RenderWindow
  115. vtkRenderWindow* renderWindow()const;
  116. /// Set/Get window interactor
  117. vtkRenderWindowInteractor* interactor()const;
  118. void setInteractor(vtkRenderWindowInteractor* newInteractor);
  119. /// Get current interactor style
  120. vtkInteractorObserver* interactorStyle();
  121. /// Get corner annotation \a text
  122. QString cornerAnnotationText() const;
  123. /// Get background color
  124. QColor backgroundColor() const;
  125. /// Get Orientation widget visibility
  126. bool orientationWidgetVisible();
  127. /// Get active camera
  128. vtkCamera* activeCamera();
  129. /// Reset camera
  130. void resetCamera();
  131. /// Get a reference to the associated vtkRenderer
  132. vtkRenderer* renderer()const;
  133. /// Return if rendering is enabled
  134. bool renderEnabled() const;
  135. /// Return pitch, roll or yaw increment (in degree)
  136. int pitchRollYawIncrement()const;
  137. /// Return if animated spin is enabled
  138. bool spinEnabled() const;
  139. /// Return spin increment (in degrees)
  140. /// \sa setSpinIncrement
  141. int spinIncrement()const;
  142. /// Amount of waiting time between spin or rock increment
  143. /// \sa setAnimationIntervalMs
  144. int animationIntervalMs()const;
  145. /// Return if animated rock is enabled
  146. bool rockEnabled() const;
  147. /// Return length of the rock animation
  148. int rockLength() const;
  149. /// Return increment of animated rock
  150. int rockIncrement() const;
  151. RotateDirection pitchDirection()const;
  152. void setPitchDirection(RotateDirection newPitchDirection);
  153. RotateDirection rollDirection()const;
  154. void setRollDirection(RotateDirection newRollDirection);
  155. RotateDirection yawDirection()const;
  156. void setYawDirection(RotateDirection newYawDirection);
  157. RotateDirection spinDirection()const;
  158. void setSpinDirection(RotateDirection newSpinDirection);
  159. /// Return zoom factor
  160. double zoomFactor()const;
  161. protected:
  162. QScopedPointer<ctkVTKRenderViewPrivate> d_ptr;
  163. private:
  164. Q_DECLARE_PRIVATE(ctkVTKRenderView);
  165. Q_DISABLE_COPY(ctkVTKRenderView);
  166. };
  167. #endif