OGS
GeoLib::QuadTree< POINT > Class Template Reference

Detailed Description

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

A quadtree is a rooted tree in which every internal node has four children. Every node corresponds to a square. (see Computational Geometry - Algorithms and Applications [Mark de Berg, Otfried Cheong, Marc van Kreveld, Mark Overmars] - Chapter 14)

One can instantiate the class template with a point type and a value for the maximal number of points per node. The point-type have to provide the access to its coordinates via operator[] and for debugging purposes operator<<)

Definition at line 37 of file QuadTree.h.

#include <QuadTree.h>

Public Types

enum class  Quadrant { NE = 0 , NW , SW , SE }
 

Public Member Functions

 QuadTree (POINT ll, POINT ur, std::size_t max_points_per_leaf)
 
 ~QuadTree ()
 
bool addPoint (POINT const *pnt)
 
void balance ()
 
void getLeafs (std::list< QuadTree< POINT > * > &leaf_list)
 
const std::vector< POINT const * > & getPoints () const
 
void getSquarePoints (POINT &ll, POINT &ur) const
 
void getLeaf (const POINT &pnt, POINT &ll, POINT &ur)
 
QuadTree< POINT > const * getFather () const
 
QuadTree< POINT > const * getChild (Quadrant quadrant) const
 
void getMaxDepth (std::size_t &max_depth) const
 
std::size_t getDepth () const
 

Private Member Functions

QuadTree< POINT > * getChild (Quadrant quadrant)
 
bool isLeaf () const
 
bool isChild (QuadTree< POINT > const *const tree, Quadrant quadrant) const
 
QuadTree< POINT > * getNorthNeighbor () const
 
QuadTree< POINT > * getSouthNeighbor () const
 
QuadTree< POINT > * getEastNeighbor () const
 
QuadTree< POINT > * getWestNeighbor () const
 
 QuadTree (POINT ll, POINT ur, QuadTree *father, std::size_t depth, std::size_t max_points_per_leaf)
 
void splitNode ()
 

Static Private Member Functions

static bool needToRefine (QuadTree< POINT > *node)
 

Private Attributes

QuadTree< POINT > * _father
 
std::array< QuadTree< POINT > *, 4 > _children
 
POINT _ll
 
POINT _ur
 
std::size_t _depth = 0
 
std::vector< POINT const * > _pnts
 
bool _is_leaf = true
 
const std::size_t _max_points_per_leaf
 

Member Enumeration Documentation

◆ Quadrant

template<typename POINT >
enum GeoLib::QuadTree::Quadrant
strong
Enumerator
NE 

north east

NW 

north west

SW 

south west

SE 

south east

Definition at line 40 of file QuadTree.h.

40  {
41  NE = 0,
42  NW,
43  SW,
44  SE
45  };

Constructor & Destructor Documentation

◆ QuadTree() [1/2]

template<typename POINT >
GeoLib::QuadTree< POINT >::QuadTree ( POINT  ll,
POINT  ur,
std::size_t  max_points_per_leaf 
)
inline

This is the constructor for class QuadTree. It takes two points (lower left and the upper right points).

Parameters
lllower left point of the square
urupper right point of the square
max_points_per_leafmaximum number of points per leaf

Definition at line 53 of file QuadTree.h.

54  : _father(nullptr),
55  _ll(std::move(ll)),
56  _ur(std::move(ur)),
57  _max_points_per_leaf(max_points_per_leaf)
58  {
59  assert (_max_points_per_leaf > 0);
60 
61  if ((_ur[0] - _ll[0]) > (_ur[1] - _ll[1]))
62  {
63  _ur[1] = _ll[1] + _ur[0] - _ll[0];
64  }
65  else
66  {
67  _ur[0] = _ll[0] + _ur[1] - _ll[1];
68  }
69 
70  DBUG(
71  "QuadTree(): lower left: ({:f},{:f},{:f}), upper right: "
72  "({:f},{:f},{:f}), depth: {:d}",
73  _ll[0],
74  _ll[1],
75  _ll[2],
76  _ur[0],
77  _ur[1],
78  _ur[2],
79  _depth);
80  }
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
QuadTree< POINT > * _father
Definition: QuadTree.h:624
const std::size_t _max_points_per_leaf
Definition: QuadTree.h:648
std::size_t _depth
Definition: QuadTree.h:642

