#include<pcl/memory.h>// for pcl::make_shared#include<pcl/point_types.h>#include<pcl/point_cloud.h>#include<pcl/point_representation.h>#include<pcl/io/pcd_io.h>#include<pcl/filters/voxel_grid.h>#include<pcl/filters/filter.h>#include<pcl/features/normal_3d.h>#include<pcl/registration/icp.h>#include<pcl/registration/icp_nl.h>#include<pcl/registration/transforms.h>#include<pcl/visualization/pcl_visualizer.h>using pcl::visualization::PointCloudColorHandlerGenericField;using pcl::visualization::PointCloudColorHandlerCustom;//convenient typedefstypedef pcl::PointXYZ PointT;typedef pcl::PointCloud<PointT> PointCloud;typedef pcl::PointNormal PointNormalT;typedef pcl::PointCloud<PointNormalT> PointCloudWithNormals;// This is a tutorial so we can afford having global variables //our visualizer
pcl::visualization::PCLVisualizer* p;//its left and right viewportsint vp_1, vp_2;//convenient structure to handle our pointcloudsstruct PCD
{
PointCloud::Ptr cloud;
std::string f_name;PCD():cloud(new PointCloud){
};};struct PCDComparator
{
booloperator()(const PCD& p1,const PCD& p2){
return(p1.f_name < p2.f_name);}};// Define a new point representation for < x, y, z, curvature >classMyPointRepresentation:public pcl::PointRepresentation <PointNormalT>{
using pcl::PointRepresentation<PointNormalT>::nr_dimensions_;public:MyPointRepresentation(){
// Define the number of dimensions
nr_dimensions_ =4;}// Override the copyToFloatArray method to define our feature vectorvirtualvoidcopyToFloatArray(const PointNormalT& p,float* out)const{
// < x, y, z, curvature >
out[0]= p.x;
out[1]= p.y;
out[2]= p.z;
out[3]= p.curvature;}};/////////////////////////////////////////////////////////////////////////////////** \brief Display source and target on the first viewport of the visualizer
*
*/voidshowCloudsLeft(const PointCloud::Ptr cloud_target,const PointCloud::Ptr cloud_source){
p->removePointCloud("vp1_target");
p->removePointCloud("vp1_source");
PointCloudColorHandlerCustom<PointT>tgt_h(cloud_target,0,255,0);
PointCloudColorHandlerCustom<PointT>src_h(cloud_source,255,0,0);
p->addPointCloud(cloud_target, tgt_h,"vp1_target"