代码遇到问题,在reconsturct的时候中断 ,请高手帮忙看看是什么原因
#include "stdafx.h"
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/surface/marching_cubes.h>
#include <pcl/surface/marching_cubes_greedy.h>
#include <pcl/surface/marching_cubes_hoppe.h>
#include <pcl/surface/marching_cubes_rbf.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/integral_image_normal.h>
#include <pcl/kdtree/kdtree.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
using namespace std;
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("table_scene_lms400_downsampled.pcd", *cloud) == -1) //* load the file
{
PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
return (-1);
}
std::cout<<"PCD load done!"<<endl;
std::cout<<"pcd size is"<<cloud->size()<<endl;
double leafSize = 0.01;
int isoLevel =0.5;//iso: must be between 0 and 1.0
// Normal estimation*
pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ> > (new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud(cloud);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
n.setInputCloud(cloud);
n.setSearchMethod(tree);
n.setKSearch(20);
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
n.compute(*normals);
//* normals should not contain the point normals + surface curvatures
// Concatenate the XYZ and normal fields*
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals(new pcl::PointCloud<pcl::PointNormal>);
concatenateFields(*cloud, *normals, *cloud_with_normals);
//* cloud_with_normals = cloud + normals
// Create search tree*
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud(cloud_with_normals);
// Init objects
pcl::PolygonMesh mesh;
// pcl::MarchingCubesGreedy<pcl::PointNormal> mc;
pcl::MarchingCubesHoppe<pcl::PointNormal> mc;
// Set parameters
mc.setInputCloud(cloud_with_normals);
mc.setSearchMethod(tree2);
// mc.setLeafSize(leafSize);
mc.setPercentageExtendGrid(leafSize);//体素大小
mc.setIsoLevel(isoLevel);//
// Reconstruct
mc.reconstruct(mesh);
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
viewer->addPolygonMesh(mesh,"MC");
viewer->setBackgroundColor (0, 0, 0);
viewer->addCoordinateSystem (1.0);
viewer->initCameraParameters ();
// 主循环
std::cerr<<"----------------finish--------------------"<<endl;
while (!viewer->wasStopped ())
{
viewer->spinOnce (100);
boost::this_thread::sleep (boost::posix_time::microseconds (100000));
}
// Finish
return (0);
}
错误截图:
|