21 #include <vtkInteractorObserver.h>
22 #include <vtkPointData.h>
23 #include <vtkPolyData.h>
30 m_ObjectNormal[0] = 0.0;
31 m_ObjectNormal[1] = 0.0;
32 m_ObjectNormal[2] = 1.0;
37 m_OriginalPolyData->Delete();
56 if (this->GetDataNode() !=
nullptr)
58 m_Surface =
dynamic_cast<Surface *
>(this->GetDataNode()->GetData());
60 if (m_Surface == NULL)
61 MITK_ERROR <<
"SurfaceDeformationDataInteractor3D::DataNodeChanged(): DataNode has to contain a surface.";
70 if (positionEvent == NULL)
76 if (interactionEvent->
GetSender()->
PickObject(currentPickedDisplayPoint, currentPickedPoint) == this->GetDataNode())
79 m_SurfaceColorizationCenter = currentPickedPoint;
88 if (positionEvent == NULL)
92 vtkPolyData *polyData = m_Surface->GetVtkPolyData(timeStep);
94 this->GetDataNode()->SetColor(1.0, 0.0, 0.0);
97 this->ColorizeSurface(polyData, timeStep, m_SurfaceColorizationCenter, COLORIZATION_GAUSS);
105 if (positionEvent == NULL)
109 vtkPolyData *polyData = m_Surface->GetVtkPolyData(timeStep);
111 this->GetDataNode()->SetColor(1.0, 1.0, 1.0);
114 this->ColorizeSurface(polyData, timeStep, m_SurfaceColorizationCenter, COLORIZATION_CONSTANT, -1.0);
122 if (positionEvent == NULL)
126 vtkPolyData *polyData = m_Surface->GetVtkPolyData(timeStep);
130 interactionEvent->
GetSender()->
PickObject(currentPickedDisplayPoint, m_InitialPickedPoint);
133 currentPickedDisplayPoint[0],
134 currentPickedDisplayPoint[1],
136 m_InitialPickedWorldPoint);
139 m_OriginalPolyData->DeepCopy(polyData);
145 if (positionEvent == NULL)
149 vtkPolyData *polyData = m_Surface->GetVtkPolyData(timeStep);
152 double currentWorldPoint[4];
155 currentDisplayPoint[0],
156 currentDisplayPoint[1],
162 interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
163 interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
164 interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];
167 this->GetDataNode()->GetData()->UpdateOutputInformation();
169 geometry->WorldToIndex(interactionMove, interactionMoveIndex);
173 geometry->WorldToIndex(m_InitialPickedPoint, pickedPoint);
175 Vector3D v1 = pickedPoint.GetVectorFromOrigin();
177 vtkDataArray *normal = polyData->GetPointData()->GetVectors(
"planeNormal");
180 m_ObjectNormal[0] = normal->GetComponent(0, 0);
181 m_ObjectNormal[1] = normal->GetComponent(0, 1);
182 m_ObjectNormal[2] = normal->GetComponent(0, 2);
185 Vector3D v2 = m_ObjectNormal * (interactionMoveIndex * m_ObjectNormal);
187 vtkPoints *originalPoints = m_OriginalPolyData->GetPoints();
188 vtkPoints *deformedPoints = polyData->GetPoints();
190 double denom = m_GaussSigma * m_GaussSigma * 2;
192 for (vtkIdType i = 0; i < deformedPoints->GetNumberOfPoints(); ++i)
198 v0[0] = originalPoint[0];
199 v0[1] = originalPoint[1];
200 v0[2] = originalPoint[2];
203 double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();
205 Vector3D t = v2 * exp(-d * d / denom);
207 point[0] = originalPoint[0] + t[0];
208 point[1] = originalPoint[1] + t[1];
209 point[2] = originalPoint[2] + t[2];
210 deformedPoints->SetPoint(i, point);
214 m_SurfaceColorizationCenter = m_InitialPickedPoint;
216 polyData->Modified();
217 m_Surface->Modified();
225 if (wheelEvent == NULL)
229 if (m_GaussSigma < 10.0)
233 else if (m_GaussSigma > 128.0)
235 m_GaussSigma = 128.0;
239 vtkPolyData *polyData = m_Surface->GetVtkPolyData(timeStep);
242 this->ColorizeSurface(polyData, timeStep, m_SurfaceColorizationCenter, COLORIZATION_GAUSS);
247 void mitk::SurfaceDeformationDataInteractor3D::ColorizeSurface(
248 vtkPolyData *polyData,
int timeStep,
const Point3D &pickedPoint,
int mode,
double scalar)
250 if (polyData == NULL)
253 vtkPoints *points = polyData->GetPoints();
254 vtkPointData *pointData = polyData->GetPointData();
255 if (pointData == NULL)
258 vtkDataArray *scalars = pointData->GetScalars();
262 if (mode == COLORIZATION_GAUSS)
267 geometry->WorldToIndex(pickedPoint, localPickedPoint);
269 Vector3D v1 = localPickedPoint.GetVectorFromOrigin();
271 vtkDataArray *normal = polyData->GetPointData()->GetVectors(
"planeNormal");
274 m_ObjectNormal[0] = normal->GetComponent(0, 0);
275 m_ObjectNormal[1] = normal->GetComponent(0, 1);
276 m_ObjectNormal[2] = normal->GetComponent(0, 2);
279 double denom = m_GaussSigma * m_GaussSigma * 2;
280 for (vtkIdType i = 0; i < points->GetNumberOfPoints(); ++i)
283 double *point = points->GetPoint(i);
290 double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();
291 double t = exp(-d * d / denom);
293 scalars->SetComponent(i, 0, t);
296 else if (mode == COLORIZATION_CONSTANT)
298 for (vtkIdType i = 0; i < pointData->GetNumberOfTuples(); ++i)
300 scalars->SetComponent(i, 0, scalar);
303 polyData->Modified();
Class for storing surfaces (vtkPolyData).
Super class for all position events.
virtual bool CheckOverObject(const InteractionEvent *)
Checks if the mouse pointer is over the object.
BaseRenderer * GetSender() const
virtual DataNode * PickObject(const Point2D &, Point3D &) const
Determines the object (mitk::DataNode) closest to the current position by means of picking...
virtual void DeselectObject(StateMachineAction *, InteractionEvent *)
Called if the mouse pointer leaves the area of the object.
Point2D GetPointerPositionOnScreen() const
virtual void SelectObject(StateMachineAction *, InteractionEvent *)
Called if the mouse pointer is over the object indicated by a color change.
T::Pointer GetData(const std::string &name)
virtual mitk::RenderingManager * GetRenderingManager() const
Setter for the RenderingManager that handles this instance of BaseRenderer.
Vector< ScalarType, 3 > Vector3D
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual unsigned int GetTimeStep() const
#define CONNECT_CONDITION(a, f)
int GetWheelDelta() const
#define CONNECT_FUNCTION(a, f)
vtkRenderer * GetVtkRenderer() const
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.