我正在尝试使用PCL中实现的Marting Cubes算法从点云生成网格。我正在调整https://github.com/atduskgreg/pcl-marching-squares-example/blob/master/marter/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);
}
看来,向量下标范围内的vector subscript来自[0]的索引到cloud_with_normals。我将检查云和云的大小,看看ConteNateFields((是否具有您期望的输出。由于您正在使用Visual Studio,因此可以使用调试工具来查看何时开始的行为。