Quellcode durchsuchen

ENH: ctkVTKRenderView - Added function setFocalPoint and resetFocalPoint

Jean-Christophe Fillion-Robin vor 14 Jahren
Ursprung
Commit
62c121ddcd

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

@@ -380,3 +380,30 @@ void ctkVTKRenderView::zoomOut()
     }
   d->zoom(-d->ZoomFactor);
 }
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::setFocalPoint(int x, int y, int z)
+{
+  CTK_D(ctkVTKRenderView);
+  if (!d->Renderer->IsActiveCameraCreated())
+    {
+    return;
+    }
+  vtkCamera * camera = d->Renderer->GetActiveCamera();
+  camera->SetFocalPoint(x, y, z);
+  camera->ComputeViewPlaneNormal();
+  camera->OrthogonalizeViewUp();
+  d->Renderer->UpdateLightsGeometryToFollowCamera();
+}
+
+//----------------------------------------------------------------------------
+void ctkVTKRenderView::resetFocalPoint()
+{
+  CTK_D(ctkVTKRenderView);
+  double bounds[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+  d->Renderer->ComputeVisiblePropBounds(bounds);
+  double x_center = (bounds[1] + bounds[0]) / 2.0;
+  double y_center = (bounds[3] + bounds[2]) / 2.0;
+  double z_center = (bounds[5] + bounds[4]) / 2.0;
+  this->setFocalPoint(x_center, y_center, z_center);
+}

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

@@ -114,6 +114,13 @@ public slots:
   /// \sa setZoomFactor
   void zoomOut();
 
+  /// Set the focal point
+  void setFocalPoint(int x, int y, int z);
+
+  /// \brief Reset focal point
+  /// The visible scene bbox is computed, then the camera is recentered around its centroid.
+  void resetFocalPoint();
+
 public:
   /// Get underlying RenderWindow
   vtkRenderWindow* renderWindow()const;