Reputation: 11
I came across a problem when trying to register two point clouds using PCL. Instead of using the provided PointT, I used custom point type and followed the tutorial(http://www.pointclouds.org/documentation/tutorials/adding_custom_ptype.php#adding-custom-ptype). However, when I complied the codes in VS2019, it failed. I also tried this post ( PCL Instantiating new Point Types for all Functions). It didn't work neither.
Here is the defination of the point
#ifndef PCL_NO_PRECOMPILE
#define PCL_NO_PRECOMPILE
#endif
#include <iostream>
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>
#include <pcl/impl/point_types.hpp>
#include <pcl/impl/instantiate.hpp>
#include <pcl/point_cloud.h>
#include <pcl/impl/point_types.hpp>
#include <pcl/common/transforms.h>
#include <pcl/common/impl/transforms.hpp>
#include <pcl/registration/icp.h>
#include <pcl/registration/impl/icp.hpp>
#include <pcl/features/fpfh.h>
#include <pcl/features/impl/fpfh.hpp>
#include <pcl/features/pfh.h>
#include <pcl/features/impl/pfh.hpp>
#include <pcl/registration/ia_ransac.h>
#include <pcl/registration/impl/ia_ransac.hpp>
#include <pcl/features/normal_3d.h>
#include <pcl/features/impl/normal_3d.hpp>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/impl/voxel_grid.hpp>
#include <pcl/filters/approximate_voxel_grid.h>
#include <pcl/filters/impl/approximate_voxel_grid.hpp>
#include <Eigen/Core>
struct dPointXYZ {
double x;
double y;
double z;
};
POINT_CLOUD_REGISTER_POINT_STRUCT(dPointXYZ,
(double, x, x)
(double, y, y)
(double, z, z)
)
PCL_INSTANTIATE(VoxelGrid, dPointXYZ);
PCL_INSTANTIATE(NormalEstimation, dPointXYZ);
PCL_INSTANTIATE(KdTree, dPointXYZ);
PCL_INSTANTIATE(FPFHEstimation,dPointXYZ);
PCL_INSTANTIATE(SampleConsensusInitialAlignment, dPointXYZ)
Here is how the custom point type is used
void voxelFilteringPoints(pcl::PointCloud<pcl::dPointXYZ>::Ptr& ProjPoint, pcl::PointCloud<pcl::dPointXYZ>::Ptr& filteredPoints, float dGridSize)
{
pcl::VoxelGrid<pcl::dPointXYZ> ApproximateVoxelGrid;
ApproximateVoxelGrid.setLeafSize(dGridSize, dGridSize, dGridSize);
ApproximateVoxelGrid.setInputCloud(ProjPoint);
ApproximateVoxelGrid.filter(*filteredPoints);
//std::cout<<"Filtered points size: "<<*filteredPoints<<std::endl;
}
pcl::PointCloud<dNormal>::Ptr computeNormals(pcl::PointCloud<dPointXYZ>::Ptr& ProjPoint, double dNormalsRadius)
{
pcl::PointCloud<dNormal>::Ptr NormalsPtr(new pcl::PointCloud<dNormal>());
pcl::NormalEstimation<dPointXYZ, dNormal> NormEstimate;
NormEstimate.setInputCloud(ProjPoint);
NormEstimate.setRadiusSearch(dNormalsRadius);
pcl::search::KdTree<dPointXYZ>::Ptr PtrSearchMethod(new pcl::search::KdTree<dPointXYZ>);
NormEstimate.setSearchMethod(PtrSearchMethod);
NormEstimate.compute(*NormalsPtr);
//std::cout<<"Normals size: "<<*NormalsPtr<<std::endl;
return NormalsPtr;
}
pcl::PointCloud<pcl::FPFHSignature33>::Ptr getFPFHFeatures(pcl::PointCloud<dPointXYZ>::Ptr& ProjCloud, pcl::PointCloud<dNormal>::Ptr& ProjNormals, double dFeatureRadius)
{
pcl::PointCloud<pcl::FPFHSignature33>::Ptr FPFHFeatures(new pcl::PointCloud<pcl::FPFHSignature33>());
//std::cout<<"FPFH size: "<<FPFHFeatures<<std::endl;
pcl::search::KdTree<dPointXYZ>::Ptr PtrSearchMethod(new pcl::search::KdTree<dPointXYZ>);
pcl::FPFHEstimation<dPointXYZ, dNormal, pcl::FPFHSignature33> FPFHEstimate;
FPFHEstimate.setInputCloud(ProjCloud);
FPFHEstimate.setInputNormals(ProjNormals);
FPFHEstimate.setSearchMethod(PtrSearchMethod);
FPFHEstimate.setRadiusSearch(dFeatureRadius);
FPFHEstimate.compute(*FPFHFeatures);
return FPFHFeatures;
}
pcl::SampleConsensusInitialAlignment<dPointXYZ,dPointXYZ, pcl::FPFHSignature33> alignFPFH(pcl::PointCloud<dPointXYZ>::Ptr& ProjPoint1,
pcl::PointCloud<dPointXYZ>::Ptr& ProjPoint2, pcl::PointCloud<pcl::FPFHSignature33>::Ptr& FPFHProjFeatures1,
pcl::PointCloud<pcl::FPFHSignature33>::Ptr& FPFHProjFeatures2, int iMaxIterations, double dMinDist, double dMaxDist)
{
pcl::SampleConsensusInitialAlignment<dPointXYZ, dPointXYZ, pcl::FPFHSignature33> SCIA;
Eigen::Matrix4f transMatrix;
SCIA.setInputCloud(ProjPoint2);
SCIA.setSourceFeatures(FPFHProjFeatures2);
SCIA.setInputTarget(ProjPoint1);
SCIA.setTargetFeatures(FPFHProjFeatures1);
SCIA.setMaximumIterations(iMaxIterations);
SCIA.setMinSampleDistance(dMinDist);
SCIA.setMaxCorrespondenceDistance(dMaxDist);
pcl::PointCloud<dPointXYZ> registeredCloud;
SCIA.align(registeredCloud);
SCIA.getCorrespondenceRandomness();
return SCIA;
}
The compiler indicates class template has been defined. Error C2953 'pcl::detail::Transformer': class template has already been defined C:\Program Files\PCL_1.9.1\include\pcl-1.9\pcl\common\impl\transforms.hpp 89
Error C2995 'void pcl::transformPointCloud(const pcl::PointCloud &,pcl::PointCloud &,const Eigen::Transform &,bool)': function template has already been defined C:\Program Files\PCL_1.9.1\include\pcl-1.9\pcl\common\impl\transforms.hpp 215
Error C2995 'void pcl::transformPointCloud(const pcl::PointCloud &,const std::vector> &,pcl::PointCloud &,const Eigen::Transform &,bool)': function template has already been defined
I know I can simply use the float type instead by normalizing the points, but I want to try the custom point type. Do you have any ideas how to solve the problem?
Upvotes: 1
Views: 3417
Reputation: 725
It seems like PCL_NO_PRECOMPILE
needs to be defined before you include any of the PCL header files.. Judging from the "template has already been defined" error.
Check your .cpp file, e.g. in main.cpp
#define PCL_NO_PRECOMPILE // !! BEFORE ANY PCL INCLUDE!!
#include <pcl/....h>
#include "your_file_that_shows_how_the_custom_point_type_is_used.h"
int main(){...}
Upvotes: 0