Medical Imaging Interaction Toolkit  2025.12.02
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 {
48  {
49  public:
51 
52  itkFactorylessNewMacro(Self);
53 
54  itkCloneMacro(Self);
55 
56  /*+++++++++++++++ typedefs +++++++++++++++++++++++++++++++*/
61  typedef std::vector<ContourElement::Pointer> ContourModelSeries;
62  /*+++++++++++++++ END typedefs ++++++++++++++++++++++++++++*/
63 
66  {
68  B_SPLINE
69  };
70 
71  /*++++++++++++++++ inline methods +++++++++++++++++++++++*/
72 
75  VertexType *GetSelectedVertex() { return this->m_SelectedVertex; }
78  void Deselect() { this->m_SelectedVertex = nullptr; }
81  void SetSelectedVertexAsControlPoint(bool isControlPoint = true)
82  {
83  if (this->m_SelectedVertex)
84  {
85  m_SelectedVertex->IsControlPoint = isControlPoint;
86  this->Modified();
87  }
88  }
89 
93  {
94  this->m_lineInterpolation = interpolation;
95  this->Modified();
96  }
97 
100  LineSegmentInterpolation GetLineSegmentInterpolation() { return this->m_lineInterpolation; }
101  /*++++++++++++++++ END inline methods +++++++++++++++++++++++*/
102 
112  void AddVertex(const Point3D &vertex, TimeStepType timestep = 0);
113 
121  void AddVertex(const VertexType &vertex, TimeStepType timestep = 0);
122 
131  void AddVertex(const Point3D& vertex, bool isControlPoint, TimeStepType timestep = 0);
132 
140  void UpdateContour(const ContourModel* sourceModel, TimeStepType destinationTimeStep, TimeStepType sourceTimeStep);
141 
151  void AddVertexAtFront(const Point3D &vertex, TimeStepType timestep = 0);
152 
162  void AddVertexAtFront(const VertexType &vertex, TimeStepType timestep = 0);
163 
175  void AddVertexAtFront(const Point3D &vertex, bool isControlPoint, TimeStepType timestep = 0);
176 
179  void InsertVertexAtIndex(const Point3D &vertex, int index, bool isControlPoint = false, TimeStepType timestep = 0);
180 
183  bool SetVertexAt(int pointId, const Point3D &point, TimeStepType timestep = 0);
184 
187  bool SetVertexAt(int pointId, const VertexType *vertex, TimeStepType timestep = 0);
188 
191  bool IsClosed(int timestep = 0) const;
192 
199  void Concatenate(ContourModel *other, TimeStepType timestep = 0, bool check = false);
200 
204  VertexIterator Begin(TimeStepType timestep = 0) const;
205 
210 
214  VertexIterator End(TimeStepType timestep = 0) const;
215 
220 
224  virtual void Close(TimeStepType timestep = 0);
225 
229  virtual void Open(TimeStepType timestep = 0);
230 
236  virtual void SetClosed(bool isClosed, TimeStepType timestep = 0);
237 
241  int GetNumberOfVertices(TimeStepType timestep = 0) const;
242 
246  virtual bool IsEmpty(TimeStepType timestep) const;
247 
250  bool IsEmpty() const override;
251 
255  virtual const VertexType *GetVertexAt(int index, TimeStepType timestep = 0) const;
256 
257  const VertexType *GetVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
258 
262  virtual const VertexType *GetNextControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
263 
267  virtual const VertexType *GetPreviousControlVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const;
268 
273  int GetIndex(const VertexType *vertex, TimeStepType timestep = 0);
274 
277  bool IsEmptyTimeStep(unsigned int t) const override;
278 
281  bool IsNearContour(Point3D &point, float eps, TimeStepType timestep) const;
282 
290  float eps,
291  TimeStepType timestep,
292  mitk::ContourElement::VertexType *previousVertex = nullptr,
293  mitk::ContourElement::VertexType *nextVertex = nullptr);
294 
300  float eps, TimeStepType timestep, ContourElement::VertexSizeType& segmentStartIndex,
301  ContourElement::VertexSizeType& segmentEndIndex, mitk::Point3D& closestContourPoint,
302  bool findClosest = true) const;
303 
306  bool SelectVertexAt(int index, TimeStepType timestep = 0);
307 
310  bool SetControlVertexAt(int index, TimeStepType timestep = 0);
311 
320  bool SelectControlVertexAt(const Point3D &point, float eps, TimeStepType timestep = 0);
321 
330  bool SelectVertexAt(const Point3D &point, float eps, TimeStepType timestep = 0);
331 
332  /*
333  \param point - query point in 3D space
334  \param eps - radius for nearest neighbour search (error bound).
335  \param timestep - search at this timestep
336 
337  @return true = vertex found; false = no vertex found
338  */
339  bool SetControlVertexAt(Point3D &point, float eps, TimeStepType timestep = 0);
340 
345  bool RemoveVertexAt(int index, TimeStepType timestep = 0);
346 
351  bool RemoveVertex(const VertexType *vertex, TimeStepType timestep = 0);
352 
361  bool RemoveVertexAt(Point3D &point, float eps, TimeStepType timestep = 0);
362 
367  void ShiftSelectedVertex(Vector3D &translate);
368 
374  void ShiftContour(Vector3D &translate, TimeStepType timestep = 0);
375 
381  virtual void Clear(TimeStepType timestep);
382 
385  void Initialize() override;
386 
390  void Initialize(const ContourModel &other);
391 
395 
399 
400  /*++++++++++++++++++ method inherit from base data +++++++++++++++++++++++++++*/
405 
410 
414  bool VerifyRequestedRegion() override;
415 
419  void SetRequestedRegion(const itk::DataObject *data) override;
420 
424  void Expand(unsigned int timeSteps) override;
425 
431  void UpdateOutputInformation() override;
432 
439  void Clear() override;
440 
444  void ExecuteOperation(Operation *operation) override;
445 
450  virtual void RedistributeControlVertices(int period, TimeStepType timestep);
451 
452  protected:
454 
456  ContourModel(const ContourModel &other);
457  ~ContourModel() override;
458 
459  // inherit from BaseData. called by Clear()
460  void ClearData() override;
461 
462  // inherit from BaseData. Initial state of a contour with no vertices and a single timestep.
463  void InitializeEmpty() override;
464 
465  // Shift a vertex
466  static void ShiftVertex(VertexType *vertex, Vector3D &vector);
467 
468  // Storage with time resolved support.
470 
471  // The currently selected vertex.
473 
474  // The interpolation of the line segment between control points.
476 
477  // only update the bounding geometry if necessary
479  };
480 
481  itkEventMacroDeclaration(ContourModelEvent, itk::AnyEvent);
482  itkEventMacroDeclaration(ContourModelShiftEvent, ContourModelEvent);
483  itkEventMacroDeclaration(ContourModelSizeChangeEvent, ContourModelEvent);
484  itkEventMacroDeclaration(ContourModelAddEvent, ContourModelSizeChangeEvent);
485  itkEventMacroDeclaration(ContourModelRemoveEvent, ContourModelSizeChangeEvent);
486  itkEventMacroDeclaration(ContourModelExpandTimeBoundsEvent, ContourModelEvent);
487  itkEventMacroDeclaration(ContourModelClosedEvent, ContourModelEvent);
488 }
489 #endif
#define MITKCONTOURMODEL_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:44
VertexListType::const_iterator ConstVertexIterator
VertexListType::iterator VertexIterator
std::deque< VertexType * > VertexListType
VertexListType::size_type VertexSizeType
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
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 interpolation of the 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)
Remove a vertex at given timestep within the container.
ContourElement::VertexType VertexType
const VertexType * GetVertexAt(mitk::Point3D &point, float eps, TimeStepType timestep) const
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 current 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
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()
Deselect vertex.
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 of the 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 if mouse cursor is near the contour.
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
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 if there isn't something at this timestep.
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 selected vertex as control point.
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
Possible interpolation of the 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 of all Operation-classes.
Definition: mitkOperation.h:30
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
std::size_t TimeStepType
itkEventMacroDeclaration(BoundingShapeInteractionEvent, itk::AnyEvent)
Represents a single vertex of a contour.