gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
DivideAndConquer.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 DIVIDE_AND_CONQUER_H
7 #define DIVIDE_AND_CONQUER_H
8 
9 #include <vector>
10 #include <algorithm>
11 #include "SPoint2.h"
12 #include "simpleFunction.h"
13 #include "Octree.h"
14 #include "MElement.h"
15 
16 template <class scalar> class fullMatrix;
17 class GFace;
18 
19 typedef struct CDList DListRecord, *DListPeek;
20 typedef int PointNumero;
21 
22 typedef struct {
23  double v;
24  double h;
25 } DPoint;
26 
27 struct PointRecord {
30  void *data;
31  int flag; // 0:to be kept, 1:to be removed
33  std::vector<void *> vicinity;
34  PointRecord() : adjacent(nullptr), data(nullptr), flag(0), identificator(0)
35  {
36  where.v = where.h = 0.;
37  }
38 };
39 
40 struct CDList {
43 };
44 
45 typedef struct {
47  int t_length;
48 } STriangle;
49 
50 typedef struct {
53 } DT;
54 
55 typedef struct {
58 } Segment;
59 
60 typedef struct {
61  PointNumero a, b, c;
62 } Triangle;
63 
64 class DocRecord {
65 private:
66  int _hullSize;
77  int Merge(DT vl, DT vr);
78  DT RecurTrig(PointNumero left, PointNumero right);
79  int DListInsert(PointNumero centerPoint, PointNumero newPoint);
80  int Insert(PointNumero a, PointNumero b);
81  int DListDelete(DListPeek *dlist, PointNumero oldPoint);
82  int Delete(PointNumero a, PointNumero b);
85  void RemoveAllDList();
86  int BuildDelaunay();
87  int CountPointsOnHull();
88  void ConvexHull();
89  bool AdjacentNullptrExists();
90 
91 public:
93  int numPoints; // number of points
95  PointRecord *points; // points to triangulate
96  int numTriangles; // number of triangles
97  Triangle *triangles; // 2D results
98  DocRecord(int n);
99  double &x(int i) { return points[i].where.h; }
100  double &y(int i) { return points[i].where.v; }
101  void *&data(int i) { return points[i].data; }
102  void setPoints(fullMatrix<double> *p);
103  ~DocRecord();
104  void MakeMeshWithPoints();
105  void Voronoi();
106  int hullSize() { return _hullSize; }
108  {
109  return std::binary_search(_hull, _hull + _hullSize, i);
110  }
111  void makePosView(const std::string &, GFace *gf = nullptr);
112  void printMedialAxis(Octree *_octree, const std::string &,
113  GFace *gf = nullptr, GEdge *ge = nullptr);
114  void voronoiCell(PointNumero pt, std::vector<SPoint2> &pts) const;
115 
116  std::set<std::pair<void *, void *> > boundaryEdges;
117 
118  void addBoundaryEdge(void *p1, void *p2)
119  {
120  void *a = (p1 < p2) ? p1 : p2;
121  void *b = (p1 > p2) ? p1 : p2;
122  boundaryEdges.insert(std::make_pair(a, b));
123  }
124  bool lookForBoundaryEdge(void *p1, void *p2)
125  {
126  void *a = (p1 < p2) ? p1 : p2;
127  void *b = (p1 > p2) ? p1 : p2;
128  auto it = boundaryEdges.find(std::make_pair(a, b));
129  return it != boundaryEdges.end();
130  }
131 
132  void recur_tag_triangles(
133  int, std::set<int> &,
134  std::map<std::pair<void *, void *>, std::pair<int, int> > &);
135  std::set<int> tagInterior(double, double);
136  void concave(double, double, GFace *);
137  bool contain(int, int, int);
138  void add(int, int);
139 
140  void initialize();
141  bool remove_point(int);
142  void remove_all();
143  void add_point(double, double, GFace *);
144 
145  std::set<std::pair<void *, void *> > mesh_edges;
146 
147  void add_edge(void *p1, void *p2)
148  {
149  void *a = (p1 < p2) ? p1 : p2;
150  void *b = (p1 > p2) ? p1 : p2;
151  mesh_edges.insert(std::make_pair(a, b));
152  }
153  bool find_edge(void *p1, void *p2)
154  {
155  void *a = (p1 < p2) ? p1 : p2;
156  void *b = (p1 > p2) ? p1 : p2;
157  auto it = mesh_edges.find(std::make_pair(a, b));
158  return it != mesh_edges.end();
159  }
160 
161  void build_edges();
162  void clear_edges();
163  bool delaunay_conformity(GFace *);
164 
165  PointNumero *ConvertDlistToArray(DListPeek *dlist, int *n);
166 };
167 
168 void centroidOfOrientedBox(std::vector<SPoint2> &pts, const double &angle,
169  double &xc, double &yc, double &inertia,
170  double &area);
171 void centroidOfPolygon(SPoint2 &pc, std::vector<SPoint2> &pts, double &xc,
172  double &yc, double &inertia, double &areaCell,
173  simpleFunction<double> *bgm = nullptr);
174 
175 #endif
DocRecord::FixFirst
int FixFirst(PointNumero x, PointNumero f)
Definition: DivideAndConquer.cpp:59
DocRecord::recur_tag_triangles
void recur_tag_triangles(int, std::set< int > &, std::map< std::pair< void *, void * >, std::pair< int, int > > &)
Definition: DivideAndConquer.cpp:886
DocRecord::Qtest
int Qtest(PointNumero h, PointNumero i, PointNumero j, PointNumero k)
Definition: DivideAndConquer.cpp:158
CDList
Definition: DivideAndConquer.h:40
DocRecord::IsRightOf
int IsRightOf(PointNumero x, PointNumero y, PointNumero check)
Definition: DivideAndConquer.cpp:94
DocRecord::tagInterior
std::set< int > tagInterior(double, double)
Definition: DivideAndConquer.cpp:913
DocRecord::_hullSize
int _hullSize
Definition: DivideAndConquer.h:66
DocRecord::numPoints
int numPoints
Definition: DivideAndConquer.h:93
DocRecord::UpperCommonTangent
Segment UpperCommonTangent(DT vl, DT vr)
Definition: DivideAndConquer.cpp:128
DocRecord::Delete
int Delete(PointNumero a, PointNumero b)
Definition: DivideAndConquer.cpp:444
GFace
Definition: GFace.h:33
DocRecord::CountPointsOnHull
int CountPointsOnHull()
Definition: DivideAndConquer.cpp:452
DocRecord::y
double & y(int i)
Definition: DivideAndConquer.h:100
DPoint
Definition: DivideAndConquer.h:22
angle
double angle(const SVector3 &a, const SVector3 &b)
Definition: SVector3.h:157
SPoint2
Definition: SPoint2.h:12
DocRecord::clear_edges
void clear_edges()
Definition: DivideAndConquer.cpp:1085
Octree.h
DocRecord::delaunay_conformity
bool delaunay_conformity(GFace *)
Definition: DivideAndConquer.cpp:1087
DocRecord::ConvertDListToVoronoiData
void ConvertDListToVoronoiData()
Definition: DivideAndConquer.cpp:515
DocRecord::ConvertDlistToArray
PointNumero * ConvertDlistToArray(DListPeek *dlist, int *n)
Definition: DivideAndConquer.cpp:488
DocRecord::mesh_edges
std::set< std::pair< void *, void * > > mesh_edges
Definition: DivideAndConquer.h:145
DocRecord::BuildDelaunay
int BuildDelaunay()
Definition: DivideAndConquer.cpp:310
PointRecord::where
DPoint where
Definition: DivideAndConquer.h:28
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
DocRecord::add
void add(int, int)
Definition: DivideAndConquer.cpp:1017
CDList::prev
DListPeek prev
Definition: DivideAndConquer.h:42
DocRecord::First
PointNumero First(PointNumero x)
Definition: DivideAndConquer.cpp:77
DocRecord::AdjacentNullptrExists
bool AdjacentNullptrExists()
Definition: DivideAndConquer.cpp:847
DocRecord::lookForBoundaryEdge
bool lookForBoundaryEdge(void *p1, void *p2)
Definition: DivideAndConquer.h:124
DocRecord::size_points
int size_points
Definition: DivideAndConquer.h:94
DocRecord::ConvertDListToTriangles
int ConvertDListToTriangles()
Definition: DivideAndConquer.cpp:762
DocRecord::points
PointRecord * points
Definition: DivideAndConquer.h:95
DocRecord::DocRecord
DocRecord(int n)
Definition: DivideAndConquer.cpp:829
Segment::to
PointNumero to
Definition: DivideAndConquer.h:57
DocRecord::boundaryEdges
std::set< std::pair< void *, void * > > boundaryEdges
Definition: DivideAndConquer.h:116
DocRecord::concave
void concave(double, double, GFace *)
Definition: DivideAndConquer.cpp:953
DocRecord::ConvexHull
void ConvexHull()
Definition: DivideAndConquer.cpp:471
DocRecord
Definition: DivideAndConquer.h:64
DocRecord::initialize
void initialize()
Definition: DivideAndConquer.cpp:1024
DocRecord::IsLeftOf
int IsLeftOf(PointNumero x, PointNumero y, PointNumero check)
Definition: DivideAndConquer.cpp:82
CDList::next
DListPeek next
Definition: DivideAndConquer.h:42
DT::begin
PointNumero begin
Definition: DivideAndConquer.h:51
PointRecord::vicinity
std::vector< void * > vicinity
Definition: DivideAndConquer.h:33
PointNumero
int PointNumero
Definition: DivideAndConquer.h:20
DocRecord::_hull
PointNumero * _hull
Definition: DivideAndConquer.h:67
DocRecord::Successor
PointNumero Successor(PointNumero a, PointNumero b)
Definition: DivideAndConquer.cpp:46
Triangle::c
PointNumero c
Definition: DivideAndConquer.h:61
PointRecord::adjacent
DListPeek adjacent
Definition: DivideAndConquer.h:29
DocRecord::Insert
int Insert(PointNumero a, PointNumero b)
Definition: DivideAndConquer.cpp:406
DocRecord::printMedialAxis
void printMedialAxis(Octree *_octree, const std::string &, GFace *gf=nullptr, GEdge *ge=nullptr)
Definition: DivideAndConquer.cpp:639
fullMatrix
Definition: MElement.h:27
DocRecord::DListInsert
int DListInsert(PointNumero centerPoint, PointNumero newPoint)
Definition: DivideAndConquer.cpp:319
DocRecord::numTriangles
int numTriangles
Definition: DivideAndConquer.h:96
DocRecord::setPoints
void setPoints(fullMatrix< double > *p)
Definition: DivideAndConquer.cpp:875
simpleFunction< double >
DocRecord::add_point
void add_point(double, double, GFace *)
Definition: DivideAndConquer.cpp:1062
DListPeek
struct CDList * DListPeek
Definition: DivideAndConquer.h:19
DocRecord::onHull
int onHull(PointNumero i)
Definition: DivideAndConquer.h:107
PointRecord
Definition: DivideAndConquer.h:27
DocRecord::~DocRecord
~DocRecord()
Definition: DivideAndConquer.cpp:836
PointRecord::flag
int flag
Definition: DivideAndConquer.h:31
DocRecord::remove_point
bool remove_point(int)
Definition: DivideAndConquer.cpp:1029
DPoint::h
double h
Definition: DivideAndConquer.h:24
DocRecord::hullSize
int hullSize()
Definition: DivideAndConquer.h:106
DocRecord::contain
bool contain(int, int, int)
Definition: DivideAndConquer.cpp:998
PointRecord::identificator
int identificator
Definition: DivideAndConquer.h:32
DocRecord::remove_all
void remove_all()
Definition: DivideAndConquer.cpp:1039
DocRecord::RemoveAllDList
void RemoveAllDList()
Definition: DivideAndConquer.cpp:812
Triangle
Definition: DivideAndConquer.h:60
DocRecord::build_edges
void build_edges()
Definition: DivideAndConquer.cpp:1072
Segment
Definition: DivideAndConquer.h:55
DocRecord::x
double & x(int i)
Definition: DivideAndConquer.h:99
STriangle::t
PointNumero * t
Definition: DivideAndConquer.h:46
PointRecord::data
void * data
Definition: DivideAndConquer.h:30
DocRecord::find_edge
bool find_edge(void *p1, void *p2)
Definition: DivideAndConquer.h:153
Octree
Definition: OctreeInternals.h:51
DocRecord::DListDelete
int DListDelete(DListPeek *dlist, PointNumero oldPoint)
Definition: DivideAndConquer.cpp:413
CDList::point_num
PointNumero point_num
Definition: DivideAndConquer.h:41
Segment::from
PointNumero from
Definition: DivideAndConquer.h:56
DocRecord::makePosView
void makePosView(const std::string &, GFace *gf=nullptr)
Definition: DivideAndConquer.cpp:572
DocRecord::LowerCommonTangent
Segment LowerCommonTangent(DT vl, DT vr)
Definition: DivideAndConquer.cpp:99
DocRecord::add_edge
void add_edge(void *p1, void *p2)
Definition: DivideAndConquer.h:147
DocRecord::Predecessor
PointNumero Predecessor(PointNumero a, PointNumero b)
Definition: DivideAndConquer.cpp:33
DocRecord::triangles
Triangle * triangles
Definition: DivideAndConquer.h:97
DPoint::v
double v
Definition: DivideAndConquer.h:23
simpleFunction.h
PointRecord::PointRecord
PointRecord()
Definition: DivideAndConquer.h:34
STriangle::t_length
int t_length
Definition: DivideAndConquer.h:47
STriangle
Definition: DivideAndConquer.h:45
MElement.h
GEdge
Definition: GEdge.h:26
centroidOfPolygon
void centroidOfPolygon(SPoint2 &pc, std::vector< SPoint2 > &pts, double &xc, double &yc, double &inertia, double &areaCell, simpleFunction< double > *bgm=nullptr)
Definition: DivideAndConquer.cpp:717
DT::end
PointNumero end
Definition: DivideAndConquer.h:52
DocRecord::Merge
int Merge(DT vl, DT vr)
Definition: DivideAndConquer.cpp:178
DocRecord::data
void *& data(int i)
Definition: DivideAndConquer.h:101
DocRecord::_adjacencies
STriangle * _adjacencies
Definition: DivideAndConquer.h:92
centroidOfOrientedBox
void centroidOfOrientedBox(std::vector< SPoint2 > &pts, const double &angle, double &xc, double &yc, double &inertia, double &area)
Definition: DivideAndConquer.cpp:690
DocRecord::MakeMeshWithPoints
void MakeMeshWithPoints()
Definition: DivideAndConquer.cpp:855
DocRecord::RecurTrig
DT RecurTrig(PointNumero left, PointNumero right)
Definition: DivideAndConquer.cpp:253
DocRecord::addBoundaryEdge
void addBoundaryEdge(void *p1, void *p2)
Definition: DivideAndConquer.h:118
DocRecord::Voronoi
void Voronoi()
Definition: DivideAndConquer.cpp:868
DocRecord::voronoiCell
void voronoiCell(PointNumero pt, std::vector< SPoint2 > &pts) const
Definition: DivideAndConquer.cpp:534
DT
Definition: DivideAndConquer.h:50
SPoint2.h