gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
alphaShapes.cpp
Go to the documentation of this file.
1 #include <set>
2 #include <map>
3 #include <unordered_map>
4 #include <unordered_set>
5 #include <stack>
6 #include "GRegion.h"
7 #include "MTetrahedron.h"
8 #include "MFace.h"
9 
11 {
14  neigh[0] = neigh[1] = neigh[2] = neigh[3] = nullptr;
15  }
16 };
17 
19  return t->gammaShapeMeasure();
20 }
21 
22 int alphaShapes (GRegion *gr, double threshold,
23  std::vector<std::vector<MTetrahedron*> > &domains,
24  std::vector<std::vector<MFace> > &boundaries) {
25 
26  std::unordered_map<MTetrahedron*, neighborContainer> t2a;
27  for (auto t : gr->tetrahedra)t2a[t] = neighborContainer();
28 
29  std::map< MFace, MTetrahedron *, MFaceLessThan> f2t;
30  for (auto t : gr->tetrahedra){
31  std::unordered_map<MTetrahedron*, neighborContainer>::iterator it1 = t2a.find(t);
32  for (int i=0;i<4;i++){
33  MFace f = t->getFace(i);
34  std::map< MFace, MTetrahedron *, MFaceLessThan>::iterator it = f2t.find(f);
35  if (it == f2t.end()){
36  f2t[f] = t;
37  }
38  else {
39  std::unordered_map<MTetrahedron*, neighborContainer>::iterator it2 = t2a.find(it->second);
40  it1->second.neigh[i] = it2->first;
41  for (int k=0;k<4;k++){
42  if (f == it2->first->getFace(k))
43  it2->second.neigh[k] = it1->first;
44  }
45  f2t.erase(it);
46  }
47  }
48  }
49 
50  std::unordered_set<MTetrahedron*> _touched;
51 
52  for (std::unordered_map<MTetrahedron*, neighborContainer>::iterator it = t2a.begin() ; it != t2a.end() ; ++it){
53  if (alphaShape(it->first) > threshold && _touched.find(it->first) == _touched.end()){
54  std::stack<MTetrahedron*> _s;
55  std::vector<MTetrahedron*> _domain;
56  std::vector<MFace> _boundary;
57  _s.push(it->first);
58  _touched.insert(it->first);
59  _domain.push_back(it->first);
60  while(!_s.empty()){
61  MTetrahedron *t = _s.top();
62  std::unordered_map<MTetrahedron*, neighborContainer>::iterator itx = t2a.find(t);
63  _s.pop();
64  for (int i=0;i<4;i++){
65  if (!itx->second.neigh[i])_boundary.push_back(itx->first->getFace(i));
66  else if (_touched.find(itx->second.neigh[i]) == _touched.end()){
67  if (alphaShape(itx->second.neigh[i]) > threshold){
68  _s.push(itx->second.neigh[i]);
69  _touched.insert(itx->second.neigh[i]);
70  _domain.push_back(itx->second.neigh[i]);
71  }
72  else {
73  _boundary.push_back(itx->first->getFace(i));
74  }
75  }
76  }
77  }
78  boundaries.push_back(_boundary);
79  domains.push_back(_domain);
80  }
81  }
82  return 0;
83 }
MTetrahedron
Definition: MTetrahedron.h:34
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
alphaShapes
int alphaShapes(GRegion *gr, double threshold, std::vector< std::vector< MTetrahedron * > > &domains, std::vector< std::vector< MFace > > &boundaries)
Definition: alphaShapes.cpp:22
neighborContainer::neigh
MTetrahedron * neigh[4]
Definition: alphaShapes.cpp:12
alphaShape
double alphaShape(MTetrahedron *t)
Definition: alphaShapes.cpp:18
neighborContainer::neighborContainer
neighborContainer()
Definition: alphaShapes.cpp:13
MFace
Definition: MFace.h:20
GRegion.h
MFace.h
GRegion
Definition: GRegion.h:28
MTetrahedron.h
MTetrahedron::gammaShapeMeasure
virtual double gammaShapeMeasure()
Definition: MTetrahedron.cpp:94
GRegion::tetrahedra
std::vector< MTetrahedron * > tetrahedra
Definition: GRegion.h:163
neighborContainer
Definition: alphaShapes.cpp:11