OGS
OctTree.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include <Eigen/Core>
7#include <cstdint>
8#include <limits>
9#include <vector>
10
11namespace GeoLib
12{
15template <typename POINT, std::size_t MAX_POINTS>
17{
18public:
36 Eigen::Vector3d ll, Eigen::Vector3d ur,
37 double eps = std::numeric_limits<double>::epsilon());
38
41 virtual ~OctTree();
42
57 bool addPoint(POINT* pnt, POINT*& ret_pnt);
58
61 template <typename T>
62 void getPointsInRange(T const& min, T const& max,
63 std::vector<POINT*>& pnts) const;
64
65#ifndef NDEBUG
66 Eigen::Vector3d const& getLowerLeftCornerPoint() const { return _ll; }
67 Eigen::Vector3d const& getUpperRightCornerPoint() const { return _ur; }
68 OctTree<POINT, MAX_POINTS> const* getChild(std::size_t i) const
69 {
70 return _children[i];
71 }
72 std::vector<POINT*> const& getPointVector() const { return _pnts; }
73#endif
74
75private:
80 OctTree(Eigen::Vector3d const& ll, Eigen::Vector3d const& ur, double eps);
81
82 enum class Quadrant : std::int8_t
83 {
84 NEL = 0,
92 };
93
99 bool addPoint_(POINT* pnt, POINT*& ret_pnt);
100
107 bool addPointToChild(POINT* pnt);
108
112 void splitNode(POINT* pnt);
113
117 bool isOutside(POINT* pnt) const;
118
121 template <typename T>
122 void getPointsInRange_(T const& min, T const& max,
123 std::vector<POINT*>& pnts) const;
124
134 std::array<OctTree<POINT, MAX_POINTS>*, 8> _children;
136 Eigen::Vector3d const _ll;
138 Eigen::Vector3d const _ur;
140 std::vector<POINT*> _pnts;
144 double const _eps;
145};
146
147} // end namespace GeoLib
148
149#include "OctTree-impl.h"
Eigen::Vector3d const _ur
upper right back face point of the cube
Definition OctTree.h:138
Eigen::Vector3d const & getLowerLeftCornerPoint() const
Definition OctTree.h:66
bool addPoint(POINT *pnt, POINT *&ret_pnt)
bool addPointToChild(POINT *pnt)
bool addPoint_(POINT *pnt, POINT *&ret_pnt)
void splitNode(POINT *pnt)
void getPointsInRange(T const &min, T const &max, std::vector< POINT * > &pnts) const
bool _is_leaf
flag if this OctTree is a leaf
Definition OctTree.h:142
OctTree(Eigen::Vector3d const &ll, Eigen::Vector3d const &ur, double eps)
void getPointsInRange_(T const &min, T const &max, std::vector< POINT * > &pnts) const
Eigen::Vector3d const & getUpperRightCornerPoint() const
Definition OctTree.h:67
@ NEU
south west upper
Definition OctTree.h:88
@ NEL
north east lower
Definition OctTree.h:84
@ SWU
south west upper
Definition OctTree.h:90
@ SEU
south east upper
Definition OctTree.h:91
@ NWL
north west lower
Definition OctTree.h:85
@ SWL
south west lower
Definition OctTree.h:86
@ NWU
south west upper
Definition OctTree.h:89
@ SEL
south east lower
Definition OctTree.h:87
std::array< OctTree< POINT, MAX_POINTS > *, 8 > _children
Definition OctTree.h:134
std::vector< POINT * > const & getPointVector() const
Definition OctTree.h:72
std::vector< POINT * > _pnts
vector of pointers to POINT objects
Definition OctTree.h:140
bool isOutside(POINT *pnt) const
double const _eps
threshold for point uniqueness
Definition OctTree.h:144
static OctTree< POINT, MAX_POINTS > * createOctTree(Eigen::Vector3d ll, Eigen::Vector3d ur, double eps=std::numeric_limits< double >::epsilon())
Definition OctTree-impl.h:7
virtual ~OctTree()
OctTree< POINT, MAX_POINTS > const * getChild(std::size_t i) const
Definition OctTree.h:68
Eigen::Vector3d const _ll
lower left front face point of the cube
Definition OctTree.h:136