我正在尝试使用在PCL中实现的Marching Cubes算法从点云生成网格。我正在调整https://github.com/atduskgreg/pcl-marching-squares-example/blob/master/marching_cubes.cpp给出的代码到我的点云(我的代码在下面给出)。 Visual Studio 2015成功构建但是当我运行它时,我收到有关调试断言失败的错误消息。表达式为"向量下标超出范围"。你能帮我解决这个错误信息吗?我的另一个问题是,如果我能成功生成多边形网格,我该如何以.obj,.ply或.wrl格式导出它? 我期待着您的回音 此致
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include<conio.h>
#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/io/pcd_io.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/surface/3rdparty/poisson4/geometry.h>
#include <pcl/registration/distances.h>
#include <pcl/common/distances.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d_omp.h>
#include <pcl/surface/marching_cubes_rbf.h>
#include <pcl/surface/marching_cubes_hoppe.h>
#include <pcl/surface/marching_cubes.h>
int
main(int argc, char** argv)
{
srand((unsigned int)time(NULL));
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//pcd'ye dönüştürülen dosyanın okunması
pcl::io::loadPCDFile<pcl::PointXYZ>("silindir_arka_ENTIRE_DATA_ELIMINATED_REG_PCD.pcd", *cloud);
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud(cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree1(new pcl::search::KdTree<pcl::PointXYZ>());
tree1->setInputCloud(cloud);
ne.setInputCloud(cloud);
ne.setSearchMethod(tree1);
ne.setKSearch(20);
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
ne.compute(*cloud_normals);
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals(new pcl::PointCloud<pcl::PointNormal>);
pcl::concatenateFields(*cloud, *cloud_normals, *cloud_with_normals);
cloud_with_normals->points[0].normal_x;
std::cout << cloud_with_normals->points[0].normal_x << " " << cloud_with_normals->points[0].normal_y << " " << cloud_with_normals->points[0].normal_z << std::endl;
pcl::search::KdTree<pcl::PointNormal>::Ptr tree(new pcl::search::KdTree<pcl::PointNormal>());
tree->setInputCloud(cloud_with_normals);
std::cout << "begin marching cubes reconstruction" << std::endl;
pcl::MarchingCubesHoppe<pcl::PointNormal> mc;
pcl::PolygonMesh::Ptr triangles(new pcl::PolygonMesh);
std::cout << "111" << std::endl;
mc.setInputCloud(cloud_with_normals);
std::cout << "222" << std::endl;
mc.setSearchMethod(tree);
std::cout << "333" << std::endl;
mc.reconstruct(*triangles);
std::cout << triangles->polygons.size() << " triangles created" << std::endl;
return(0);
}
答案 0 :(得分:0)
看起来超出范围的向量下标来自于在[0]处索引到cloud_with_normals。我会检查cloud和cloud_normals的大小,看看concatenateFields()是否具有你期望的输出。由于您使用的是Visual Studio,因此可以使用调试工具查看意外行为何时开始。