47 template<std::
size_t dim>
53 const auto&
d = (*data)[0];
58 if(std::size_t(
d)<idx)
77 pts.conservativeResize(idx);
98 template<std::
size_t dim>
104 const std::size_t nbData = (*data).size() - 1;
105 const std::size_t randId =
106 static_cast<std::size_t
>( nbData *
107 (
static_cast<float>(std::rand()/
static_cast<float>(RAND_MAX))));
109 const auto&
d = (*data)[randId];
114 if(std::size_t(
d)<idx)
118 pts.swapCols(idx, j);
146 template<std::
size_t dim>
151 const int featDim(pts.features.rows());
152 const int descDim(pts.descriptors.rows());
153 const int timeDim(pts.times.rows());
156 const std::size_t nbData = (*data).size();
158 const auto&
d = (*data)[0];
162 if(std::size_t(
d)<idx)
166 for(std::size_t
id=1;
id<nbData;++id)
169 const auto& curId = (*data)[id];
170 std::size_t i = curId;
173 if(std::size_t(curId)<idx)
176 for (
int f = 0;
f < (featDim - 1); ++
f)
177 pts.features(
f,j) += pts.features(
f,i);
179 if (pts.descriptors.cols() > 0)
180 for (
int d = 0;
d < descDim; ++
d)
181 pts.descriptors(
d,j) += pts.descriptors(
d,i);
183 if (pts.times.cols() > 0)
184 for (
int t = 0;
t < timeDim; ++
t)
185 pts.times(
t,j) += pts.times(
t,i);
189 for (
int f = 0;
f < (featDim - 1); ++
f)
190 pts.features(
f,j) /= T(nbData);
192 if (pts.descriptors.cols() > 0)
193 for (
int d = 0;
d < descDim; ++
d)
194 pts.descriptors(
d,j) /= T(nbData);
196 if (pts.times.cols() > 0)
197 for (
int t = 0;
t < timeDim; ++
t)
198 pts.times(
t,j) /= T(nbData);
201 pts.swapCols(idx, j);
218 template<std::
size_t dim>
224 const std::size_t nbData = (*data).size();
227 return (p1 - p2).norm();
232 for(std::size_t i=0;i<dim;++i) center(i)=T(0.);
234 for(std::size_t
id=0;
id<nbData;++id)
237 const auto& curId = (*data)[id];
238 std::size_t i = curId;
241 if(std::size_t(curId)<idx)
244 for (std::size_t
f = 0;
f < dim; ++
f)
245 center(
f) += pts.features(
f,i);
247 for(std::size_t i=0;i<dim;++i) center(i)/=T(nbData);
250 T minDist = std::numeric_limits<T>::max();
251 std::size_t medId = 0;
253 for(std::size_t
id=0;
id<nbData;++id)
256 const auto curId = (*data)[id];
257 std::size_t i = curId;
260 if(std::size_t(curId)<idx)
263 const T curDist = dist(pts.features.col(i).head(dim), center);
272 pts.swapCols(idx, medId);
285 template <
typename T>
290 maxPointByNode{Parametrizable::get<std::size_t>(
"maxPointByNode")},
291 maxSizeByNode{Parametrizable::get<T>(
"maxSizeByNode")}
295 const int sm = this->
template get<int>(
"samplingMethod");
296 samplingMethod = SamplingMethod(sm);
298 catch (
const InvalidParameter& e)
300 samplingMethod = SamplingMethod::FIRST_PTS;
304 template <
typename T>
309 inPlaceFilter(output);
313 template <
typename T>
316 const std::size_t featDim = cloud.
features.rows();
318 assert(featDim == 4 or featDim == 3);
321 this->sample<2>(cloud);
324 this->sample<3>(cloud);
328 template<std::
size_t dim>
333 oc.
build(cloud, maxPointByNode, maxSizeByNode, buildParallel);
335 switch(samplingMethod)
337 case SamplingMethod::FIRST_PTS:
344 case SamplingMethod::RAND_PTS:
351 case SamplingMethod::CENTROID:
358 case SamplingMethod::MEDOID: