37template <
typename POINT>
73 "QuadTree(): lower left: ({:f},{:f},{:f}), upper right: "
74 "({:f},{:f},{:f}), depth: {:d}",
103 if ((*pnt)[0] <
_ll[0])
107 if ((*pnt)[0] >=
_ur[0])
111 if ((*pnt)[1] <
_ll[1])
115 if ((*pnt)[1] >=
_ur[1])
124 {
return child->addPoint(pnt); });
128 bool pnt_in_quadtree(
false);
129 for (std::size_t k(0); k <
_pnts.size() && !pnt_in_quadtree; k++)
131 const double v0((*(
_pnts[k]))[0] - (*pnt)[0]);
132 const double v1((*(
_pnts[k]))[1] - (*pnt)[1]);
133 const double sqr_dist(v0 * v0 + v1 * v1);
134 if (sqr_dist < std::numeric_limits<double>::epsilon())
136 pnt_in_quadtree =
true;
139 if (!pnt_in_quadtree)
141 _pnts.push_back(pnt);
164 std::list<QuadTree<POINT>*> leaf_list;
167 while (!leaf_list.empty())
170 leaf_list.pop_front();
184 if (north_neighbor !=
nullptr)
188 if (north_neighbor->
isLeaf())
190 leaf_list.push_back(north_neighbor);
197 if (west_neighbor !=
nullptr)
201 if (west_neighbor->
isLeaf())
203 leaf_list.push_back(west_neighbor);
210 if (south_neighbor !=
nullptr)
214 if (south_neighbor->
isLeaf())
216 leaf_list.push_back(south_neighbor);
223 if (east_neighbor !=
nullptr)
227 if (east_neighbor->
isLeaf())
229 leaf_list.push_back(east_neighbor);
246 leaf_list.push_back(
this);
252 child->getLeafs(leaf_list);
274 if (pnt[0] <= 0.5 * (
_ur[0] +
_ll[0]))
276 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
289 if (pnt[1] <= 0.5 * (
_ur[1] +
_ll[1]))
327 child->getMaxDepth(max_depth);
341 return _children[
static_cast<int>(quadrant)];
348 return _children[
static_cast<int>(quadrant)] == tree;
368 if (north_neighbor ==
nullptr)
372 if (north_neighbor->
isLeaf())
374 return north_neighbor;
402 if (south_neighbor ==
nullptr)
406 if (south_neighbor->
isLeaf())
408 return south_neighbor;
436 if (east_neighbor ==
nullptr)
440 if (east_neighbor->
isLeaf())
442 return east_neighbor;
470 if (west_neighbor ==
nullptr)
474 if (west_neighbor->
isLeaf())
476 return west_neighbor;
499 std::size_t max_points_per_leaf)
512 mid_point[0] += (
_ur[0] -
_ll[0]) / 2.0;
513 mid_point[1] += (
_ur[1] -
_ll[1]) / 2.0;
517 POINT h_ll(mid_point), h_ur(mid_point);
527 h_ll[0] = mid_point[0];
529 h_ur[1] = mid_point[1];
535 for (std::size_t j(0); j <
_pnts.size(); j++)
538 for (std::size_t k(0); k < 4 && nfound; k++)
553 if (north_neighbor !=
nullptr)
557 if (!north_neighbor->
isLeaf())
572 if (west_neighbor !=
nullptr)
576 if (!west_neighbor->
isLeaf())
591 if (south_neighbor !=
nullptr)
595 if (!south_neighbor->
isLeaf())
610 if (east_neighbor !=
nullptr)
614 if (!east_neighbor->
isLeaf())
638 std::array<QuadTree<POINT>*, 4>
_children = {
nullptr,
nullptr,
nullptr,
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
QuadTree< POINT > * _father
QuadTree< POINT > * getNorthNeighbor() const
bool isChild(QuadTree< POINT > const *const tree, Quadrant quadrant) const
static bool needToRefine(QuadTree< POINT > const *const node)
QuadTree< POINT > const * getChild(Quadrant quadrant) const
std::array< QuadTree< POINT > *, 4 > _children
QuadTree< POINT > const * getFather() const
std::size_t getDepth() const
void getMaxDepth(std::size_t &max_depth) const
void getLeafs(std::list< QuadTree< POINT > * > &leaf_list)
const std::vector< POINT const * > & getPoints() const
QuadTree< POINT > * getWestNeighbor() const
const std::size_t _max_points_per_leaf
std::vector< POINT const * > _pnts
void getLeaf(const POINT &pnt, POINT &ll, POINT &ur)
QuadTree< POINT > * getSouthNeighbor() const
bool addPoint(POINT const *pnt)
QuadTree< POINT > * getChild(Quadrant quadrant)
QuadTree< POINT > * getEastNeighbor() const
void getSquarePoints(POINT &ll, POINT &ur) const
QuadTree(POINT ll, POINT ur, QuadTree *father, std::size_t depth, std::size_t max_points_per_leaf)
QuadTree(POINT ll, POINT ur, std::size_t max_points_per_leaf)