Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::ContourElement Class Reference

Represents a contour in 3D space as a sequence of linked vertices. More...

#include <mitkContourElement.h>

Inheritance diagram for mitk::ContourElement:
Collaboration diagram for mitk::ContourElement:

Classes

struct  ContourModelVertex
 Represents a single vertex of a contour. More...
 

Public Types

using VertexType = ContourModelVertex
 Alias for the vertex type used in this contour. More...
 
using VertexListType = std::deque< VertexType * >
 Alias for the container type storing vertex pointers. More...
 
using VertexIterator = VertexListType::iterator
 Mutable iterator for traversing vertices. More...
 
using ConstVertexIterator = VertexListType::const_iterator
 Const iterator for traversing vertices. More...
 
using VertexSizeType = VertexListType::size_type
 Size type for indexing into the vertex list. More...
 

Public Member Functions

 mitkClassMacroItkParent (ContourElement, itk::LightObject)
 
Pointer Clone () const
 
ConstVertexIterator ConstIteratorBegin () const
 Return a const iterator to the first vertex. More...
 
ConstVertexIterator ConstIteratorEnd () const
 Return a const iterator past the last vertex. More...
 
VertexIterator IteratorBegin ()
 Return a mutable iterator to the first vertex. More...
 
VertexIterator IteratorEnd ()
 Return a mutable iterator past the last vertex. More...
 
ConstVertexIterator begin () const
 Return a const iterator to the first vertex (STL-compatible). More...
 
ConstVertexIterator end () const
 Return a const iterator past the last vertex (STL-compatible). More...
 
VertexIterator begin ()
 Return a mutable iterator to the first vertex (STL-compatible). More...
 
VertexIterator end ()
 Return a mutable iterator past the last vertex (STL-compatible). More...
 
VertexSizeType GetSize () const
 Return the number of vertices in this contour element. More...
 
void AddVertex (const mitk::Point3D &point, bool isControlPoint)
 Add a vertex at the end of the contour. More...
 
void AddVertexAtFront (const mitk::Point3D &point, bool isControlPoint)
 Add a vertex at the front of the contour. More...
 
void InsertVertexAtIndex (const mitk::Point3D &point, bool isControlPoint, VertexSizeType index)
 Insert a vertex at the given index in the contour. More...
 
void SetVertexAt (VertexSizeType pointId, const mitk::Point3D &point)
 Set the coordinates of an existing vertex at the given index. More...
 
void SetVertexAt (VertexSizeType pointId, const VertexType *vertex)
 Set the vertex data at a given index by copying from the provided vertex. More...
 
VertexType * GetVertexAt (VertexSizeType index)
 Return the vertex at the given index. More...
 
const VertexType * GetVertexAt (VertexSizeType index) const
 Return the vertex at the given index (const version). More...
 
VertexType * GetVertexAt (const mitk::Point3D &point, float eps)
 Find the nearest vertex to a given 3D position within a search radius. More...
 
VertexType * GetNextControlVertexAt (const mitk::Point3D &point, float eps)
 Return the next control vertex after the nearest vertex to a given 3D position. More...
 
VertexType * GetPreviousControlVertexAt (const mitk::Point3D &point, float eps)
 Return the previous control vertex before the nearest vertex to a given 3D position. More...
 
VertexType * GetControlVertexAt (const mitk::Point3D &point, float eps)
 Find the nearest control vertex to a given 3D position within a search radius. More...
 
VertexSizeType GetIndex (const VertexType *vertex) const
 Return the index of a given vertex within the contour. More...
 
const VertexListType * GetVertexList () const
 Return a pointer to the internal vertex container. More...
 
bool IsEmpty () const
 Check whether the contour element contains no vertices. More...
 
bool IsClosed () const
 Check whether the contour is closed. More...
 
bool IsNearContour (const mitk::Point3D &point, float eps) const
 Check whether a given point lies near the contour within a specified tolerance. More...
 
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. More...
 
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). More...
 
void Close ()
 Close the contour by logically connecting the last vertex to the first. More...
 
void Open ()
 Open the contour by removing the logical connection between last and first vertex. More...
 
void SetClosed (bool isClosed)
 Set the closed state of the contour. More...
 
