61 if (contour ==
nullptr)
78 int downIndex = this->SplitContourFromSelectedVertex(contour, m_ContourLeft,
false, timestep);
80 m_NextActiveVertexDownIter = contour->
IteratorBegin() + downIndex;
81 m_NextActiveVertexDown = (*m_NextActiveVertexDownIter)->Coordinates;
86 int upIndex = this->SplitContourFromSelectedVertex(contour, m_ContourRight,
true, timestep);
88 m_NextActiveVertexUpIter = contour->
IteratorBegin() + upIndex;
89 m_NextActiveVertexUp = (*m_NextActiveVertexUpIter)->Coordinates;
92 this->m_LiveWireFilter->ClearRepulsivePoints();
97 for (; iter != m_NextActiveVertexDownIter; iter++)
100 this->m_WorkingSlice->GetGeometry()->WorldToIndex((*iter)->Coordinates, idx);
101 this->m_LiveWireFilter->AddRepulsivePoint(idx);
105 iter = m_NextActiveVertexUpIter + 1;
106 for (; iter != contour->
IteratorEnd(timestep); iter++)
109 this->m_WorkingSlice->GetGeometry()->WorldToIndex((*iter)->Coordinates, idx);
110 this->m_LiveWireFilter->AddRepulsivePoint(idx);
114 m_ContourBeingModified.clear();
134 if (this->m_EditingContourNode != _arg)
136 this->m_EditingContourNode = _arg;
142 if (this->m_WorkingSlice != _arg)
144 this->m_WorkingSlice = _arg;
145 this->m_LiveWireFilter->SetInput(this->m_WorkingSlice);
154 if (contour ==
nullptr)
165 newContour->Concatenate(m_ContourLeft, timestep);
168 this->m_LiveWireFilter->SetStartPoint(this->m_NextActiveVertexDown);
169 this->m_LiveWireFilter->SetEndPoint(this->m_NextActiveVertexUp);
171 this->m_LiveWireFilter->Update();
174 assert(liveWireContour);
176 if (liveWireContour->
IsEmpty(timestep))
183 newContour->Concatenate(liveWireContour, timestep);
186 newContour->Concatenate(this->m_ContourRight, timestep);
188 newContour->SetClosed(contour->
IsClosed(timestep), timestep);
191 if (newContour->GetNumberOfVertices(timestep) <= 2)
193 newContour->Clear(timestep);
196 this->GetDataNode()->SetData(newContour);
212 if (contour ==
nullptr)
222 this->m_LiveWireFilter->SetStartPoint(this->m_NextActiveVertexDown);
223 this->m_LiveWireFilter->SetEndPoint(currentPosition);
226 if (!m_ContourBeingModified.empty())
228 std::vector<itk::Index<2>>::const_iterator iter = m_ContourBeingModified.begin();
229 for (; iter != m_ContourBeingModified.end(); iter++)
231 this->m_LiveWireFilter->RemoveRepulsivePoint((*iter));
237 this->m_LiveWireFilter->Update();
240 assert(leftLiveWire);
242 if (!leftLiveWire->IsEmpty(timestep))
243 leftLiveWire->RemoveVertexAt(0, timestep);
245 editingContour->Concatenate(leftLiveWire, timestep);
248 unsigned int selectedVertexIndex =
249 this->m_ContourLeft->GetNumberOfVertices(timestep) + leftLiveWire->GetNumberOfVertices(timestep) - 1;
252 m_ContourBeingModified.clear();
256 for (; iter != leftLiveWire->IteratorEnd(timestep); iter++)
259 this->m_WorkingSlice->GetGeometry()->WorldToIndex((*iter)->Coordinates, idx);
260 this->m_LiveWireFilter->AddRepulsivePoint(idx);
263 m_ContourBeingModified.push_back(idx);
267 this->m_LiveWireFilter->SetStartPoint(currentPosition);
268 this->m_LiveWireFilter->SetEndPoint(m_NextActiveVertexUp);
271 this->m_LiveWireFilter->Update();
274 assert(rightLiveWire);
277 if (abs(rightLiveWire->GetNumberOfVertices(timestep) - leftLiveWire->GetNumberOfVertices(timestep)) > 50)
282 if (!leftLiveWire->IsEmpty(timestep))
283 leftLiveWire->SetControlVertexAt(leftLiveWire->GetNumberOfVertices() - 1, timestep);
285 if (!rightLiveWire->IsEmpty(timestep))
286 rightLiveWire->RemoveVertexAt(0, timestep);
288 editingContour->Concatenate(rightLiveWire, timestep);
290 m_EditingContourNode->SetData(editingContour);
296 newContour->Concatenate(this->m_ContourLeft, timestep);
298 newContour->Concatenate(editingContour, timestep,
true);
301 newContour->SelectVertexAt(selectedVertexIndex, timestep);
304 newContour->SetSelectedVertexAsControlPoint(
true);
307 newContour->Concatenate(this->m_ContourRight, timestep);
309 newContour->SetClosed(contour->
IsClosed(timestep), timestep);
310 this->GetDataNode()->SetData(newContour);
327 bool isHover =
false;
328 this->GetDataNode()->GetBoolProperty(
"contour.hovering", isHover, positionEvent->
GetSender());
331 if (isHover ==
false)
333 this->GetDataNode()->SetBoolProperty(
"contour.hovering",
true);
341 this->GetDataNode()->SetBoolProperty(
"contour.hovering",
false);
350 bool fromSelectedUpwards,
366 if (fromSelectedUpwards)
375 while (itUp != end && !((*itUp)->IsControlPoint))
382 if (itSelected != begin)
387 destContour->
AddVertex((*it)->Coordinates, (*it)->IsControlPoint, timestep);
396 return std::distance(begin, itUp) - 1;
400 return std::distance(begin, itUp);
408 if (itSelected != begin)
415 while (itDown != begin && !((*itDown)->IsControlPoint))
423 destContour->
AddVertex((*it)->Coordinates, (*it)->IsControlPoint, timestep);
429 destContour->
AddVertex((*it)->Coordinates, (*it)->IsControlPoint, timestep);
438 while (!((*itDown)->IsControlPoint) && itDown != begin)
446 while ((it != end) && !((*it)->IsControlPoint))
454 destContour->
AddVertex((*it)->Coordinates, (*it)->IsControlPoint, timestep);
468 return std::distance(begin, itDown);
472 return std::distance(begin, itDown) - 1;
483 editingContour->
Clear(timestep);
virtual bool IsHovering(const InteractionEvent *interactionEvent) override
virtual void OnMovePoint(StateMachineAction *, InteractionEvent *interactionEvent) override
bool RemoveVertexAt(int index, int timestep=0)
Remove a vertex at given index within the container.
virtual void Clear(int timestep)
Clear the storage container at given timestep.
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
Super class for all position events.
BaseRenderer * GetSender() const
void Deselect()
Deselect vertex.
virtual void OnFinishEditing(StateMachineAction *, InteractionEvent *interactionEvent) override
Point3D GetPositionInWorld() const
virtual bool IsEmpty(int timestep) const
Returns whether the contour model is empty at a given timestep. timestep - default = 0...
mitk::ContourElement::VertexIterator VertexIterator
virtual bool OnCheckPointClick(const InteractionEvent *interactionEvent) override
Constants for most interaction classes, due to the generic StateMachines.
unsigned int GetTimeSteps() const
Get the number of time steps from the TimeGeometry As the base data has not a data vector given by it...
mitk::Point3D m_NextActiveVertexDown
int SplitContourFromSelectedVertex(mitk::ContourModel *srcContour, mitk::ContourModel *destContour, bool fromSelectedUpwards, int timestep)
VertexIterator IteratorBegin(int timestep=0) const
Returns a const VertexIterator at the start element of the contour.
mitk::ImageLiveWireContourModelFilter::Pointer m_LiveWireFilter
bool SelectVertexAt(int index, int timestep=0)
Mark a vertex at an index in the container as selected.
void AddVertex(mitk::Point3D &vertex, int timestep=0)
Add a vertex to the contour at given timestep. The vertex is added at the end of contour.
ContourModelLiveWireInteractor()
virtual bool IsNearContour(mitk::Point3D &point, float eps, int timestep)
Check if mouse cursor is near the contour.
VertexType * GetSelectedVertex()
Get the current selected vertex.
mitk::Point3D m_NextActiveVertexUp
static RenderingManager * GetInstance()
Represents an action, that is executed after a certain event (in statemachine-mechanism) TODO: implem...
Image class for storing images.
void SetSelectedVertexAsControlPoint(bool isControlPoint=true)
Set selected vertex as control point.
virtual void SetWorkingImage(mitk::Image *_arg)
virtual unsigned int GetTimeStep() const
void RequestUpdate(vtkRenderWindow *renderWindow)
virtual void ConnectActionsAndFunctions() override
#define CONNECT_CONDITION(a, f)
bool IsClosed(int timestep=0) const
Return if the contour is closed or not.
virtual ~ContourModelLiveWireInteractor()
#define CONNECT_FUNCTION(a, f)
VertexIterator IteratorEnd(int timestep=0) const
Returns a const VertexIterator at the end element of the contour.
itk::SmartPointer< Self > Pointer
virtual void OnDeletePoint(StateMachineAction *, InteractionEvent *interactionEvent) override
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
virtual void SetEditingContourModelNode(mitk::DataNode *_arg)
Class for nodes of the DataTree.
int GetNumberOfVertices(int timestep=0) const
Returns the number of vertices at a given timestep.