17 #define PLANARFIGUREINTERACTOR_DBG MITK_DEBUG("PlanarFigureInteractor") << __LINE__ << ": "
35 :
DataInteractor(), m_Precision(6.5), m_MinimumPointDistance(25.0), m_IsHovering(false), m_LastPointWasValid(false)
81 bool isFigureFinished =
false;
82 planarFigure->
GetPropertyList()->GetBoolProperty(
"initiallyplaced", isFigureFinished);
84 return planarFigure->
IsPlaced() && isFigureFinished;
90 if (positionEvent ==
nullptr)
93 bool isEditable =
true;
94 GetDataNode()->GetBoolProperty(
"planarfigure.iseditable", isEditable);
102 if (abstractTransformGeometry !=
nullptr)
108 if (!this->TransformPositionEventToPoint2D(positionEvent, planarFigureGeometry, point2D) || !isEditable)
113 planarFigure->InvokeEvent(StartInteractionPlanarFigureEvent());
116 bool hidecontrolpointsduringinteraction =
false;
117 GetDataNode()->GetBoolProperty(
"planarfigure.hidecontrolpointsduringinteraction", hidecontrolpointsduringinteraction);
121 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints", !hidecontrolpointsduringinteraction);
138 planarFigure->Modified();
142 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints",
true);
143 GetDataNode()->Modified();
144 planarFigure->InvokeEvent(EndPlacementPlanarFigureEvent());
145 planarFigure->InvokeEvent(EndInteractionPlanarFigureEvent());
156 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints",
true);
157 planarFigure->Modified();
158 planarFigure->InvokeEvent(EndInteractionPlanarFigureEvent());
164 if (interactionEvent->
GetSender() ==
nullptr)
178 m_IsHovering =
false;
179 planarFigure->InvokeEvent(EndHoverPlanarFigureEvent());
182 GetDataNode()->SetBoolProperty(
"planarfigure.ishovering",
false);
190 planarFigure->RemoveAllObservers();
191 GetDataNode()->RemoveAllObservers();
217 bool isExtendable(
false);
218 GetDataNode()->GetBoolProperty(
"planarfigure.isextendable", isExtendable);
225 bool isDeletable(
true);
226 GetDataNode()->GetBoolProperty(
"planarfigure.isdeletable", isDeletable);
233 bool isEditable(
true);
234 GetDataNode()->GetBoolProperty(
"planarfigure.iseditable", isEditable);
247 planarFigure->Modified();
248 planarFigure->InvokeEvent(EndInteractionPlanarFigureEvent());
250 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints",
true);
252 GetDataNode()->Modified();
260 if (positionEvent ==
nullptr)
286 bool isFigureFinished =
false;
287 data->GetPropertyList()->GetBoolProperty(
"initiallyplaced", isFigureFinished);
289 bool selected =
false;
290 bool isEditable =
true;
292 node->GetBoolProperty(
"selected", selected);
293 node->GetBoolProperty(
"planarfigure.iseditable", isEditable);
295 if (!selected || !isEditable)
304 if (dynamic_cast<PlanarBezierCurve *>(planarFigure) !=
nullptr && isFigureFinished)
311 if (abstractTransformGeometry !=
nullptr)
322 Point2D point2D, projectedPoint;
323 if (!this->TransformPositionEventToPoint2D(positionEvent, planarFigureGeometry, point2D))
338 if (dynamic_cast<mitk::PlanarPolygon *>(planarFigure) && isFigureFinished)
341 this->IsPositionOverFigure(positionEvent, planarFigure, planarFigureGeometry, projectionPlane, projectedPoint);
371 if (positionEvent ==
nullptr)
381 planarFigure->InvokeEvent(StartPlacementPlanarFigureEvent());
386 if (planeGeometry !=
nullptr && abstractTransformGeometry ==
nullptr)
388 planarFigureGeometry = planeGeometry;
399 if (!this->TransformPositionEventToPoint2D(positionEvent, planarFigureGeometry, point2D))
415 GetDataNode()->SetBoolProperty(
"PlanarFigureInitializedWindow",
true, renderer);
425 if (positionEvent ==
nullptr)
435 planarFigure->InvokeEvent(StartHoverPlanarFigureEvent());
438 GetDataNode()->SetBoolProperty(
"planarfigure.ishovering",
true);
448 if (positionEvent ==
nullptr)
458 bool selected(
false);
459 bool isExtendable(
false);
460 bool isEditable(
true);
461 GetDataNode()->GetBoolProperty(
"selected", selected);
462 GetDataNode()->GetBoolProperty(
"planarfigure.isextendable", isExtendable);
463 GetDataNode()->GetBoolProperty(
"planarfigure.iseditable", isEditable);
465 if (selected && isExtendable && isEditable)
467 renderer->
DisplayToPlane(pointProjectedOntoLine, pointProjectedOntoLine);
476 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints",
false);
492 if (positionEvent ==
nullptr)
502 if (abstractTransformGeometry !=
nullptr)
506 int previousControlPoint = this->IsPositionOverFigure(
507 positionEvent, planarFigure, planarFigureGeometry, projectionPlane, pointProjectedOntoLine);
509 bool isHovering = (previousControlPoint != -1);
527 if (positionEvent ==
nullptr)
537 if (abstractTransformGeometry !=
nullptr)
542 positionEvent, planarFigure, planarFigureGeometry, projectionPlane, renderer);
556 bool selected =
false;
557 GetDataNode()->GetBoolProperty(
"selected", selected);
565 planarFigure->InvokeEvent(SelectPlanarFigureEvent());
572 if (positionEvent ==
nullptr)
582 if (abstractTransformGeometry !=
nullptr)
586 positionEvent, planarFigure, planarFigureGeometry, projectionPlane, renderer);
607 if (positionEvent ==
nullptr)
612 m_LastPointWasValid = IsMousePositionAcceptableAsNewControlPoint(positionEvent, planarFigure);
613 return m_LastPointWasValid;
626 planarFigure->Modified();
628 GetDataNode()->SetBoolProperty(
"planarfigure.drawcontrolpoints",
true);
629 planarFigure->InvokeEvent(EndInteractionPlanarFigureEvent());
639 bool selected =
false;
640 GetDataNode()->GetBoolProperty(
"selected", selected);
645 planarFigure->InvokeEvent(SelectPlanarFigureEvent());
648 planarFigure->InvokeEvent(ContextMenuPlanarFigureEvent());
655 bool isEditable =
true;
656 GetDataNode()->GetBoolProperty(
"planarfigure.iseditable", isEditable);
667 if (posEvent ==
nullptr)
677 if (abstractTransformGeometry !=
nullptr)
680 const double planeThickness = planarFigurePlaneGeometry->
GetExtentInMM(2);
681 if (planarFigurePlaneGeometry->
Distance(worldPoint3D) > planeThickness)
691 m_Precision = precision;
696 m_MinimumPointDistance = minimumDistance;
706 if (planarFigureGeometry->
Distance(worldPoint3D) > 0.1)
712 planarFigureGeometry->
Map(worldPoint3D, point2D);
725 objectGeometry->
Map(point2D, point3D);
727 const double planeThickness = objectGeometry->
GetExtentInMM(2);
730 if (rendererGeometry->
Distance(point3D) < planeThickness / 3.0)
749 const double l1 = n1 * (point - startPoint);
750 const double l2 = -n1 * (point - endPoint);
754 projectedPoint = crossPoint;
756 const float dist1 = crossPoint.SquaredEuclideanDistanceTo(point);
757 const float dist2 = endPoint.SquaredEuclideanDistanceTo(point);
758 const float dist3 = startPoint.SquaredEuclideanDistanceTo(point);
763 if (((dist1 < 20.0) && (l1 > 0.0) && (l2 > 0.0)) || dist2 < 20.0 || dist3 < 20.0)
775 Point2D &pointProjectedOntoLine)
const
786 for (
unsigned short loop = 0; loop < planarFigure->
GetPolyLinesSize(); ++loop)
788 const VertexContainerType polyLine = planarFigure->
GetPolyLine(loop);
790 bool firstPoint(
true);
791 for (VertexContainerType::const_iterator it = polyLine.begin(); it != polyLine.end(); ++it)
794 if (!this->TransformObjectToDisplay(
795 *it, polyLinePoint, planarFigureGeometry, rendererGeometry, positionEvent->
GetSender()))
802 firstPolyLinePoint = polyLinePoint;
805 else if (this->IsPointNearLine(displayPosition, previousPolyLinePoint, polyLinePoint, pointProjectedOntoLine))
808 return std::distance(polyLine.begin(), it);
810 previousPolyLinePoint = polyLinePoint;
815 this->IsPointNearLine(displayPosition, polyLinePoint, firstPolyLinePoint, pointProjectedOntoLine))
836 for (
int i = 0; i < numberOfControlPoints; i++)
838 if (this->TransformObjectToDisplay(
839 planarFigure->
GetControlPoint(i), displayControlPoint, planarFigureGeometry, rendererGeometry, renderer))
842 if (displayPosition.SquaredEuclideanDistanceTo(displayControlPoint) < 20.0)
854 MITK_INFO <<
"PlanarFigure: " << planarFigure->GetNameOfClass();
865 assert(positionEvent && planarFigure);
871 const int timeStep(renderer->
GetTimeStep(planarFigure));
873 bool tooClose(
false);
880 if (abstractTransformGeometry !=
nullptr)
885 if (!this->TransformPositionEventToPoint2D(positionEvent, planarFigureGeometry, point2D))
892 const Point2D correctedPoint =
const_cast<PlanarFigure *
>(planarFigure)->ApplyControlPointConstraints(0, point2D);
897 planarFigureGeometry->
Map(correctedPoint, newPoint3D);
904 if (i != selectedControlPoint)
915 renderer->
WorldToDisplay(previousPoint3D, previousDisplayPosition);
919 const double a = newDisplayPosition[0] - previousDisplayPosition[0];
920 const double b = newDisplayPosition[1] - previousDisplayPosition[1];
923 tooClose = (a * a + b * b < m_MinimumPointDistance);
937 std::string precision =
"";
938 if (properties->GetStringProperty(
"precision", precision))
940 m_Precision = atof(precision.c_str());
947 std::string minPointDistance =
"";
948 if (properties->GetStringProperty(
"minPointDistance", minPointDistance))
950 m_MinimumPointDistance = atof(minPointDistance.c_str());
Super class for all position events.
BaseRenderer * GetSender() const
virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
Point3D GetPositionInWorld() const
Organizes the rendering process.
ScalarType Distance(const Point3D &pt3d_mm) const
Distance of the point from the geometry (bounding-box not considered)
virtual const PlaneGeometry * GetCurrentWorldPlaneGeometry()
Get the current 2D-worldgeometry (m_CurrentWorldPlaneGeometry) used for 2D-rendering.
Point2D GetPointerPositionOnScreen() const
virtual DataStorage::Pointer GetDataStorage() const
Base class from with interactors that handle DataNodes are to be derived.
void SetProperty(const char *propertyKey, BaseProperty *property)
void WorldToDisplay(const Point3D &worldIndex, Point2D &displayPoint) const
This method converts a 3D world index to the display point using the geometry of the renderWindow...
virtual mitk::RenderingManager * GetRenderingManager() const
Setter for the RenderingManager that handles this instance of BaseRenderer.
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
virtual MapperSlotId GetMapperID()
Get the MapperSlotId to use.
const mitk::PlaneGeometry * GetCurrentPlaneGeometry()
Returns the currently selected Plane in the current BaseGeometry (if existent).
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
void DisplayToPlane(const Point2D &displayPoint, Point2D &planePointInMM) const
This method converts a display point to the 2D world index, mapped onto the display plane using the g...
virtual unsigned int GetTimeStep() const
#define CONNECT_CONDITION(a, f)
virtual SliceNavigationController * GetSliceNavigationController()
static Pointer New(BaseRenderer *_arga, DataInteractor *_argb, const std::string &_argc)
Describes a two-dimensional, rectangular plane.
#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.
ScalarType GetExtentInMM(int direction) const
Get the extent of the bounding-box in the specified direction in mm.
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
Class for nodes of the DataTree.