void Concatenate (const mitk::ContourElement *other, bool check)
 Append all vertices of another contour to the end of this contour. More...
 
bool RemoveVertex (const VertexType *vertex)
 Remove a specific vertex from the contour by pointer identity. More...
 
bool RemoveVertexAt (VertexSizeType index)
 Remove the vertex at a given index. More...
 
bool RemoveVertexAt (const mitk::Point3D &point, double eps)
 Remove the nearest vertex to a given 3D position within a search radius. More...
 
void Clear ()
 Remove all vertices from the contour and free their memory. More...
 
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. More...
 
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. More...
 
VertexListType GetControlVertices () const
 Return a list of all vertices that are marked as control points. More...
 
void RedistributeControlVertices (const VertexType *vertex, int period)
 Uniformly redistribute control point markers among the vertices. More...
 

Static Public Member Functions

static Pointer New ()
 

Static Public Attributes

static const VertexSizeType NPOS
 Sentinel value indicating an invalid vertex index. More...
 

Protected Member Functions

 mitkCloneMacro (Self)
 
 ContourElement ()=default
 
 ContourElement (const mitk::ContourElement &other)
 
 ~ContourElement ()
 
ContourElement & operator= (const ContourElement &other)
 
bool RemoveVertexByIterator (VertexListType::iterator &iter)
 

Protected Attributes

VertexListType m_Vertices
 
bool m_IsClosed
 

Detailed Description

Represents a contour in 3D space as a sequence of linked vertices.

A ContourElement consists of linked vertices that implicitly define a contour. The vertices are stored in a double-ended queue (std::deque), making it possible to add vertices at the front and end of the contour and to iterate in both directions. Individual vertices can be marked as control points to distinguish them from regular interpolation points.

This class owns all its vertices. When a vertex is added, ownership is transferred to this ContourElement instance, which manages deletion.

Note
This class is designed as an internal component of ContourModel. It is strongly recommended to use ContourModel rather than ContourElement directly when working with contour representations in MITK.
See also
ContourModel
ContourModelSet

Definition at line 41 of file mitkContourElement.h.

Member Typedef Documentation

◆ ConstVertexIterator

using mitk::ContourElement::ConstVertexIterator = VertexListType::const_iterator

Const iterator for traversing vertices.

Definition at line 96 of file mitkContourElement.h.

◆ VertexIterator

using mitk::ContourElement::VertexIterator = VertexListType::iterator

Mutable iterator for traversing vertices.

Definition at line 94 of file mitkContourElement.h.

◆ VertexListType

Alias for the container type storing vertex pointers.

Definition at line 92 of file mitkContourElement.h.

◆ VertexSizeType

using mitk::ContourElement::VertexSizeType = VertexListType::size_type

Size type for indexing into the vertex list.

Definition at line 98 of file mitkContourElement.h.

◆ VertexType

Alias for the vertex type used in this contour.

Definition at line 90 of file mitkContourElement.h.

Constructor & Destructor Documentation

◆ ContourElement() [1/2]

mitk::ContourElement::ContourElement ( )
protecteddefault

◆ ContourElement() [2/2]

mitk::ContourElement::ContourElement ( const mitk::ContourElement &  other)
protected

◆ ~ContourElement()

mitk::ContourElement::~ContourElement ( )
protected

Member Function Documentation

◆ AddVertex()

void mitk::ContourElement::AddVertex ( const mitk::Point3D &  point,
bool  isControlPoint 
)

Add a vertex at the end of the contour.

Parameters
[in]pointCoordinates of the new vertex in 3D space.
[in]isControlPointIf true, the vertex is marked as a control point.

◆ AddVertexAtFront()

void mitk::ContourElement::AddVertexAtFront ( const mitk::Point3D &  point,
bool  isControlPoint 
)

Add a vertex at the front of the contour.

Parameters
[in]pointCoordinates of the new vertex in 3D space.
[in]isControlPointIf true, the vertex is marked as a control point.

◆ begin() [1/2]

VertexIterator mitk::ContourElement::begin ( )

Return a mutable iterator to the first vertex (STL-compatible).

Returns
Iterator pointing to the beginning of the vertex container.

◆ begin() [2/2]

