论文地址pdf下载地址
源码
#include
#include
#include
#include
#include
#include // Types
typedef pcl::PointXYZRGBA PointT;
typedef pcl::PointCloud PointCloudT;
typedef pcl::PointNormal PointNT;
typedef pcl::PointCloud PointNCloudT;
typedef pcl::PointXYZL PointLT;
typedef pcl::PointCloud PointLCloudT;void addSupervoxelConnectionsToViewer (PointT &supervoxel_center,PointCloudT &adjacent_supervoxel_centers,std::string supervoxel_name,boost::shared_ptr & viewer);int main (int argc, char ** argv)
{if (argc <2){pcl::console::print_error ("Syntax is: %s \n ""--NT Dsables the single cloud transform \n""-v \n-s \n""-c \n-z \n""-n \n", argv[0]);return (1);}PointCloudT::Ptr cloud &#61; boost::make_shared ();pcl::console::print_highlight ("Loading point cloud...\n");if (pcl::io::loadPCDFile (argv[1], *cloud)){pcl::console::print_error ("Error loading cloud file!\n");return (1);}cout<<"point size of input: "<size()< super (voxel_resolution, seed_resolution);if (disable_transform)super.setUseSingleCameraTransform (false);super.setInputCloud (cloud);super.setColorImportance (color_importance);super.setSpatialImportance (spatial_importance);super.setNormalImportance (normal_importance);std::map ::Ptr > supervoxel_clusters;//该单映射容器以标签为键值存储所有超体素pcl::console::print_highlight ("Extracting supervoxels!\n");super.extract (supervoxel_clusters);pcl::console::print_info ("Found %d supervoxels\n", supervoxel_clusters.size ());boost::shared_ptr viewer (new pcl::visualization::PCLVisualizer ("点云库PCL学习教程第二版-超体素分割"));viewer->setBackgroundColor (1,1,1);PointCloudT::Ptr voxel_centroid_cloud &#61; super.getVoxelCentroidCloud ();cout<<"voxel centroids: "<size()<addPointCloud(voxel_centroid_cloud,"voxel centroids");pcl::io::savePCDFile("voxel_centroids.pcd",*voxel_centroid_cloud);viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE,4, "voxel centroids");viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY,0.5, "voxel centroids");}PointLCloudT::Ptr labeled_voxel_cloud &#61; super.getLabeledVoxelCloud ();if(1){//超体素分割结果显示与保存pcl::io::savePCDFile("labeled_voxels.pcd",*labeled_voxel_cloud);viewer->addPointCloud (labeled_voxel_cloud, "labeled voxels");cout<<"labeled voxels: "<size()<setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE,3, "labeled voxels");// viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY,0.8, "labeled voxels");}PointNCloudT::Ptr sv_normal_cloud &#61; super.makeSupervoxelNormalCloud (supervoxel_clusters);//if(0)//超体素对应的法线特征可视化viewer->addPointCloudNormals (sv_normal_cloud,1,0.05f, "supervoxel_normals");pcl::console::print_highlight ("Getting supervoxel adjacency\n");std::multimap supervoxel_adjacency;super.getSupervoxelAdjacency (supervoxel_adjacency);cout<<"size of supervoxel_adjacency: "<::iterator label_itr &#61; supervoxel_adjacency.begin ();for ( ; label_itr !&#61; supervoxel_adjacency.end (); ){//获取标签值uint32_t supervoxel_label &#61; label_itr->first;//根据标签索引到该超体素pcl::Supervoxel::Ptr supervoxel &#61; supervoxel_clusters.at (supervoxel_label);//遍历该超体素相邻超体素并以其相邻超体素中心为点集构造点云&#xff0c;用于后续可视化&#xff0c;这里的相邻超体素在多重映射容器中具有相同的键值PointCloudT adjacent_supervoxel_centers;std::multimap::iterator adjacent_itr &#61; supervoxel_adjacency.equal_range (supervoxel_label).first;for ( ; adjacent_itr!&#61;supervoxel_adjacency.equal_range (supervoxel_label).second; &#43;&#43;adjacent_itr){pcl::Supervoxel::Ptr neighbor_supervoxel &#61; supervoxel_clusters.at (adjacent_itr->second);adjacent_supervoxel_centers.push_back (neighbor_supervoxel->centroid_);}//std::stringstream ss;ss <<"supervoxel_" <centroid_, adjacent_supervoxel_centers, ss.str (), viewer);//使迭代器指向下一个标签。label_itr &#61; supervoxel_adjacency.upper_bound (supervoxel_label);}while (!viewer->wasStopped ()){viewer->spinOnce();}return (0);
}void addSupervoxelConnectionsToViewer (PointT &supervoxel_center,PointCloudT &adjacent_supervoxel_centers,std::string supervoxel_name,boost::shared_ptr & viewer)
{int i&#61;0;//Iterate through all adjacent points, and add a center point to adjacent point pairPointCloudT::iterator adjacent_itr &#61; adjacent_supervoxel_centers.begin ();for ( ; adjacent_itr !&#61; adjacent_supervoxel_centers.end (); &#43;&#43;adjacent_itr){std::stringstream ss;ss<addLine(supervoxel_center,*adjacent_itr,ss.str());viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_LINE_WIDTH,3,ss.str());viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR,0,255,0,ss.str());ss<addSphere(supervoxel_center,0.008,0,0,255,ss.str());viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_SHADING,pcl::visualization::PCL_VISUALIZER_SHADING_GOURAUD,ss.str());//viewer->setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY,0.9,ss.str());i&#43;&#43;;}}