Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitkContourElement.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 mitkContourElement_h
13 #define mitkContourElement_h
14 
15 #include <mitkCommon.h>
17 #include <mitkNumericTypes.h>
18 
19 #include <deque>
20 
21 namespace mitk
22 {
41  class MITKCONTOURMODEL_EXPORT ContourElement : public itk::LightObject
42  {
43  public:
45 
46  itkFactorylessNewMacro(Self);
47 
48  itkCloneMacro(Self);
49 
57  {
62  ContourModelVertex(const mitk::Point3D& point, bool active = false) : IsControlPoint(active), Coordinates(point) {};
63 
68  : IsControlPoint(other.IsControlPoint), Coordinates(other.Coordinates)
69  {
70  };
71 
78 
81 
86  bool operator ==(const ContourModelVertex& other) const;
87  };
88 
92  using VertexListType = std::deque<VertexType*>;
94  using VertexIterator = VertexListType::iterator;
96  using ConstVertexIterator = VertexListType::const_iterator;
98  using VertexSizeType = VertexListType::size_type;
99 
104  static const VertexSizeType NPOS = -1;
105 
110 
115 
120 
125 
130 
135 
140 
145 
150 
155  void AddVertex(const mitk::Point3D &point, bool isControlPoint);
156 
161  void AddVertexAtFront(const mitk::Point3D &point, bool isControlPoint);
162 
171  void InsertVertexAtIndex(const mitk::Point3D &point, bool isControlPoint, VertexSizeType index);
172 
177  void SetVertexAt(VertexSizeType pointId, const mitk::Point3D &point);
178 
185  void SetVertexAt(VertexSizeType pointId, const VertexType* vertex);
186 
194 
201  const VertexType* GetVertexAt(VertexSizeType index) const;
202 
208  VertexType *GetVertexAt(const mitk::Point3D &point, float eps);
209 
216 
223 
230 
235  VertexSizeType GetIndex(const VertexType *vertex) const;
236 
241 
245  bool IsEmpty() const;
246 
250  bool IsClosed() const;
251 
257  bool IsNearContour(const mitk::Point3D &point, float eps) const;
258 
273  float eps,
274  mitk::ContourElement::VertexType *previousVertex,
275  mitk::ContourElement::VertexType *nextVertex) const;
276 
294  float eps, VertexSizeType& segmentStartIndex, VertexSizeType& segmentEndIndex, mitk::Point3D& closestContourPoint, bool findClosest = true) const;
295 
299  void Close();
300 
304  void Open();
305 
309  void SetClosed(bool isClosed);
310 
320  void Concatenate(const mitk::ContourElement *other, bool check);
321 
326  bool RemoveVertex(const VertexType *vertex);
327 
333 
339  bool RemoveVertexAt(const mitk::Point3D &point, double eps);
340 
344  void Clear();
345 
358  VertexType *BruteForceGetVertexAt(const mitk::Point3D &point, double eps, bool isControlPoint = false, int offset = 0);
359 
368  double eps,
369  VertexListType verticesList);
370 
380 
389  void RedistributeControlVertices(const VertexType *vertex, int period);
390 
391  protected:
393 
394  ContourElement() = default;
397 
398  ContourElement& operator = (const ContourElement & other);
399 
404  bool RemoveVertexByIterator(VertexListType::iterator& iter);
405 
406  VertexListType m_Vertices; // double ended queue with vertices
407  bool m_IsClosed = false;
408  };
409 } // namespace mitk
410 
411 #endif
#define MITKCONTOURMODEL_EXPORT
Represents a contour in 3D space as a sequence of linked vertices.
ConstVertexIterator ConstIteratorBegin() const
Return a const iterator to the first vertex.
VertexListType::const_iterator ConstVertexIterator
Const iterator for traversing vertices.
void Concatenate(const mitk::ContourElement *other, bool check)
Append all vertices of another contour to the end of this contour.
bool IsEmpty() const
Check whether the contour element contains no vertices.
const VertexType * GetVertexAt(VertexSizeType index) const
Return the vertex at the given index (const version).
bool IsNearContour(const mitk::Point3D &point, float eps) const
Check whether a given point lies near the contour within a specified tolerance.
ConstVertexIterator begin() const
Return a const iterator to the first vertex (STL-compatible).
bool GetLineSegmentForPoint(const mitk::Point3D &point, float eps, mitk::ContourElement::VertexType *previousVertex, mitk::ContourElement::VertexType *nextVertex) const
Find the contour line segment closest to a given point.
VertexIterator end()
Return a mutable iterator past the last vertex (STL-compatible).
VertexListType::iterator VertexIterator
Mutable iterator for traversing vertices.
VertexType * GetControlVertexAt(const mitk::Point3D &point, float eps)
Find the nearest control vertex to a given 3D position within a search radius.
std::deque< VertexType * > VertexListType
Alias for the container type storing vertex pointers.
VertexType * BruteForceGetVertexAt(const mitk::Point3D &point, double eps, bool isControlPoint=false, int offset=0)
Find the nearest vertex to a given 3D position using brute-force search.
void AddVertex(const mitk::Point3D &point, bool isControlPoint)
Add a vertex at the end of the contour.
bool RemoveVertexAt(VertexSizeType index)
Remove the vertex at a given index.
void SetVertexAt(VertexSizeType pointId, const mitk::Point3D &point)
Set the coordinates of an existing vertex at the given index.
int BruteForceGetVertexIndexAt(const mitk::Point3D &point, double eps, VertexListType verticesList)
Find the index of the nearest vertex to a given 3D position using brute-force search.
VertexSizeType GetIndex(const VertexType *vertex) const
Return the index of a given vertex within the contour.
ContourElement()=default
bool IsClosed() const
Check whether the contour is closed.
bool RemoveVertexAt(const mitk::Point3D &point, double eps)
Remove the nearest vertex to a given 3D position within a search radius.
VertexIterator IteratorBegin()
Return a mutable iterator to the first vertex.
void Close()
Close the contour by logically connecting the last vertex to the first.
void SetVertexAt(VertexSizeType pointId, const VertexType *vertex)
Set the vertex data at a given index by copying from the provided vertex.
mitkClassMacroItkParent(ContourElement, itk::LightObject)
void Open()
Open the contour by removing the logical connection between last and first vertex.
VertexType * GetNextControlVertexAt(const mitk::Point3D &point, float eps)
Return the next control vertex after the nearest vertex to a given 3D position.
VertexType * GetVertexAt(const mitk::Point3D &point, float eps)
Find the nearest vertex to a given 3D position within a search radius.
void RedistributeControlVertices(const VertexType *vertex, int period)
Uniformly redistribute control point markers among the vertices.
void Clear()
Remove all vertices from the contour and free their memory.
VertexListType::size_type VertexSizeType
Size type for indexing into the vertex list.
bool RemoveVertexByIterator(VertexListType::iterator &iter)
bool RemoveVertex(const VertexType *vertex)
Remove a specific vertex from the contour by pointer identity.
VertexIterator IteratorEnd()
Return a mutable iterator past the last vertex.
ContourElement(const mitk::ContourElement &other)
void SetClosed(bool isClosed)
Set the closed state of the contour.
VertexType * GetVertexAt(VertexSizeType index)
Return the vertex at the given index.
VertexType * GetPreviousControlVertexAt(const mitk::Point3D &point, float eps)
Return the previous control vertex before the nearest vertex to a given 3D position.
const VertexListType * GetVertexList() const
Return a pointer to the internal vertex container.
void AddVertexAtFront(const mitk::Point3D &point, bool isControlPoint)
Add a vertex at the front of the contour.
bool GetLineSegmentForPoint(const mitk::Point3D &point, float eps, VertexSizeType &segmentStartIndex, VertexSizeType &segmentEndIndex, mitk::Point3D &closestContourPoint, bool findClosest=true) const
Find the contour line segment closest to a given point (extended version).
VertexListType GetControlVertices() const
Return a list of all vertices that are marked as control points.
void InsertVertexAtIndex(const mitk::Point3D &point, bool isControlPoint, VertexSizeType index)
Insert a vertex at the given index in the contour.
VertexIterator begin()
Return a mutable iterator to the first vertex (STL-compatible).
VertexSizeType GetSize() const
Return the number of vertices in this contour element.
ConstVertexIterator end() const
Return a const iterator past the last vertex (STL-compatible).
ConstVertexIterator ConstIteratorEnd() const
Return a const iterator past the last vertex.
Convenience header that includes all MITK numeric types.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
MITKCORE_EXPORT bool operator==(const InteractionEvent &a, const InteractionEvent &b)
Represents a single vertex of a contour.
ContourModelVertex(const mitk::Point3D &point, bool active=false)
Construct a vertex at the given position.
ContourModelVertex(const ContourModelVertex &other)
Copy constructor.
bool IsControlPoint
Flag indicating whether this vertex is a control point.
mitk::Point3D Coordinates
The 3D world coordinates of this vertex.