问题
I have declared a new point type as such below. However, I need it to work with all available PCL functions. Such as segmentation, voxel grid etc. It is a pain to include all the implementation headers do the PCL_INSTANTIATE call. Is there anyway to do this for all major functions? For example, compile my point type for all functions in the segmentation library?
#define PCL_NO_PRECOMPILE
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/impl/instantiate.hpp>
#include <pcl/kdtree/kdtree.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/search/impl/kdtree.hpp>
#include <pcl/octree/octree_search.h>
#include <pcl/octree/impl/octree_search.hpp>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/impl/sac_segmentation.hpp>
struct FeaturePoint
{
PCL_ADD_POINT4D;
PCL_ADD_RGB;
PCL_ADD_NORMAL4D;
static const int DESCRIPTOR_SIZE = 128;
float descriptor[DESCRIPTOR_SIZE];
FeaturePoint() {}
FeaturePoint(const FeaturePoint& input)
{
this->x = input.x;
this->y = input.y;
this->z = input.z;
this->rgb = input.rgb;
this->normal_x = input.normal_x;
this->normal_y = input.normal_y;
this->normal_z = input.normal_z;
for(int i = 0; i < DESCRIPTOR_SIZE; ++i) { this->descriptor[i] = input.descriptor[i]; } // Ugly, as I was lazy
}
EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
} EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT (FeaturePoint,
(float, x, x)
(float, y, y)
(float, z, z)
(float, rgb, rgb)
(float, normal_x, normal_x)
(float, normal_y, normal_y)
(float, normal_z, normal_z)
(float, descriptor, descriptor)
);
PCL_INSTANTIATE(KdTree, FeaturePoint);
PCL_INSTANTIATE(KdTreeFLANN, FeaturePoint);
PCL_INSTANTIATE(OctreePointCloudSearch, FeatureP
回答1:
UPDATE: After trying solutions for hours this works correctly for all functions:
Representative part of code in PCLapp.h:
include pcl-1.8/pcl/point_cloud.h
include pcl-1.8/pcl/point_types.h
include pcl-1.8/pcl/filters/voxel_grid.h
include boost/shared_ptr.hpp
namespace pcl{
struct PointXYZIR
{
PCL_ADD_POINT4D // Macro quad-word XYZ
float intensity; // Laser intensity
uint16_t ring; // Laser ring number
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // Ensure proper alignment
} EIGEN_ALIGN16;
}
POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZIR,
(float, x, x)
(float, y, y)
(float, z, z)
(float, intensity, intensity)
(uint16_t, ring, ring)
)
typedef pcl::PointCloud<pcl::PointXYZIR> PointCloudXYZIR;
### I didn't include any .hpp file (like tutorial said)
Representative part of code in PCLapp.cpp (VoxelGrid example)
boost::shared_ptr<PointCloudXYZIR> input_cloud(new PointCloudXYZIR);
PointCloudXYZIR::ConstPtr input_cloudPtr(input_cloud);
pcl::VoxelGrid<pcl::PointXYZIR> vox;
vox.setInputCloud(input_cloudPtr);
vox.setLeafSize(0.05,0.05,0.05);
vox.filter(*input_cloud);
And this works perfectly with all filters without doing anything more.
回答2:
THIS DOESN'T WORK!!
Instead of using
PCL_INSTANTIATE(function,template);
try
PCL_INSTANTIATE_PointCloud(template);
I hope it helps. I was 2 day looking for this solution.
来源:https://stackoverflow.com/questions/39221424/pcl-instantiating-new-point-types-for-all-functions