17 Eigen::Vector3d ll, Eigen::Vector3d ur,
double eps)
20 const double dx(ur[0] - ll[0]);
21 const double dy(ur[1] - ll[1]);
22 const double dz(ur[2] - ll[2]);
23 if (dx >= dy && dx >= dz)
25 ll[1] -= (dx - dy) / 2.0;
26 ur[1] += (dx - dy) / 2.0;
27 ll[2] -= (dx - dz) / 2.0;
28 ur[2] += (dx - dz) / 2.0;
32 if (dy >= dx && dy >= dz)
34 ll[0] -= (dy - dx) / 2.0;
35 ur[0] += (dy - dx) / 2.0;
36 ll[2] -= (dy - dz) / 2.0;
37 ur[2] += (dy - dz) / 2.0;
41 ll[0] -= (dz - dx) / 2.0;
42 ur[0] += (dz - dx) / 2.0;
43 ll[1] -= (dz - dy) / 2.0;
44 ur[1] += (dz - dy) / 2.0;
49 eps = std::numeric_limits<double>::epsilon();
51 for (std::size_t k(0); k < 3; ++k)
53 if (ur[k] - ll[k] > 0.0)
55 ur[k] += (ur[k] - ll[k]) * 1e-6;
62 Eigen::Vector3d lower_left{ll[0], ll[1], ll[2]};
63 Eigen::Vector3d upper_right{ur[0], ur[1], ur[2]};
80 std::vector<POINT*> query_pnts;
81 Eigen::Vector3d
const min = pnt->asEigenVector3d().array() - _eps;
82 Eigen::Vector3d
const max = {
83 std::abs(((*pnt)[0] + _eps) - (*pnt)[0]) > 0.0
85 : std::nextafter((*pnt)[0],
86 std::numeric_limits<double>::infinity()),
87 std::abs(((*pnt)[1] + _eps) - (*pnt)[1]) > 0.0
89 : std::nextafter((*pnt)[1],
90 std::numeric_limits<double>::infinity()),
91 std::abs(((*pnt)[2] + _eps) - (*pnt)[2]) > 0.0
93 : std::nextafter((*pnt)[2],
94 std::numeric_limits<double>::infinity())};
95 getPointsInRange(min, max, query_pnts);
97 std::find_if(query_pnts.begin(), query_pnts.end(),
98 [pnt,
this](
auto const* p)
100 return (p->asEigenVector3d() - pnt->asEigenVector3d())
101 .squaredNorm() < _eps * _eps;
103 if (it != query_pnts.end())
119 for (
auto c : _children)
121 if (c->addPoint_(pnt, ret_pnt))
125 if (ret_pnt !=
nullptr)
134 if (_pnts.size() < MAX_POINTS)
136 _pnts.push_back(pnt);
149 T
const& min, T
const& max, std::vector<POINT*>& pnts)
const
151 if (_ur[0] < min[0] || _ur[1] < min[1] || _ur[2] < min[2])
156 if (max[0] < _ll[0] || max[1] < _ll[1] || max[2] < _ll[2])
163 std::copy_if(_pnts.begin(), _pnts.end(), std::back_inserter(pnts),
164 [&min, &max](
auto const* p)
166 return (min[0] <= (*p)[0] && (*p)[0] < max[0] &&
167 min[1] <= (*p)[1] && (*p)[1] < max[1] &&
168 min[2] <= (*p)[2] && (*p)[2] < max[2]);
173 for (std::size_t k(0); k < 8; k++)
175 _children[k]->getPointsInRange(min, max, pnts);
249 const double x_mid((_ur[0] + _ll[0]) / 2.0);
250 const double y_mid((_ur[1] + _ll[1]) / 2.0);
251 const double z_mid((_ur[2] + _ll[2]) / 2.0);
252 Eigen::Vector3d p0{x_mid, y_mid, _ll[2]};
253 Eigen::Vector3d p1{_ur[0], _ur[1], z_mid};
256 _children[
static_cast<std::int8_t
>(Quadrant::NEL)] =
262 _children[
static_cast<std::int8_t
>(Quadrant::NWL)] =
268 _children[
static_cast<std::int8_t
>(Quadrant::SWL)] =
272 _children[
static_cast<std::int8_t
>(Quadrant::NEU)] =
278 _children[
static_cast<std::int8_t
>(Quadrant::SEL)] =
288 _children[
static_cast<std::int8_t
>(Quadrant::NWU)] =
294 _children[
static_cast<std::int8_t
>(Quadrant::SWU)] =
302 _children[
static_cast<std::int8_t
>(Quadrant::SEU)] =
306 for (std::size_t k(0); k < 8; k++)
308 if (_children[k]->addPointToChild(pnt))
315 const std::size_t n_pnts(_pnts.size());
316 for (std::size_t j(0); j < n_pnts; j++)
318 if (std::any_of(begin(_children), end(_children),
320 {
return child->addPointToChild(_pnts[j]); }))