G+Smo  23.12.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsHalfEdgeMesh< T >::Chain Class Reference

Detailed Description

template<class T>
class gismo::gsHalfEdgeMesh< T >::Chain

Class that maintains chain of halfedges.

The halfedges of the chain are stored in a list, in order to easily insert new halfedges at the beginning and at the end of the list.

There are functions for testing whether the chain is empty or closed. Using getter functions the number of halfedges or vertices, as well as the length and the lengths of all halfedges can be returned. Furthermore the vertex indices ordered like they appear in the chain and the first and last halfedge can be returned. The distance between two vertices can be calculated. It can be questioned whether a vertex is contained in the chain and wheter another halfedge can be appended at the beginning or end.

A chain can be printed by printing its halfedges.

Public Member Functions

void appendNextHalfedge (const Halfedge &nextHalfedge, bool ignoreWarning=false)
 Appends halfedge at end of chain if possible. More...
 
void appendPrevHalfedge (const Halfedge &prevHalfedge)
 Appends halfedge at beginning of chain if possible. More...
 
getDistanceBetween (size_t i, size_t j) const
 Get distance between vertices. More...
 
const HalfedgegetFirstHalfedge () const
 Get first halfedge. More...
 
std::vector< T > getHalfedgeLengths () const
 Get vector of halfedge lengths. More...
 
const HalfedgegetLastHalfedge () const
 Get last halfedge. More...
 
getLength () const
 Get length of the chain. More...
 
size_t getNumberOfVertices () const
 Get number of vertices. More...
 
getShortestDistanceBetween (size_t i, size_t j, T precision) const
 Get shortest distance between vertices. More...
 
const std::list< size_t > getVertexIndices () const
 Get list of vertex indices. More...
 
bool isAppendableAsNext (const Halfedge &nextHalfedge) const
 Tells if halfedge is appendable at end. More...
 
bool isAppendableAsPrev (const Halfedge &previousHalfedge) const
 Tells if halfedge is appendable at beginning. More...
 
bool isClosed () const
 Tells whether chain is closed or not. More...
 
bool isEmpty () const
 Tells whether chain is empty or not. More...
 
bool isVertexContained (const size_t &vertexIndex) const
 Tells if vertex is contained in chain. More...
 

Private Attributes

std::list< Halfedgem_chainedHalfedges
 list of halfedges
 

Member Function Documentation

void appendNextHalfedge ( const Halfedge nextHalfedge,
bool  ignoreWarning = false 
)

Appends halfedge at end of chain if possible.

The method tests whether halfedge is appendable at the end using isAppendableAsNext(nextHalfedge) and appends the halfedge if possible. Otherwise a warning is printed.

Parameters
[in]nextHalfedgehalfedge that should be appended at end
Note
will be append to m_chainedHalfedges
void appendPrevHalfedge ( const Halfedge prevHalfedge)

Appends halfedge at beginning of chain if possible.

The method tests whether halfedge is appendable at the beginning using isAppendableAsPrev(prevHalfedge) and appends the halfedge if possible. Otherwise a warning is printed.

Parameters
[in]prevHalfedgehalfedge that should be appended at beginning
T getDistanceBetween ( size_t  i,
size_t  j 
) const

Get distance between vertices.

The distance between two vertices i and j in a particular direction is calculated. If the chain is empty a warning is printed and 0 is returned. If either of the vertices is

number of vertices in the chain or < 1 an error message

is printed and 0 is returned, too.

If i < j the chain simply is traversed from i-th to j-th vertex and halfedge lengths are summed up. Otherwise the remaining length of the chain is returned, provided that the chain is closed. If i > j and chain is not closed, the distance from i to j is returned and a warning is printed.

Parameters
[in]inumber of the vertex in the chain, where the length should start, e. g. i=1 for first vertex
[in]jnumber of the vertex in the chain, where the length should end, e. g. j=4 for fourth vertex
Returns
distance between vertices, e.g. between first and fourth chain vertex
const gsHalfEdgeMesh< T >::Halfedge & getFirstHalfedge ( ) const