References GeoLib::QuadTree< POINT >::_depth, GeoLib::QuadTree< POINT >::_ll, GeoLib::QuadTree< POINT >::_max_points_per_leaf, GeoLib::QuadTree< POINT >::_ur, and DBUG().

◆ ~QuadTree()

template<typename POINT >
GeoLib::QuadTree< POINT >::~QuadTree ( )
inline

destructor

Definition at line 85 of file QuadTree.h.

86  {
87  for (auto& child : _children)
88  {
89  delete child;
90  }
91  }
std::array< QuadTree< POINT > *, 4 > _children
Definition: QuadTree.h:632

References GeoLib::QuadTree< POINT >::_children.

◆ QuadTree() [2/2]

template<typename POINT >
GeoLib::QuadTree< POINT >::QuadTree ( POINT  ll,
POINT  ur,
QuadTree< POINT > *  father,
std::size_t  depth,
std::size_t  max_points_per_leaf 
)
inlineprivate

private constructor

Parameters
lllower left point
urupper right point
fatherfather in the tree
depthdepth of the node
max_points_per_leafmaximum number of points per leaf
Returns

Definition at line 494 of file QuadTree.h.

499  : _father(father),
500  _ll(std::move(ll)),
501  _ur(std::move(ur)),
502  _depth(depth),
503  _max_points_per_leaf(max_points_per_leaf)
504  {
505  }

Member Function Documentation

◆ addPoint()

template<typename POINT >
bool GeoLib::QuadTree< POINT >::addPoint ( POINT const *  pnt)
inline

This method adds the given point to the quadtree. If necessary, the quadtree will be extended.

Parameters
pntthe point
Returns
If the point can be inserted the method returns true, else false.

Definition at line 99 of file QuadTree.h.

100  {
101  if ((*pnt)[0] < _ll[0])
102  {
103  return false;
104  }
105  if ((*pnt)[0] >= _ur[0])
106  {
107  return false;
108  }
109  if ((*pnt)[1] < _ll[1])
110  {
111  return false;
112  }
113  if ((*pnt)[1] >= _ur[1])
114  {
115  return false;
116  }
117 
118  if (!_is_leaf) {
119  for (auto& child : _children)
120  {
121  if (child->addPoint(pnt))
122  {
123  return true;
124  }
125  }
126  return false;
127  }
128 
129  // check if point is already in quadtree
130  bool pnt_in_quadtree (false);
131  for (std::size_t k(0); k < _pnts.size() && !pnt_in_quadtree; k++) {
132  const double v0((*(_pnts[k]))[0] - (*pnt)[0]);
133  const double v1((*(_pnts[k]))[1] - (*pnt)[1]);
134  const double sqr_dist (v0*v0 + v1*v1);
135  if (sqr_dist < std::numeric_limits<double>::epsilon())
136  {
137  pnt_in_quadtree = true;
138  }
139  }
140  if (!pnt_in_quadtree)
141  {
142  _pnts.push_back (pnt);
143  }
144  else
145  {
146  return false;
147  }
148 
149  if (_pnts.size() > _max_points_per_leaf)
150  {
151  splitNode();
152  }
153  return true;
154  }
std::vector< POINT const * > _pnts
Definition: QuadTree.h:643
void splitNode()
Definition: QuadTree.h:507

References GeoLib::QuadTree< POINT >::_children, GeoLib::QuadTree< POINT >::_is_leaf, GeoLib::QuadTree< POINT >::_ll, GeoLib::QuadTree< POINT >::_max_points_per_leaf, GeoLib::QuadTree< POINT >::_pnts, GeoLib::QuadTree< POINT >::_ur, and GeoLib::QuadTree< POINT >::splitNode().

Referenced by FileIO::GMSH::GMSHAdaptiveMeshDensity::addPoints(), and GeoLib::QuadTree< POINT >::splitNode().

◆ balance()

template<typename POINT >
void GeoLib::QuadTree< POINT >::balance ( )
inline

This method balances the quadtree, i.e., it will be inserted nodes such that the depth between neighbored leafs is at most one. If you want to create a mesh (for instance with GMSH) you can use this method to improve the mesh quality. The balance method should be used after inserting all points.

Definition at line 163 of file QuadTree.h.

