Skip to content

Commit 18e3db6

Browse files
committed
Provide default estimator algorithm
1 parent 6491dec commit 18e3db6

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

libraries/YarpCloudUtils/YarpCloudUtils-pcl.cpp

+39-39
Original file line numberDiff line numberDiff line change
@@ -270,45 +270,6 @@ namespace
270270
}
271271
}
272272

273-
template <typename T>
274-
void estimateNormals(const typename pcl::PointCloud<T>::ConstPtr & in, const pcl::PointCloud<pcl::Normal>::Ptr & out, const yarp::os::Searchable & options)
275-
{
276-
auto algorithm = options.check("estimatorAlgorithm", yarp::os::Value("")).asString();
277-
auto kSearch = options.check("estimatorKSearch", yarp::os::Value(0)).asInt32();
278-
auto radiusSearch = options.check("estimatorRadiusSearch", yarp::os::Value(0.0)).asFloat64();
279-
280-
typename pcl::NormalEstimation<T, pcl::Normal>::Ptr estimator;
281-
282-
if (algorithm == "NormalEstimationOMP")
283-
{
284-
auto numberOfThreads = options.check("estimatorNumberOfThreads", yarp::os::Value(0)).asInt32();
285-
auto * omp = new pcl::NormalEstimationOMP<T, pcl::Normal>();
286-
omp->setNumberOfThreads(numberOfThreads);
287-
estimator.reset(omp);
288-
}
289-
else if (algorithm == "NormalEstimation")
290-
{
291-
estimator.reset(new pcl::NormalEstimation<T, pcl::Normal>());
292-
}
293-
else
294-
{
295-
throw std::invalid_argument("unsupported normal estimation algorithm: " + algorithm);
296-
}
297-
298-
typename pcl::search::KdTree<T>::Ptr tree(new pcl::search::KdTree<T>());
299-
tree->setInputCloud(in);
300-
estimator->setInputCloud(in);
301-
estimator->setKSearch(kSearch);
302-
estimator->setRadiusSearch(radiusSearch);
303-
estimator->setSearchMethod(tree);
304-
estimator->compute(*out);
305-
306-
if (out->empty())
307-
{
308-
throw std::runtime_error("got empty cloud after normal estimation step");
309-
}
310-
}
311-
312273
template <typename T>
313274
void reconstructHull(const typename pcl::PointCloud<T>::ConstPtr & in, const pcl::PolygonMesh::Ptr & out, const yarp::os::Searchable & options)
314275
{
@@ -400,6 +361,45 @@ namespace
400361
organized.reconstruct(*out);
401362
}
402363

364+
template <typename T>
365+
void estimateNormals(const typename pcl::PointCloud<T>::ConstPtr & in, const pcl::PointCloud<pcl::Normal>::Ptr & out, const yarp::os::Searchable & options)
366+
{
367+
auto algorithm = options.check("estimatorAlgorithm", yarp::os::Value("")).asString();
368+
auto kSearch = options.check("estimatorKSearch", yarp::os::Value(0)).asInt32();
369+
auto radiusSearch = options.check("estimatorRadiusSearch", yarp::os::Value(0.0)).asFloat64();
370+
371+
typename pcl::NormalEstimation<T, pcl::Normal>::Ptr estimator;
372+
373+
if (algorithm == "NormalEstimation")
374+
{
375+
estimator.reset(new pcl::NormalEstimation<T, pcl::Normal>());
376+
}
377+
else if (algorithm == "NormalEstimationOMP")
378+
{
379+
auto numberOfThreads = options.check("estimatorNumberOfThreads", yarp::os::Value(0)).asInt32();
380+
auto * omp = new pcl::NormalEstimationOMP<T, pcl::Normal>();
381+
omp->setNumberOfThreads(numberOfThreads);
382+
estimator.reset(omp);
383+
}
384+
else
385+
{
386+
throw std::invalid_argument("unsupported normal estimation algorithm: " + algorithm);
387+
}
388+
389+
typename pcl::search::KdTree<T>::Ptr tree(new pcl::search::KdTree<T>());
390+
tree->setInputCloud(in);
391+
estimator->setInputCloud(in);
392+
estimator->setKSearch(kSearch);
393+
estimator->setRadiusSearch(radiusSearch);
394+
estimator->setSearchMethod(tree);
395+
estimator->compute(*out);
396+
397+
if (out->empty())
398+
{
399+
throw std::runtime_error("got empty cloud after normal estimation step");
400+
}
401+
}
402+
403403
template <typename T>
404404
void reconstructNormal(const typename pcl::PointCloud<T>::ConstPtr & in, const pcl::PolygonMesh::Ptr & out, const yarp::os::Searchable & options)
405405
{

libraries/YarpCloudUtils/YarpCloudUtils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ bool meshFromCloud(const yarp::sig::PointCloud<T> & cloud,
5050
const yarp::os::Searchable & options = yarp::os::Property({
5151
{"downsampleAlgorithm", yarp::os::Value("VoxelGrid")},
5252
{"downsampleLeafSize", yarp::os::Value(0.02f)},
53+
{"estimatorAlgorithm", yarp::os::Value("NormalEstimationOMP")},
5354
{"estimatorKSearch", yarp::os::Value(40)},
5455
{"surfaceAlgorithm", yarp::os::Value("Poisson")}
5556
}));

0 commit comments

Comments
 (0)