Browse Source

ENH: ctkVTKRenderView - Add pitch, yaw, roll feature

Also added possibility to:
 - change the direction of either pitch, roll or yaw.
 - set the amount of degrees that the view should be rotated with
Jean-Christophe Fillion-Robin 14 years ago
parent
commit
765f7d3bb2

+ 76 - 0
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.cpp

@@ -51,6 +51,10 @@ ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate()
   this->RenderPending = false;
   this->RenderEnabled = false;
   this->ZoomFactor = 0.05;
+  this->RotateDegrees = 5;
+  this->PitchDirection = ctkVTKRenderView::PitchUp;
+  this->RollDirection = ctkVTKRenderView::RollRight;
+  this->YawDirection = ctkVTKRenderView::YawLeft;
 }
 
 // --------------------------------------------------------------------------
@@ -282,6 +286,70 @@ CTK_SET_CXX(ctkVTKRenderView, bool, setRenderEnabled, RenderEnabled);
 CTK_GET_CXX(ctkVTKRenderView, bool, renderEnabled, RenderEnabled);
 
 //----------------------------------------------------------------------------
+CTK_GET_CXX(ctkVTKRenderView, int, rotateDegrees, RotateDegrees);
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::setRotateDegrees(int newRotateDegrees)
+{
+  CTK_D(ctkVTKRenderView);
+  d->RotateDegrees = qAbs(newRotateDegrees);
+}
+
+//----------------------------------------------------------------------------
+CTK_GET_CXX(ctkVTKRenderView, ctkVTKRenderView::PitchDirection, pitchDirection, PitchDirection);
+CTK_SET_CXX(ctkVTKRenderView, ctkVTKRenderView::PitchDirection, setPitchDirection, PitchDirection);
+
+//----------------------------------------------------------------------------
+CTK_GET_CXX(ctkVTKRenderView, ctkVTKRenderView::RollDirection, rollDirection, RollDirection);
+CTK_SET_CXX(ctkVTKRenderView, ctkVTKRenderView::RollDirection, setRollDirection, RollDirection);
+
+//----------------------------------------------------------------------------
+CTK_GET_CXX(ctkVTKRenderView, ctkVTKRenderView::YawDirection, yawDirection, YawDirection);
+CTK_SET_CXX(ctkVTKRenderView, ctkVTKRenderView::YawDirection, setYawDirection, YawDirection);
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::pitch()
+{
+  CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
+  vtkCamera *cam = d->Renderer->GetActiveCamera();
+  cam->Elevation(d->PitchDirection == Self::PitchDown ? d->RotateDegrees : -d->RotateDegrees);
+  cam->OrthogonalizeViewUp();
+  d->Renderer->UpdateLightsGeometryToFollowCamera();
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::roll()
+{
+  CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
+  vtkCamera *cam = d->Renderer->GetActiveCamera();
+  cam->Roll(d->RollDirection == Self::RollLeft ? d->RotateDegrees : -d->RotateDegrees);
+  cam->OrthogonalizeViewUp();
+  d->Renderer->UpdateLightsGeometryToFollowCamera();
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::yaw()
+{
+  CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
+  vtkCamera *cam = d->Renderer->GetActiveCamera();
+  cam->Azimuth(d->YawDirection == Self::YawLeft ? d->RotateDegrees : -d->RotateDegrees);
+  cam->OrthogonalizeViewUp();
+  d->Renderer->UpdateLightsGeometryToFollowCamera();
+}
+
+//----------------------------------------------------------------------------
 void ctkVTKRenderView::setZoomFactor(double newZoomFactor)
 {
   CTK_D(ctkVTKRenderView);
@@ -295,6 +363,10 @@ CTK_GET_CXX(ctkVTKRenderView, double, zoomFactor, ZoomFactor);
 void ctkVTKRenderView::zoomIn()
 {
   CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
   d->zoom(d->ZoomFactor);
 }
 
@@ -302,5 +374,9 @@ void ctkVTKRenderView::zoomIn()
 void ctkVTKRenderView::zoomOut()
 {
   CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
   d->zoom(-d->ZoomFactor);
 }

+ 42 - 0
Libs/Visualization/VTK/Widgets/ctkVTKRenderView.h

@@ -45,8 +45,20 @@ class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKRenderView : public QWidget
   Q_PROPERTY(bool orientationWidgetVisible READ orientationWidgetVisible
              WRITE setOrientationWidgetVisible)
   Q_PROPERTY(double zoomFactor READ zoomFactor WRITE setZoomFactor)
+  Q_PROPERTY(int rotateDegrees READ rotateDegrees WRITE setRotateDegrees)
+  Q_ENUMS(PitchDirection)
+  Q_PROPERTY(PitchDirection pitchDirection READ pitchDirection WRITE setPitchDirection)
+  Q_ENUMS(RollDirection)
+  Q_PROPERTY(RollDirection rollDirection READ rollDirection WRITE setRollDirection)
+  Q_ENUMS(YawDirection)
+  Q_PROPERTY(YawDirection yawDirection READ yawDirection WRITE setYawDirection)
 
 public:
+
+  enum PitchDirection { PitchUp, PitchDown };
+  enum RollDirection {RollLeft, RollRight};
+  enum YawDirection {YawLeft, YawRight};
+
   /// Constructors
   typedef QWidget   Superclass;
   explicit ctkVTKRenderView(QWidget* parent = 0);
@@ -72,8 +84,26 @@ public slots:
   /// Show/Hide Orientation widget
   void setOrientationWidgetVisible(bool visible);
 
+  /// Set absolute amount degrees the view should be either pitched, rolled or yawed with.
+  /// \sa pitch setPitchDirection roll setRollDirection yaw setYawDirection
+  /// \note The default is 5 degrees
+  void setRotateDegrees(int newRotateDegrees);
+
+  /// Pitch view of X degrees. X been set using setRotateDegrees
+  /// \sa setRotateDegrees
+  void pitch();
+
+  /// Rool view of X degrees. X been set using setRotateDegrees
+  /// \sa setRotateDegrees
+  void roll();
+
+  /// Yaw view of X degrees. X been set using setRotateDegrees
+  /// \sa setRotateDegrees
+  void yaw();
+
   /// \brief Set zoom factor
   /// zoomFactor is a value between 0.0 and 1.0
+  /// \note The default value is 0.05
   void setZoomFactor(double newZoomFactor);
 
   /// Zoom in using the \a zoomfactor
@@ -116,6 +146,18 @@ public:
   /// Return if rendering is enabled
   bool renderEnabled() const;
 
+  /// Return amount of degrees used to either pitch, roll or yaw the view
+  int rotateDegrees()const;
+
+  PitchDirection pitchDirection()const;
+  void setPitchDirection(PitchDirection newPitchDirection);
+
+  RollDirection rollDirection()const;
+  void setRollDirection(RollDirection newRollDirection);
+
+  YawDirection yawDirection()const;
+  void setYawDirection(YawDirection newYawDirection);
+
   /// Return zoom factor
   double zoomFactor()const;
   

+ 4 - 0
Libs/Visualization/VTK/Widgets/ctkVTKRenderView_p.h

@@ -67,6 +67,10 @@ public:
   vtkSmartPointer<vtkOrientationMarkerWidget>   Orientation;
   vtkSmartPointer<vtkCornerAnnotation>          CornerAnnotation;
   double                                        ZoomFactor;
+  int                                           RotateDegrees;
+  ctkVTKRenderView::PitchDirection              PitchDirection;
+  ctkVTKRenderView::RollDirection               RollDirection;
+  ctkVTKRenderView::YawDirection                YawDirection;
 
   vtkWeakPointer<vtkRenderWindowInteractor>     CurrentInteractor;