G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsSolidHeVertex.h
Go to the documentation of this file.
1
14#pragma once
15
18
19namespace gismo {
20
21template <class T> class gsSolidHalfEdge;
22
23template <class T>
24class gsSolidHeVertex : public gsSolidElement<T>
25{
26public:
27 # define Eigen gsEigen
28 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29# undef Eigen
30 typedef T scalar_t;
31 typedef gsSolidElement<T> SolidElement;
32 typedef typename SolidElement::gsSolidHeVertexHandle gsSolidHeVertexHandle;
33 typedef typename SolidElement::gsSolidHalfEdgeHandle gsSolidHalfEdgeHandle;
34 typedef typename SolidElement::gsSolidHalfFaceHandle gsSolidHalfFaceHandle;
35
36// Data members
37public:
38 gsVector3d<T> coords; // TODO: should be inherited instead, makes it more naturally
39 // halfedge out of this vertex
40 gsSolidHalfEdgeHandle hed;
41
42public:
43 gsSolidHeVertex(scalar_t x, scalar_t y, scalar_t z = 0) : SolidElement(), coords(x,y,z), hed(0) { }
44 gsSolidHeVertex(scalar_t x, scalar_t y, scalar_t z, int i) : SolidElement(i), coords(x,y,z), hed(0) { }
45
46 virtual ~gsSolidHeVertex(){ }
47
49 void move(scalar_t dx, scalar_t dy, scalar_t dz) {coords.x() += dx;coords.y() += dy;coords.z() += dz;}
50
51//--------------------------------------------------------------------------
52// const members
53public:
54 gsVector3d<T> getCoordinate() const {return coords;}
55 T x () const { return coords(0); }
56 T y () const { return coords(1); }
57 T z () const { return coords(2); }
58
59 std::ostream &print(std::ostream &os) const;
60
62 std::vector<gsSolidHalfFaceHandle> getHalfFaces() const;
63
65 gsSolidHalfEdgeHandle getHalfEdge(gsSolidHeVertexHandle anotherVertex) const;
66
68 bool hasHalfEdge(gsSolidHeVertexHandle anotherVertex) const;
69
71 std::vector< gsSolidHalfFaceHandle > getFacesContaining2Vertices(gsSolidHeVertexHandle anotherVertex, bool const & IsBoundaryHalfEdge=false) const;
72
74 gsSolidHalfEdgeHandle getHalfEdgeOnFace(gsSolidHalfFaceHandle f, bool dest);
75
77 std::vector<gsSolidHalfEdgeHandle> halfEdges() const;
78
81 bool isEquiv(gsSolidHeVertexHandle other, T tol) const
82 { using std::abs;if ( abs(x()-other->x())<=tol && abs(y()-other->y())<=tol && abs(z()-other->z())<=tol ) return true; return false; }
83};
84
85//=============================================================================
86// SOURCE
87//=============================================================================
88template <class T>
89std::ostream &gsSolidHeVertex<T>::print(std::ostream &os) const
90{
91 os<<"Vertex " << this->getId() << "( "<<coords.x() << " " << coords.y() << " " << coords.z() << " )\n";
92 return os;
93}
94
95template <class T>
96std::vector<typename gsSolidHeVertex<T>::gsSolidHalfFaceHandle> gsSolidHeVertex<T>::getHalfFaces() const
97{
98 // See gsSolid<T>::getHEwrtTwoVertexIDs for algorithm explaination
99 std::vector< gsSolidHalfFaceHandle > faceList;
100 gsSolidHalfEdgeHandle he1 = hed;
101 gsSolidHalfEdgeHandle instant_he = he1;
102 do
103 {
104 faceList.push_back(instant_he->face);
105 instant_he = instant_he->prev->mate;
106 } while (instant_he!= he1);
107 return faceList;
108}
109
110template <class T>
111typename gsSolidHeVertex<T>::gsSolidHalfEdgeHandle gsSolidHeVertex<T>::getHalfEdge(gsSolidHeVertexHandle anotherVertex) const
112{
113 // Theoretical background: ID1: the current vertex, ID2: = anotherVertex. Let he1 is the HE emanating from ID1, then he1->prev and he1 are the two HEs of 1 face containing ID1.
114 // Furthermore: he1->prev->mate and he1->prev->mate->pre are the two HEs of the adjacent face containing ID1 in a CCW fashion.
115 // Continue to do that way, we can access all HEs emanating or shooting at ID1
116 const gsSolidHalfEdgeHandle he1 = hed;
117 gsSolidHalfEdgeHandle instant_he = he1;
118 do
119 {
120 // check if target of instant_he is ID2
121 if (instant_he->target()==anotherVertex)
122 return instant_he;
123 instant_he = instant_he->prev->mate;
124 } while (instant_he!=he1);
125
126 GISMO_ERROR("ERROR:gsSolidHeVertex.h: No HE is found while it is supposed to be existent");
127}
128
129template <class T>
130bool gsSolidHeVertex<T>::hasHalfEdge(gsSolidHeVertexHandle anotherVertex) const
131{
132 gsSolidHalfEdgeHandle he1 = hed;
133 gsSolidHalfEdgeHandle instant_he = he1;
134 do
135 {
136 if (instant_he->target()==anotherVertex) {return true;};
137 instant_he = instant_he->prev->mate;
138 } while (instant_he!=he1);
139 return false;
140}
141
142template <class T>
143std::vector< typename gsSolidHeVertex<T>::gsSolidHalfFaceHandle >
144// *isBoundaryHalfEdge* = is an existing half-edge
145gsSolidHeVertex<T>::getFacesContaining2Vertices(gsSolidHeVertexHandle anotherVertex, bool const & IsBoundaryHalfEdge) const
146{
147 std::vector<gsSolidHalfFaceHandle> faceList;
148 if (IsBoundaryHalfEdge)
149 {
150 gsSolidHalfEdgeHandle he = getHalfEdge(anotherVertex);
151 // as this is a boundary edge, there are exactly two faces incident to the edge
152 faceList.push_back(he->face);
153 faceList.push_back(he->mate->face);
154 }
155 else
156 {
157 // as this is NOT a boundary edge, there are only ONE face containing the edge
158 std::vector<gsSolidHalfFaceHandle> faceList1;
159 std::vector<gsSolidHalfFaceHandle> faceList2;
160 faceList1 = getHalfFaces();
161 faceList2 = anotherVertex->getHalfFaces();
162 // find intersection of faceList and faceList2
163 for (unsigned i=0;i!=faceList1.size();i++)
164 {
165 for (unsigned j=0;j!=faceList2.size();j++)
166 {
167 if (faceList1[i]==faceList2[j]) {faceList.push_back(faceList1[i]); break;};
168 };
169 };
170
171 };
172 return faceList;
173}
174
175template<class T>
176typename gsSolidHeVertex<T>::gsSolidHalfEdgeHandle gsSolidHeVertex<T>::getHalfEdgeOnFace(typename gsSolidHeVertex<T>::gsSolidHalfFaceHandle f, bool dest)
177{
178 gsSolidHalfEdgeHandle currentEdge = hed;
179 while(1)
180 {
181 if(!dest && currentEdge->face == f) return currentEdge;
182 currentEdge = currentEdge->mate;
183 if(dest && currentEdge->face == f) return currentEdge;
184 currentEdge = currentEdge->next;
185 assert(currentEdge != hed); // didn't find the face
186 }
187}
188
189template<class T>
190std::vector<typename gsSolidHeVertex<T>::gsSolidHalfEdgeHandle> gsSolidHeVertex<T>::halfEdges() const
191{
192 gsSolidHalfEdgeHandle he1 = hed;
193 gsSolidHalfEdgeHandle instant_he = he1;
194 std::vector<gsSolidHalfEdgeHandle> heSet;
195 do
196 {
197 heSet.push_back(instant_he);
198 instant_he = instant_he->prev->mate;
199 } while (instant_he!=he1);
200 return heSet;
201}
202
203} // namespace gismo
204
205
#define GISMO_ERROR(message)
Definition gsDebug.h:118
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides gsSolidElement class - interface for an element (vertex, edge or face) of a solid.
EIGEN_STRONG_INLINE abs_expr< E > abs(const E &u)
Absolute value.
Definition gsExpressions.h:4486
The G+Smo namespace, containing all definitions for the library.