41 template<
typename T, std::
size_t dim>
44 for(
size_t i=0; i< nbCells; ++i) cells[i]=
nullptr;
47 template<
typename T, std::
size_t dim>
57 for(
size_t i=0; i<nbCells; ++i)
60 data.insert(data.end(), o.data.begin(), o.data.end());
65 for(
size_t i=0; i<nbCells;++i)
69 cells[i]->parent =
this;
73 template<
typename T, std::
size_t dim>
75 parent{
nullptr}, bb{o.bb.center, o.bb.radius}, depth{o.depth}
83 data.insert(data.end(),
84 std::make_move_iterator(o.data.begin()),
85 std::make_move_iterator(o.data.end()));
88 for(
size_t i=0; i<nbCells; ++i)
90 cells[i] = o.cells[i];
96 template<
typename T, std::
size_t dim>
101 for(
size_t i=0; i<nbCells; ++i)
105 template<
typename T, std::
size_t dim>
116 for(
size_t i=0; i<nbCells; ++i)
119 data.insert(data.end(), o.
data.begin(), o.
data.end());
124 for(
size_t i=0; i<nbCells; ++i)
128 cells[i]->parent =
this;
134 template<
typename T, std::
size_t dim>
141 bb.center = o.bb.center;
142 bb.radius = o.bb.radius;
149 data.insert(data.end(),
150 std::make_move_iterator(o.data.begin()),
151 std::make_move_iterator(o.data.end()));
155 for(
size_t i=0; i<nbCells; ++i)
157 cells[i] = o.cells[i];
165 template<
typename T, std::
size_t dim>
168 return (cells[0]==
nullptr);
170 template<
typename T, std::
size_t dim>
173 return (parent==
nullptr);
175 template<
typename T, std::
size_t dim>
178 return (data.size() == 0);
180 template<
typename T, std::
size_t dim>
185 for(
size_t i=0; i<dim; ++i)
186 id|= ((
pt(i) > bb.center(i)) << i);
191 template<
typename T, std::
size_t dim>
194 return idx(pts.features.col(
d).head(dim));
196 template<
typename T, std::
size_t dim>
201 template<
typename T, std::
size_t dim>
206 template<
typename T, std::
size_t dim>
211 template<
typename T, std::
size_t dim>
216 template<
typename T, std::
size_t dim>
223 template<
typename T, std::
size_t dim>
230 template<
typename T, std::
size_t dim>
238 Vector minValues = pts.features.rowwise().minCoeff();
239 Vector maxValues = pts.features.rowwise().maxCoeff();
242 Point max = maxValues.head(dim);
245 box.center =
min + radii * 0.5;
247 box.radius = radii(0);
248 for(
size_t i=1; i<dim; ++i)
249 if (box.radius < radii(i)) box.radius = radii(i);
254 const size_t nbpts = pts.getNbPoints();
255 std::vector<Id> indexes;
256 indexes.reserve(nbpts);
258 for(
size_t i=0; i<nbpts; ++i)
259 indexes.emplace_back(
Id(i));
264 return this->build(pts, std::move(datas), std::move(box), maxDataByNode, maxSizeByNode, parallelBuild);
268 template<
typename T, std::
size_t dim>
303 template<
typename T, std::
size_t dim>
305 size_t maxDataByNode, T maxSizeByNode,
bool parallelBuild)
308 this->bb.center = bb.center;
309 this->bb.radius = bb.radius;
312 if((bb.radius*2.0 <= maxSizeByNode) or (datas.size() <= maxDataByNode))
315 data.insert(data.end(),
316 std::make_move_iterator(datas.begin()), make_move_iterator(datas.end()));
321 const std::size_t nbData = datas.size();
324 for(
size_t i=0; i<nbCells; ++i)
325 sDatas[i].reserve(nbData);
327 for(
auto&&
d : datas)
328 (sDatas[idx(pts,
d)]).emplace_back(
d);
330 for(
size_t i=0; i<nbCells; ++i)
331 sDatas[i].shrink_to_fit();
334 BoundingBox boxes[nbCells];
335 const T half_radius = this->bb.radius * 0.5;
336 for(
size_t i=0; i<nbCells; ++i)
339 boxes[i].radius = half_radius;
340 boxes[i].center = this->bb.center + offset;
345 std::vector<std::future<void>> futures;
347 for(
size_t i=0; i<nbCells; ++i)
349 auto compute = [maxDataByNode, maxSizeByNode, i, &pts, &sDatas, &boxes,
this](){
352 this->cells[i]->depth = this->depth+1;
354 this->cells[i]->parent =
this;
356 this->cells[i]->build(pts, std::move(sDatas[i]), std::move(boxes[i]), maxDataByNode, maxSizeByNode,
false);
360 futures.push_back( std::async( std::launch::async, compute ));
365 for(
auto&
f : futures)
f.get();
367 return (!isLeaf() and ret);
371 template<
typename T, std::
size_t dim>
372 template<
typename Callback>
377 if (!cb(*
this))
return false;
381 for (
size_t i=0; i<nbCells; ++i)
382 if (!cells[i]->visit(cb))
return false;