G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMesh.h
Go to the documentation of this file.
1 
14 #pragma once
15 
18 #include <gsUtils/gsMesh/gsFace.h>
19 #include <gsUtils/gsMesh/gsEdge.h>
20 #include <gsUtils/gsSortedVector.h>
21 
22 
23 namespace gismo {
24 
30 template <class T>
31 class GISMO_EXPORT gsMesh : public gsMeshElement<T>
32 {
33 public:
34  typedef memory::shared_ptr<gsMesh> Ptr;
35  typedef memory::unique_ptr<gsMesh> uPtr;
36  typedef gsMeshElement<T> MeshElement;
37  typedef typename MeshElement::scalar_t scalar_t;
39  typedef typename MeshElement::gsFaceHandle FaceHandle;
40  typedef typename MeshElement::gsEdgeHandle EdgeHandle;
41  //typedef typename gsMeshElement<Vertex>::gsCellHandle gsCellHandle;
42  typedef gsEdge<T> Edge;
43  typedef gsVertex<T> Vertex;
44 
45 public:
46 
47  gsMesh() : MeshElement()
48  { }
49 
50  gsMesh(const gsMesh<T> & mesh) : MeshElement()
51  {
52  this->operator=(mesh);
53  }
54 
55  gsMesh& operator=(const gsMesh& other)
56  {
57  if (this!=&other)
58  {
59  // Assert a already cleared gsMesh (getId)
60  cloneAll(other.m_vertex, m_vertex); // fine, new pointers for all vertices
61 
62  // copy all pointers to it's original counterpart in face
63  cloneAll(other.m_face, m_face);
64  for (size_t i = 0; i < other.m_face.size(); ++i)
65  {
66  for (size_t j = 0; j != other.m_face[i]->vertices.size(); ++j)
67  {
68  GISMO_ASSERT(m_vertex[other.m_face[i]->vertices[j]->getId()]->getId() == other.m_face[i]->vertices[j]->getId(), "gsMesh(const gsMesh<T> & mesh): getId() of vertex and face don't match");
69  m_face[i]->vertices[j] = m_vertex[other.m_face[i]->vertices[j]->getId()];
70  }
71  }
72 
73  // iterate over all edges and make them new
74  m_edge = other.m_edge;
75  for (size_t i = 0; i != other.m_edge.size(); ++i)
76  {
77  // The two GISMO_ASSERTS were removed as part of PR #448, which got integrated into PR #421.
78  //GISMO_ASSERT(other.m_edge[i].source->getId() == m_vertex[i]->getId(), "gsMesh(const gsMesh<T> & mesh): getId() of vertex and edge.source don't match");
79  m_edge[i].source = m_vertex[other.m_edge[i].source->getId()];
80 
81  //GISMO_ASSERT(other.m_edge[i].source->getId() == m_vertex[i]->getId(), "gsMesh(const gsMesh<T> & mesh): getId() of vertex and edge.target don't match");
82  m_edge[i].target = m_vertex[other.m_edge[i].target->getId()];
83  }
84  }
85  return *this;
86  }
87 
94  explicit gsMesh(const gsBasis<T> & basis, int midPts = 0);
95 
96  virtual ~gsMesh();
97 
98  // void addVertex(gsVertexHandle v){
99  // vertices.push_back(v);
100  // if(!initialized) {
101  // bb.pMax.x() = bb.pMin.x() = v->x();
102  // bb.pMax.y() = bb.pMin.y() = v->y();
103  // bb.pMax.z() = bb.pMin.z() = v->z();
104  // initialized = true;
105  // }
106  // else {
107  // if (bb.pMax.x() < v->x())
108  // bb.pMax.x() = v->x();
109  // if (bb.pMin.x() > v->x())
110  // bb.pMin.x() = v->x();
111 
112  // if (bb.pMax.y < v->y())
113  // bb.pMax.y = v->y();
114  // if (bb.pMin.y > v->y())
115  // bb.pMin.y = v->y();
116 
117  // if (bb.pMax.z() < v->z())
118  // bb.pMax.z() = v->z();
119  // if (bb.pMin.z() > v->z())
120  // bb.pMin.z() = v->z();
121  // }
122  // numVertices++;
123  // };
124 
125  VertexHandle addVertex(scalar_t const& x, scalar_t const& y, scalar_t const& z=0);
126 
127  VertexHandle addVertex(gsVector<T> const & u);
128 
129  void addEdge(VertexHandle v0, VertexHandle v1);
130 
131  void addEdge(int const vind0, int const vind1);
132 
133  void addEdge(gsVector<T> const & u0,
134  gsVector<T> const & u1 );
135 
136  FaceHandle addFace(std::vector<VertexHandle> const & vert);
137 
138  FaceHandle addFace(VertexHandle const & v0, VertexHandle const & v1,
139  VertexHandle const & v2);
140 
141  FaceHandle addFace(VertexHandle const & v0, VertexHandle const & v1,
142  VertexHandle const & v2, VertexHandle const & v3);
143 
144  FaceHandle addFace(std::vector<int> const & vert);
145 
146  FaceHandle addFace(const int v0, const int v1, const int v2);
147 
148  FaceHandle addFace(const int v0, const int v1, const int v2, const int v3);
149 
154  // works for 2D vertices for now
155  void addLine(gsMatrix<T> const & points);
156 
160  void addLine(VertexHandle v0, VertexHandle v1, int midPts = 0);
161 
162  std::ostream &print(std::ostream &os) const;
163 
164 // bool getTurnDirection(gsVector3d<T> A, gsVector3d<T> B, gsVector3d<T> C)
165 // {
166 // gsVector3d<T> vec1 = B - A ;
167 // gsVector3d<T> vec2 = C - B ;
168 // gsVector3d<T> normal = vec2.cross( vec1 ) ;
169 // if (conditionedAngle( vec1, vec2, normal) >= EIGEN_PI)
170 // {
171 // return 1;
172 // }
173 // else
174 // {
175 // return 0;
176 // }
177 // }
178 
183  gsMesh& cleanMesh();
184 
185  gsMesh& reserve(size_t vertex, size_t face, size_t edge);
186 
187  size_t numVertices() const { return m_vertex.size(); }
188  size_t numEdges() const { return m_edge.size(); }
189  size_t numFaces() const { return m_face.size(); }
190 
191  const std::vector<VertexHandle > & vertices() const
192  { return m_vertex; }
193 
194  const std::vector<Edge > & edges() const
195  { return m_edge; }
196 
197  const std::vector<FaceHandle > & faces() const
198  { return m_face; }
199 
200  const Vertex & vertex(size_t i) const { return *m_vertex[i]; }
201  Vertex & vertex(size_t i) { return *m_vertex[i]; }
202 
203  const FaceHandle & face(size_t i) const { return m_face[i]; }
204  FaceHandle & face(size_t i) { return m_face[i]; }
205 
206  const Edge & edge(size_t i) const { return m_edge[i]; }
207  Edge & edge(size_t i) { return m_edge[i]; }
208 
209  gsVector<index_t> faceIndices(size_t i) const
210  {
211  const FaceHandle & f = face(i);
212  gsVector<index_t> res(f->vertices.size());
213  typename std::vector<VertexHandle >::const_iterator v;
214  for (size_t j = 0; j!=f->vertices.size(); ++j)
215  {
216  v = std::find(m_vertex.begin(), m_vertex.end(), f->vertices[j] );
217  //
218  res[j] = std::distance(m_vertex.begin(),v);
219  }
220  return res;
221  }
222 
223 public: //protected: -- todo
224 
225  std::vector<VertexHandle > m_vertex;
226  std::vector<FaceHandle > m_face;
227  gsSortedVector<Edge> m_edge;
228 };
229 
230 
231 } // namespace gismo
232 
233 #ifndef GISMO_BUILD_LIB
234 #include GISMO_HPP_HEADER(gsMesh.hpp)
235 #endif
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 &lt;j&gt; in the set ; by def...
Provides gsMeshElement class - a vertex, edge, face or cell of a gsMesh.
Provides gsFace class for a face of a gsMesh.
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
void cloneAll(It start, It end, ItOut out)
Clones all pointers in the range [start end) and stores new raw pointers in iterator out...
Definition: gsMemory.h:295
Class Representing a triangle mesh with 3D vertices.
Definition: gsMesh.h:31
Provides gsVertex class for a vertex of a gsMesh.
Provides gsEdge class for an edge of a gsMesh.
An std::vector with sorting capabilities.
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
gsVertex class that represents a 3D vertex for a gsMesh.
Definition: gsVertex.h:26