20 #include <vtkCamera.h> 21 #include <vtkInteractorObserver.h> 22 #include <vtkInteractorStyle.h> 23 #include <vtkPointData.h> 24 #include <vtkPolyData.h> 25 #include <vtkRenderWindowInteractor.h> 32 m_ObjectNormal[0] = 0.0;
33 m_ObjectNormal[1] = 0.0;
34 m_ObjectNormal[2] = 1.0;
63 if (positionEvent ==
nullptr)
67 if (interactionEvent->
GetSender()->
PickObject(positionEvent->GetPointerPositionOnScreen(), currentWorldPoint) ==
81 node->SetColor(1.0, 0.0, 0.0);
84 this->ColorizeSurface(interactionEvent->
GetSender(), 0.0);
96 node->SetColor(1.0, 1.0, 1.0);
99 this->ColorizeSurface(interactionEvent->
GetSender(), -1.0);
107 if (positionEvent ==
nullptr)
110 m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
113 m_InitialPickedDisplayPoint[0],
114 m_InitialPickedDisplayPoint[1],
116 m_InitialPickedWorldPoint);
120 if ((interactionEvent->
GetSender()) !=
nullptr)
132 if (positionEvent ==
nullptr)
135 m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
138 m_InitialPickedDisplayPoint[0],
139 m_InitialPickedDisplayPoint[1],
141 m_InitialPickedWorldPoint);
155 if (positionEvent ==
nullptr)
158 double currentWorldPoint[4];
159 mitk::Point2D currentDisplayPoint = positionEvent->GetPointerPositionOnScreen();
161 currentDisplayPoint[0],
162 currentDisplayPoint[1],
167 interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
168 interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
169 interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];
171 Point3D origin = m_OriginalGeometry->GetOrigin();
178 vtkPolyData *polyData =
nullptr;
179 if (surface.IsNotNull())
181 polyData = surface->GetVtkPolyData(timeStep);
184 vtkPointData *pointData = polyData->GetPointData();
185 if (pointData !=
nullptr)
187 vtkDataArray *normal = polyData->GetPointData()->GetVectors(
"planeNormal");
188 if (normal !=
nullptr)
190 m_ObjectNormal[0] = normal->GetComponent(0, 0);
191 m_ObjectNormal[1] = normal->GetComponent(0, 1);
192 m_ObjectNormal[2] = normal->GetComponent(0, 2);
201 origin + transformedObjectNormal * (interactionMove * transformedObjectNormal));
209 if (positionEvent ==
nullptr)
212 double currentWorldPoint[4];
213 Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
215 currentPickedDisplayPoint[0],
216 currentPickedDisplayPoint[1],
220 vtkCamera *camera =
nullptr;
221 vtkRenderer *currentVtkRenderer =
nullptr;
223 if ((interactionEvent->
GetSender()) !=
nullptr)
226 if (renderWindow !=
nullptr)
228 vtkRenderWindowInteractor *renderWindowInteractor = renderWindow->GetInteractor();
229 if (renderWindowInteractor !=
nullptr)
231 currentVtkRenderer = renderWindowInteractor->GetInteractorStyle()->GetCurrentRenderer();
232 if (currentVtkRenderer !=
nullptr)
233 camera = currentVtkRenderer->GetActiveCamera();
240 camera->GetViewPlaneNormal(vpn);
243 viewPlaneNormal[0] = vpn[0];
244 viewPlaneNormal[1] = vpn[1];
245 viewPlaneNormal[2] = vpn[2];
248 interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
249 interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
250 interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];
252 if (interactionMove[0] == 0 && interactionMove[1] == 0 && interactionMove[2] == 0)
255 Vector3D rotationAxis = itk::CrossProduct(viewPlaneNormal, interactionMove);
256 rotationAxis.Normalize();
258 int *size = currentVtkRenderer->GetSize();
259 double l2 = (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) *
260 (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) +
261 (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) *
262 (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]);
264 double rotationAngle = 360.0 * sqrt(l2 / (size[0] * size[0] + size[1] * size[1]));
267 Point3D rotationCenter = m_OriginalGeometry->GetCenter();
270 if ((interactionEvent->
GetSender()) !=
nullptr)
277 newGeometry->ExecuteOperation(&op);
279 if (timeGeometry.IsNotNull())
280 timeGeometry->SetTimeStepGeometry(newGeometry, timeStep);
291 MITK_ERROR <<
"ClippingPlaneInteractor3D: No data object present!";
297 if (renderer.IsNotNull())
298 timeStep = renderer->GetTimeStep(data);
302 vtkPolyData *polyData =
nullptr;
303 if (surface.IsNotNull())
304 polyData = surface->GetVtkPolyData(timeStep);
306 if (polyData ==
nullptr)
308 MITK_ERROR <<
"ClippingPlaneInteractor3D: No poly data present!";
312 vtkPointData *pointData = polyData->GetPointData();
313 if (pointData ==
nullptr)
315 MITK_ERROR <<
"ClippingPlaneInteractor3D: No point data present!";
319 vtkDataArray *scalars = pointData->GetScalars();
320 if (scalars ==
nullptr)
322 MITK_ERROR <<
"ClippingPlaneInteractor3D: No scalars for point data present!";
326 for (vtkIdType i = 0; i < pointData->GetNumberOfTuples(); ++i)
328 scalars->SetComponent(i, 0, scalar);
331 polyData->Modified();
Class for storing surfaces (vtkPolyData).
Super class for all position events.
void IndexToWorld(const mitk::Vector3D &vec_units, mitk::Vector3D &vec_mm) const
Convert (continuous or discrete) index coordinates of a vector vec_units to world coordinates (in mm)...
Standard implementation of BaseGeometry.
ClippingPlaneInteractor3D()
vtkRenderer * GetVtkRenderer() const
virtual void InitRotate(StateMachineAction *, InteractionEvent *)
Constants for most interaction classes, due to the generic StateMachines.
DataNode * GetDataNode() const
BaseRenderer * GetSender() const
virtual void RotateObject(StateMachineAction *, InteractionEvent *)
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
virtual void InitTranslate(StateMachineAction *, InteractionEvent *)
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual unsigned int GetTimeStep() const
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
virtual bool CheckOverObject(const InteractionEvent *)
virtual void SelectObject(StateMachineAction *, InteractionEvent *)
void UpdateOutputInformation() override
Update the information for this BaseData (the geometry in particular) so that it can be used as an ou...
virtual DataNode * PickObject(const Point2D &, Point3D &) const
Determines the object (mitk::DataNode) closest to the current position by means of picking...
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
virtual void DeselectObject(StateMachineAction *, InteractionEvent *)
#define CONNECT_CONDITION(a, f)
void ConnectActionsAndFunctions() override
virtual void TranslateObject(StateMachineAction *, InteractionEvent *)
~ClippingPlaneInteractor3D() override
void DataNodeChanged() override
#define CONNECT_FUNCTION(a, f)
Operation, that holds everything necessary for an rotation operation on mitk::BaseData.
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)