17 #include <vtkInteractorObserver.h> 18 #include <vtkPointData.h> 19 #include <vtkPolyData.h> 23 m_OriginalPolyData = vtkPolyData::New();
26 m_ObjectNormal[0] = 0.0;
27 m_ObjectNormal[1] = 0.0;
28 m_ObjectNormal[2] = 1.0;
33 m_OriginalPolyData->Delete();
56 if (m_Surface ==
nullptr)
57 MITK_ERROR <<
"SurfaceDeformationDataInteractor3D::DataNodeChanged(): DataNode has to contain a surface.";
66 if (positionEvent ==
nullptr)
69 Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
75 m_SurfaceColorizationCenter = currentPickedPoint;
84 if (positionEvent ==
nullptr)
93 this->ColorizeSurface(polyData, timeStep, m_SurfaceColorizationCenter,
COLORIZATION_GAUSS);
101 if (positionEvent ==
nullptr)
118 if (positionEvent ==
nullptr)
125 mitk::Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen();
126 interactionEvent->
GetSender()->
PickObject(currentPickedDisplayPoint, m_InitialPickedPoint);
129 currentPickedDisplayPoint[0],
130 currentPickedDisplayPoint[1],
132 m_InitialPickedWorldPoint);
135 m_OriginalPolyData->DeepCopy(polyData);
141 if (positionEvent ==
nullptr)
148 double currentWorldPoint[4];
149 mitk::Point2D currentDisplayPoint = positionEvent->GetPointerPositionOnScreen();
151 currentDisplayPoint[0],
152 currentDisplayPoint[1],
158 interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0];
159 interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1];
160 interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2];
165 geometry->WorldToIndex(interactionMove, interactionMoveIndex);
169 geometry->WorldToIndex(m_InitialPickedPoint, pickedPoint);
171 Vector3D v1 = pickedPoint.GetVectorFromOrigin();
173 vtkDataArray *normal = polyData->GetPointData()->GetVectors(
"planeNormal");
174 if (normal !=
nullptr)
176 m_ObjectNormal[0] = normal->GetComponent(0, 0);
177 m_ObjectNormal[1] = normal->GetComponent(0, 1);
178 m_ObjectNormal[2] = normal->GetComponent(0, 2);
181 Vector3D v2 = m_ObjectNormal * (interactionMoveIndex * m_ObjectNormal);
183 vtkPoints *originalPoints = m_OriginalPolyData->GetPoints();
184 vtkPoints *deformedPoints = polyData->GetPoints();
186 double denom = m_GaussSigma * m_GaussSigma * 2;
188 for (vtkIdType i = 0; i < deformedPoints->GetNumberOfPoints(); ++i)
194 v0[0] = originalPoint[0];
195 v0[1] = originalPoint[1];
196 v0[2] = originalPoint[2];
199 double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();
201 Vector3D t = v2 * exp(-d * d / denom);
203 point[0] = originalPoint[0] + t[0];
204 point[1] = originalPoint[1] + t[1];
205 point[2] = originalPoint[2] + t[2];
206 deformedPoints->SetPoint(i, point);
210 m_SurfaceColorizationCenter = m_InitialPickedPoint;
212 polyData->Modified();
213 m_Surface->Modified();
220 const auto *wheelEvent =
dynamic_cast<const MouseWheelEvent *
>(interactionEvent);
221 if (wheelEvent ==
nullptr)
224 m_GaussSigma += (double)(wheelEvent->GetWheelDelta()) / 20;
225 if (m_GaussSigma < 10.0)
229 else if (m_GaussSigma > 128.0)
231 m_GaussSigma = 128.0;
238 this->ColorizeSurface(polyData, timeStep, m_SurfaceColorizationCenter,
COLORIZATION_GAUSS);
243 void mitk::SurfaceDeformationDataInteractor3D::ColorizeSurface(
244 vtkPolyData *polyData,
int timeStep,
const Point3D &pickedPoint,
int mode,
double scalar)
246 if (polyData ==
nullptr)
249 vtkPoints *points = polyData->GetPoints();
250 vtkPointData *pointData = polyData->GetPointData();
251 if (pointData ==
nullptr)
254 vtkDataArray *scalars = pointData->GetScalars();
255 if (scalars ==
nullptr)
263 geometry->WorldToIndex(pickedPoint, localPickedPoint);
265 Vector3D v1 = localPickedPoint.GetVectorFromOrigin();
267 vtkDataArray *normal = polyData->GetPointData()->GetVectors(
"planeNormal");
268 if (normal !=
nullptr)
270 m_ObjectNormal[0] = normal->GetComponent(0, 0);
271 m_ObjectNormal[1] = normal->GetComponent(0, 1);
272 m_ObjectNormal[2] = normal->GetComponent(0, 2);
275 double denom = m_GaussSigma * m_GaussSigma * 2;
276 for (vtkIdType i = 0; i < points->GetNumberOfPoints(); ++i)
279 double *point = points->GetPoint(i);
286 double d = itk::CrossProduct(m_ObjectNormal, (v1 - v0)).GetNorm();
287 double t = exp(-d * d / denom);
289 scalars->SetComponent(i, 0, t);
294 for (vtkIdType i = 0; i < pointData->GetNumberOfTuples(); ++i)
296 scalars->SetComponent(i, 0, scalar);
299 polyData->Modified();
Class for storing surfaces (vtkPolyData).
Super class for all position events.
virtual vtkPolyData * GetVtkPolyData(unsigned int t=0) const
vtkRenderer * GetVtkRenderer() const
DataNode * GetDataNode() const
BaseRenderer * GetSender() const
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual unsigned int GetTimeStep() const
void SetColor(const mitk::Color &color, const mitk::BaseRenderer *renderer=nullptr, const char *propertyKey="color")
Convenience method for setting color properties (instances of ColorProperty)
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...
#define CONNECT_CONDITION(a, f)
#define CONNECT_FUNCTION(a, f)
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)