Get first halfedge.

The first halfedge stored in the list m_chainedHalfedges is returned. If the chain is empty an error message is printed.

Returns
first halfedge
std::vector< T > getHalfedgeLengths ( ) const

Get vector of halfedge lengths.

The list of halfedges is traversed and all halfedge lengths are stored in a vector, s. t. the order is maintained. E. g. returnVector[i] stores the length of the (i+1)-th halfedge of the chain.

Returns
vector of halfedge lengths
const gsHalfEdgeMesh< T >::Halfedge & getLastHalfedge ( ) const

Get last halfedge.

The last halfedge stored in the list m_chainedHalfedges is returned. If the chain is empty an error message is printed.

Returns
last halfedge
T getLength ( ) const

Get length of the chain.

The length of the chain is obtained by adding the lengths of all halfedges.

Returns
length
size_t getNumberOfVertices ( ) const

Get number of vertices.

The number of vertices equals the number of halfedges if the chain is closed. Otherwise the number of halfedges has to be increased by 1 to obtain the number of vertices.

Returns
number of vertices
T getShortestDistanceBetween ( size_t  i,
size_t  j,
precision 
) const

Get shortest distance between vertices.

The shortest distance between two vertices i and j on a closed chain is calculated and returned.

Just in case the chain is closed, it is checked wheter the distance between the two given vertices in a clockwise or counterclockwise direction is shorter. Otherwise the distance from smaller to greater number of vertex is returned automatically.

If the chain is empty a warning is printed and 0 is returned. If either of the vertex indices is > number of vertices in the chain or < 1 an error message is printed and 0 is returned, too.

Parameters
[in]inumber of the first vertex in the chain
[in]jnumber of the second vertex in the chain
[in]precisiontolerance
Returns
(shortest) distance between vertices
const std::list< size_t > getVertexIndices ( ) const

Get list of vertex indices.

The list m_chainedHalfedges is traversed and every vertex is stored in a list once. This is done maintaining the order of the vertices. Firstly every origin vertex index is stored and in case the list is not closed, the end vertex index of the last halfedge is stored, too.

If the list m_chainedHalfedges is still empty, an empty list is returned and a warning is printed.

Returns
list of vertex indices
bool isAppendableAsNext ( const Halfedge nextHalfedge) const

Tells if halfedge is appendable at end.

For empty chains TRUE is returned. Otherwise the last halfedge in the list m_chainedHalfedges is tested with isPrev(nextHalfedge) and obtained bool value is returned.

Parameters
[in]nextHalfedgehalfedge which is tested to append at end
Returns
bool value
bool isAppendableAsPrev ( const Halfedge previousHalfedge) const

Tells if halfedge is appendable at beginning.

For empty chains TRUE is returned. Otherwise the first halfedge in the list m_chainedHalfedges is tested with isNext(previousHalfedge) and obtained bool value is returned.

Parameters
[in]previousHalfedgehalfedge which is tested to append at beginning
Returns
bool value
bool isClosed ( ) const

Tells whether chain is closed or not.

The chain is closed if the origin point of the first halfedge and the end point of the last halfedge equal each other. It is returned TRUE if the chain is closed or empty. FALSE otherwise. In case the chain is empty, e. g. there are no halfedges stored yet, a warning is printed.

Returns
bool value
bool isEmpty ( ) const
inline

Tells whether chain is empty or not.

The chain is empty if there are no halfedges stored in the list m_chainedHalfedges yet. This is tested with size() operator of lists. It is returned TRUE if chain is empty. FALSE otherwise.

Returns
bool value
bool isVertexContained ( const size_t &  vertexIndex) const

Tells if vertex is contained in chain.

If the chain is empty, a warning is printed and FALSE is returned.

The list m_chainedHalfedges is traversed and every origin vertex index of the halfedges is checked for equality with index. If the input vertex index is found TRUE is returned, FALSE otherwise. For not closed chains, the end vertex index for the last halfedge is checked, too.

Parameters
[in]vertexIndexvertex index of the searched point
Returns
bool value