ConstVertexIterator mitk::ContourElement::begin ( ) const

Return a const iterator to the first vertex (STL-compatible).

Returns
Const iterator pointing to the beginning of the vertex container.

◆ BruteForceGetVertexAt()

VertexType* mitk::ContourElement::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.

Optionally filters for control points only and supports returning a vertex at an offset from the nearest match (e.g., +1 for the next, -1 for the previous). Wrapping is applied if the offset goes past either end of the list.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance (open boundary). Must be >= 0.
[in]isControlPointIf true, only control vertices are considered. Default is false.
[in]offsetIndex offset from the nearest vertex. Default is 0 (return the nearest).
Returns
Pointer to the matching vertex, or nullptr if no vertex is within eps.

◆ BruteForceGetVertexIndexAt()

int mitk::ContourElement::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.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance (open boundary). Must be >= 0.
[in]verticesListThe vertex list to search (may be a subset, e.g., only control vertices).
Returns
Index of the nearest vertex within eps, or -1 if none is found.
Exceptions
mitk::Exceptionif eps is negative.

◆ Clear()

void mitk::ContourElement::Clear ( )

Remove all vertices from the contour and free their memory.

Postcondition
GetSize() returns 0.

◆ Clone()

Pointer mitk::ContourElement::Clone ( ) const

◆ Close()

void mitk::ContourElement::Close ( )

Close the contour by logically connecting the last vertex to the first.

Postcondition
IsClosed() returns true.

◆ Concatenate()

void mitk::ContourElement::Concatenate ( const mitk::ContourElement *  other,
bool  check 
)

Append all vertices of another contour to the end of this contour.

All vertices from other are cloned and appended after the last vertex of this contour.

Parameters
[in]otherThe contour whose vertices are to be appended.
[in]checkIf true, vertices whose coordinates already exist in this contour are skipped to avoid duplicates.

◆ ConstIteratorBegin()

ConstVertexIterator mitk::ContourElement::ConstIteratorBegin ( ) const

Return a const iterator to the first vertex.

Returns
Const iterator pointing to the beginning of the vertex container.

◆ ConstIteratorEnd()

ConstVertexIterator mitk::ContourElement::ConstIteratorEnd ( ) const

Return a const iterator past the last vertex.

Returns
Const iterator pointing past the end of the vertex container.

◆ end() [1/2]

VertexIterator mitk::ContourElement::end ( )

Return a mutable iterator past the last vertex (STL-compatible).

Returns
Iterator pointing past the end of the vertex container.

◆ end() [2/2]

ConstVertexIterator mitk::ContourElement::end ( ) const

Return a const iterator past the last vertex (STL-compatible).

Returns
Const iterator pointing past the end of the vertex container.

◆ GetControlVertexAt()

VertexType* mitk::ContourElement::GetControlVertexAt ( const mitk::Point3D &  point,
float  eps 
)

Find the nearest control vertex to a given 3D position within a search radius.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance for a control vertex to be considered a match.
Returns
Pointer to the nearest control vertex, or nullptr if none is within eps.

◆ GetControlVertices()

VertexListType mitk::ContourElement::GetControlVertices ( ) const

Return a list of all vertices that are marked as control points.

The returned list contains pointers to the internally stored vertices. The ContourElement retains ownership of the vertices; callers must clone any vertices they wish to manage independently.

Returns
A VertexListType containing pointers to all control point vertices.

◆ GetIndex()

VertexSizeType mitk::ContourElement::GetIndex ( const VertexType *  vertex) const

Return the index of a given vertex within the contour.

Parameters
[in]vertexPointer to the vertex to search for (by pointer identity).
Returns
Index of the vertex, or ContourElement::NPOS if not found.

◆ GetLineSegmentForPoint() [1/2]

bool mitk::ContourElement::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.

Searches for the line segment whose distance to point is at most eps. If found, the start and end vertices of the segment are written to previousVertex and nextVertex.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum squared distance for a segment to be considered close enough.
[out]previousVertexReceives the start vertex of the found segment.
[out]nextVertexReceives the end vertex of the found segment.
Returns
True if a matching segment was found, false otherwise.
Note
previousVertex and nextVertex are only valid when the return value is true.

