Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkContourModel.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #ifndef mitkContourModel_h
13 #define mitkContourModel_h
14 
15 #include <mitkBaseData.h>
16 #include <mitkCommon.h>
18 
19 #include <mitkContourElement.h>
20 
21 namespace mitk
22 {
47  {
48  public:
50 
51  itkFactorylessNewMacro(Self);
52 
53  itkCloneMacro(Self);
54 
55  /*+++++++++++++++ typedefs +++++++++++++++++++++++++++++++*/
60  typedef std::vector<ContourElement::Pointer> ContourModelSeries;
61  /*+++++++++++++++ END typedefs ++++++++++++++++++++++++++++*/
62 
68  {
70  B_SPLINE
71  };
72 
73  /*++++++++++++++++ inline methods +++++++++++++++++++++++*/
74 
78  VertexType *GetSelectedVertex() { return this->m_SelectedVertex; }
79 
83  void Deselect() { this->m_SelectedVertex = nullptr; }
84 
90  void SetSelectedVertexAsControlPoint(bool isControlPoint = true)
91  {
92  if (this->m_SelectedVertex)
93  {
94  m_SelectedVertex->IsControlPoint = isControlPoint;
95  this->Modified();
96  }
97  }
98 
104  {
105  this->m_lineInterpolation = interpolation;
106  this->Modified();
107  }
108 
113  LineSegmentInterpolation GetLineSegmentInterpolation() { return this->m_lineInterpolation; }
114  /*++++++++++++++++ END inline methods +++++++++++++++++++++++*/
115 
125  void AddVertex(const Point3D &vertex, TimeStepType timestep = 0);
126 
134  void AddVertex(const VertexType &vertex, TimeStepType timestep = 0);
135 
144  void AddVertex(const Point3D& vertex, bool isControlPoint, TimeStepType timestep = 0);
145 
153  void UpdateContour(const ContourModel* sourceModel, TimeStepType destinationTimeStep, TimeStepType sourceTimeStep);
154 
164  void AddVertexAtFront(const Point3D &vertex, TimeStepType timestep = 0);
165 
175  void AddVertexAtFront(const VertexType &vertex, TimeStepType timestep = 0);
176 
188  void AddVertexAtFront(const Point3D &vertex, bool isControlPoint, TimeStepType timestep = 0);
189 
192  void InsertVertexAtIndex(const Point3D &vertex, int index, bool isControlPoint = false, TimeStepType timestep = 0);
193 
196  bool SetVertexAt(int pointId, const Point3D &point, TimeStepType timestep = 0);
197 
200  bool SetVertexAt(int pointId, const VertexType *vertex, TimeStepType timestep = 0);
201 
204  bool IsClosed(int timestep = 0) const;
205 
212  void Concatenate(ContourModel *other, TimeStepType timestep = 0, bool check = false);
213 
217  VertexIterator Begin(TimeStepType timestep = 0) const;
218 
223 
227  VertexIterator End(TimeStepType timestep = 0) const;
228 
233 
237  virtual void Close(TimeStepType timestep = 0);
238 
242  virtual void Open(TimeStepType timestep = 0);
243 
249  virtual void SetClosed(bool isClosed, TimeStepType timestep = 0);
250 
254  int GetNumberOfVertices(TimeStepType timestep = 0) const;
255 
259  virtual bool IsEmpty(TimeStepType timestep) const;
260 
263  bool IsEmpty() const override;
264 
268  virtual const VertexType *GetVertexAt(int index, TimeStepType timestep = 0) const;
269 
276  const VertexType *GetVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
277 
284  virtual const VertexType *GetNextControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
285 
292  virtual const VertexType *GetPreviousControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
293 
299  int GetIndex(const VertexType *vertex, TimeStepType timestep = 0);
300 
305  bool IsEmptyTimeStep(unsigned int t) const override;
306 
313  bool IsNearContour(Point3D &point, float eps, TimeStepType timestep) const;
314 
322  float eps,
323  TimeStepType timestep,
324  mitk::ContourElement::VertexType *previousVertex = nullptr,
325  mitk::ContourElement::VertexType *nextVertex = nullptr);
326 
332  float eps, TimeStepType timestep, ContourElement::VertexSizeType& segmentStartIndex,
333  ContourElement::VertexSizeType& segmentEndIndex, mitk::Point3D& closestContourPoint,
334  bool findClosest = true) const;
335 
338  bool SelectVertexAt(int index, TimeStepType timestep = 0);
339 
342  bool SetControlVertexAt(int index, TimeStepType timestep = 0);
343 
352  bool SelectControlVertexAt(const Point3D &point, float eps, TimeStepType timestep = 0);
353 
362  bool SelectVertexAt(const Point3D &point, float eps, TimeStepType timestep = 0);
363 
364  /*
365  \param point - query point in 3D space
366  \param eps - radius for nearest neighbour search (error bound).
367  \param timestep - search at this timestep
368 
369  @return true = vertex found; false = no vertex found
370  */
371  bool SetControlVertexAt(Point3D &point, float eps, TimeStepType timestep = 0);
372 
377  bool RemoveVertexAt(int index, TimeStepType timestep = 0);
378 
383  bool RemoveVertex(const VertexType *vertex, TimeStepType timestep = 0);
384 
393  bool RemoveVertexAt(Point3D &point, float eps, TimeStepType timestep = 0);
394 
399  void ShiftSelectedVertex(Vector3D &translate);
400 
406  void ShiftContour(Vector3D &translate, TimeStepType timestep = 0);
407 
413  virtual void Clear(TimeStepType timestep);
414 
417  void Initialize() override;
418 
422  void Initialize(const ContourModel &other);
423 
427 
431 
432  /*++++++++++++++++++ method inherit from base data +++++++++++++++++++++++++++*/
437 
442 
446  bool VerifyRequestedRegion() override;
447 
451  void SetRequestedRegion(const itk::DataObject *data) override;
452 
456  void Expand(unsigned int timeSteps) override;
457 
463  void UpdateOutputInformation() override;
464 
471  void Clear() override;
472 
476  void ExecuteOperation(Operation *operation) override;
477 
482  virtual void RedistributeControlVertices(int period, TimeStepType timestep);
483 
484  protected:
486 
488  ContourModel(const ContourModel &other);
489  ~ContourModel() override;
490 
491  // inherit from BaseData. called by Clear()
492  void ClearData() override;
493 
494  // inherit from BaseData. Initial state of a contour with no vertices and a single timestep.
495  void InitializeEmpty() override;
496 
497  // Shift a vertex
498  static void ShiftVertex(VertexType *vertex, Vector3D &vector);
499 
500  // Storage with time resolved support.
502 
503  // The currently selected vertex.
505 
506  // The interpolation of the line segment between control points.
508 
509  // only update the bounding geometry if necessary
511  };
512 
513  itkEventMacroDeclaration(ContourModelEvent, itk::AnyEvent);
514  itkEventMacroDeclaration(ContourModelShiftEvent, ContourModelEvent);
515  itkEventMacroDeclaration(ContourModelSizeChangeEvent, ContourModelEvent);
516  itkEventMacroDeclaration(ContourModelAddEvent, ContourModelSizeChangeEvent);
517  itkEventMacroDeclaration(ContourModelRemoveEvent, ContourModelSizeChangeEvent);
518  itkEventMacroDeclaration(ContourModelExpandTimeBoundsEvent, ContourModelEvent);
519  itkEventMacroDeclaration(ContourModelClosedEvent, ContourModelEvent);
520 }
521 #endif
#define MITKCONTOURMODEL_EXPORT
Base class of all data objects.
Definition: mitkBaseData.h:60
VertexListType::const_iterator ConstVertexIterator
Const iterator for traversing vertices.
VertexListType::iterator VertexIterator
Mutable iterator for traversing vertices.
std::deque< VertexType * > VertexListType
Alias for the container type storing vertex pointers.
VertexListType::size_type VertexSizeType
Size type for indexing into the vertex list.
A time-resolved contour representation consisting of linked vertices in 3D space.
void InsertVertexAtIndex(const Point3D &vertex, int index, bool isControlPoint=false, TimeStepType timestep=0)
Insert a vertex at given index.
void Concatenate(ContourModel *other, TimeStepType timestep=0, bool check=false)
Concatenate two contours. The starting control point of the other will be added at the end of the con...
void UpdateContour(const ContourModel *sourceModel, TimeStepType destinationTimeStep, TimeStepType sourceTimeStep)
VertexIterator Begin(TimeStepType timestep=0) const
Returns a const VertexIterator at the start element of the contour.
bool GetLineSegmentForPoint(Point3D &point, float eps, TimeStepType timestep, mitk::ContourElement::VertexType *previousVertex=nullptr, mitk::ContourElement::VertexType *nextVertex=nullptr)
LineSegmentInterpolation GetLineSegmentInterpolation()
Get the current interpolation mode for line segments between control points.
void AddVertex(const Point3D &vertex, TimeStepType timestep=0)
Add a vertex to the contour at given timestep. The vertex is added at the end of contour.
int GetIndex(const VertexType *vertex, TimeStepType timestep=0)
Return the index of a given vertex within the contour at the specified time step.
ContourElement::VertexType VertexType
const VertexType * GetVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const
Find the nearest vertex to a given 3D position at a specific time step.
void AddVertexAtFront(const Point3D &vertex, TimeStepType timestep=0)
Add a vertex to the contour at given timestep AT THE FRONT of the contour. The vertex is added at the...
static void ShiftVertex(VertexType *vertex, Vector3D &vector)
void AddVertexAtFront(const Point3D &vertex, bool isControlPoint, TimeStepType timestep=0)
Add a vertex to the contour at given timestep AT THE FRONT of the contour.
virtual bool IsEmpty(TimeStepType timestep) const
Returns whether the contour model is empty at a given timestep.
LineSegmentInterpolation m_lineInterpolation
mitkClassMacro(ContourModel, BaseData)
virtual void SetClosed(bool isClosed, TimeStepType timestep=0)
Set closed property to given boolean.
VertexType * GetSelectedVertex()
Get the currently selected vertex.
ContourElement::VertexIterator VertexIterator
virtual const VertexType * GetVertexAt(int index, TimeStepType timestep=0) const
Returns the vertex at the index position within the container. If the index or timestep is invalid a ...
void SetRequestedRegionToLargestPossibleRegion() override
Inherit from base data - no region support available for contourModel objects.
std::vector< ContourElement::Pointer > ContourModelSeries
ContourModelSeries m_ContourSeries
~ContourModel() override
virtual void Clear(TimeStepType timestep)
Clear the storage container at given timestep.
bool IsEmpty() const override
Returns whether the contour model is empty.
virtual void Open(TimeStepType timestep=0)
Set isClosed to false contour. The link between the last control point the first point will be remove...
virtual void RedistributeControlVertices(int period, TimeStepType timestep)
Redistributes control vertices with a given period (as number of vertices)
ContourElement::VertexListType VertexListType
virtual const VertexType * GetPreviousControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const
Return the previous control vertex before the nearest vertex to a given 3D position.
void ShiftContour(Vector3D &translate, TimeStepType timestep=0)
Shift the whole contour by a translation vector at given timestep.
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Inherit from base data - no region support available for contourModel objects.
VertexListType GetControlVertices(TimeStepType timestep)
Returns a list pointing to all vertices that are indicated to be control points.
void ShiftSelectedVertex(Vector3D &translate)
Shift the currently selected vertex by a translation vector.
void Initialize() override
Initialize all data objects.
void AddVertexAtFront(const VertexType &vertex, TimeStepType timestep=0)
Add a vertex to the contour at given timestep AT THE FRONT of the contour. The vertex is added at the...
bool SetControlVertexAt(Point3D &point, float eps, TimeStepType timestep=0)
void Deselect()
Clear the current vertex selection.
bool RemoveVertexAt(Point3D &point, float eps, TimeStepType timestep=0)
Remove a vertex at a query position in 3D space.
void SetLineSegmentInterpolation(LineSegmentInterpolation interpolation)
Set the interpolation mode for line segments between control points.
void ExecuteOperation(Operation *operation) override
overwrite if the Data can be called by an Interactor (StateMachine).
VertexIterator IteratorBegin(TimeStepType timestep=0) const
Returns a const VertexIterator at the start element of the contour.
bool IsNearContour(Point3D &point, float eps, TimeStepType timestep) const
Check whether a given point lies near the contour at the specified time step.
int GetNumberOfVertices(TimeStepType timestep=0) const
Returns the number of vertices at a given timestep.
void Clear() override
Clear the storage container.
void ClearData() override
reset to non-initialized state, release memory
bool SelectControlVertexAt(const Point3D &point, float eps, TimeStepType timestep=0)
Mark a control vertex at a given position in 3D space.
void SetRequestedRegion(const itk::DataObject *data) override
Inherit from base data - no region support available for contourModel objects.
void Initialize(const ContourModel &other)
Initialize object with specs of other contour. Note: No data will be copied.
virtual const VertexType * GetNextControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const
Return the next control vertex after the nearest vertex to a given 3D position.
void AddVertex(const VertexType &vertex, TimeStepType timestep=0)
Add a vertex to the contour at given timestep. A copy of the passed vertex is added at the end of con...
bool IsEmptyTimeStep(unsigned int t) const override
Check whether the given time step has no associated contour data.
bool IsClosed(int timestep=0) const
Return if the contour is closed or not.
void AddVertex(const Point3D &vertex, bool isControlPoint, TimeStepType timestep=0)
Add a vertex to the contour.
ContourModel(const ContourModel &other)
void SetSelectedVertexAsControlPoint(bool isControlPoint=true)
Set or clear the control point flag on the currently selected vertex.
VertexType * m_SelectedVertex
void UpdateOutputInformation() override
Update the OutputInformation of a ContourModel object.
bool GetLineSegmentForPoint(const mitk::Point3D &point, float eps, TimeStepType timestep, ContourElement::VertexSizeType &segmentStartIndex, ContourElement::VertexSizeType &segmentEndIndex, mitk::Point3D &closestContourPoint, bool findClosest=true) const
bool RemoveVertexAt(int index, TimeStepType timestep=0)
Remove a vertex at given index within the container.
void Expand(unsigned int timeSteps) override
Expand the contour model and its TimeGeometry to given number of timesteps.
bool SetVertexAt(int pointId, const VertexType *vertex, TimeStepType timestep=0)
Set a coordinates and control state for point at given index.
bool RemoveVertex(const VertexType *vertex, TimeStepType timestep=0)
Remove a vertex at given timestep within the container.
bool SetVertexAt(int pointId, const Point3D &point, TimeStepType timestep=0)
Set a coordinates for point at given index.
bool SelectVertexAt(const Point3D &point, float eps, TimeStepType timestep=0)
Mark a vertex at a given position in 3D space.
LineSegmentInterpolation
Interpolation mode for line segments between control points.
@ LINEAR
Straight line segments between control points.
VertexIterator End(TimeStepType timestep=0) const
Returns a const VertexIterator at the end element of the contour.
void InitializeEmpty() override
Pure virtual; Must be used in subclasses to get a data object to a valid state. Should at least creat...
virtual void Close(TimeStepType timestep=0)
Close the contour. The last control point will be linked with the first point.
VertexIterator IteratorEnd(TimeStepType timestep=0) const
Returns a const VertexIterator at the end element of the contour.
VertexListType GetVertexList(TimeStepType timestep)
Returns the container of the vertices.
bool VerifyRequestedRegion() override
Inherit from base data - no region support available for contourModel objects.
bool SelectVertexAt(int index, TimeStepType timestep=0)
Mark a vertex at an index in the container as selected.
ContourElement::ConstVertexIterator ConstVertexIterator
bool SetControlVertexAt(int index, TimeStepType timestep=0)
Mark a vertex at an index in the container as control point.
Base class for all operations in the undo/redo framework.
Definition: mitkOperation.h:38
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
std::size_t TimeStepType
Type for time step indices (non-negative integers starting from 0).
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)
Represents a single vertex of a contour.