gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MVertex.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #ifndef MVERTEX_H
7 #define MVERTEX_H
8 
9 #include <cmath>
10 #include <stdio.h>
11 #include <set>
12 #include <map>
13 #include <fstream>
14 #include "SPoint2.h"
15 #include "SPoint3.h"
17 
18 class GEntity;
19 class GEdge;
20 class GFace;
21 class MVertex;
22 
23 // A mesh vertex (a "node").
24 class MVertex {
25 protected:
26  // the id of the vertex: this number is unique and is guaranteed never to
27  // change once a vertex has been created, unless the mesh is explicitly
28  // renumbered
29  std::size_t _num;
30  // a vertex index, used during mesh generation or for some IO operations (this
31  // index is not necessarily unique, can change after mesh renumbering,
32  // etc.). By convention, vertices with negative indices are not saved. (On
33  // some architectures _index will be smaller than _num: this is OK, as _index
34  // is only used for partial indexing in 2D and 3D meshing, or for IO formats
35  // that don't support 64 bit indexing; _index is destined to be eventually
36  // removed anyway.)
37  long int _index;
38  // a visibility and polynomial order flags
40  // the cartesian coordinates of the vertex
41  double _x, _y, _z;
42  // the geometrical entity the vertex is associated with
44 
45 public:
46  MVertex(double x, double y, double z, GEntity *ge = nullptr,
47  std::size_t num = 0);
48  virtual ~MVertex() {}
49  void deleteLast();
50 
51  // get/set the visibility flag
52  virtual char getVisibility() { return _visible; }
53  virtual void setVisibility(char val) { _visible = val; }
54 
55  // get the "polynomial order" of the vertex
56  int getPolynomialOrder() { return _order; }
57  void setPolynomialOrder(int order) { _order = (char)order; }
58 
59  // get/set the coordinates
60  double x() const { return _x; }
61  double y() const { return _y; }
62  double z() const { return _z; }
63  double &x() { return _x; }
64  double &y() { return _y; }
65  double &z() { return _z; }
66 
67  SPoint3 point() const { return SPoint3(_x, _y, _z); }
68  void setXYZ(double x, double y, double z)
69  {
70  _x = x;
71  _y = y;
72  _z = z;
73  }
74  void setXYZ(const SPoint3& pt)
75  {
76  _x = pt.x();
77  _y = pt.y();
78  _z = pt.z();
79  }
80 
81  // get/set the parent entity
82  GEntity *onWhat() const { return _ge; }
83  void setEntity(GEntity *ge) { _ge = ge; }
84 
85  // get the immutab vertex number
86  std::size_t getNum() const { return _num; }
87 
88  // force the immutable number (this should never be used, except when
89  // explicitly renumbering the mesh)
90  void forceNum(std::size_t num);
91 
92  // get/set the index
93  long int getIndex() const { return _index; }
94  void setIndex(long int index) { _index = index; }
95 
96  // get/set ith parameter
97  virtual bool getParameter(int i, double &par) const
98  {
99  par = 0.;
100  return false;
101  }
102  virtual bool setParameter(int i, double par) { return false; }
103 
104  // measure distance to another vertex
105  double distance(MVertex *const v)
106  {
107  double dx = _x - v->x();
108  double dy = _y - v->y();
109  double dz = _z - v->z();
110  return std::sqrt(dx * dx + dy * dy + dz * dz);
111  }
112 
113  // IO routines
114  void writeMSH(FILE *fp, bool binary = false, bool saveParametric = false,
115  double scalingFactor = 1.0);
116  void writeMSH2(FILE *fp, bool binary = false, bool saveParametric = false,
117  double scalingFactor = 1.0);
118  void writePLY2(FILE *fp);
119  void writeVRML(FILE *fp, double scalingFactor = 1.0);
120  void writeUNV(FILE *fp, bool officialExponentFormat,
121  double scalingFactor = 1.0);
122  void writeVTK(FILE *fp, bool binary = false, double scalingFactor = 1.0,
123  bool bigEndian = false);
124  void writeMATLAB(FILE *fp, int type, bool binary, double scalingFactor = 1.0);
125  void writeTOCHNOG(FILE *fp, int dim, double scalingFactor = 1.0);
126  void writeMESH(FILE *fp, double scalingFactor = 1.0);
127  void writeOFF(FILE *fp, double scalingFactor = 1.0);
128  void writeNEU(FILE *fp, int dim, double scalingFactor = 1.0);
129  void writeBDF(FILE *fp, int format = 0, double scalingFactor = 1.0);
130  void writeINP(FILE *fp, double scalingFactor = 1.0);
131  void writeKEY(FILE *fp, double scalingFactor = 1.0);
132  void writeRAD(FILE *fp, double scalingFactor = 1.0);
133  void writeDIFF(FILE *fp, bool binary, double scalingFactor = 1.0);
134  void writeSU2(FILE *fp, int dim, double scalingFactor = 1.0);
135 };
136 
137 class MEdgeVertex : public MVertex {
138 protected:
139  double _u, _lc;
140 
141 public:
143 
144  MEdgeVertex(double x, double y, double z, GEntity *ge, double u,
145  std::size_t num = 0, double lc = -1.0)
146  : MVertex(x, y, z, ge, num), _u(u), _lc(lc), bl_data(nullptr)
147  {
148  }
149  virtual ~MEdgeVertex()
150  {
151  if(bl_data) delete bl_data;
152  }
153  virtual bool getParameter(int i, double &par) const
154  {
155  if(i != 0) return false;
156  par = _u;
157  return true;
158  }
159  virtual bool setParameter(int i, double par)
160  {
161  if(i != 0) return false;
162  _u = par;
163  return true;
164  }
165  double getLc() const { return _lc; }
166 };
167 
168 class MFaceVertex : public MVertex {
169 protected:
170  double _u, _v;
171 
172 public:
174 
175  MFaceVertex(double x, double y, double z, GEntity *ge, double u, double v,
176  std::size_t num = 0)
177  : MVertex(x, y, z, ge, num), _u(u), _v(v), bl_data(nullptr)
178  {
179  }
180  virtual ~MFaceVertex()
181  {
182  if(bl_data) delete bl_data;
183  }
184  virtual bool getParameter(int i, double &par) const
185  {
186  if(i == 0) {
187  par = _u;
188  return true;
189  }
190  else if(i == 1) {
191  par = _v;
192  return true;
193  }
194  return false;
195  }
196  virtual bool setParameter(int i, double par)
197  {
198  if(i == 0) {
199  _u = par;
200  return true;
201  }
202  else if(i == 1) {
203  _v = par;
204  return true;
205  }
206  return false;
207  }
208 };
209 
211  static double tolerance;
212 
213 public:
214  static double getTolerance();
215  bool operator()(const MVertex *v1, const MVertex *v2) const;
216 };
217 
219  bool operator()(const MVertex *v1, const MVertex *v2) const
220  {
221  return v1->getNum() < v2->getNum();
222  }
223 };
224 
226  bool operator()(const MVertex *v1, const MVertex *v2) const
227  {
228  return v1->getNum() == v2->getNum();
229  }
230 };
231 
233  size_t operator()(const MVertex *v) const { return v->getNum(); }
234 };
235 
236 bool reparamMeshEdgeOnFace(MVertex *v1, MVertex *v2, GFace *gf, SPoint2 &param1,
237  SPoint2 &param2);
238 bool reparamMeshVertexOnFace(MVertex const *v, const GFace *gf, SPoint2 &param,
239  bool onSurface = true, bool failOnSeam = true,
240  int dir = 1);
241 bool reparamMeshVertexOnEdge(MVertex *v, const GEdge *ge, double &param);
242 
243 double angle3Vertices(const MVertex *p1, const MVertex *p2, const MVertex *p3);
244 
245 inline double distance(MVertex *v1, MVertex *v2)
246 {
247  const double dx = v1->x() - v2->x();
248  const double dy = v1->y() - v2->y();
249  const double dz = v1->z() - v2->z();
250  return std::sqrt(dx * dx + dy * dy + dz * dz);
251 }
252 
253 #endif
MVertex::getPolynomialOrder
int getPolynomialOrder()
Definition: MVertex.h:56
MVertex::writeRAD
void writeRAD(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:380
MVertexPtrHash
Definition: MVertex.h:232
MVertexPtrLessThan
Definition: MVertex.h:218
MVertexPtrHash::operator()
size_t operator()(const MVertex *v) const
Definition: MVertex.h:233
reparamMeshEdgeOnFace
bool reparamMeshEdgeOnFace(MVertex *v1, MVertex *v2, GFace *gf, SPoint2 &param1, SPoint2 &param2)
Definition: MVertex.cpp:474
MVertex::~MVertex
virtual ~MVertex()
Definition: MVertex.h:48
MVertexPtrEqual::operator()
bool operator()(const MVertex *v1, const MVertex *v2) const
Definition: MVertex.h:226
MVertex::writeVRML
void writeVRML(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:191
MEdgeVertex::bl_data
MVertexBoundaryLayerData * bl_data
Definition: MVertex.h:142
MVertexPtrLessThan::operator()
bool operator()(const MVertex *v1, const MVertex *v2) const
Definition: MVertex.h:219
distance
double distance(MVertex *v1, MVertex *v2)
Definition: MVertex.h:245
MVertexPtrLessThanLexicographic::operator()
bool operator()(const MVertex *v1, const MVertex *v2) const
Definition: MVertex.cpp:412
GFace
Definition: GFace.h:33
MVertex::setPolynomialOrder
void setPolynomialOrder(int order)
Definition: MVertex.h:57
MVertex::writeUNV
void writeUNV(FILE *fp, bool officialExponentFormat, double scalingFactor=1.0)
Definition: MVertex.cpp:199
SPoint2
Definition: SPoint2.h:12
MEdgeVertex::MEdgeVertex
MEdgeVertex(double x, double y, double z, GEntity *ge, double u, std::size_t num=0, double lc=-1.0)
Definition: MVertex.h:144
MVertex::writeINP
void writeINP(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:364
MVertex
Definition: MVertex.h:24
MVertex::z
double z() const
Definition: MVertex.h:62
MFaceVertex::~MFaceVertex
virtual ~MFaceVertex()
Definition: MVertex.h:180
SPoint3
Definition: SPoint3.h:14
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
reparamMeshVertexOnEdge
bool reparamMeshVertexOnEdge(MVertex *v, const GEdge *ge, double &param)
Definition: MVertex.cpp:592
MEdgeVertex::_u
double _u
Definition: MVertex.h:139
MVertex::onWhat
GEntity * onWhat() const
Definition: MVertex.h:82
MVertex::z
double & z()
Definition: MVertex.h:65
MVertex::point
SPoint3 point() const
Definition: MVertex.h:67
MFaceVertex::_v
double _v
Definition: MVertex.h:170
MEdgeVertex::getParameter
virtual bool getParameter(int i, double &par) const
Definition: MVertex.h:153
MVertex::setXYZ
void setXYZ(const SPoint3 &pt)
Definition: MVertex.h:74
MFaceVertex::MFaceVertex
MFaceVertex(double x, double y, double z, GEntity *ge, double u, double v, std::size_t num=0)
Definition: MVertex.h:175
GEntity
Definition: GEntity.h:31
MVertex::_z
double _z
Definition: MVertex.h:41
MVertex::writeMESH
void writeMESH(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:274
MFaceVertex::getParameter
virtual bool getParameter(int i, double &par) const
Definition: MVertex.h:184
MEdgeVertex::getLc
double getLc() const
Definition: MVertex.h:165
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
MVertex::setParameter
virtual bool setParameter(int i, double par)
Definition: MVertex.h:102
MVertex::setIndex
void setIndex(long int index)
Definition: MVertex.h:94
MVertex::_y
double _y
Definition: MVertex.h:41
MEdgeVertex
Definition: MVertex.h:137
MEdgeVertex::setParameter
virtual bool setParameter(int i, double par)
Definition: MVertex.h:159
MEdgeVertex::~MEdgeVertex
virtual ~MEdgeVertex()
Definition: MVertex.h:149
MVertex::y
double & y()
Definition: MVertex.h:64
MVertex::writeBDF
void writeBDF(FILE *fp, int format=0, double scalingFactor=1.0)
Definition: MVertex.cpp:335
MVertex::writeVTK
void writeVTK(FILE *fp, bool binary=false, double scalingFactor=1.0, bool bigEndian=false)
Definition: MVertex.cpp:225
MVertex::setXYZ
void setXYZ(double x, double y, double z)
Definition: MVertex.h:68
MVertex::writeNEU
void writeNEU(FILE *fp, int dim, double scalingFactor=1.0)
Definition: MVertex.cpp:291
MVertex::writePLY2
void writePLY2(FILE *fp)
Definition: MVertex.cpp:184
MFaceVertex::setParameter
virtual bool setParameter(int i, double par)
Definition: MVertex.h:196
MVertex::writeSU2
void writeSU2(FILE *fp, int dim, double scalingFactor=1.0)
Definition: MVertex.cpp:396
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
MVertexPtrLessThanLexicographic
Definition: MVertex.h:210
MVertex::writeMATLAB
void writeMATLAB(FILE *fp, int type, bool binary, double scalingFactor=1.0)
Definition: MVertex.cpp:243
MVertexPtrLessThanLexicographic::getTolerance
static double getTolerance()
Definition: MVertex.cpp:410
MEdgeVertex::_lc
double _lc
Definition: MVertex.h:139
MVertex::writeMSH2
void writeMSH2(FILE *fp, bool binary=false, bool saveParametric=false, double scalingFactor=1.0)
Definition: MVertex.cpp:124
MVertex::getVisibility
virtual char getVisibility()
Definition: MVertex.h:52
MFaceVertex
Definition: MVertex.h:168
MVertex::writeMSH
void writeMSH(FILE *fp, bool binary=false, bool saveParametric=false, double scalingFactor=1.0)
Definition: MVertex.cpp:55
MVertex::_num
std::size_t _num
Definition: MVertex.h:29
MVertexPtrLessThanLexicographic::tolerance
static double tolerance
Definition: MVertex.h:211
MVertex::forceNum
void forceNum(std::size_t num)
Definition: MVertex.cpp:48
MVertex::deleteLast
void deleteLast()
Definition: MVertex.cpp:41
MVertex::x
double & x()
Definition: MVertex.h:63
reparamMeshVertexOnFace
bool reparamMeshVertexOnFace(MVertex const *v, const GFace *gf, SPoint2 &param, bool onSurface=true, bool failOnSeam=true, int dir=1)
Definition: MVertex.cpp:522
MVertex::_order
char _order
Definition: MVertex.h:39
MVertex::_x
double _x
Definition: MVertex.h:41
MVertex::getParameter
virtual bool getParameter(int i, double &par) const
Definition: MVertex.h:97
MVertex::setVisibility
virtual void setVisibility(char val)
Definition: MVertex.h:53
MVertex::getIndex
long int getIndex() const
Definition: MVertex.h:93
MVertex::_index
long int _index
Definition: MVertex.h:37
MFaceVertex::_u
double _u
Definition: MVertex.h:170
GEdge
Definition: GEdge.h:26
MVertexBoundaryLayerData
Definition: MVertexBoundaryLayerData.h:18
MFaceVertex::bl_data
MVertexBoundaryLayerData * bl_data
Definition: MVertex.h:173
MVertex::_ge
GEntity * _ge
Definition: MVertex.h:43
MVertex::writeKEY
void writeKEY(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:372
MVertexPtrEqual
Definition: MVertex.h:225
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
MVertex::_visible
char _visible
Definition: MVertex.h:39
MVertex::writeTOCHNOG
void writeTOCHNOG(FILE *fp, int dim, double scalingFactor=1.0)
Definition: MVertex.cpp:255
MVertex::writeOFF
void writeOFF(FILE *fp, double scalingFactor=1.0)
Definition: MVertex.cpp:283
MVertex::y
double y() const
Definition: MVertex.h:61
MVertex::distance
double distance(MVertex *const v)
Definition: MVertex.h:105
SPoint3.h
MVertex::setEntity
void setEntity(GEntity *ge)
Definition: MVertex.h:83
MVertex::writeDIFF
void writeDIFF(FILE *fp, bool binary, double scalingFactor=1.0)
Definition: MVertex.cpp:388
MVertex::MVertex
MVertex(double x, double y, double z, GEntity *ge=nullptr, std::size_t num=0)
Definition: MVertex.cpp:26
angle3Vertices
double angle3Vertices(const MVertex *p1, const MVertex *p2, const MVertex *p3)
Definition: MVertex.cpp:16
MVertexBoundaryLayerData.h
MVertex::x
double x() const
Definition: MVertex.h:60
SPoint2.h