◆ GetLineSegmentForPoint() [2/2]

bool mitk::ContourElement::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).

In addition to the basic version, this overload returns the indices of the segment endpoints, the closest point on the segment, and supports choosing between the first close-enough segment or the globally closest segment.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum squared distance for a segment to be considered close enough.
[out]segmentStartIndexIndex of the segment's start vertex.
[out]segmentEndIndexIndex of the segment's end vertex.
[out]closestContourPointThe point on the segment closest to point.
[in]findClosestIf true, finds the globally closest segment; if false, returns the first segment within eps. Default is true.
Returns
True if a matching segment was found, false otherwise.
Note
Output parameters are only valid when the return value is true.

◆ GetNextControlVertexAt()

VertexType* mitk::ContourElement::GetNextControlVertexAt ( const mitk::Point3D &  point,
float  eps 
)

Return the next control vertex after the nearest vertex to a given 3D position.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance for the initial nearest vertex search.
Returns
Pointer to the next control vertex, or nullptr if none is found.

◆ GetPreviousControlVertexAt()

VertexType* mitk::ContourElement::GetPreviousControlVertexAt ( const mitk::Point3D &  point,
float  eps 
)

Return the previous control vertex before the nearest vertex to a given 3D position.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance for the initial nearest vertex search.
Returns
Pointer to the previous control vertex, or nullptr if none is found.

◆ GetSize()

VertexSizeType mitk::ContourElement::GetSize ( ) const

Return the number of vertices in this contour element.

Returns
The number of contained vertices.

◆ GetVertexAt() [1/3]

VertexType* mitk::ContourElement::GetVertexAt ( const mitk::Point3D &  point,
float  eps 
)

Find the nearest vertex to a given 3D position within a search radius.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance for a vertex to be considered a match.
Returns
Pointer to the nearest vertex, or nullptr if none is within eps.

◆ GetVertexAt() [2/3]

VertexType* mitk::ContourElement::GetVertexAt ( VertexSizeType  index)

Return the vertex at the given index.

Parameters
[in]indexIndex of the vertex to retrieve.
Returns
Pointer to the vertex at the specified index.
Precondition
index must be a valid index (< GetSize()).
Exceptions
std::out_of_rangeif the index is out of bounds.

◆ GetVertexAt() [3/3]

const VertexType* mitk::ContourElement::GetVertexAt ( VertexSizeType  index) const

Return the vertex at the given index (const version).

Parameters
[in]indexIndex of the vertex to retrieve.
Returns
Const pointer to the vertex at the specified index.
Precondition
index must be a valid index (< GetSize()).
Exceptions
std::out_of_rangeif the index is out of bounds.

◆ GetVertexList()

const VertexListType* mitk::ContourElement::GetVertexList ( ) const

Return a pointer to the internal vertex container.

Returns
Const pointer to the internal deque of vertex pointers.

◆ InsertVertexAtIndex()

void mitk::ContourElement::InsertVertexAtIndex ( const mitk::Point3D &  point,
bool  isControlPoint,
VertexSizeType  index 
)

Insert a vertex at the given index in the contour.

If the index equals or exceeds the current size, the vertex is appended.

Parameters
[in]pointCoordinates of the new vertex in 3D space.
[in]isControlPointIf true, the vertex is marked as a control point.
[in]indexPosition at which the vertex is inserted.

◆ IsClosed()

bool mitk::ContourElement::IsClosed ( ) const

Check whether the contour is closed.

Returns
True if the contour is closed (first and last vertex are logically connected).

◆ IsEmpty()

bool mitk::ContourElement::IsEmpty ( ) const

Check whether the contour element contains no vertices.

Returns
True if the contour has no vertices, false otherwise.

◆ IsNearContour()

bool mitk::ContourElement::IsNearContour ( const mitk::Point3D &  point,
float  eps 
) const

Check whether a given point lies near the contour within a specified tolerance.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum squared distance for the point to be considered near the contour.
Returns
True if the point is within eps squared distance of any contour line segment.

◆ IteratorBegin()

VertexIterator mitk::ContourElement::IteratorBegin ( )

Return a mutable iterator to the first vertex.

Returns
Iterator pointing to the beginning of the vertex container.

