OGS
GeoLib::Grid< POINT > Class Template Referencefinal

Detailed Description

template<typename POINT>
class GeoLib::Grid< POINT >

Definition at line 32 of file Grid.h.

#include <Grid.h>

Inheritance diagram for GeoLib::Grid< POINT >:
[legend]
Collaboration diagram for GeoLib::Grid< POINT >:
[legend]

Public Member Functions

template<typename InputIterator >
 Grid (InputIterator first, InputIterator last, std::size_t max_num_per_grid_cell=512)
 The constructor of the grid object takes a vector of points or nodes. Furthermore the user can specify the average maximum number of points per grid cell. More...
 
virtual ~Grid ()
 
template<typename P >
POINT * getNearestPoint (P const &pnt) const
 
template<typename P >
std::vector< std::size_t > getPointsInEpsilonEnvironment (P const &pnt, double eps) const
 
template<typename P >
std::vector< std::vector< POINT * > const * > getPntVecsOfGridCellsIntersectingCube (P const &center, double half_len) const
 
std::vector< std::vector< POINT * > const * > getPntVecsOfGridCellsIntersectingCuboid (Eigen::Vector3d const &min_pnt, Eigen::Vector3d const &max_pnt) const
 
void createGridGeometry (GeoLib::GEOObjects *geo_obj) const
 
- Public Member Functions inherited from GeoLib::AABB
template<typename PNT_TYPE >
 AABB (std::vector< PNT_TYPE * > const &pnts, std::vector< std::size_t > const &ids)
 
template<typename InputIterator >
 AABB (InputIterator first, InputIterator last)
 
template<typename PNT_TYPE >
bool update (PNT_TYPE const &p)
 
template<typename T >
bool containsPoint (T const &pnt, double eps) const
 
template<typename T >
bool containsPointXY (T const &pnt) const
 
Eigen::Vector3d const & getMinPoint () const
 
Eigen::Vector3d const & getMaxPoint () const
 
bool containsAABB (AABB const &other_aabb) const
 

Private Member Functions

void initNumberOfSteps (std::size_t n_per_cell, std::size_t n_pnts, std::array< double, 3 > const &extensions)
 
template<typename T >
std::array< std::size_t, 3 > getGridCoords (T const &pnt) const
 
template<typename P >
std::array< double, 6 > getPointCellBorderDistances (P const &pnt, std::array< std::size_t, 3 > const &coords) const
 
template<typename P >
bool calcNearestPointInGridCell (P const &pnt, std::array< std::size_t, 3 > const &coords, double &sqr_min_dist, POINT *&nearest_pnt) const
 

Static Private Member Functions

static POINT * copyOrAddress (POINT &p)
 
static POINT const * copyOrAddress (POINT const &p)
 
static POINT * copyOrAddress (POINT *p)
 

Private Attributes

std::array< std::size_t, 3 > _n_steps = {{1, 1, 1}}
 
std::array< double, 3 > _step_sizes = {{0.0, 0.0, 0.0}}
 
std::vector< POINT * > * _grid_cell_nodes_map = nullptr
 

Constructor & Destructor Documentation

◆ Grid()

template<typename POINT >
template<typename InputIterator >
GeoLib::Grid< POINT >::Grid ( InputIterator  first,
InputIterator  last,
std::size_t  max_num_per_grid_cell = 512 
)

The constructor of the grid object takes a vector of points or nodes. Furthermore the user can specify the average maximum number of points per grid cell.

The number of grid cells are computed with the following formula \(\frac{n_{points}}{n_{cells}} \le n_{max\_per\_cell}\)

In order to limit the memory wasting the maximum number of points per grid cell (in the average) should be a power of two (since std::vector objects resize itself with this step size).

Parameters
first,lastthe range of elements to examine
max_num_per_grid_cell(input) max number per grid cell in the average

Definition at line 192 of file Grid.h.

