gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
meshGFaceDelaunayInsertion.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 MESH_GFACE_DELAUNAY_INSERTIONFACE_H
7 #define MESH_GFACE_DELAUNAY_INSERTIONFACE_H
8 
9 #include "MTriangle.h"
10 #include "MQuadrangle.h"
11 #include "STensor3.h"
12 #include "GEntity.h"
13 #include "MFace.h"
14 #include <list>
15 #include <set>
16 #include <map>
17 
18 class GModel;
19 class GFace;
20 class BDS_Mesh;
21 class BDS_Point;
22 
23 struct bidimMeshData {
24  std::map<MVertex *, int> indices;
25  std::vector<double> Us, Vs, vSizes, vSizesBGM;
26  std::vector<SMetric3> vMetricsBGM;
27  std::map<MVertex *, MVertex *> *equivalence;
28  std::map<MVertex *, SPoint2> *parametricCoordinates;
29  std::set<MEdge, MEdgeLessThan> internalEdges; // embedded edges
30  // std::set<MVertex*> internalVertices; // embedded vertices
31  inline void addVertex(MVertex *mv, double u, double v, double size,
32  double sizeBGM)
33  {
34  int index = Us.size();
35  if(mv->onWhat()->dim() == 2)
36  mv->setIndex(index);
37  else
38  indices[mv] = index;
40  auto it = parametricCoordinates->find(mv);
41  if(it != parametricCoordinates->end()) {
42  u = it->second.x();
43  v = it->second.y();
44  }
45  }
46  Us.push_back(u);
47  Vs.push_back(v);
48  vSizes.push_back(size);
49  vSizesBGM.push_back(sizeBGM);
50  }
51  inline int getIndex(MVertex *mv)
52  {
53  if(mv->onWhat()->dim() == 2) return mv->getIndex();
54  return indices[mv];
55  }
56  inline MVertex *equivalent(MVertex *v1) const
57  {
58  if(equivalence) {
59  auto it = equivalence->find(v1);
60  if(it == equivalence->end()) return nullptr;
61  return it->second;
62  }
63  return nullptr;
64  }
65  bidimMeshData(std::map<MVertex *, MVertex *> *e = nullptr,
66  std::map<MVertex *, SPoint2> *p = nullptr)
68  {
69  }
70 };
71 
72 void buildMetric(GFace *gf, double *uv, double *metric);
73 int inCircumCircleAniso(GFace *gf, double *p1, double *p2, double *p3,
74  double *p4, double *metric);
75 int inCircumCircleAniso(GFace *gf, MTriangle *base, const double *uv,
76  const double *metric, bidimMeshData &data);
77 
78 class MTri3 {
79 protected:
80  bool deleted;
81  double circum_radius;
83  MTri3 *neigh[3];
84 
85 public:
87  static int radiusNorm;
88  bool isDeleted() const { return deleted; }
89  void forceRadius(double r) { circum_radius = r; }
90  inline double getRadius() const { return circum_radius; }
91  inline MVertex *otherSide(int i)
92  {
93  MTri3 *n = neigh[i];
94  if(!n) return nullptr;
95  MVertex *v1 = base->getVertex((i + 2) % 3);
96  MVertex *v2 = base->getVertex(i);
97  for(int j = 0; j < 3; j++)
98  if(n->tri()->getVertex(j) != v1 && n->tri()->getVertex(j) != v2)
99  return n->tri()->getVertex(j);
100  return nullptr;
101  }
102  MTri3(MTriangle *t, double lc, SMetric3 *m = nullptr,
103  bidimMeshData *data = nullptr, GFace *gf = nullptr);
104  inline void setTri(MTriangle *t) { base = t; }
105  inline MTriangle *tri() const { return base; }
106  inline void setNeigh(int iN, MTri3 *n) { neigh[iN] = n; }
107  inline MTri3 *getNeigh(int iN) const { return neigh[iN]; }
108  int inCircumCircle(const double *p) const;
109  inline int inCircumCircle(double x, double y) const
110  {
111  const double p[2] = {x, y};
112  return inCircumCircle(p);
113  }
114  inline int inCircumCircle(const MVertex *v) const
115  {
116  return inCircumCircle(v->x(), v->y());
117  }
118  inline void setDeleted(bool d) { deleted = d; }
119  inline bool assertNeigh() const
120  {
121  if(deleted) return true;
122  for(int i = 0; i < 3; i++)
123  if(neigh[i] && (neigh[i]->isNeigh(this) == false)) return false;
124  return true;
125  }
126  inline bool isNeigh(const MTri3 *t) const
127  {
128  for(int i = 0; i < 3; i++)
129  if(neigh[i] == t) return true;
130  return false;
131  }
132 };
133 
136 
137 public:
138  inline bool operator()(const MTri3 *a, const MTri3 *b) const
139  {
140  if(a->getRadius() > b->getRadius()) return true;
141  if(a->getRadius() < b->getRadius()) return false;
142  return lf(a->tri()->getFace(0), b->tri()->getFace(0));
143  }
144 };
145 
146 void connectTriangles(std::list<MTri3 *> &);
147 void connectTriangles(std::vector<MTri3 *> &);
148 void connectTriangles(std::set<MTri3 *, compareTri3Ptr> &AllTris);
149 void bowyerWatson(
150  GFace *gf, int MAXPNT = 1000000000,
151  std::map<MVertex *, MVertex *> *equivalence = nullptr,
152  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr);
154  GFace *gf, std::map<MVertex *, MVertex *> *equivalence = nullptr,
155  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr,
156  std::vector<SPoint2> *true_boundary = nullptr);
158  GFace *gf, bool quad, std::map<MVertex *, MVertex *> *equivalence = nullptr,
159  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr);
161  GFace *gf, std::map<MVertex *, MVertex *> *equivalence = nullptr,
162  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr);
164  GFace *gf, const std::set<MVertex *> &constr_vertices,
165  std::map<MVertex *, MVertex *> *equivalence = nullptr,
166  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr);
168  GFace *gf, bool crossFieldClosestPoint = false,
169  std::map<MVertex *, MVertex *> *equivalence = nullptr,
170  std::map<MVertex *, SPoint2> *parametricCoordinates = nullptr);
171 
172 void delaunayMeshIn2D(std::vector<MVertex *> &, std::vector<MTriangle *> &,
173  bool removeBox = true,
174  std::vector<MEdge> *edgesToRecover = nullptr,
175  bool hilbertSort = true);
176 
177 struct edgeXface {
178  MVertex *v[2];
180  int i1;
181  int ori;
182  edgeXface(MTri3 *_t, int iFac) : t1(_t), i1(iFac), ori(1)
183  {
184  v[0] = t1->tri()->getVertex(iFac == 0 ? 2 : iFac - 1);
185  v[1] = t1->tri()->getVertex(iFac);
186  if(v[0]->getNum() > v[1]->getNum()) {
187  ori = -1;
188  MVertex *tmp = v[0];
189  v[0] = v[1];
190  v[1] = tmp;
191  }
192  }
193  inline MVertex *_v(int i) const { return v[i]; }
194  inline bool operator<(const edgeXface &other) const
195  {
196  if(_v(0)->getNum() < other._v(0)->getNum()) return true;
197  if(_v(0)->getNum() > other._v(0)->getNum()) return false;
198  if(_v(1)->getNum() < other._v(1)->getNum()) return true;
199  return false;
200  }
201  inline bool operator==(const edgeXface &other) const
202  {
203  if(_v(0)->getNum() == other._v(0)->getNum() &&
204  _v(1)->getNum() == other._v(1)->getNum())
205  return true;
206  return false;
207  }
208 };
209 
210 #endif
edgeXface::i1
int i1
Definition: meshGFaceDelaunayInsertion.h:180
compareTri3Ptr::operator()
bool operator()(const MTri3 *a, const MTri3 *b) const
Definition: meshGFaceDelaunayInsertion.h:138
parametricCoordinates
static void parametricCoordinates(MElement *t, GFace *gf, double u[4], double v[4], MVertex *close=nullptr)
Definition: meshGFaceOptimize.cpp:472
MTriangle.h
MTriangle::getFace
virtual MFace getFace(int num) const
Definition: MTriangle.h:91
MTri3::assertNeigh
bool assertNeigh() const
Definition: meshGFaceDelaunayInsertion.h:119
edgeXface::ori
int ori
Definition: meshGFaceDelaunayInsertion.h:181
buildMetric
void buildMetric(GFace *gf, double *uv, double *metric)
Definition: meshGFaceDelaunayInsertion.cpp:332
bidimMeshData::parametricCoordinates
std::map< MVertex *, SPoint2 > * parametricCoordinates
Definition: meshGFaceDelaunayInsertion.h:28
BDS_Mesh
Definition: BDS.h:339
SMetric3
Definition: STensor3.h:17
MTri3::isNeigh
bool isNeigh(const MTri3 *t) const
Definition: meshGFaceDelaunayInsertion.h:126
inCircumCircleAniso
int inCircumCircleAniso(GFace *gf, double *p1, double *p2, double *p3, double *p4, double *metric)
Definition: meshGFaceDelaunayInsertion.cpp:348
MTri3::tri
MTriangle * tri() const
Definition: meshGFaceDelaunayInsertion.h:105
GFace
Definition: GFace.h:33
MTri3::neigh
MTri3 * neigh[3]
Definition: meshGFaceDelaunayInsertion.h:83
MTri3::base
MTriangle * base
Definition: meshGFaceDelaunayInsertion.h:82
GEntity.h
bowyerWatsonParallelogramsConstrained
void bowyerWatsonParallelogramsConstrained(GFace *gf, const std::set< MVertex * > &constr_vertices, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1711
bidimMeshData::equivalence
std::map< MVertex *, MVertex * > * equivalence
Definition: meshGFaceDelaunayInsertion.h:27
MVertex
Definition: MVertex.h:24
bidimMeshData
Definition: meshGFaceDelaunayInsertion.h:23
bidimMeshData::addVertex
void addVertex(MVertex *mv, double u, double v, double size, double sizeBGM)
Definition: meshGFaceDelaunayInsertion.h:31
MVertex::getNum
std::size_t getNum() const
Definition: MVertex.h:86
MTriangle::getVertex
virtual MVertex * getVertex(int num)
Definition: MTriangle.h:62
MVertex::onWhat
GEntity * onWhat() const
Definition: MVertex.h:82
connectTriangles
void connectTriangles(std::list< MTri3 * > &)
Definition: meshGFaceDelaunayInsertion.cpp:543
compareTri3Ptr
Definition: meshGFaceDelaunayInsertion.h:134
MTri3::MTri3
MTri3(MTriangle *t, double lc, SMetric3 *m=nullptr, bidimMeshData *data=nullptr, GFace *gf=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:411
bowyerWatsonFrontalLayers
void bowyerWatsonFrontalLayers(GFace *gf, bool quad, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1497
MTri3::getNeigh
MTri3 * getNeigh(int iN) const
Definition: meshGFaceDelaunayInsertion.h:107
bowyerWatsonParallelograms
void bowyerWatsonParallelograms(GFace *gf, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1621
bowyerWatson
void bowyerWatson(GFace *gf, int MAXPNT=1000000000, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1033
MTri3::otherSide
MVertex * otherSide(int i)
Definition: meshGFaceDelaunayInsertion.h:91
MTri3
Definition: meshGFaceDelaunayInsertion.h:78
MFace.h
MVertex::setIndex
void setIndex(long int index)
Definition: MVertex.h:94
MTri3::radiusNorm
static int radiusNorm
2 is euclidian norm, -1 is infinite norm , 3 quality
Definition: meshGFaceDelaunayInsertion.h:87
MTri3::setTri
void setTri(MTriangle *t)
Definition: meshGFaceDelaunayInsertion.h:104
GModel
Definition: GModel.h:44
MTri3::inCircumCircle
int inCircumCircle(double x, double y) const
Definition: meshGFaceDelaunayInsertion.h:109
edgeXface::t1
MTri3 * t1
Definition: meshGFaceDelaunayInsertion.h:179
edgeXface::v
MVertex * v[2]
Definition: meshGFaceDelaunayInsertion.h:178
MTri3::forceRadius
void forceRadius(double r)
Definition: meshGFaceDelaunayInsertion.h:89
delaunayMeshIn2D
void delaunayMeshIn2D(std::vector< MVertex * > &, std::vector< MTriangle * > &, bool removeBox=true, std::vector< MEdge > *edgesToRecover=nullptr, bool hilbertSort=true)
Definition: meshGFaceDelaunayInsertion.cpp:1834
bidimMeshData::bidimMeshData
bidimMeshData(std::map< MVertex *, MVertex * > *e=nullptr, std::map< MVertex *, SPoint2 > *p=nullptr)
Definition: meshGFaceDelaunayInsertion.h:65
bidimMeshData::internalEdges
std::set< MEdge, MEdgeLessThan > internalEdges
Definition: meshGFaceDelaunayInsertion.h:29
edgeXface::operator<
bool operator<(const edgeXface &other) const
Definition: meshGFaceDelaunayInsertion.h:194
bidimMeshData::getIndex
int getIndex(MVertex *mv)
Definition: meshGFaceDelaunayInsertion.h:51
MTri3::inCircumCircle
int inCircumCircle(const double *p) const
Definition: meshGFaceDelaunayInsertion.cpp:483
MTriangle
Definition: MTriangle.h:26
edgeXface::edgeXface
edgeXface(MTri3 *_t, int iFac)
Definition: meshGFaceDelaunayInsertion.h:182
edgeXface::_v
MVertex * _v(int i) const
Definition: meshGFaceDelaunayInsertion.h:193
bowyerWatsonFrontal
void bowyerWatsonFrontal(GFace *gf, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr, std::vector< SPoint2 > *true_boundary=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1289
compareTri3Ptr::lf
MFaceLessThan lf
Definition: meshGFaceDelaunayInsertion.h:135
bidimMeshData::vMetricsBGM
std::vector< SMetric3 > vMetricsBGM
Definition: meshGFaceDelaunayInsertion.h:26
bidimMeshData::equivalent
MVertex * equivalent(MVertex *v1) const
Definition: meshGFaceDelaunayInsertion.h:56
MVertex::getIndex
long int getIndex() const
Definition: MVertex.h:93
MTri3::setDeleted
void setDeleted(bool d)
Definition: meshGFaceDelaunayInsertion.h:118
MTri3::isDeleted
bool isDeleted() const
Definition: meshGFaceDelaunayInsertion.h:88
MQuadrangle.h
MTri3::inCircumCircle
int inCircumCircle(const MVertex *v) const
Definition: meshGFaceDelaunayInsertion.h:114
STensor3.h
edgeXface::operator==
bool operator==(const edgeXface &other) const
Definition: meshGFaceDelaunayInsertion.h:201
MTri3::getRadius
double getRadius() const
Definition: meshGFaceDelaunayInsertion.h:90
MFaceLessThan
Definition: MFace.h:130
BDS_Point
Definition: BDS.h:49
edgeXface
Definition: meshGFaceDelaunayInsertion.h:177
MVertex::y
double y() const
Definition: MVertex.h:61
bidimMeshData::Vs
std::vector< double > Vs
Definition: meshGFaceDelaunayInsertion.h:25
bidimMeshData::Us
std::vector< double > Us
Definition: meshGFaceDelaunayInsertion.h:25
MTri3::circum_radius
double circum_radius
Definition: meshGFaceDelaunayInsertion.h:81
GEntity::dim
virtual int dim() const
Definition: GEntity.h:196
MTri3::setNeigh
void setNeigh(int iN, MTri3 *n)
Definition: meshGFaceDelaunayInsertion.h:106
bidimMeshData::vSizesBGM
std::vector< double > vSizesBGM
Definition: meshGFaceDelaunayInsertion.h:25
bidimMeshData::vSizes
std::vector< double > vSizes
Definition: meshGFaceDelaunayInsertion.h:25
MTri3::deleted
bool deleted
Definition: meshGFaceDelaunayInsertion.h:80
buildBackgroundMesh
void buildBackgroundMesh(GFace *gf, bool crossFieldClosestPoint=false, std::map< MVertex *, MVertex * > *equivalence=nullptr, std::map< MVertex *, SPoint2 > *parametricCoordinates=nullptr)
Definition: meshGFaceDelaunayInsertion.cpp:1453
MVertex::x
double x() const
Definition: MVertex.h:60
bidimMeshData::indices
std::map< MVertex *, int > indices
Definition: meshGFaceDelaunayInsertion.h:24