Skip to content

Commit

Permalink
Add specialized instantiations for the MLS algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Oct 17, 2024
1 parent 5553e25 commit 2b92820
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libraries/YarpCloudUtils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(ENABLE_YarpCloudUtils)
target_link_libraries(YarpCloudUtils PRIVATE YARP::YARP_pcl
${PCL_LIBRARIES})

target_compile_definitions(YarpCloudUtils PUBLIC YCU_HAVE_PCL PCL_NO_PRECOMPILE)
target_compile_definitions(YarpCloudUtils PUBLIC YCU_HAVE_PCL)
endif()

add_library(ROBOTICSLAB::YarpCloudUtils ALIAS YarpCloudUtils)
Expand Down
35 changes: 35 additions & 0 deletions libraries/YarpCloudUtils/YarpCloudUtils-pcl-traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ struct pcl_xyzi_types_tag {}; // XYZI(+Normal)

struct pcl_normal_types_tag {};

// special cases for pcl::MovingLeastSquares, see:
// https://github.com/PointCloudLibrary/pcl/pull/5764
struct pcl_mls_types_tag : public pcl_all_xyz_types_tag {};
struct pcl_mls_normal_types_tag : public pcl_normal_types_tag {};

// map PCL type according to selected tag

template <typename T, typename tag>
Expand Down Expand Up @@ -130,6 +135,36 @@ template <>
struct pcl_decay<pcl::InterestPoint, pcl_normal_types_tag>
{ typedef pcl::PointNormal type; };

// mappings for pcl::MovingLeastSquares (special case, less precompiled instantiations)

template <typename T>
struct pcl_decay<T, pcl_mls_types_tag>
{ typedef T type; };

template <>
struct pcl_decay<pcl::InterestPoint, pcl_mls_types_tag>
{ typedef pcl::PointXYZ type; };

template <typename T>
struct pcl_decay<T, pcl_mls_normal_types_tag>
{ typedef T type; };

template <>
struct pcl_decay<pcl::PointXYZ, pcl_mls_normal_types_tag>
{ typedef pcl::PointNormal type; };

template <>
struct pcl_decay<pcl::PointXYZRGB, pcl_mls_normal_types_tag>
{ typedef pcl::PointXYZRGBNormal type; };

template <>
struct pcl_decay<pcl::PointXYZI, pcl_mls_normal_types_tag>
{ typedef pcl::PointNormal type; };

template <>
struct pcl_decay<pcl::InterestPoint, pcl_mls_normal_types_tag>
{ typedef pcl::PointNormal type; };

// register allowed conversions

template <typename T1, typename T2>
Expand Down
6 changes: 4 additions & 2 deletions libraries/YarpCloudUtils/YarpCloudUtils-pcl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ namespace
using rgb_t = typename pcl_decay<T, pcl_rgb_types_tag>::type;
using xyzi_t = typename pcl_decay<T, pcl_xyzi_types_tag>::type;
using normal_t = typename pcl_decay<T, pcl_normal_types_tag>::type;
using mls_t = typename pcl_decay<T, pcl_mls_types_tag>::type;
using mls_normal_t = typename pcl_decay<T, pcl_mls_normal_types_tag>::type;

if (!options.check("algorithm"))
{
Expand Down Expand Up @@ -142,9 +144,9 @@ namespace
break;
case "MovingLeastSquares"_hash:
if (options.check("computeNormals"), yarp::os::Value(false).asBool())
doMovingLeastSquares<any_xyz_t, normal_t>(prev.getCloud<any_xyz_t>(), curr.setCloud<normal_t>(), options);
doMovingLeastSquares<mls_t, mls_normal_t>(prev.getCloud<mls_t>(), curr.setCloud<mls_normal_t>(), options);
else
doMovingLeastSquares<any_xyz_t>(prev.getCloud<any_xyz_t>(), curr.setCloud<any_xyz_t>(), options);
doMovingLeastSquares<mls_t>(prev.getCloud<mls_t>(), curr.setCloud<mls_t>(), options);
break;
case "NormalEstimation"_hash:
pcl::copyPointCloud(*prev.getCloud<any_xyz_t>(), *curr.setCloud<normal_t>());
Expand Down

0 comments on commit 2b92820

Please sign in to comment.