164  {
165  std::list<QuadTree<POINT>*> leaf_list;
166  getLeafs (leaf_list);
167 
168  while (!leaf_list.empty())
169  {
170  QuadTree<POINT>* node (leaf_list.front());
171  leaf_list.pop_front ();
172 
173  if (node->isLeaf())
174  {
175  if (needToRefine (node))
176  {
177  node->splitNode ();
178  leaf_list.push_back (node->getChild(Quadrant::NE));
179  leaf_list.push_back (node->getChild(Quadrant::NW));
180  leaf_list.push_back (node->getChild(Quadrant::SW));
181  leaf_list.push_back (node->getChild(Quadrant::SE));
182 
183  // check if north neighbor has to be refined
184  QuadTree<POINT>* north_neighbor (node->getNorthNeighbor());
185  if (north_neighbor != nullptr)
186  {
187  if (north_neighbor->getDepth() < node->getDepth())
188  {
189  if (north_neighbor->isLeaf())
190  {
191  leaf_list.push_back(north_neighbor);
192  }
193  }
194  }
195 
196  // check if west neighbor has to be refined
197  QuadTree<POINT>* west_neighbor (node->getWestNeighbor());
198  if (west_neighbor != nullptr)
199  {
200  if (west_neighbor->getDepth() < node->getDepth())
201  {
202  if (west_neighbor->isLeaf())
203  {
204  leaf_list.push_back(west_neighbor);
205  }
206  }
207  }
208 
209  // check if south neighbor has to be refined
210  QuadTree<POINT>* south_neighbor (node->getSouthNeighbor());
211  if (south_neighbor != nullptr)
212  {
213  if (south_neighbor->getDepth() < node->getDepth())
214  {
215  if (south_neighbor->isLeaf())
216  {
217  leaf_list.push_back(south_neighbor);
218  }
219  }
220  }
221 
222  // check if east neighbor has to be refined
223  QuadTree<POINT>* east_neighbor (node->getEastNeighbor());
224  if (east_neighbor != nullptr)
225  {
226  if (east_neighbor->getDepth() < node->getDepth())
227  {
228  if (east_neighbor->isLeaf())
229  {
230  leaf_list.push_back(east_neighbor);
231  }
232  }
233  }
234  }
235  }
236  }
237  }
void getLeafs(std::list< QuadTree< POINT > * > &leaf_list)
Definition: QuadTree.h:243
static bool needToRefine(QuadTree< POINT > *node)
Definition: QuadTree.h:544

References GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::getDepth(), GeoLib::QuadTree< POINT >::getEastNeighbor(), GeoLib::QuadTree< POINT >::getLeafs(), GeoLib::QuadTree< POINT >::getNorthNeighbor(), GeoLib::QuadTree< POINT >::getSouthNeighbor(), GeoLib::QuadTree< POINT >::getWestNeighbor(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::needToRefine(), GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, GeoLib::QuadTree< POINT >::splitNode(), and GeoLib::QuadTree< POINT >::SW.

Referenced by FileIO::GMSH::GMSHAdaptiveMeshDensity::addPoints().

◆ getChild() [1/2]

template<typename POINT >
QuadTree<POINT>* GeoLib::QuadTree< POINT >::getChild ( Quadrant  quadrant)
inlineprivate

Definition at line 337 of file QuadTree.h.

338  {
339  return _children[static_cast<int>(quadrant)];
340  }

References GeoLib::QuadTree< POINT >::_children.

◆ getChild() [2/2]

◆ getDepth()

template<typename POINT >
std::size_t GeoLib::QuadTree< POINT >::getDepth ( ) const
inline

Method returns the depth of the current QuadTree node.

Returns
the depth of the current QuadTree node

Definition at line 334 of file QuadTree.h.

334 { return _depth; }

References GeoLib::QuadTree< POINT >::_depth.

Referenced by GeoLib::QuadTree< POINT >::balance(), and GeoLib::QuadTree< POINT >::needToRefine().

◆ getEastNeighbor()

template<typename POINT >
QuadTree<POINT>* GeoLib::QuadTree< POINT >::getEastNeighbor ( ) const
inlineprivate

Definition at line 417 of file QuadTree.h.

418  {
419  if (this->_father == nullptr)
420  { // root of QuadTree
421  return nullptr;
422  }
423 
424  if (this->_father->isChild(this, Quadrant::NW))
425  {
426  return this->_father->getChild(Quadrant::NE);
427  }
428  if (this->_father->isChild(this, Quadrant::SW))
429  {
430  return this->_father->getChild(Quadrant::SE);
431  }
432 
433  QuadTree<POINT>* east_neighbor (this->_father->getEastNeighbor ());
434  if (east_neighbor == nullptr)
435  {
436  return nullptr;
437  }
438  if (east_neighbor->isLeaf())
439  {
440  return east_neighbor;
441  }
442 
443  if (this->_father->isChild(this, Quadrant::SE))
444  {
445  return east_neighbor->getChild(Quadrant::SW);
446  }
447 
448  return east_neighbor->getChild(Quadrant::NW);
449  }

References GeoLib::QuadTree< POINT >::_father, GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by GeoLib::QuadTree< POINT >::balance(), and GeoLib::QuadTree< POINT >::needToRefine().

◆ getFather()

template<typename POINT >
QuadTree<POINT> const* GeoLib::QuadTree< POINT >::getFather ( ) const
inline

Definition at line 302 of file QuadTree.h.

302 { return _father; }

References GeoLib::QuadTree< POINT >::_father.

◆ getLeaf()

template<typename POINT >
void GeoLib::QuadTree< POINT >::getLeaf ( const POINT &  pnt,
POINT &  ll,
POINT &  ur 
)
inline

Definition at line 266 of file QuadTree.h.

267  {
268  if (this->isLeaf())
269  {
270  ll = _ll;
271  ur = _ur;
272  }
273  else
274  {
275  if (pnt[0] <= 0.5 * (_ur[0] + _ll[0])) // WEST
276  {
277  if (pnt[1] <= 0.5 * (_ur[1] + _ll[1]))
278  { // SOUTH
279  _children[static_cast<int>(Quadrant::SW)]->getLeaf (pnt, ll, ur);
280  }
281  else
282  { // NORTH
283  _children[static_cast<int>(Quadrant::NW)]->getLeaf(
284  pnt, ll, ur);
285  }
286  }
287  else // EAST
288  {
289  if (pnt[1] <= 0.5 * (_ur[1] + _ll[1]))
290  { // SOUTH
291  _children[static_cast<int>(Quadrant::SE)]->getLeaf (pnt, ll, ur);
292  }
293  else
294  { // NORTH
295  _children[static_cast<int>(Quadrant::NE)]->getLeaf(
296  pnt, ll, ur);
297  }
298  }
299  }
300  }
bool isLeaf() const
Definition: QuadTree.h:342
void getLeaf(const POINT &pnt, POINT &ll, POINT &ur)
Definition: QuadTree.h:266

References GeoLib::QuadTree< POINT >::_children, GeoLib::QuadTree< POINT >::_ll, GeoLib::QuadTree< POINT >::_ur, GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by FileIO::GMSH::GMSHAdaptiveMeshDensity::getMeshDensityAtPoint(), and FileIO::GMSH::GMSHAdaptiveMeshDensity::getMeshDensityAtStation().

◆ getLeafs()

template<typename POINT >
void GeoLib::QuadTree< POINT >::getLeafs ( std::list< QuadTree< POINT > * > &  leaf_list)
inline

add all leafs of the quadtree to the list

Parameters
leaf_listlist of leafs

Definition at line 243 of file QuadTree.h.

244  {
245  if (_is_leaf)
246  {
247  leaf_list.push_back (this);
248  }
249  else
250  {
251  for (auto& child : _children)
252  {
253  child->getLeafs(leaf_list);
254  }
255  }
256  }

References GeoLib::QuadTree< POINT >::_children, and GeoLib::QuadTree< POINT >::_is_leaf.

Referenced by GeoLib::QuadTree< POINT >::balance(), FileIO::GMSH::GMSHAdaptiveMeshDensity::getQuadTreeGeometry(), and FileIO::GMSH::GMSHAdaptiveMeshDensity::getSteinerPoints().

◆ getMaxDepth()

template<typename POINT >
void GeoLib::QuadTree< POINT >::getMaxDepth ( std::size_t &  max_depth) const
inline

Method calculates the maximum depth of the QuadTree instance. It is used within the method GMSHAdaptiveMeshDensity::getSteinerPoints().

Parameters
max_depth(input/output) at the entry max_depth contains the maximum depth up to now

Definition at line 314 of file QuadTree.h.

315  {
316  if (max_depth < _depth)
317  {
318  max_depth = _depth;
319  }
320 
321  for (auto& child : _children)
322  {
323  if (child)
324  {
325  child->getMaxDepth(max_depth);
326  }
327  }
328  }

References GeoLib::QuadTree< POINT >::_children, and GeoLib::QuadTree< POINT >::_depth.

Referenced by FileIO::GMSH::GMSHAdaptiveMeshDensity::getSteinerPoints().

◆ getNorthNeighbor()

template<typename POINT >
QuadTree<POINT>* GeoLib::QuadTree< POINT >::getNorthNeighbor ( ) const
inlineprivate

Definition at line 349 of file QuadTree.h.

350  {
351  if (this->_father == nullptr)
352  { // root of QuadTree
353  return nullptr;
354  }
355 
356  if (this->_father->isChild(this, Quadrant::SW))
357  {
358  return this->_father->getChild(Quadrant::NW);
359  }
360  if (this->_father->isChild(this, Quadrant::SE))
361  {
362  return this->_father->getChild(Quadrant::NE);
363  }
364 
365  QuadTree<POINT>* north_neighbor (this->_father->getNorthNeighbor ());
366  if (north_neighbor == nullptr)
367  {
368  return nullptr;
369  }
370  if (north_neighbor->isLeaf())
371  {
372  return north_neighbor;
373  }
374 
375  if (this->_father->isChild(this, Quadrant::NW))
376  {
377  return north_neighbor->getChild(Quadrant::SW);
378  }
379 
380  return north_neighbor->getChild(Quadrant::SE);
381  }

References GeoLib::QuadTree< POINT >::_father, GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by GeoLib::QuadTree< POINT >::balance(), and GeoLib::QuadTree< POINT >::needToRefine().

◆ getPoints()

template<typename POINT >
const std::vector<POINT const*>& GeoLib::QuadTree< POINT >::getPoints ( ) const
inline

Definition at line 258 of file QuadTree.h.

258 { return _pnts; }

References GeoLib::QuadTree< POINT >::_pnts.

◆ getSouthNeighbor()

template<typename POINT >
QuadTree<POINT>* GeoLib::QuadTree< POINT >::getSouthNeighbor ( ) const
inlineprivate

Definition at line 383 of file QuadTree.h.

384  {
385  if (this->_father == nullptr)
386  { // root of QuadTree
387  return nullptr;
388  }
389 
390  if (this->_father->isChild(this, Quadrant::NW))
391  {
392  return this->_father->getChild(Quadrant::SW);
393  }
394  if (this->_father->isChild(this, Quadrant::NE))
395  {
396  return this->_father->getChild(Quadrant::SE);
397  }
398 
399  QuadTree<POINT>* south_neighbor (this->_father->getSouthNeighbor ());
400  if (south_neighbor == nullptr)
401  {
402  return nullptr;
403  }
404  if (south_neighbor->isLeaf())
405  {
406  return south_neighbor;
407  }
408 
409  if (this->_father->isChild(this, Quadrant::SW))
410  {
411  return south_neighbor->getChild(Quadrant::NW);
412  }
413 
414  return south_neighbor->getChild(Quadrant::NE);
415  }

References GeoLib::QuadTree< POINT >::_father, GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by GeoLib::QuadTree< POINT >::balance(), and GeoLib::QuadTree< POINT >::needToRefine().

◆ getSquarePoints()

template<typename POINT >
void GeoLib::QuadTree< POINT >::getSquarePoints ( POINT &  ll,
POINT &  ur 
) const
inline

Definition at line 260 of file QuadTree.h.

261  {
262  ll = _ll;
263  ur = _ur;
264  }

References GeoLib::QuadTree< POINT >::_ll, and GeoLib::QuadTree< POINT >::_ur.

◆ getWestNeighbor()

template<typename POINT >
QuadTree<POINT>* GeoLib::QuadTree< POINT >::getWestNeighbor ( ) const
inlineprivate

Definition at line 451 of file QuadTree.h.

452  {
453  if (this->_father == nullptr)
454  { // root of QuadTree
455  return nullptr;
456  }
457 
458  if (this->_father->isChild(this, Quadrant::NE))
459  {
460  return this->_father->getChild(Quadrant::NW);
461  }
462  if (this->_father->isChild(this, Quadrant::SE))
463  {
464  return this->_father->getChild(Quadrant::SW);
465  }
466 
467  QuadTree<POINT>* west_neighbor (this->_father->getWestNeighbor ());
468  if (west_neighbor == nullptr)
469  {
470  return nullptr;
471  }
472  if (west_neighbor->isLeaf())
473  {
474  return west_neighbor;
475  }
476 
477  if (this->_father->isChild(this, Quadrant::SW))
478  {
479  return west_neighbor->getChild(Quadrant::SE);
480  }
481 
482  return west_neighbor->getChild(Quadrant::NE);
483  }

References GeoLib::QuadTree< POINT >::_father, GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by GeoLib::QuadTree< POINT >::balance(), and GeoLib::QuadTree< POINT >::needToRefine().

◆ isChild()

template<typename POINT >
bool GeoLib::QuadTree< POINT >::isChild ( QuadTree< POINT > const *const  tree,
Quadrant  quadrant 
) const
inlineprivate

Definition at line 344 of file QuadTree.h.

345  {
346  return _children[static_cast<int>(quadrant)] == tree;
347  }

References GeoLib::QuadTree< POINT >::_children.

◆ isLeaf()

◆ needToRefine()

template<typename POINT >
static bool GeoLib::QuadTree< POINT >::needToRefine ( QuadTree< POINT > *  node)
inlinestaticprivate

Definition at line 544 of file QuadTree.h.

545  {
546  QuadTree<POINT>* north_neighbor (node->getNorthNeighbor ());
547  if (north_neighbor != nullptr)
548  {
549  if (north_neighbor->getDepth() == node->getDepth())
550  {
551  if (!north_neighbor->isLeaf ())
552  {
553  if (!(north_neighbor->getChild(Quadrant::SW))->isLeaf())
554  {
555  return true;
556  }
557  if (!(north_neighbor->getChild(Quadrant::SE))->isLeaf())
558  {
559  return true;
560  }
561  }
562  }
563  }
564 
565  QuadTree<POINT>* west_neighbor (node->getWestNeighbor ());
566  if (west_neighbor != nullptr)
567  {
568  if (west_neighbor->getDepth() == node->getDepth())
569  {
570  if (!west_neighbor->isLeaf ())
571  {
572  if (!(west_neighbor->getChild(Quadrant::SE))->isLeaf())
573  {
574  return true;
575  }
576  if (!(west_neighbor->getChild(Quadrant::NE))->isLeaf())
577  {
578  return true;
579  }
580  }
581  }
582  }
583 
584  QuadTree<POINT>* south_neighbor (node->getSouthNeighbor ());
585  if (south_neighbor != nullptr)
586  {
587  if (south_neighbor->getDepth() == node->getDepth())
588  {
589  if (!south_neighbor->isLeaf())
590  {
591  if (!(south_neighbor->getChild(Quadrant::NE))->isLeaf())
592  {
593  return true;
594  }
595  if (!(south_neighbor->getChild(Quadrant::NW))->isLeaf())
596  {
597  return true;
598  }
599  }
600  }
601  }
602 
603  QuadTree<POINT>* east_neighbor (node->getEastNeighbor ());
604  if (east_neighbor != nullptr)
605  {
606  if (east_neighbor->getDepth() == node->getDepth())
607  {
608  if (!east_neighbor->isLeaf ())
609  {
610  if (!(east_neighbor->getChild(Quadrant::NW))->isLeaf())
611  {
612  return true;
613  }
614  if (!(east_neighbor->getChild(Quadrant::SW))->isLeaf())
615  {
616  return true;
617  }
618  }
619  }
620  }
621  return false;
622  }

References GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::getDepth(), GeoLib::QuadTree< POINT >::getEastNeighbor(), GeoLib::QuadTree< POINT >::getNorthNeighbor(), GeoLib::QuadTree< POINT >::getSouthNeighbor(), GeoLib::QuadTree< POINT >::getWestNeighbor(), GeoLib::QuadTree< POINT >::isLeaf(), GeoLib::QuadTree< POINT >::NE, GeoLib::QuadTree< POINT >::NW, GeoLib::QuadTree< POINT >::SE, and GeoLib::QuadTree< POINT >::SW.

Referenced by GeoLib::QuadTree< POINT >::balance().

◆ splitNode()

template<typename POINT >
void GeoLib::QuadTree< POINT >::splitNode ( )
inlineprivate

Definition at line 507 of file QuadTree.h.

508  {
509  // create children
510  POINT mid_point(_ll);
511  mid_point[0] += (_ur[0] - _ll[0]) / 2.0;
512  mid_point[1] += (_ur[1] - _ll[1]) / 2.0;
513  assert(_children[0] == nullptr);
514  _children[0] = new QuadTree<POINT> (mid_point, _ur, this, _depth + 1, _max_points_per_leaf); // north east
515  POINT h_ll(mid_point), h_ur(mid_point);
516  h_ll[0] = _ll[0];
517  h_ur[1] = _ur[1];
518  assert(_children[1] == nullptr);
519  _children[1] = new QuadTree<POINT> (h_ll, h_ur, this, _depth + 1, _max_points_per_leaf); // north west
520  assert(_children[2] == nullptr);
521  _children[2] = new QuadTree<POINT> (_ll, mid_point, this, _depth + 1, _max_points_per_leaf); // south west
522  h_ll = _ll;
523  h_ll[0] = mid_point[0];
524  h_ur = _ur;
525  h_ur[1] = mid_point[1];
526  assert(_children[3] == nullptr);
527  _children[3] = new QuadTree<POINT> (h_ll, h_ur, this, _depth + 1, _max_points_per_leaf); // south east
528 
529  // distribute points to sub quadtrees
530  for (std::size_t j(0); j < _pnts.size(); j++) {
531  bool nfound(true);
532  for (std::size_t k(0); k < 4 && nfound; k++)
533  {
534  if (_children[k]->addPoint(_pnts[j]))
535  {
536  nfound = false;
537  }
538  }
539  }
540  _pnts.clear();
541  _is_leaf = false;
542  }
bool addPoint(POINT const *pnt)
Definition: QuadTree.h:99

References GeoLib::QuadTree< POINT >::_children, GeoLib::QuadTree< POINT >::_depth, GeoLib::QuadTree< POINT >::_is_leaf, GeoLib::QuadTree< POINT >::_ll, GeoLib::QuadTree< POINT >::_max_points_per_leaf, GeoLib::QuadTree< POINT >::_pnts, GeoLib::QuadTree< POINT >::_ur, GeoLib::QuadTree< POINT >::addPoint(), and GeoLib::POINT.

Referenced by GeoLib::QuadTree< POINT >::addPoint(), and GeoLib::QuadTree< POINT >::balance().

Member Data Documentation

◆ _children

template<typename POINT >
std::array<QuadTree<POINT>*, 4> GeoLib::QuadTree< POINT >::_children
private
Initial value:
= {nullptr, nullptr, nullptr,
nullptr}

children are sorted: _children[0] is north east child _children[1] is north west child _children[2] is south west child _children[3] is south east child

Definition at line 632 of file QuadTree.h.

Referenced by GeoLib::QuadTree< POINT >::~QuadTree(), GeoLib::QuadTree< POINT >::addPoint(), GeoLib::QuadTree< POINT >::getChild(), GeoLib::QuadTree< POINT >::getLeaf(), GeoLib::QuadTree< POINT >::getLeafs(), GeoLib::QuadTree< POINT >::getMaxDepth(), GeoLib::QuadTree< POINT >::isChild(), and GeoLib::QuadTree< POINT >::splitNode().

◆ _depth

template<typename POINT >
std::size_t GeoLib::QuadTree< POINT >::_depth = 0
private

◆ _father

◆ _is_leaf

template<typename POINT >
bool GeoLib::QuadTree< POINT >::_is_leaf = true
private

◆ _ll

◆ _max_points_per_leaf

template<typename POINT >
const std::size_t GeoLib::QuadTree< POINT >::_max_points_per_leaf
private

maximum number of points per leaf

Definition at line 648 of file QuadTree.h.

Referenced by GeoLib::QuadTree< POINT >::QuadTree(), GeoLib::QuadTree< POINT >::addPoint(), and GeoLib::QuadTree< POINT >::splitNode().

◆ _pnts

template<typename POINT >
std::vector<POINT const*> GeoLib::QuadTree< POINT >::_pnts
private

◆ _ur


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