36 :
gsMesh<T>(mesh), m_precision(precision)
45 for (
size_t i = 0; i < this->m_face.size(); i++)
60 return this->m_vertex.size();
66 return this->m_face.size();
78 return m_boundary.getNumberOfVertices();
84 GISMO_ASSERT(vertexIndex <= this->m_vertex.size(),
"Vertex with index 'vertexIndex'=" << vertexIndex
85 <<
" does not exist. There are only " << this->m_vertex.size() <<
" vertices.");
86 return ((this->m_vertex[m_sorting[vertexIndex - 1]]));
99 return m_inverseSorting[findVertex(vertex)];
105 return m_inverseSorting[this->m_face[triangleIndex]->vertices[localVertexIndex-1]->getId()];
111 return m_boundary.getLength();
115bool rangeCheck(
const std::vector<index_t> &corners,
const size_t minimum,
const size_t maximum)
117 for (std::vector<index_t>::const_iterator it = corners.begin(); it != corners.end(); it++)
119 if ((
size_t)*it < minimum || (size_t)*it > maximum)
128 GISMO_ASSERT(rangeCheck<T>(corners, 1, getNumberOfBoundaryVertices()),
"The corners must be <= number of boundary vertices.");
130 std::sort(corners.begin(), corners.end());
131 size_t s = corners.size();
132 std::vector<T> lengths;
133 for (
size_t i = 0; i < s; i++)
135 lengths.push_back(m_boundary.getDistanceBetween(corners[i], corners[(i + 1) % s]));
143 return m_boundary.getShortestDistanceBetween(i, j, m_precision);
149 return m_boundary.getHalfedgeLengths();
155 GISMO_ASSERT(originVertexIndex <= this->m_vertex.size() && endVertexIndex <= this->m_vertex.size(),
156 "One of the input vertex indices " << originVertexIndex <<
" or " << endVertexIndex
157 <<
" does not exist. There are only " << this->m_vertex.size() <<
" vertices.");
159 return gsVector3d<T>(getVertex(originVertexIndex)->x() - getVertex(endVertexIndex)->x(),
160 getVertex(originVertexIndex)->y() - getVertex(endVertexIndex)->y(),
161 getVertex(originVertexIndex)->z() - getVertex(endVertexIndex)->z()).norm();
167 if (vertexIndex > this->m_vertex.size())
169 gsWarn <<
"gsHalfEdgeMesh::isTriangleVertex: Vertex with vertex index " << vertexIndex
170 <<
" does not exist. There are only " << this->m_vertex.size() <<
" vertices.\n";
173 if (triangleIndex > getNumberOfTriangles())
175 gsWarn <<
"gsHalfEdgeMesh::isTriangleVertex: The " << triangleIndex
176 <<
"-th triangle does not exist. There are only " << getNumberOfTriangles() <<
" triangles.\n";
179 if (*(this->m_vertex[m_sorting[vertexIndex - 1]]) == *(this->m_face[triangleIndex]->vertices[0]))
181 if (*(this->m_vertex[m_sorting[vertexIndex - 1]]) == *(this->m_face[triangleIndex]->vertices[1]))
183 if (*(this->m_vertex[m_sorting[vertexIndex - 1]]) == *(this->m_face[triangleIndex]->vertices[2]))
189const std::queue<typename gsHalfEdgeMesh<T>::Halfedge>
192 std::queue<Halfedge> oppositeHalfedges;
193 if (vertexIndex > this->m_vertex.size())
195 gsInfo <<
"gsHalfEdgeMesh::getOppositeHalfedges: The vertex with index " << vertexIndex
196 <<
" does not exist. There are only " << this->m_vertex.size() <<
" vertices.\n";
197 return oppositeHalfedges;
199 else if (vertexIndex > m_n && innerVertex)
201 gsWarn <<
"gsHalfEdgeMesh::getOppositeHalfedges: Inner vertex with index 'vertexIndex' = " << vertexIndex
202 <<
"is not an inner vertex. There are only " << m_n <<
" inner vertices.\n";
206 for (
size_t i = 0; i < getNumberOfTriangles(); i++)
208 switch (isTriangleVertex(vertexIndex, i))
211 v3 = getGlobalVertexIndex(3, i);
212 v2 = getGlobalVertexIndex(2, i);
213 oppositeHalfedges.push(
Halfedge(v3, v2, getHalfedgeLength(v3, v2)));
216 v1 = getGlobalVertexIndex(1, i);
217 v3 = getGlobalVertexIndex(3, i);
218 oppositeHalfedges.push(
Halfedge(v1, v3, getHalfedgeLength(v1, v3)));
221 v2 = getGlobalVertexIndex(2, i);
222 v1 = getGlobalVertexIndex(1, i);
223 oppositeHalfedges.push(
Halfedge(v2, v1, getHalfedgeLength(v2, v1)));
230 return oppositeHalfedges;
236 size_t numVertices = getNumberOfVertices();
238 for( ; i<numVertices; i++)
242 if((math::abs(x - handle->
x()) < tol) &&
243 (math::abs(y - handle->
y()) < tol) &&
244 (math::abs(z - handle->
z()) < tol))
245 return sorted ? i+1 : i;
247 return std::numeric_limits<size_t>::max();
253 if (internVertexIndex > this->m_vertex.size() - 1)
255 gsWarn <<
"gsHalfEdgeMesh::isBoundaryVertex: Vertex with intern vertex index = " << internVertexIndex
256 <<
" does not exist. There are only " << this->m_vertex.size() <<
" vertices.\n";
260 return m_boundary.isVertexContained(internVertexIndex);
267 size_t index1 = triangle->vertices[0]->getId();
268 size_t index2 = triangle->vertices[1]->getId();
269 size_t index3 = triangle->vertices[2]->getId();
270 if (numberOfHalfedge < 1 || numberOfHalfedge > 3)
272 gsWarn <<
"gsHalfEdgeMesh::getInternHalfedge: The inputted number of the halfedge " << numberOfHalfedge
273 <<
" is supposed to be 1,2 or 3. Because input was not expected, first halfedge is returned.\n";
274 numberOfHalfedge = 1;
276 if (numberOfHalfedge == 1)
280 triangle->vertices[1]->x() - triangle->vertices[0]->x(),
281 triangle->vertices[1]->y() - triangle->vertices[0]->y(),
282 triangle->vertices[1]->z() - triangle->vertices[0]->z()).norm());
284 if (numberOfHalfedge == 2)
288 triangle->vertices[2]->x() - triangle->vertices[1]->x(),
289 triangle->vertices[2]->y() - triangle->vertices[1]->y(),
290 triangle->vertices[2]->z() - triangle->vertices[1]->z()).norm());
292 if (numberOfHalfedge == 3)
296 triangle->vertices[0]->x() - triangle->vertices[2]->x(),
297 triangle->vertices[0]->y() - triangle->vertices[2]->y(),
298 triangle->vertices[0]->z() - triangle->vertices[2]->z()).norm());
308 size_t numberOfInnerVerticesFound = 0;
309 m_sorting.resize(this->m_vertex.size(), 0);
310 m_inverseSorting.resize(this->m_vertex.size(), 0);
312 for (
size_t i = 0; i != this->m_vertex.size(); ++i)
314 if (!isBoundaryVertex(i))
316 numberOfInnerVerticesFound++;
317 m_sorting[numberOfInnerVerticesFound - 1] = i;
318 m_inverseSorting[i] = numberOfInnerVerticesFound;
322 std::list<size_t> boundaryVertices = m_boundary.getVertexIndices();
323 for (
size_t i = 0; i < getNumberOfBoundaryVertices(); i++)
325 m_sorting[m_n + i] = boundaryVertices.front();
326 m_inverseSorting[boundaryVertices.front()] = m_n + i + 1;
327 boundaryVertices.pop_front();
338 while(!unsortedNonTwinHalfedges.empty())
342 component.appendNextHalfedge(unsortedNonTwinHalfedges.front());
343 unsortedNonTwinHalfedges.pop_front();
344 std::queue<Halfedge> nonFittingHalfedges;
345 while (!unsortedNonTwinHalfedges.empty())
347 if (component.isAppendableAsNext(unsortedNonTwinHalfedges.front()))
349 component.appendNextHalfedge(unsortedNonTwinHalfedges.front());
350 unsortedNonTwinHalfedges.pop_front();
351 while (!nonFittingHalfedges.empty())
353 unsortedNonTwinHalfedges.push_back(nonFittingHalfedges.front());
354 nonFittingHalfedges.pop();
357 else if (component.isAppendableAsPrev(unsortedNonTwinHalfedges.front()))
359 component.appendPrevHalfedge(unsortedNonTwinHalfedges.front());
360 unsortedNonTwinHalfedges.pop_front();
361 while (!nonFittingHalfedges.empty())
363 unsortedNonTwinHalfedges.push_back(nonFittingHalfedges.front());
364 nonFittingHalfedges.pop();
369 nonFittingHalfedges.push(unsortedNonTwinHalfedges.front());
370 unsortedNonTwinHalfedges.pop_front();
377 while(!nonFittingHalfedges.empty())
379 unsortedNonTwinHalfedges.push_back( nonFittingHalfedges.front() );
380 nonFittingHalfedges.pop();
390 std::queue<Halfedge> queue0;
391 std::queue<Halfedge> queue1;
392 bool actualQueue = 0;
393 std::list<Halfedge> nonTwinHalfedges;
394 for (
size_t i = 0; i < allHalfedges.size(); ++i)
396 queue0.push(allHalfedges[i]);
398 while (!(queue0.empty() && queue1.empty()))
400 if (actualQueue == 0)
402 nonTwinHalfedges.push_back(queue0.front());
404 while (!queue0.empty())
406 if (nonTwinHalfedges.back().isTwin(queue0.front()))
409 nonTwinHalfedges.pop_back();
410 while (!queue0.empty())
412 queue1.push(queue0.front());
418 queue1.push(queue0.front());
424 else if (actualQueue == 1)
426 nonTwinHalfedges.push_back(queue1.front());
428 while (!queue1.empty())
430 if (nonTwinHalfedges.back().isTwin(queue1.front()))
433 nonTwinHalfedges.pop_back();
434 while (!queue1.empty())
436 queue0.push(queue1.front());
442 queue0.push(queue1.front());
449 return nonTwinHalfedges;
457 if (m_chainedHalfedges.empty())
459 gsWarn <<
"gsHalfEdgeMesh<T>::Chain::isClosed: The chain does not store any halfedges yet.\n";
462 return (m_chainedHalfedges.front().getOrigin() == m_chainedHalfedges.back().getEnd());
468 if (this->isClosed())
469 return m_chainedHalfedges.size();
471 return m_chainedHalfedges.size() + 1;
478 for (
typename std::list<Halfedge>::const_iterator it = m_chainedHalfedges.begin();
479 it != m_chainedHalfedges.end(); ++it)
481 length += it->getLength();
491 gsWarn <<
"gsHalfEdgeMesh::Chain::getHalfedgeLengths: The chain does not store any halfedges yet.\n";
493 std::vector<T> lengths;
494 for (
typename std::list<Halfedge>::const_iterator it = m_chainedHalfedges.begin();
495 it != m_chainedHalfedges.end(); ++it)
497 lengths.push_back(it->getLength());
507 gsInfo <<
"gsHalfEdgeMesh::Chain::getFirstHalfedge: The chain does not store any halfedges yet.\n";
509 return m_chainedHalfedges.front();
517 gsInfo <<
"gsHalfEdgeMesh::Chain::getLastHalfedge: The chain does not store any halfedges yet.\n";
519 return m_chainedHalfedges.back();
527 gsWarn <<
"gsHalfEdgeMesh::Chain::getVertexIndices: The chain does not store any halfedges yet.\n";
529 std::list<size_t> vertexIndices;
530 for (
typename std::list<Halfedge>::const_iterator it = m_chainedHalfedges.begin();
531 it != m_chainedHalfedges.end(); ++it)
533 vertexIndices.push_back(it->getOrigin());
535 if (m_chainedHalfedges.size() == 1 || !(this->isClosed()))
537 vertexIndices.push_back(m_chainedHalfedges.back().getEnd());
539 return vertexIndices;
547 gsWarn <<
"gsHalfEdgeMesh::Chain::getShortestDistanceBetween: The chain does not store any halfedges yet.\n";
552 gsInfo <<
"gsHalfEdgeMesh::Chain::getShortestDistanceBetween: FirstIndex: " << i <<
" and second index: "
554 <<
" must be positiv integers smaller than the number of points of the chain, which is "
558 if (i > j) std::swap(i, j);
560 std::vector<T> l = this->getHalfedgeLengths();
561 for (
size_t z = i - 1; z < j - 1; z++)
565 if (this->isClosed() && (this->getLength() -
distance <
distance - precision))
577 gsWarn <<
"gsHalfEdgeMesh::Chain::getDistanceBetween: The chain does not store any halfedges yet.\n";
582 gsInfo <<
"gsHalfEdgeMesh::Chain::getDistanceBetween: FirstIndex: " << i <<
" and second index: "
584 <<
" must be positiv integers smaller than the number of points of the chain, which is "
588 bool ordered = (i < j);
589 if (!ordered) std::swap(i, j);
591 std::vector<T> l = this->getHalfedgeLengths();
592 for (
size_t z = i - 1; z < j - 1; z++)
596 if (this->isClosed() && !ordered)
601 gsWarn <<
"gsHalfEdgeMesh::Chain::getDistanceBetween: The chain is supposed to be closed in case the input is not ordered.\n";
610 gsWarn <<
"gsHalfEdgeMesh::Chain::isVertexContained: The chain does not store any halfedges yet.\n";
613 for (
typename std::list<Halfedge>::const_iterator it = m_chainedHalfedges.begin();
614 it != m_chainedHalfedges.end(); ++it)
616 if (it->getOrigin() == vertexIndex)
619 if (!(this->isClosed()) && this->getLastHalfedge().getEnd() == vertexIndex)
627 if (m_chainedHalfedges.empty())
630 return m_chainedHalfedges.front().isNext(previousHalfedge);
636 if (m_chainedHalfedges.empty())
639 return m_chainedHalfedges.back().isPrev(nextHalfedge);
645 if (!this->isAppendableAsPrev(prevHalfedge))
647 gsWarn <<
"gsHalfEdgeMesh::Chain::appendPrevHalfedge: This halfedge is not appendable at the beginning.\n";
648 gsInfo <<
"The first halfedge of the chain has origin " << this->getFirstHalfedge().getOrigin()
649 <<
" and prevHalfedge has the end " << prevHalfedge.
getEnd() <<
".\n";
653 m_chainedHalfedges.push_front(prevHalfedge);
661 if (!ignoreWarning && !isAppendableAsNext(nextHalfedge))
663 gsWarn <<
"gsHalfEdgeMesh::Chain::appendNextHalfedge: This halfedge is not appendable at the end.\n";
664 gsInfo <<
"The last halfedge of the chain has end " << this->getLastHalfedge().getEnd()
665 <<
" and nextHalfedge has the origin " << nextHalfedge.
getOrigin() <<
".\n";
669 m_chainedHalfedges.push_back(nextHalfedge);
Class that maintains boundary of triangle mesh.
Definition gsHalfEdgeMesh.h:379
size_t getNumberOfVertices() const
Get number of vertices.
Definition gsHalfEdgeMesh.h:407
const std::list< Halfedge > findNonTwinHalfedges(const std::vector< Halfedge > &allHalfedges)
Finds halfedges without twin halfedge.
Definition gsHalfEdgeMesh.hpp:388
Boundary()
Empty Constructor.
Definition gsHalfEdgeMesh.h:383
std::vector< Chain > m_boundary
boundary chains
Definition gsHalfEdgeMesh.h:538
void appendNextHalfedge(const Halfedge &nextHalfedge, bool ignoreWarning=false)
Appends halfedge at end of chain if possible.
Definition gsHalfEdgeMesh.hpp:658
T getDistanceBetween(size_t i, size_t j) const
Get distance between vertices.
Definition gsHalfEdgeMesh.hpp:573
size_t getNumberOfVertices() const
Get number of vertices.
Definition gsHalfEdgeMesh.hpp:466
T getShortestDistanceBetween(size_t i, size_t j, T precision) const
Get shortest distance between vertices.
Definition gsHalfEdgeMesh.hpp:543
const Halfedge & getLastHalfedge() const
Get last halfedge.
Definition gsHalfEdgeMesh.hpp:513
bool isAppendableAsPrev(const Halfedge &previousHalfedge) const
Tells if halfedge is appendable at beginning.
Definition gsHalfEdgeMesh.hpp:625
bool isAppendableAsNext(const Halfedge &nextHalfedge) const
Tells if halfedge is appendable at end.
Definition gsHalfEdgeMesh.hpp:634
void appendPrevHalfedge(const Halfedge &prevHalfedge)
Appends halfedge at beginning of chain if possible.
Definition gsHalfEdgeMesh.hpp:643
bool isVertexContained(const size_t &vertexIndex) const
Tells if vertex is contained in chain.
Definition gsHalfEdgeMesh.hpp:606
bool isClosed() const
Tells whether chain is closed or not.
Definition gsHalfEdgeMesh.hpp:455
const std::list< size_t > getVertexIndices() const
Get list of vertex indices.
Definition gsHalfEdgeMesh.hpp:523
const Halfedge & getFirstHalfedge() const
Get first halfedge.
Definition gsHalfEdgeMesh.hpp:503
std::vector< T > getHalfedgeLengths() const
Get vector of halfedge lengths.
Definition gsHalfEdgeMesh.hpp:487
T getLength() const
Get length of the chain.
Definition gsHalfEdgeMesh.hpp:475
Class that maintains directed halfedges in any dimension.
Definition gsHalfEdgeMesh.h:65
size_t getEnd() const
Get end vertex index.
Definition gsHalfEdgeMesh.h:97
size_t getOrigin() const
Get origin vertex index.
Definition gsHalfEdgeMesh.h:91
gsHalfEdgeMesh is a gsMesh implementation that handles Halfedges
Definition gsHalfEdgeMesh.h:47
const Halfedge getInternHalfedge(const typename gsMesh< T >::gsFaceHandle &triangle, size_t numberOfHalfedge) const
Returns halfedge of triangle For a given triangle the first, second or third halfedge are constructed...
Definition gsHalfEdgeMesh.hpp:265
size_t findVertex(const typename gsMesh< T >::gsVertexHandle &vertex) const
Finds the vertex that has the same coordinates (up to a tolerance) as vertex.
Definition gsHalfEdgeMesh.h:707
void sortVertices()
Creates ordering for vertices The vertices in m_vertices are not ordered. Therefore two index vectors...
Definition gsHalfEdgeMesh.hpp:304
std::vector< T > getCornerLengths(std::vector< index_t > &corners) const
Get boundary part lengths between corners A vector containing the numbers of the boundary corners ser...
Definition gsHalfEdgeMesh.hpp:126
size_t getNumberOfTriangles() const
Get number of triangles The number of triangles of the triangle mesh is returned.
Definition gsHalfEdgeMesh.hpp:64
size_t getNumberOfVertices() const
Get number of vertices The number of vertices of the triangle mesh is returned.
Definition gsHalfEdgeMesh.hpp:58
T getBoundaryLength() const
Get length of the boundary of the triangle mesh. The length of the boundary of the triangle mesh is r...
Definition gsHalfEdgeMesh.hpp:109
std::vector< Halfedge > m_halfedges
vector of halfedges
Definition gsHalfEdgeMesh.h:779
Boundary m_boundary
boundary of the mesh
Definition gsHalfEdgeMesh.h:780
const std::queue< Halfedge > getOppositeHalfedges(const size_t vertexIndex, const bool innerVertex=1) const
Returns queue of all opposite halfedges of vertex The opposite halfedge of a point in a triangle is m...
Definition gsHalfEdgeMesh.hpp:190
T getHalfedgeLength(const size_t originVertexIndex, const size_t endVertexIndex) const
Get halfedge length The length of the halfedge with origin and end vertex is returned....
Definition gsHalfEdgeMesh.hpp:153
gsHalfEdgeMesh(size_t nv=0)
Default constructor.
Definition gsHalfEdgeMesh.h:544
T getShortestBoundaryDistanceBetween(size_t i, size_t j) const
Get distance between vertices The distance between i-th and j-th boundary vertex is returned....
Definition gsHalfEdgeMesh.hpp:141
size_t getGlobalVertexIndex(const size_t localVertexIndex, const size_t triangleIndex) const
Get vertex index for firts, second or third vertex of triangle Returns the vertex index of a vertex w...
Definition gsHalfEdgeMesh.hpp:103
bool isBoundaryVertex(const size_t internVertexIndex) const
Tells whether a vertex is a boundary vertex or not. The boundary is constructed and it is tested whet...
Definition gsHalfEdgeMesh.hpp:251
const std::vector< T > getBoundaryChordLengths() const
Get chord lengths of boundary A vector storing the lengths of the halfedges of the boundary is return...
Definition gsHalfEdgeMesh.hpp:147
size_t getNumberOfInnerVertices() const
Get number of inner vertices The number of inner vertices of the triangle mesh is returned.
Definition gsHalfEdgeMesh.hpp:70
size_t m_n
number of inner vertices in the mesh
Definition gsHalfEdgeMesh.h:781
const gsMesh< T >::gsVertexHandle & getVertex(const size_t vertexIndex) const
Get vertex The vertex with index 'vertexIndex' is returned.
Definition gsHalfEdgeMesh.hpp:82
size_t getNumberOfBoundaryVertices() const
Get number of boundary vertices The number of boundary vertices of the triangle mesh is returned.
Definition gsHalfEdgeMesh.hpp:76
short_t isTriangleVertex(size_t vertexIndex, size_t triangleIndex) const
Returns the index of a vertex contained in triangle The integers 0 for not contained 1 for being vert...
Definition gsHalfEdgeMesh.hpp:165
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
A fixed-size, statically allocated 3D vector.
Definition gsVector.h:219
gsVertex class that represents a 3D vertex for a gsMesh.
Definition gsVertex.h:27
T x() const
Definition gsVertex.h:120
T z() const
Definition gsVertex.h:124
T y() const
Definition gsVertex.h:122
#define short_t
Definition gsConfig.h:35
#define gsWarn
Definition gsDebug.h:50
#define GISMO_UNUSED(x)
Definition gsDebug.h:112
#define gsInfo
Definition gsDebug.h:43
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.
T distance(gsMatrix< T > const &A, gsMatrix< T > const &B, index_t i=0, index_t j=0, bool cols=false)
compute a distance between the point number in the set and the point number <j> in the set ; by def...