MCPcopy Create free account
hub / github.com/MITK/MITK / OnAddPoint

Method OnAddPoint

Modules/Segmentation/src/Interactions/mitkContourModelInteractor.cpp:93–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93void mitk::ContourModelInteractor::OnAddPoint(StateMachineAction*, InteractionEvent* interactionEvent)
94{
95 const auto* positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent);
96 if (!positionEvent)
97 return;
98
99 const auto timeStep = interactionEvent->GetSender()->GetTimeStep(GetDataNode()->GetData());
100
101 auto* contour = dynamic_cast<mitk::ContourModel*>(this->GetDataNode()->GetData());
102
103 Point3D currentPosition = positionEvent->GetPositionInWorld();
104
105 ContourElement::VertexSizeType segmentStart;
106 ContourElement::VertexSizeType segmentEnd;
107 Point3D closestContourPoint;
108 if (contour->GetLineSegmentForPoint(currentPosition, ContourModelInteractor::eps, timeStep, segmentStart, segmentEnd, closestContourPoint, true))
109 {
110 const auto vertexList = contour->GetVertexList(timeStep);
111 //check if the segment is NOT within restricted control points.
112 auto controlStartIt = vertexList.begin();
113 auto controlEndIt = vertexList.begin();
114 for (auto searchIt = vertexList.begin() + segmentStart; searchIt != vertexList.begin(); searchIt--)
115 {
116 if ((*searchIt)->IsControlPoint)
117 {
118 controlStartIt = searchIt;
119 break;
120 }
121 }
122 for (auto searchIt = vertexList.begin() + segmentEnd; searchIt != vertexList.end(); searchIt++)
123 {
124 if ((*searchIt)->IsControlPoint)
125 {
126 controlEndIt = searchIt;
127 break;
128 }
129 }
130
131 const auto restrictedVs = m_RestrictedArea->GetVertexList(timeStep);
132 bool startIsRestricted = false;
133 bool stopIsRestricted = false;
134
135 for (auto restrictedV : restrictedVs)
136 {
137 if (restrictedV->Coordinates == (*controlStartIt)->Coordinates)
138 {
139 startIsRestricted = true;
140 }
141 if (restrictedV->Coordinates == (*controlEndIt)->Coordinates)
142 {
143 stopIsRestricted = true;
144 }
145 }
146
147 if (!(startIsRestricted && stopIsRestricted))
148 {
149 //add the point
150 contour->InsertVertexAtIndex(closestContourPoint, segmentEnd, true, timeStep);

Callers

nothing calls this directly

Calls 13

GetSenderMethod · 0.80
GetPositionInWorldMethod · 0.80
SelectVertexAtMethod · 0.80
GetTimeStepMethod · 0.45
GetDataMethod · 0.45
GetDataNodeMethod · 0.45
GetVertexListMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
InsertVertexAtIndexMethod · 0.45
RequestUpdateMethod · 0.45

Tested by

no test coverage detected