◆ IteratorEnd()

VertexIterator mitk::ContourElement::IteratorEnd ( )

Return a mutable iterator past the last vertex.

Returns
Iterator pointing past the end of the vertex container.

◆ mitkClassMacroItkParent()

mitk::ContourElement::mitkClassMacroItkParent ( ContourElement  ,
itk::LightObject   
)

◆ mitkCloneMacro()

mitk::ContourElement::mitkCloneMacro ( Self  )
protected

◆ New()

static Pointer mitk::ContourElement::New ( )
static

◆ Open()

void mitk::ContourElement::Open ( )

Open the contour by removing the logical connection between last and first vertex.

Postcondition
IsClosed() returns false.

◆ operator=()

ContourElement& mitk::ContourElement::operator= ( const ContourElement &  other)
protected

◆ RedistributeControlVertices()

void mitk::ContourElement::RedistributeControlVertices ( const VertexType *  vertex,
int  period 
)

Uniformly redistribute control point markers among the vertices.

Starting from vertex (or the first vertex if nullptr), marks every period-th vertex as a control point and clears the flag on all others.

Parameters
[in]vertexThe vertex around which redistribution is centered. May be nullptr.
[in]periodNumber of vertices between successive control points.

◆ RemoveVertex()

bool mitk::ContourElement::RemoveVertex ( const VertexType *  vertex)

Remove a specific vertex from the contour by pointer identity.

Parameters
[in]vertexPointer to the vertex to remove.
Returns
True if the vertex was found and removed, false otherwise.

◆ RemoveVertexAt() [1/2]

bool mitk::ContourElement::RemoveVertexAt ( const mitk::Point3D &  point,
double  eps 
)

Remove the nearest vertex to a given 3D position within a search radius.

Parameters
[in]pointQuery position in 3D space.
[in]epsMaximum Euclidean distance for a vertex to be considered a match.
Returns
True if a vertex was found and removed, false otherwise.

◆ RemoveVertexAt() [2/2]

bool mitk::ContourElement::RemoveVertexAt ( VertexSizeType  index)

Remove the vertex at a given index.

Parameters
[in]indexIndex of the vertex to remove.
Returns
True if the index was valid and the vertex was removed, false otherwise.

◆ RemoveVertexByIterator()

bool mitk::ContourElement::RemoveVertexByIterator ( VertexListType::iterator &  iter)
protected

Internal helper function to correctly remove the element indicated by the iterator from the list. After the call the iterator is invalid. Caller of the function must ensure that the iterator is valid!.

Returns
Indicates if the element indicated by the iterator was removed. If iterator points to end it returns false.

◆ SetClosed()

void mitk::ContourElement::SetClosed ( bool  isClosed)

Set the closed state of the contour.

Parameters
[in]isClosedIf true, the contour is closed; if false, it is opened.

◆ SetVertexAt() [1/2]

void mitk::ContourElement::SetVertexAt ( VertexSizeType  pointId,
const mitk::Point3D &  point 
)

Set the coordinates of an existing vertex at the given index.

Parameters
[in]pointIdIndex of the vertex to modify.
[in]pointNew 3D coordinates.

◆ SetVertexAt() [2/2]

void mitk::ContourElement::SetVertexAt ( VertexSizeType  pointId,
const VertexType *  vertex 
)

Set the vertex data at a given index by copying from the provided vertex.

Parameters
[in]pointIdIndex of the vertex to modify.
[in]vertexSource vertex whose coordinates and control point flag are copied.
Precondition
vertex must be a valid (non-null) pointer.
Exceptions
mitk::Exceptionif vertex is nullptr.

Member Data Documentation

◆ m_IsClosed

bool mitk::ContourElement::m_IsClosed
protected

Definition at line 407 of file mitkContourElement.h.

◆ m_Vertices

VertexListType mitk::ContourElement::m_Vertices
protected

Definition at line 406 of file mitkContourElement.h.

◆ NPOS

const VertexSizeType mitk::ContourElement::NPOS
static

Sentinel value indicating an invalid vertex index.

Equivalent to the maximum value of the unsigned size type.

Definition at line 104 of file mitkContourElement.h.


The documentation for this class was generated from the following file: