G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsSolidHalfFace.h
Go to the documentation of this file.
1 
14 #pragma once
15 
16 
18 
19 namespace gismo {
20 
21 
22 
23 template <class T>
24 class gsSolidHalfFace : public gsSolidElement<T>
25 {
26 public:
27  typedef gsSolidElement<T> SolidElement;
28  typedef T Scalar_t;
29  typedef typename gsSolidElement<T>::gsSolidHeVertexHandle gsSolidHeVertexHandle;
30  typedef typename gsSolidElement<T>::gsSolidHalfEdgeHandle gsSolidHalfEdgeHandle;
31  typedef typename gsSolidElement<T>::gsSolidHalfFaceHandle gsSolidHalfFaceHandle;
32  typedef typename gsSolidElement<T>::gsVolumeHandle gsVolumeHandle;
33 
34 public:
35  gsVolumeHandle vol; // Point to the volume that the face belongs to
36  gsSolidHalfFaceHandle mate;
37  // Every half-edge represents an edge loop
38  // loop[0] is the outer loop oriented CCW
39  std::vector<gsSolidHalfEdgeHandle > loop;
40  gsTrimSurface<T> * surf;
41 
42 public:
43  gsSolidHalfFace() : SolidElement() { vol = 0; }
44 
45  explicit gsSolidHalfFace(int i) : SolidElement(i) { vol = 0; }
46 
47  virtual ~gsSolidHalfFace() { delete surf; }
48 
50  void setBoundary(std::vector<gsSolidHalfEdgeHandle> const & hedges);
51 
52 //----------------------------------------------------------------------------
53 // const members
54 public:
56  int loopN() const {return loop.size();}
57 
59  virtual std::ostream &print(std::ostream &os) const;
60 
62  std::vector<gsSolidHeVertexHandle> getVertices() const;
63 
65  std::vector<gsSolidHalfEdgeHandle> getHalfEdges() const;
66 
67  gsSolidHalfEdgeHandle getHalfEdgeFromLoopOrder(unsigned loopNumber,int curveNumber) const
68  {
69  gsSolidHalfEdgeHandle he=*(loop.begin()+loopNumber);
70  for ( int i=0; i != surf->domain().loop(loopNumber).size(); ++i)
71  {
72  if (i==curveNumber) break;
73  he=he->next;
74  }
75  return he;
76  }
77 
78  gsSolidHalfEdgeHandle getHalfEdgeFromBoundaryOrder(unsigned curveNumber) const {return getHalfEdgeFromLoopOrder(0, curveNumber);}
79 
80  unsigned nCurvesOfOneLoop(unsigned loopNumber) { return surf->domain().loop(loopNumber).curves().size(); }
81 
83  int indexOfEdge(gsSolidHalfEdgeHandle e) const;
84 
86  int indexOfVertex(gsSolidHeVertexHandle v) const;
87 
89  bool containsVertex(const gsSolidHeVertexHandle v) const;
90 
91 }; // end class
92 
93 //=============================================================================
94 // SOURCE
95 //=============================================================================
96 template <class T>
97 std::ostream &operator<<(std::ostream &os, const gsSolidHalfFace<T>& obj)
98 {return obj.print(os); }
99 
100 template <class T>
101 void gsSolidHalfFace<T>::setBoundary(std::vector<gsSolidHalfEdgeHandle> const & hedges)
102 {
103  typename std::vector<gsSolidHalfEdgeHandle>::const_iterator p = hedges.begin();
104  loop.push_back(*p);
105  (*p)->prev = hedges.back();
106  (*p)->face = this;
107  for ( typename std::vector<gsSolidHalfEdgeHandle>::const_iterator
108  it = hedges.begin()+1; it!= hedges.end(); ++it)
109  {
110  (*it)->face = this;
111  (*it)->prev = *p;
112  (*p)->next = *it;
113  p++;
114  }
115  (*p)->next = hedges.front();
116 }
117 
118 template <class T>
119 std::ostream &gsSolidHalfFace<T>::print(std::ostream &os) const
120 {
121  os<<"\nHalf face ID = "<< this->getId() << " with ";
122  os<<"Coordinates of vertices of face 0: \n";
123  std::vector<gsSolidHeVertexHandle> fvert = getVertices();
124  for (typename std::vector<gsSolidHeVertexHandle>::const_iterator it=fvert.begin();it!=fvert.end();++it) os<<**it;
125  os<<"\n";
126  return os;
127 }
128 
129 template <class T>
130 std::vector<typename gsSolidHalfFace<T>::gsSolidHeVertexHandle> gsSolidHalfFace<T>::getVertices() const
131 {
132  std::vector<gsSolidHeVertexHandle> vert;
133  gsSolidHalfEdgeHandle edge1 = loop[0];
134  vert.push_back(edge1->source);
135  gsSolidHalfEdgeHandle current_edge=edge1->next;
136  while ( current_edge != edge1 )
137  {
138  vert.push_back(current_edge->source);
139  current_edge=current_edge->next;
140  }
141  return vert;
142 }
143 
144 template <class T>
145 std::vector< typename gsSolidHalfFace<T>::gsSolidHalfEdgeHandle > gsSolidHalfFace<T>::getHalfEdges() const
146 {
147  std::vector<gsSolidHalfEdgeHandle> HEs;
148  gsSolidHalfEdgeHandle edge1 = loop[0];
149  HEs.push_back(edge1);
150  gsSolidHalfEdgeHandle current_edge=edge1->next;
151  while ( current_edge != edge1 )
152  {
153  HEs.push_back(current_edge);
154  current_edge=current_edge->next;
155  }
156  return HEs;
157 }
158 
159 template <class T>
160 int gsSolidHalfFace<T>::indexOfEdge(gsSolidHalfEdgeHandle e) const
161 {
162  int idx = 0;
163  gsSolidHalfEdgeHandle tempEdge = this->loop[0];
164  while(tempEdge != e)
165  {
166  tempEdge = tempEdge->next;
167  idx++;
168  assert(tempEdge != this->loop[0]); // went round the loop without finding the edge
169  }
170  return idx;
171 }
172 
173 template <class T>
174 int gsSolidHalfFace<T>::indexOfVertex(gsSolidHeVertexHandle v) const
175 {
176  int idx = 0;
177  gsSolidHalfEdgeHandle tempEdge = this->loop[0];
178  while(tempEdge->source != v)
179  {
180  tempEdge = tempEdge->next;
181  idx++;
182  assert(tempEdge != this->loop[0]); // went round the loop without finding the vertex
183  }
184  return idx;
185 }
186 
187 template <class T>
188 bool gsSolidHalfFace<T>::containsVertex(const gsSolidHeVertexHandle v) const
189 {
190  gsSolidHalfEdgeHandle tempEdge = this->loop[0];
191  do
192  {
193  tempEdge = tempEdge->next;
194  if (tempEdge->source == v) { return true; };
195  } while (tempEdge != this->loop[0]);
196  return false;
197 }
198 
199 
200 } // namespace gismo
Provides gsSolidElement class - interface for an element (vertex, edge or face) of a solid...