Medical Imaging Interaction Toolkit  2025.12.02
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 {
36  class MITKCONTOURMODEL_EXPORT ContourElement : public itk::LightObject
37  {
38  public:
40 
41  itkFactorylessNewMacro(Self);
42 
43  itkCloneMacro(Self);
44 
48  {
49  ContourModelVertex(const mitk::Point3D& point, bool active = false) : IsControlPoint(active), Coordinates(point) {};
51  : IsControlPoint(other.IsControlPoint), Coordinates(other.Coordinates)
52  {
53  };
54 
57 
60 
61  bool operator ==(const ContourModelVertex& other) const;
62  };
63 
65  using VertexListType = std::deque<VertexType*>;
66  using VertexIterator = VertexListType::iterator;
67  using ConstVertexIterator = VertexListType::const_iterator;
68  using VertexSizeType = VertexListType::size_type;
69 
72  static const VertexSizeType NPOS = -1;
73 
86 
103 
107 
112  void AddVertex(const mitk::Point3D &point, bool isControlPoint);
113 
118  void AddVertexAtFront(const mitk::Point3D &point, bool isControlPoint);
119 
125  void InsertVertexAtIndex(const mitk::Point3D &point, bool isControlPoint, VertexSizeType index);
126 
131  void SetVertexAt(VertexSizeType pointId, const mitk::Point3D &point);
132 
138  void SetVertexAt(VertexSizeType pointId, const VertexType* vertex);
139 
145  const VertexType* GetVertexAt(VertexSizeType index) const;
146 
151  VertexType *GetVertexAt(const mitk::Point3D &point, float eps);
152 
158 
164 
170 
175  VertexSizeType GetIndex(const VertexType *vertex) const;
176 
180 
183  bool IsEmpty() const;
184 
187  bool IsClosed() const;
188 
193  bool IsNearContour(const mitk::Point3D &point, float eps) const;
194 
202  float eps,
203  mitk::ContourElement::VertexType *previousVertex,
204  mitk::ContourElement::VertexType *nextVertex) const;
211  float eps, VertexSizeType& segmentStartIndex, VertexSizeType& segmentEndIndex, mitk::Point3D& closestContourPoint, bool findClosest = true) const;
212 
216  void Close();
217 
221  void Open();
222 
226  void SetClosed(bool isClosed);
227 
233  void Concatenate(const mitk::ContourElement *other, bool check);
234 
238  bool RemoveVertex(const VertexType *vertex);
239 
244 
249  bool RemoveVertexAt(const mitk::Point3D &point, double eps);
250 
253  void Clear();
254 
262  VertexType *BruteForceGetVertexAt(const mitk::Point3D &point, double eps, bool isControlPoint = false, int offset = 0);
263 
270  double eps,
271  VertexListType verticesList);
272 
281 
286  void RedistributeControlVertices(const VertexType *vertex, int period);
287 
288  protected:
290 
291  ContourElement() = default;
294 
295  ContourElement& operator = (const ContourElement & other);
296 
301  bool RemoveVertexByIterator(VertexListType::iterator& iter);
302 
303  VertexListType m_Vertices; // double ended queue with vertices
304  bool m_IsClosed = false;
305  };
306 } // namespace mitk
307 
308 #endif
#define MITKCONTOURMODEL_EXPORT
Represents a contour in 3D space. A ContourElement is consisting of linked vertices implicitly defini...
ConstVertexIterator ConstIteratorBegin() const
Return a const iterator a the front.
VertexListType::const_iterator ConstVertexIterator
void Concatenate(const mitk::ContourElement *other, bool check)
Concatenate the contuor with a another contour. All vertices of the other contour will be cloned and ...
bool IsEmpty() const
Returns whether the contour element is empty.
const VertexType * GetVertexAt(VertexSizeType index) const
bool IsNearContour(const mitk::Point3D &point, float eps) const
Returns whether a given point is near a contour, according to eps.
ConstVertexIterator begin() const
Return a const iterator a the front. For easier support of stl functionality.
bool GetLineSegmentForPoint(const mitk::Point3D &point, float eps, mitk::ContourElement::VertexType *previousVertex, mitk::ContourElement::VertexType *nextVertex) const
VertexIterator end()
Return an iterator a the end. For easier support of stl functionality.
VertexListType::iterator VertexIterator
VertexType * GetControlVertexAt(const mitk::Point3D &point, float eps)
Returns the approximate nearest control vertex a given posoition in 3D space, if the clicked position...
std::deque< VertexType * > VertexListType
VertexType * BruteForceGetVertexAt(const mitk::Point3D &point, double eps, bool isControlPoint=false, int offset=0)
Returns the approximate nearest vertex a given position in 3D space. With the parameter 'isControlPoi...
void AddVertex(const mitk::Point3D &point, bool isControlPoint)
Add a vertex at the end of the contour.
bool RemoveVertexAt(VertexSizeType index)
Remove a vertex at given index within the container if exists.
void SetVertexAt(VertexSizeType pointId, const mitk::Point3D &point)
Set coordinates a given index.
int BruteForceGetVertexIndexAt(const mitk::Point3D &point, double eps, VertexListType verticesList)
Returns the index of the approximate nearest vertex of a given position in 3D space.
VertexSizeType GetIndex(const VertexType *vertex) const
Returns the index of the given vertex within the contour.
ContourElement()=default
bool IsClosed() const
Returns if the conour is closed or not.
bool RemoveVertexAt(const mitk::Point3D &point, double eps)
Remove the approximate nearest vertex at given position in 3D space if one exists.
VertexIterator IteratorBegin()
Return an iterator a the front.
void Close()
Close the contour. Connect first with last element.
void SetVertexAt(VertexSizeType pointId, const VertexType *vertex)
Set vertex a given index (by copying the values).
mitkClassMacroItkParent(ContourElement, itk::LightObject)
void Open()
Open the contour. Disconnect first and last element.
VertexType * GetNextControlVertexAt(const mitk::Point3D &point, float eps)
Returns the next vertex to the approximate nearest vertex of a given position in 3D space.
VertexType * GetVertexAt(const mitk::Point3D &point, float eps)
Returns the approximate nearest vertex a given position in 3D space.
void RedistributeControlVertices(const VertexType *vertex, int period)
Uniformly redistribute control points with a given period (in number of vertices)
void Clear()
Clear the storage container.
VertexListType::size_type VertexSizeType
bool RemoveVertexByIterator(VertexListType::iterator &iter)
bool RemoveVertex(const VertexType *vertex)
Remove the given vertex from the container if exists.
VertexIterator IteratorEnd()
Return an iterator a the end.
ContourElement(const mitk::ContourElement &other)
void SetClosed(bool isClosed)
Set the contours IsClosed property.
VertexType * GetVertexAt(VertexSizeType index)
Returns the vertex a given index.
VertexType * GetPreviousControlVertexAt(const mitk::Point3D &point, float eps)
Returns the previous vertex to the approximate nearest vertex of a given position in 3D space.
const VertexListType * GetVertexList() const
Returns the container of the vertices.
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
VertexListType GetControlVertices() const
void InsertVertexAtIndex(const mitk::Point3D &point, bool isControlPoint, VertexSizeType index)
Add a vertex at a given index of the contour.
VertexIterator begin()
Return an iterator a the front. For easier support of stl functionality.
VertexSizeType GetSize() const
Returns the number of contained vertices.
ConstVertexIterator end() const
Return a const iterator a the end. For easier support of stl functionality.
ConstVertexIterator ConstIteratorEnd() const
Return a const iterator a the end.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
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)
ContourModelVertex(const ContourModelVertex &other)
mitk::Point3D Coordinates
Coordinates in 3D space.