OGS
GMSHAdaptiveMeshDensity.cpp
Go to the documentation of this file.
1 
15 
16 #include <list>
17 
18 #include "BaseLib/Logging.h"
19 #include "GeoLib/Point.h"
20 #include "GeoLib/Polygon.h"
21 #ifndef NDEBUG
22 #include "GeoLib/Polyline.h"
23 #endif
24 #include "GeoLib/QuadTree.h"
25 #include "MathLib/MathTools.h"
26 
27 namespace FileIO
28 {
29 namespace GMSH
30 {
32  double station_density,
33  std::size_t max_pnts_per_leaf)
34  : _pnt_density(pnt_density),
35  _station_density(station_density),
36  _max_pnts_per_leaf(max_pnts_per_leaf),
37  _quad_tree(nullptr)
38 {
39 }
40 
42 {
43  delete _quad_tree;
44 }
45 
47  std::vector<GeoLib::Point const*> const& pnts)
48 {
49  // *** QuadTree - determining bounding box
50  DBUG(
51  "GMSHAdaptiveMeshDensity::init(): computing axis aligned bounding box "
52  "(2D) for quadtree.");
53 
54  GeoLib::Point min(*pnts[0]);
55  GeoLib::Point max(*pnts[0]);
56  std::size_t n_pnts(pnts.size());
57  for (std::size_t k(1); k < n_pnts; k++)
58  {
59  for (std::size_t j(0); j < 2; j++)
60  {
61  if ((*(pnts[k]))[j] < min[j])
62  {
63  min[j] = (*(pnts[k]))[j];
64  }
65  }
66  for (std::size_t j(0); j < 2; j++)
67  {
68  if ((*(pnts[k]))[j] > max[j])
69  {
70  max[j] = (*(pnts[k]))[j];
71  }
72  }
73  }
74  min[2] = 0.0;
75  max[2] = 0.0;
76  DBUG("GMSHAdaptiveMeshDensity::init(): \tok");
77 
78  // *** QuadTree - create object
79  DBUG("GMSHAdaptiveMeshDensity::init(): Creating quadtree.");
80  _quad_tree =
82  DBUG("GMSHAdaptiveMeshDensity::init(): \tok.");
83 
84  // *** QuadTree - insert points
85  addPoints(pnts);
86 }
87 
89  std::vector<GeoLib::Point const*> const& pnts)
90 {
91  // *** QuadTree - insert points
92  const std::size_t n_pnts(pnts.size());
93  DBUG(
94  "GMSHAdaptiveMeshDensity::addPoints(): Inserting {:d} points into "
95  "quadtree.",
96  n_pnts);
97  for (std::size_t k(0); k < n_pnts; k++)
98  {
99  _quad_tree->addPoint(pnts[k]);
100  }
101  DBUG("GMSHAdaptiveMeshDensity::addPoints(): \tok.");
102  _quad_tree->balance();
103 }
104 
106  GeoLib::Point const* const pnt) const
107 {
108  GeoLib::Point ll;
109  GeoLib::Point ur;
110  _quad_tree->getLeaf(*pnt, ll, ur);
111  return _pnt_density * (ur[0] - ll[0]);
112 }
113 
115  GeoLib::Point const* const pnt) const
116 {
117  GeoLib::Point ll;
118  GeoLib::Point ur;
119  _quad_tree->getLeaf(*pnt, ll, ur);
120  return _station_density * (ur[0] - ll[0]);
121 }
122 
124  std::vector<GeoLib::Point*>& pnts, std::size_t additional_levels) const
125 {
126  // get Steiner points
127  std::size_t max_depth(0);
128  _quad_tree->getMaxDepth(max_depth);
129 
130  std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list;
131  _quad_tree->getLeafs(leaf_list);
132 
133  for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(
134  leaf_list.begin());
135  it != leaf_list.end();
136  ++it)
137  {
138  if ((*it)->getPoints().empty())
139  {
140  // compute point from square
141  GeoLib::Point ll;
142  GeoLib::Point ur;
143  (*it)->getSquarePoints(ll, ur);
144  if ((*it)->getDepth() + additional_levels > max_depth)
145  {
146  additional_levels = max_depth - (*it)->getDepth();
147  }
148  const std::size_t n_pnts_per_quad_dim = static_cast<std::size_t>(1)
149  << additional_levels;
150  const double delta((ur[0] - ll[0]) / (2 * n_pnts_per_quad_dim));
151  for (std::size_t i(0); i < n_pnts_per_quad_dim; i++)
152  {
153  for (std::size_t j(0); j < n_pnts_per_quad_dim; j++)
154  {
155  pnts.push_back(new GeoLib::Point(
156  ll[0] + (2 * i + 1) * delta,
157  ll[1] + (2 * j + 1) * delta, 0.0, pnts.size()));
158  }
159  }
160  }
161  }
162 }
163 
164 #ifndef NDEBUG
166  std::vector<GeoLib::Point*>& pnts,
167  std::vector<GeoLib::Polyline*>& plys) const
168 {
169  std::list<GeoLib::QuadTree<GeoLib::Point>*> leaf_list;
170  _quad_tree->getLeafs(leaf_list);
171 
172  for (std::list<GeoLib::QuadTree<GeoLib::Point>*>::const_iterator it(
173  leaf_list.begin());
174  it != leaf_list.end();
175  ++it)
176  {
177  // fetch corner points from leaf
178  GeoLib::Point ll;
179  GeoLib::Point ur;
180  (*it)->getSquarePoints(ll, ur);
181  std::size_t const pnt_offset(pnts.size());
182  pnts.push_back(new GeoLib::Point(ll, pnt_offset));
183  pnts.push_back(new GeoLib::Point(ur[0], ll[1], 0.0, pnt_offset + 1));
184  pnts.push_back(new GeoLib::Point(ur, pnt_offset + 2));
185  pnts.push_back(new GeoLib::Point(ll[0], ur[1], 0.0, pnt_offset + 3));
186  plys.push_back(new GeoLib::Polyline(pnts));
187  plys[plys.size() - 1]->addPoint(pnt_offset);
188  plys[plys.size() - 1]->addPoint(pnt_offset + 1);
189  plys[plys.size() - 1]->addPoint(pnt_offset + 2);
190  plys[plys.size() - 1]->addPoint(pnt_offset + 3);
191  plys[plys.size() - 1]->addPoint(pnt_offset);
192  }
193 }
194 #endif
195 } // namespace GMSH
196 
197 } // end namespace FileIO
Definition of the Point class.
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Definition of the Polygon class.
Definition of the PolyLine class.
Definition of the QuadTree class.
double getMeshDensityAtPoint(GeoLib::Point const *const pnt) const override
double getMeshDensityAtStation(GeoLib::Point const *const) const override
void getQuadTreeGeometry(std::vector< GeoLib::Point * > &pnts, std::vector< GeoLib::Polyline * > &plys) const
void getSteinerPoints(std::vector< GeoLib::Point * > &pnts, std::size_t additional_levels=0) const
void initialize(std::vector< GeoLib::Point const * > const &pnts) override
GMSHAdaptiveMeshDensity(double pnt_density, double station_density, std::size_t max_pnts_per_leaf)
void addPoints(std::vector< GeoLib::Point const * > const &pnts)
GeoLib::QuadTree< GeoLib::Point > * _quad_tree
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
void balance()
Definition: QuadTree.h:163
void getMaxDepth(std::size_t &max_depth) const
Definition: QuadTree.h:314
void getLeafs(std::list< QuadTree< POINT > * > &leaf_list)
Definition: QuadTree.h:243
void getLeaf(const POINT &pnt, POINT &ll, POINT &ur)
Definition: QuadTree.h:266
bool addPoint(POINT const *pnt)
Definition: QuadTree.h:99