194  : GeoLib::AABB(first, last)
195 {
196  auto const n_pnts(std::distance(first, last));
197 
198  auto const& max{getMaxPoint()};
199  auto const& min{getMinPoint()};
200  std::array<double, 3> delta = {
201  {max[0] - min[0], max[1] - min[1], max[2] - min[2]}};
202 
203  // enlarge delta
204  for (auto& d : delta)
205  {
206  d = std::nextafter(d, std::numeric_limits<double>::max());
207  }
208 
209  assert(n_pnts > 0);
210  initNumberOfSteps(max_num_per_grid_cell, static_cast<std::size_t>(n_pnts),
211  delta);
212 
213  const std::size_t n_plane(_n_steps[0] * _n_steps[1]);
214  _grid_cell_nodes_map = new std::vector<POINT*>[n_plane * _n_steps[2]];
215 
216  // some frequently used expressions to fill the grid vectors
217  for (std::size_t k(0); k < 3; k++)
218  {
219  if (std::abs(delta[k]) < std::numeric_limits<double>::epsilon())
220  {
221  delta[k] = std::numeric_limits<double>::epsilon();
222  }
223  _step_sizes[k] = delta[k] / _n_steps[k];
224  }
225 
226  // fill the grid vectors
227  InputIterator it(first);
228  while (it != last)
229  {
230  std::array<std::size_t, 3> coords(getGridCoords(*copyOrAddress(*it)));
231  if (coords < _n_steps)
232  {
233  std::size_t const pos(coords[0] + coords[1] * _n_steps[0] +
234  coords[2] * n_plane);
235  _grid_cell_nodes_map[pos].push_back(
236  const_cast<POINT*>(copyOrAddress(*it)));
237  }
238  else
239  {
240  ERR("Grid constructor: error computing indices [{:d}, {:d}, {:d}], "
241  "max indices [{:d}, {:d}, {:d}].",
242  coords[0], coords[1], coords[2], _n_steps[0], _n_steps[1],
243  _n_steps[2]);
244  }
245  it++;
246  }
247 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
Eigen::Vector3d const & getMinPoint() const
Definition: AABB.h:172
Eigen::Vector3d const & getMaxPoint() const
Definition: AABB.h:179
std::array< std::size_t, 3 > getGridCoords(T const &pnt) const
Definition: Grid.h:417
static POINT * copyOrAddress(POINT &p)
Definition: Grid.h:178
std::array< std::size_t, 3 > _n_steps
Definition: Grid.h:182
std::array< double, 3 > _step_sizes
Definition: Grid.h:183
std::vector< POINT * > * _grid_cell_nodes_map
Definition: Grid.h:187
void initNumberOfSteps(std::size_t n_per_cell, std::size_t n_pnts, std::array< double, 3 > const &extensions)
Definition: Grid.h:564

References GeoLib::Grid< POINT >::_grid_cell_nodes_map, GeoLib::Grid< POINT >::_n_steps, GeoLib::Grid< POINT >::_step_sizes, GeoLib::Grid< POINT >::copyOrAddress(), ERR(), GeoLib::Grid< POINT >::getGridCoords(), GeoLib::AABB::getMaxPoint(), GeoLib::AABB::getMinPoint(), GeoLib::Grid< POINT >::initNumberOfSteps(), and GeoLib::POINT.

◆ ~Grid()

template<typename POINT >
virtual GeoLib::Grid< POINT >::~Grid ( )
inlinevirtual

This is the destructor of the class. It deletes the internal data structures not including the pointers to the points.

Definition at line 59 of file Grid.h.

59 { delete[] _grid_cell_nodes_map; }

References GeoLib::Grid< POINT >::_grid_cell_nodes_map.

Member Function Documentation

◆ calcNearestPointInGridCell()

template<typename POINT >
template<typename P >
bool GeoLib::Grid< POINT >::calcNearestPointInGridCell ( P const &  pnt,
std::array< std::size_t, 3 > const &  coords,
double &  sqr_min_dist,
POINT *&  nearest_pnt 
) const
private

Definition at line 641 of file Grid.h.

646 {
647  const std::size_t grid_idx(coords[0] + coords[1] * _n_steps[0] +
648  coords[2] * _n_steps[0] * _n_steps[1]);
649  std::vector<typename std::add_pointer<
650  typename std::remove_pointer<POINT>::type>::type> const&
651  pnts(_grid_cell_nodes_map[grid_idx]);
652  if (pnts.empty())
653  return false;
654 
655  auto to_eigen = [](auto const& point)
656  { return Eigen::Map<Eigen::Vector3d const>(point.getCoords()); };
657 
658  const std::size_t n_pnts(pnts.size());
659  sqr_min_dist = (to_eigen(*pnts[0]) - to_eigen(pnt)).squaredNorm();
660  nearest_pnt = pnts[0];
661  for (std::size_t i(1); i < n_pnts; i++)
662  {
663  const double sqr_dist(
664  (to_eigen(*pnts[i]) - to_eigen(pnt)).squaredNorm());
665  if (sqr_dist < sqr_min_dist)
666  {
667  sqr_min_dist = sqr_dist;
668  nearest_pnt = pnts[i];
669  }
670  }
671  return true;
672 }

◆ copyOrAddress() [1/3]

template<typename POINT >
static POINT* GeoLib::Grid< POINT >::copyOrAddress ( POINT &  p)
inlinestaticprivate

Definition at line 178 of file Grid.h.

178 { return &p; }

References GeoLib::POINT.

Referenced by GeoLib::Grid< POINT >::Grid().

◆ copyOrAddress() [2/3]

template<typename POINT >
static POINT* GeoLib::Grid< POINT >::copyOrAddress ( POINT *  p)
inlinestaticprivate

Definition at line 180 of file Grid.h.

180 { return p; }

References GeoLib::POINT.

◆ copyOrAddress() [3/3]

template<typename POINT >
static POINT const* GeoLib::Grid< POINT >::copyOrAddress ( POINT const &  p)
inlinestaticprivate

Definition at line 179 of file Grid.h.

179 { return &p; }

References GeoLib::POINT.

◆ createGridGeometry()

template<typename POINT >
void GeoLib::Grid< POINT >::createGridGeometry ( GeoLib::GEOObjects geo_obj) const

Method creates a geometry for every mesh grid box. Additionally it creates one geometry containing all the box geometries.

Parameters
geo_obj

Definition at line 315 of file Grid.h.

316 {
317  std::vector<std::string> grid_names;
318 
319  GeoLib::Point const& llf(getMinPoint());
320  GeoLib::Point const& urb(getMaxPoint());
321 
322  const double dx((urb[0] - llf[0]) / _n_steps[0]);
323  const double dy((urb[1] - llf[1]) / _n_steps[1]);
324  const double dz((urb[2] - llf[2]) / _n_steps[2]);
325 
326  // create grid names and grid boxes as geometry
327  for (std::size_t i(0); i < _n_steps[0]; i++)
328  {
329  for (std::size_t j(0); j < _n_steps[1]; j++)
330  {
331  for (std::size_t k(0); k < _n_steps[2]; k++)
332  {
333  std::string name("Grid-");
334  name += std::to_string(i);
335  name += "-";
336  name += std::to_string(j);
337  name += "-";
338  name += std::to_string(k);
339  grid_names.push_back(name);
340 
341  {
342  std::vector<GeoLib::Point*> points;
343  points.push_back(new GeoLib::Point(
344  llf[0] + i * dx, llf[1] + j * dy, llf[2] + k * dz));
345  points.push_back(new GeoLib::Point(llf[0] + i * dx,
346  llf[1] + (j + 1) * dy,
347  llf[2] + k * dz));
348  points.push_back(new GeoLib::Point(llf[0] + (i + 1) * dx,
349  llf[1] + (j + 1) * dy,
350  llf[2] + k * dz));
351  points.push_back(new GeoLib::Point(llf[0] + (i + 1) * dx,
352  llf[1] + j * dy,
353  llf[2] + k * dz));
354  points.push_back(new GeoLib::Point(llf[0] + i * dx,
355  llf[1] + j * dy,
356  llf[2] + (k + 1) * dz));
357  points.push_back(new GeoLib::Point(llf[0] + i * dx,
358  llf[1] + (j + 1) * dy,
359  llf[2] + (k + 1) * dz));
360  points.push_back(new GeoLib::Point(llf[0] + (i + 1) * dx,
361  llf[1] + (j + 1) * dy,
362  llf[2] + (k + 1) * dz));
363  points.push_back(new GeoLib::Point(llf[0] + (i + 1) * dx,
364  llf[1] + j * dy,
365  llf[2] + (k + 1) * dz));
366  geo_obj->addPointVec(std::move(points), grid_names.back());
367  }
368 
369  std::vector<GeoLib::Polyline*> plys;
370  auto const& points = *geo_obj->getPointVec(grid_names.back());
371 
372  auto* ply0(new GeoLib::Polyline(points));
373  for (std::size_t l(0); l < 4; l++)
374  ply0->addPoint(l);
375  ply0->addPoint(0);
376  plys.push_back(ply0);
377 
378  auto* ply1(new GeoLib::Polyline(points));
379  for (std::size_t l(4); l < 8; l++)
380  ply1->addPoint(l);
381  ply1->addPoint(4);
382  plys.push_back(ply1);
383 
384  auto* ply2(new GeoLib::Polyline(points));
385  ply2->addPoint(0);
386  ply2->addPoint(4);
387  plys.push_back(ply2);
388 
389  auto* ply3(new GeoLib::Polyline(points));
390  ply3->addPoint(1);
391  ply3->addPoint(5);
392  plys.push_back(ply3);
393 
394  auto* ply4(new GeoLib::Polyline(points));
395  ply4->addPoint(2);
396  ply4->addPoint(6);
397  plys.push_back(ply4);
398 
399  auto* ply5(new GeoLib::Polyline(points));
400  ply5->addPoint(3);
401  ply5->addPoint(7);
402  plys.push_back(ply5);
403 
404  geo_obj->addPolylineVec(std::move(plys), grid_names.back(),
406  }
407  }
408  }
409  std::string merged_geo_name("Grid");
410 
411  geo_obj->mergeGeometries(grid_names, merged_geo_name);
412 }
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
Definition: GEOObjects.cpp:152
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:72
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
Definition: GEOObjects.cpp:47
int mergeGeometries(std::vector< std::string > const &geo_names, std::string &merged_geo_name)
Definition: GEOObjects.cpp:376
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:53
std::map< std::string, std::size_t > NameIdMap
Definition: TemplateVec.h:44

References GeoLib::GEOObjects::addPointVec(), GeoLib::GEOObjects::addPolylineVec(), GeoLib::GEOObjects::getPointVec(), GeoLib::GEOObjects::mergeGeometries(), and MaterialPropertyLib::name.

◆ getGridCoords()

template<typename POINT >
template<typename T >
std::array< std::size_t, 3 > GeoLib::Grid< POINT >::getGridCoords ( T const &  pnt) const
private

Method calculates the grid cell coordinates for the given point pnt. If the point is located outside of the bounding box the coordinates of the grid cell on the border that is nearest to given point will be returned.

Parameters
pnt(input) the coordinates of the point
Returns
the coordinates of the grid cell

Definition at line 417 of file Grid.h.

418 {
419  auto const& min_point{getMinPoint()};
420  auto const& max_point{getMinPoint()};
421  std::array<std::size_t, 3> coords{0, 0, 0};
422  for (std::size_t k(0); k < 3; k++)
423  {
424  if (pnt[k] < min_point[k])
425  {
426  continue;
427  }
428  if (pnt[k] >= max_point[k])
429  {
430  coords[k] = _n_steps[k] - 1;
431  continue;
432  }
433  coords[k] = static_cast<std::size_t>(
434  std::floor((pnt[k] - min_point[k])) /
435  std::nextafter(_step_sizes[k], std::numeric_limits<double>::max()));
436  }
437  return coords;
438 }

Referenced by GeoLib::Grid< POINT >::Grid().

◆ getNearestPoint()

template<typename POINT >
template<typename P >
POINT * GeoLib::Grid< POINT >::getNearestPoint ( P const &  pnt) const

The method calculates the grid cell the given point is belonging to, i.e., the (internal) coordinates of the grid cell are computed. The method searches the actual grid cell and all its neighbors for the POINT object which has the smallest distance. A pointer to this object is returned.

If there is not such a point, i.e., all the searched grid cells do not contain any POINT object a nullptr is returned.

Parameters
pntsearch point
Returns
a pointer to the point with the smallest distance within the grid cells that are outlined above or nullptr

Definition at line 466 of file Grid.h.

467 {
468  std::array<std::size_t, 3> coords(getGridCoords(pnt));
469  auto const& min_point{getMinPoint()};
470  auto const& max_point{getMaxPoint()};
471 
472  double sqr_min_dist = (max_point - min_point).squaredNorm();
473  POINT* nearest_pnt(nullptr);
474 
475  std::array<double, 6> dists(getPointCellBorderDistances(pnt, coords));
476 
477  if (calcNearestPointInGridCell(pnt, coords, sqr_min_dist, nearest_pnt))
478  {
479  double min_dist(std::sqrt(sqr_min_dist));
480  if (dists[0] >= min_dist && dists[1] >= min_dist &&
481  dists[2] >= min_dist && dists[3] >= min_dist &&
482  dists[4] >= min_dist && dists[5] >= min_dist)
483  {
484  return nearest_pnt;
485  }
486  }
487  else
488  {
489  // search in all border cells for at least one neighbor
490  double sqr_min_dist_tmp;
491  POINT* nearest_pnt_tmp(nullptr);
492  std::size_t offset(1);
493 
494  while (nearest_pnt == nullptr)
495  {
496  std::array<std::size_t, 3> ijk{
497  {coords[0] < offset ? 0 : coords[0] - offset,
498  coords[1] < offset ? 0 : coords[1] - offset,
499  coords[2] < offset ? 0 : coords[2] - offset}};
500  for (; ijk[0] < coords[0] + offset; ijk[0]++)
501  {
502  for (; ijk[1] < coords[1] + offset; ijk[1]++)
503  {
504  for (; ijk[2] < coords[2] + offset; ijk[2]++)
505  {
506  // do not check the origin grid cell twice
507  if (ijk[0] == coords[0] && ijk[1] == coords[1] &&
508  ijk[2] == coords[2])
509  {
510  continue;
511  }
512  // check if temporary grid cell coordinates are valid
513  if (ijk[0] >= _n_steps[0] || ijk[1] >= _n_steps[1] ||
514  ijk[2] >= _n_steps[2])
515  {
516  continue;
517  }
518 
520  pnt, ijk, sqr_min_dist_tmp, nearest_pnt_tmp))
521  {
522  if (sqr_min_dist_tmp < sqr_min_dist)
523  {
524  sqr_min_dist = sqr_min_dist_tmp;
525  nearest_pnt = nearest_pnt_tmp;
526  }
527  }
528  } // end k
529  } // end j
530  } // end i
531  offset++;
532  } // end while
533  } // end else
534 
535  auto to_eigen = [](auto const& point)
536  { return Eigen::Map<Eigen::Vector3d const>(point.getCoords()); };
537 
538  double len((to_eigen(pnt) - to_eigen(*nearest_pnt)).norm());
539  // search all other grid cells within the cube with the edge nodes
540  std::vector<std::vector<POINT*> const*> vecs_of_pnts(
542 
543  const std::size_t n_vecs(vecs_of_pnts.size());
544  for (std::size_t j(0); j < n_vecs; j++)
545  {
546  std::vector<POINT*> const& pnts(*(vecs_of_pnts[j]));
547  const std::size_t n_pnts(pnts.size());
548  for (std::size_t k(0); k < n_pnts; k++)
549  {
550  const double sqr_dist(
551  (to_eigen(pnt) - to_eigen(*pnts[k])).squaredNorm());
552  if (sqr_dist < sqr_min_dist)
553  {
554  sqr_min_dist = sqr_dist;
555  nearest_pnt = pnts[k];
556  }
557  }
558  }
559 
560  return nearest_pnt;
561 }
std::array< double, 6 > getPointCellBorderDistances(P const &pnt, std::array< std::size_t, 3 > const &coords) const
Definition: Grid.h:442
bool calcNearestPointInGridCell(P const &pnt, std::array< std::size_t, 3 > const &coords, double &sqr_min_dist, POINT *&nearest_pnt) const
Definition: Grid.h:641
std::vector< std::vector< POINT * > const * > getPntVecsOfGridCellsIntersectingCube(P const &center, double half_len) const
Definition: Grid.h:252
double norm(MatrixOrVector const &x, MathLib::VecNormType type)
Definition: LinAlg.h:88

References MathLib::LinAlg::norm(), and GeoLib::POINT.

Referenced by MeshGeoToolsLib::GeoMapper::getMeshElevation().

◆ getPntVecsOfGridCellsIntersectingCube()

template<typename POINT >
template<typename P >
std::vector< std::vector< POINT * > const * > GeoLib::Grid< POINT >::getPntVecsOfGridCellsIntersectingCube ( P const &  center,
double  half_len 
) const

Method fetches the vectors of all grid cells intersecting the axis aligned cuboid defined by two points. The first point with minimal coordinates in all directions. The second point with maximal coordinates in all directions.

Parameters
center(input) the center point of the axis aligned cube
half_len(input) half of the edge length of the axis aligned cube
Returns
vector of vectors of points within grid cells that intersects the axis aligned cube

Definition at line 252 of file Grid.h.

254 {
255  Eigen::Vector3d const c{center[0], center[1], center[2]};
256  std::array<std::size_t, 3> min_coords(getGridCoords(c.array() - half_len));
257  std::array<std::size_t, 3> max_coords(getGridCoords(c.array() + half_len));
258 
259  std::vector<std::vector<POINT*> const*> pnts;
260  pnts.reserve(
261  (Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(max_coords.data()) -
262  Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(min_coords.data()))
263  .prod());
264 
265  std::size_t const steps0_x_steps1(_n_steps[0] * _n_steps[1]);
266  for (std::size_t c0 = min_coords[0]; c0 < max_coords[0] + 1; c0++)
267  {
268  for (std::size_t c1 = min_coords[1]; c1 < max_coords[1] + 1; c1++)
269  {
270  const std::size_t coords0_p_coords1_x_steps0(c0 + c1 * _n_steps[0]);
271  for (std::size_t c2 = min_coords[2]; c2 < max_coords[2] + 1; c2++)
272  {
273  pnts.push_back(
274  &(_grid_cell_nodes_map[coords0_p_coords1_x_steps0 +
275  c2 * steps0_x_steps1]));
276  }
277  }
278  }
279  return pnts;
280 }

References MaterialPropertyLib::c.

Referenced by MeshLib::MeshRevision::collapseNodeIndices().

◆ getPntVecsOfGridCellsIntersectingCuboid()

template<typename POINT >
std::vector< std::vector< POINT * > const * > GeoLib::Grid< POINT >::getPntVecsOfGridCellsIntersectingCuboid ( Eigen::Vector3d const &  min_pnt,
Eigen::Vector3d const &  max_pnt 
) const

Definition at line 284 of file Grid.h.

286 {
287  std::array<std::size_t, 3> min_coords(getGridCoords(min_pnt));
288  std::array<std::size_t, 3> max_coords(getGridCoords(max_pnt));
289 
290  std::vector<std::vector<POINT*> const*> pnts;
291  pnts.reserve(
292  (Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(max_coords.data()) -
293  Eigen::Map<Eigen::Matrix<std::size_t, 3, 1>>(min_coords.data()))
294  .prod());
295 
296  std::size_t const steps0_x_steps1(_n_steps[0] * _n_steps[1]);
297  for (std::size_t c0 = min_coords[0]; c0 < max_coords[0] + 1; c0++)
298  {
299  for (std::size_t c1 = min_coords[1]; c1 < max_coords[1] + 1; c1++)
300  {
301  const std::size_t coords0_p_coords1_x_steps0(c0 + c1 * _n_steps[0]);
302  for (std::size_t c2 = min_coords[2]; c2 < max_coords[2] + 1; c2++)
303  {
304  pnts.push_back(
305  &(_grid_cell_nodes_map[coords0_p_coords1_x_steps0 +
306  c2 * steps0_x_steps1]));
307  }
308  }
309  }
310  return pnts;
311 }

Referenced by MeshLib::Mesh2MeshPropertyInterpolation::interpolatePropertiesForMesh().

◆ getPointCellBorderDistances()

template<typename POINT >
template<typename P >
std::array< double, 6 > GeoLib::Grid< POINT >::getPointCellBorderDistances ( P const &  pnt,
std::array< std::size_t, 3 > const &  coords 
) const
private

point numbering of the grid cell is as follow

7 -------- 6
/: /|
/ : / |
/ : / |
/ : / |
4 -------- 5 |
| 3 ....|... 2
| . | /
| . | /
| . | /
|. |/
0 -------- 1

the face numbering is as follow: face nodes 0 0,3,2,1 bottom 1 0,1,5,4 front 2 1,2,6,5 right 3 2,3,7,6 back 4 3,0,4,7 left 5 4,5,6,7 top

Parameters
pnt(input) coordinates of the point
coordsof the grid cell
Returns
squared distances of the point to the faces of the grid cell ordered in the same sequence as above described

Definition at line 442 of file Grid.h.

444 {
445  auto const& min_point{getMinPoint()};
446  std::array<double, 6> dists{};
447  dists[0] =
448  std::abs(pnt[2] - min_point[2] + coords[2] * _step_sizes[2]); // bottom
449  dists[5] = std::abs(pnt[2] - min_point[2] +
450  (coords[2] + 1) * _step_sizes[2]); // top
451 
452  dists[1] =
453  std::abs(pnt[1] - min_point[1] + coords[1] * _step_sizes[1]); // front
454  dists[3] = std::abs(pnt[1] - min_point[1] +
455  (coords[1] + 1) * _step_sizes[1]); // back
456 
457  dists[4] =
458  std::abs(pnt[0] - min_point[0] + coords[0] * _step_sizes[0]); // left
459  dists[2] = std::abs(pnt[0] - min_point[0] +
460  (coords[0] + 1) * _step_sizes[0]); // right
461  return dists;
462 }

◆ getPointsInEpsilonEnvironment()

template<typename POINT >
template<typename P >
std::vector< std::size_t > GeoLib::Grid< POINT >::getPointsInEpsilonEnvironment ( P const &  pnt,
double  eps 
) const

Definition at line 676 of file Grid.h.

678 {
679  std::vector<std::vector<POINT*> const*> vec_pnts(
681 
682  double const sqr_eps(eps * eps);
683 
684  auto to_eigen = [](auto const& point)
685  { return Eigen::Map<Eigen::Vector3d const>(point.getCoords()); };
686 
687  std::vector<std::size_t> pnts;
688  for (auto vec : vec_pnts)
689  {
690  for (auto const p : *vec)
691  {
692  if ((to_eigen(*p) - to_eigen(pnt)).squaredNorm() <= sqr_eps)
693  {
694  pnts.push_back(p->getID());
695  }
696  }
697  }
698 
699  return pnts;
700 }

Referenced by MeshGeoToolsLib::MeshNodesOnPoint::MeshNodesOnPoint(), and MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs().

◆ initNumberOfSteps()

template<typename POINT >
void GeoLib::Grid< POINT >::initNumberOfSteps ( std::size_t  n_per_cell,
std::size_t  n_pnts,
std::array< double, 3 > const &  extensions 
)
private

Computes the number of grid cells per spatial dimension the objects (points or mesh nodes) will be sorted in. On the one hand the number of grid cells should be small to reduce the management overhead. On the other hand the number should be large such that each grid cell contains only a small number of objects. Under the assumption that the points are distributed equidistant in space the grid cells should be as cubical as possible. At first it is necessary to determine the spatial dimension the grid should have. The dimensions are computed from the spatial extensions Let \(\max\) be the largest spatial extension. The grid will have a spatial dimension if the ratio of the corresponding spatial extension and the maximal extension is \(\ge 10^{-4}\). The second step consists of computing the number of cells per dimension.

Definition at line 564 of file Grid.h.

566 {
567  double const max_extension(
568  *std::max_element(extensions.cbegin(), extensions.cend()));
569 
570  std::bitset<3> dim; // all bits set to zero
571  for (std::size_t k(0); k < 3; ++k)
572  {
573  // set dimension if the ratio kth-extension/max_extension >= 1e-4
574  if (extensions[k] >= 1e-4 * max_extension)
575  {
576  dim[k] = true;
577  }
578  }
579 
580  // structured grid: n_cells = _n_steps[0] * _n_steps[1] * _n_steps[2]
581  // *** condition: n_pnts / n_cells < n_per_cell
582  // => n_pnts / n_per_cell < n_cells
583  // _n_steps[1] = _n_steps[0] * extensions[1]/extensions[0],
584  // _n_steps[2] = _n_steps[0] * extensions[2]/extensions[0],
585  // => n_cells = _n_steps[0]^3 * extensions[1]/extensions[0] *
586  // extensions[2]/extensions[0],
587  // => _n_steps[0] = cbrt(n_cells * extensions[0]^2 /
588  // (extensions[1]*extensions[2]))
589  auto sc_ceil = [](double v) { return static_cast<std::size_t>(ceil(v)); };
590 
591  switch (dim.count())
592  {
593  case 3: // 3d case
594  _n_steps[0] = sc_ceil(
595  std::cbrt(n_pnts * (extensions[0] / extensions[1]) *
596  (extensions[0] / extensions[2]) / n_per_cell));
597  _n_steps[1] = sc_ceil(
598  _n_steps[0] * std::min(extensions[1] / extensions[0], 100.0));
599  _n_steps[2] = sc_ceil(
600  _n_steps[0] * std::min(extensions[2] / extensions[0], 100.0));
601  break;
602  case 2: // 2d cases
603  if (dim[0] && dim[1])
604  { // xy
605  _n_steps[0] = sc_ceil(std::sqrt(n_pnts * extensions[0] /
606  (n_per_cell * extensions[1])));
607  _n_steps[1] =
608  sc_ceil(_n_steps[0] *
609  std::min(extensions[1] / extensions[0], 100.0));
610  }
611  else if (dim[0] && dim[2])
612  { // xz
613  _n_steps[0] = sc_ceil(std::sqrt(n_pnts * extensions[0] /
614  (n_per_cell * extensions[2])));
615  _n_steps[2] =
616  sc_ceil(_n_steps[0] *
617  std::min(extensions[2] / extensions[0], 100.0));
618  }
619  else if (dim[1] && dim[2])
620  { // yz
621  _n_steps[1] = sc_ceil(std::sqrt(n_pnts * extensions[1] /
622  (n_per_cell * extensions[2])));
623  _n_steps[2] =
624  sc_ceil(std::min(extensions[2] / extensions[1], 100.0));
625  }
626  break;
627  case 1: // 1d cases
628  for (std::size_t k(0); k < 3; ++k)
629  {
630  if (dim[k])
631  {
632  _n_steps[k] =
633  sc_ceil(static_cast<double>(n_pnts) / n_per_cell);
634  }
635  }
636  }
637 }
static const double v

References MathLib::v.

Referenced by GeoLib::Grid< POINT >::Grid().

Member Data Documentation

◆ _grid_cell_nodes_map

template<typename POINT >
std::vector<POINT*>* GeoLib::Grid< POINT >::_grid_cell_nodes_map = nullptr
private

This is an array that stores pointers to POINT objects.

Definition at line 187 of file Grid.h.

Referenced by GeoLib::Grid< POINT >::Grid(), and GeoLib::Grid< POINT >::~Grid().

◆ _n_steps

template<typename POINT >
std::array<std::size_t, 3> GeoLib::Grid< POINT >::_n_steps = {{1, 1, 1}}
private

Definition at line 182 of file Grid.h.

Referenced by GeoLib::Grid< POINT >::Grid().

◆ _step_sizes

template<typename POINT >
std::array<double, 3> GeoLib::Grid< POINT >::_step_sizes = {{0.0, 0.0, 0.0}}
private

Definition at line 183 of file Grid.h.

Referenced by GeoLib::Grid< POINT >::Grid().


The documentation for this class was generated from the following file: