G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsHalfEdgeMesh.h
Go to the documentation of this file.
1
14#pragma once
15
17#include <queue>
18
19namespace gismo
20{
21
45template <class T>
46class GISMO_EXPORT gsHalfEdgeMesh : public gsMesh<T>
47{
49public:
65 {
66 public:
75 explicit Halfedge(const size_t origin = 0,
76 const size_t end = 0,
77 const T length = 0)
78 : m_origin(origin), m_end(end), m_length(length)
79 {
80 if (length < 0)
81 gsWarn << "Halfedge: Origin and end must be indices > 0 and length should be positiv or 0. One of the values is not correct:"
82 << std::endl << "origin: " << origin << std::endl << "end: " << end << std::endl
83 << "length: "
84 << length;
85 }
86
91 size_t getOrigin() const { return m_origin; }
92
97 size_t getEnd() const { return m_end; }
98
103 T getLength() const { return m_length; }
104
110 bool isPrev(const Halfedge &nextHalfedge) const
111 { return (m_end == nextHalfedge.m_origin); }
112
118 bool isNext(const Halfedge &previousHalfedge) const
119 { return (m_origin == previousHalfedge.m_end); }
120
126 bool isTwin(const Halfedge &halfedge) const
127 { return (m_origin == halfedge.m_end && m_end == halfedge.m_origin); }
128
129 private:
130 size_t m_origin;
131 size_t m_end;
133 };
134
156 class Chain
157 {
158 public:
159
170 bool isEmpty() const { return m_chainedHalfedges.empty(); }
171
183 bool isClosed() const;
184
193 size_t getNumberOfVertices() const;
194
202 T getLength() const;
203
212 std::vector<T> getHalfedgeLengths() const;
213
222 const Halfedge &getFirstHalfedge() const;
223
232 const Halfedge &getLastHalfedge() const;
233
248 const std::list<size_t> getVertexIndices() const;
249
272 T getShortestDistanceBetween(size_t i, size_t j, T precision) const;
273
297 T getDistanceBetween(size_t i, size_t j) const;
298
314 bool isVertexContained(const size_t &vertexIndex) const;
315
325 bool isAppendableAsPrev(const Halfedge &previousHalfedge) const;
326
336 bool isAppendableAsNext(const Halfedge &nextHalfedge) const;
337
346 void appendPrevHalfedge(const Halfedge &prevHalfedge);
347
357 void appendNextHalfedge(const Halfedge &nextHalfedge, bool ignoreWarning = false);
358
359 private:
360 std::list<Halfedge> m_chainedHalfedges;
361 };
362
363private:
378 class Boundary // todo: replace by Chain
379 {
380 public:
381
384
398 Boundary(const std::vector<Halfedge> &halfedges);
399
407 size_t getNumberOfVertices() const
408 {
409 size_t result = 0;
410 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
411 result += it->getNumberOfVertices();
412 return result;
413 }
414
422 T getLength() const
423 {
424 T result = 0;
425 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
426 result += it->getLength();
427 return result;
428 }
429
437 const std::vector<T> getHalfedgeLengths() const
438 {
439 std::vector<T> result;
440 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
441 {
442 const std::vector<T> lengthsOneComp = it->getHalfedgeLengths();
443 result.insert(result.end(), lengthsOneComp.begin(), lengthsOneComp.end());
444 }
445 return result;
446 }
447
455 const std::list<size_t > getVertexIndices() const
456 {
457 std::list<size_t> result;
458 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
459 {
460 const std::list<size_t>& indicesOneComp = it->getVertexIndices();
461 result.insert(result.end(), indicesOneComp.begin(), indicesOneComp.end());
462 }
463 return result;
464 }
465
477 T getShortestDistanceBetween(const size_t &i, const size_t &j, T precision) const
478 {
479 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
480 {
481 T dist = it->getShortestDistanceBetween(i, j, precision);
482 if(dist > 0)
483 return dist;
484 }
485 return 0;
486 }
487
500 T getDistanceBetween(const size_t &i, const size_t &j) const
501 {
502 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
503 {
504 T dist = it->getDistanceBetween(i, j);
505 if(dist > 0)
506 return dist;
507 }
508 return 0;
509 }
510
518 bool isVertexContained(const size_t &internVertexIndex) const
519 {
520 for(typename std::vector<Chain>::const_iterator it=m_boundary.begin(); it!=m_boundary.end(); ++it)
521 if(it->isVertexContained(internVertexIndex))
522 return true;
523 return false;
524 }
525
526 private:
536 const std::list<Halfedge> findNonTwinHalfedges(const std::vector<Halfedge> &allHalfedges);
537
538 std::vector<Chain> m_boundary;
539 };
540
541public:
542
544 explicit gsHalfEdgeMesh(size_t nv = 0) : m_n(nv) { }
545
553 explicit gsHalfEdgeMesh(const gsMesh<T> &mesh, T precision = 1e-8, bool periodic = false);
554
555 virtual ~gsHalfEdgeMesh() { }
556
563 size_t getNumberOfVertices() const;
564
571 size_t getNumberOfTriangles() const;
572
579 size_t getNumberOfInnerVertices() const;
580
587 size_t getNumberOfBoundaryVertices() const;
588
596 const typename gsMesh<T>::gsVertexHandle &getVertex(const size_t vertexIndex) const;
597
598 /*
604 size_t getVertexIndex(const typename gsMesh<T>::gsVertexHandle &vertex) const;
605
614 size_t getGlobalVertexIndex(const size_t localVertexIndex, const size_t triangleIndex) const;
615
622 T getBoundaryLength() const;
623
634 std::vector<T> getCornerLengths(/*const*/ std::vector<index_t> &corners) const;
635 //std::vector<T> getBoundaryPartLengths(const std::vector<size_t >& corners) const;
636
644 const std::vector<T> getBoundaryChordLengths() const;
645
655 T getShortestBoundaryDistanceBetween(size_t i, size_t j) const;
656
666 T getHalfedgeLength(const size_t originVertexIndex, const size_t endVertexIndex) const;
667
680 const std::queue<Halfedge>
681 getOppositeHalfedges(const size_t vertexIndex, const bool innerVertex = 1) const;
682
698 short_t isTriangleVertex(size_t vertexIndex, size_t triangleIndex) const;
699
701 std::list<size_t> getBoundaryVertexIndices() const
702 {
703 return m_boundary.getVertexIndices();
704 }
705
707 size_t findVertex(const typename gsMesh<T>::gsVertexHandle& vertex) const
708 {
709 return findVertex(vertex->x(), vertex->y(), vertex->z());
710 }
711
713 size_t findVertex(T x, T y, T z, bool sorted = false, real_t tol = 1e-6) const;
714
716 const typename gsMesh<T>::gsVertexHandle &getVertexUnsorted(const size_t globIndex) const
717 {
718 return this->m_vertex[globIndex];
719 }
720
721 size_t unsorted(const size_t index) const
722 {
723 return m_inverseSorting[index];
724 }
725
726private:
735 bool isBoundaryVertex(const size_t internVertexIndex) const;
736
737 public:
746 size_t getInternVertexIndex(const typename gsMesh<T>::gsVertexHandle &vertex) const;
747
748 private:
762 const Halfedge
763 getInternHalfedge(const typename gsMesh<T>::gsFaceHandle &triangle, size_t numberOfHalfedge) const;
764
777 void sortVertices();
778
779 std::vector<Halfedge> m_halfedges;
781 size_t m_n;
782
783 std::vector<index_t> m_inverseSorting;
784 std::vector<index_t> m_sorting;
785 T m_precision;
786
787
788};//class gsHalfEdgeMesh
789
790} // namespace gismo
791
792#ifndef GISMO_BUILD_LIB
793#include GISMO_HPP_HEADER(gsHalfEdgeMesh.hpp)
794#endif
Class that maintains boundary of triangle mesh.
Definition gsHalfEdgeMesh.h:379
T getDistanceBetween(const size_t &i, const size_t &j) const
Get distance between vertices.
Definition gsHalfEdgeMesh.h:500
size_t getNumberOfVertices() const
Get number of vertices.
Definition gsHalfEdgeMesh.h:407
T getShortestDistanceBetween(const size_t &i, const size_t &j, T precision) const
Get distance between vertices.
Definition gsHalfEdgeMesh.h:477
Boundary()
Empty Constructor.
Definition gsHalfEdgeMesh.h:383
bool isVertexContained(const size_t &internVertexIndex) const
Tells if vertex is contained in boundary chain.
Definition gsHalfEdgeMesh.h:518
const std::vector< T > getHalfedgeLengths() const
Get halfedge lengths.
Definition gsHalfEdgeMesh.h:437
std::vector< Chain > m_boundary
boundary chains
Definition gsHalfEdgeMesh.h:538
const std::list< size_t > getVertexIndices() const
Get list of vertex indices in the chain.
Definition gsHalfEdgeMesh.h:455
Boundary(const std::vector< Halfedge > &halfedges)
Constructor.
T getLength() const
Get length.
Definition gsHalfEdgeMesh.h:422
Class that maintains chain of halfedges.
Definition gsHalfEdgeMesh.h:157
std::list< Halfedge > m_chainedHalfedges
list of halfedges
Definition gsHalfEdgeMesh.h:360
bool isEmpty() const
Tells whether chain is empty or not.
Definition gsHalfEdgeMesh.h:170
Class that maintains directed halfedges in any dimension.
Definition gsHalfEdgeMesh.h:65
bool isNext(const Halfedge &previousHalfedge) const
Tells if halfedge can be added at beginning.
Definition gsHalfEdgeMesh.h:118
size_t m_end
index of end vertex
Definition gsHalfEdgeMesh.h:131
bool isPrev(const Halfedge &nextHalfedge) const
Tells if halfedge can be added at end.
Definition gsHalfEdgeMesh.h:110
T m_length
length of halfedge
Definition gsHalfEdgeMesh.h:132
size_t m_origin
index of origin vertex
Definition gsHalfEdgeMesh.h:130
Halfedge(const size_t origin=0, const size_t end=0, const T length=0)
This constructor sets the origin- and * end-point indices as well as length to preferred values.
Definition gsHalfEdgeMesh.h:75
size_t getEnd() const
Get end vertex index.
Definition gsHalfEdgeMesh.h:97
bool isTwin(const Halfedge &halfedge) const
Tells if halfedge is twin.
Definition gsHalfEdgeMesh.h:126
T getLength() const
Get length of halfedge.
Definition gsHalfEdgeMesh.h:103
size_t getOrigin() const
Get origin vertex index.
Definition gsHalfEdgeMesh.h:91
gsHalfEdgeMesh is a gsMesh implementation that handles Halfedges
Definition gsHalfEdgeMesh.h:47
size_t getInternVertexIndex(const typename gsMesh< T >::gsVertexHandle &vertex) const
Get intern index of the vertex stored in disordered vertex vector The index i of the intern vector of...
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
std::vector< Halfedge > m_halfedges
vector of halfedges
Definition gsHalfEdgeMesh.h:779
Boundary m_boundary
boundary of the mesh
Definition gsHalfEdgeMesh.h:780
gsHalfEdgeMesh(size_t nv=0)
Default constructor.
Definition gsHalfEdgeMesh.h:544
const gsMesh< T >::gsVertexHandle & getVertexUnsorted(const size_t globIndex) const
Returns the handle to the vertex with index globIndex.
Definition gsHalfEdgeMesh.h:716
std::vector< index_t > m_sorting
vector that stores the internVertexIndices s. t. m_sorting[vertexIndex-1] = internVertexIndex
Definition gsHalfEdgeMesh.h:784
size_t m_n
number of inner vertices in the mesh
Definition gsHalfEdgeMesh.h:781
std::vector< index_t > m_inverseSorting
vector of indices s. t. m_inverseSorting[internVertexIndex] = vertexIndex
Definition gsHalfEdgeMesh.h:783
std::list< size_t > getBoundaryVertexIndices() const
Returns the vertex indices of the boundary.
Definition gsHalfEdgeMesh.h:701
Class Representing a triangle mesh with 3D vertices.
Definition gsMesh.h:32
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
Provides declaration of the Mesh class.
The G+Smo namespace, containing all definitions for the library.