Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrganizedFastMesh fails during compilation with certain point types #2890

Closed
mattforestyoung opened this issue Mar 5, 2019 · 3 comments
Closed

Comments

@mattforestyoung
Copy link

mattforestyoung commented Mar 5, 2019

This is more of an FYI for others and a suggestion for a fix... but when declaring the OrganizedFastMesh<PointT> object, compilation may fail depending on what PointT is typedef'd to be. Generally any point type that includes a normal component fails. Specifically:

PointXYZ             compiles
PointXYZI            fails
PointRGB             compiles
PointRGBA            compiles
PointNormal          fails
PointXYZINormal      fails
PointXYZRGBNormal    fails

Your Environment

  • Operating System and version: Ubuntu 14.04
  • Compiler: GCC v4.8.4
  • PCL Version: 1.8.1
  • C++ Version: C++11

Context

Discovered this while trying to improve my Generalized ICP results with sparse LiDAR scans, using the methodology provided in Listing 12 of Registration with the Point Cloud Library.

This problem has been discussed elsewhere, in this mailing list thread and this rtab mapping issue but these threads treat the problem as a linker error, whereas my (very brief) testing suggests its a type declaration issue.

Expected Behavior

I expect the code below to compile and override the normals with the normals calculated from the mesh, or warn the user that the object cannot be compiled with this point type.

Current Behavior

If an incompatible point type is used, the code fails to compile with the following warning:

[100%] Linking CXX executable /home/matt/canis_repo/workspace/devel/lib/canis/rosmap_main
/home/matt/canis_repo/workspace/devel/lib/librosmap_registration.so: undefined reference to `pcl::OrganizedFastMesh<pcl::PointXYZRGBNormal>::performReconstruction(pcl::PolygonMesh&)'
/home/matt/canis_repo/workspace/devel/lib/librosmap_registration.so: undefined reference to `pcl::OrganizedFastMesh<pcl::PointXYZRGBNormal>::performReconstruction(std::vector<pcl::Vertices, std::allocator<pcl::Vertices> >&)'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/matt/canis_repo/workspace/devel/lib/canis/rosmap_main] Error 1
make[1]: *** [canis/CMakeFiles/rosmap_main.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

Code to Reproduce

The relevant code is:

#include <pcl/PolygonMesh.h>
#include <pcl/features/from_meshes.h>
#include <pcl/registration/icp.h>               // Standard ICP
#include <pcl/registration/gicp.h>              // Generalized ICP
#include <pcl/surface/organized_fast_mesh.h>

typedef pcl::PointXYZRGBNormal PointT;
typedef pcl::PointCloud<PointT> PointCloudT;
typedef std::vector< Eigen::Matrix3d, Eigen::aligned_allocator<Eigen::Matrix3d> > MatricesVector;

  void
  RegisterCloudsWithApproximateCovariance(pcl::PointCloud<PointT>::Ptr target_cloud,
                                          pcl::PointCloud<PointT>::Ptr source_cloud,
                                          Eigen::Affine3d& correction_affine)
  {
    PolygonMesh::Ptr target_mesh (new PolygonMesh);
    PolygonMesh::Ptr source_mesh (new PolygonMesh);

    // Reconstruct meshes for source and target
    OrganizedFastMesh<PointT> fast_mesh;
    fast_mesh.setInputCloud(target_cloud);
    fast_mesh.reconstruct(*target_mesh);
    fast_mesh.setInputCloud(source_cloud);
    fast_mesh.reconstruct(*source_mesh);

    // Compute normals and covariances for mesh
    PointCloud<Normal>::Ptr target_normals (new PointCloud<Normal>);
    PointCloud<Normal>::Ptr source_normals (new PointCloud<Normal>);
    boost::shared_ptr< MatricesVector > target_covariances (new MatricesVector);
    boost::shared_ptr< MatricesVector > source_covariances (new MatricesVector);
    pcl::features::computeApproximateNormals(*target_cloud, target_mesh->polygons, *target_normals);
    pcl::features::computeApproximateCovariances(*target_cloud, *target_normals, *target_covariances);

    pcl::features::computeApproximateNormals(*source_cloud, source_mesh->polygons, *source_normals);
    pcl::features::computeApproximateCovariances(*source_cloud, *source_normals, *source_covariances);

// ... ordinary GICP registration code ...
}

Possible Solution

Modify the OrganizedFastMesh object so it can be compiled with a PointT that includes a normal component, or warn the user that it won't work.

@kartikmadhira1
Copy link

Works for me by adding, #include <pcl/surface/impl/organized_fast_mesh.hpp>

@SergioRAgostinho
Copy link
Member

About the compilation issue. It is very likely that this is not a bug. We're just not precompiling the class for the types you're using. Declare

#define PCL_NO_PRECOMPILE

before including pcl headers.

@kunaltyagi kunaltyagi added the kind: compile error Type of issue label Mar 5, 2020
@kunaltyagi
Copy link
Member

kunaltyagi commented Mar 5, 2020

Indeed. The PCL being used has been pre-compiled for only a few point types. While this has several benefits, it locks-in the user of the library to the pre-decided point types. In order to use with any other type, you need to choose one of the following options:

  • compile PCL with PCL_NO_PRECOMPILE
  • define PCL_NO_PRECOMPILE before including any PCL header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants