0

我正在尝试使用在 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); 

} 
4

1 回答 1

0

看起来超出范围的向量下标来自在 [0] 处对 cloud_with_normals 的索引。我会检查 cloud 和 cloud_normals 的大小,看看 concatenateFields() 是否具有您期望的输出。由于您使用的是 Visual Studio,因此您可以使用调试工具查看意外行为何时开始。

于 2017-04-24T14:37:52.503 回答