行进立方体重建 - 矢量下标超出范围

时间:2022-12-22 16:45:04

I am trying to generate mesh from a point cloud using Marching Cubes algorithm implemented in PCL. I am adapting the code given at https://github.com/atduskgreg/pcl-marching-squares-example/blob/master/marching_cubes.cpp to my point cloud (my code is given below). Visual Studio 2015 successfully builds but when I run it I get an error message about debug assertion fail. The expression is "Vector subscript out of range". Can you help me about this error message? My another question is if I can successfully generate the polygon mesh, how can I export it in .obj, .ply or .wrl format? I am looking forward to hearing from you Regards

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

} 

2 个解决方案

#1


0  

It looks like the vector subscript out of range comes from indexing into cloud_with_normals at [0]. I would check the size of cloud and cloud_normals and see if concatenateFields() has the output you expect. Since you are using Visual Studio, you can use the debugging tools to see when the unexpected behavior starts.

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

#2


0  

I appreciate for your helps. When I was playing with the code I realized that I did not define some members of the marching cube. When I define these members I do not get any error message. However, the mesh I generated is totally different. I am trying to figure out the reason. Regards

感谢您的帮助。当我玩代码时,我意识到我没有定义行进立方体的某些成员。当我定义这些成员时,我没有收到任何错误消息。但是,我生成的网格完全不同。我想找出原因。问候

#1


0  

It looks like the vector subscript out of range comes from indexing into cloud_with_normals at [0]. I would check the size of cloud and cloud_normals and see if concatenateFields() has the output you expect. Since you are using Visual Studio, you can use the debugging tools to see when the unexpected behavior starts.

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

#2


0  

I appreciate for your helps. When I was playing with the code I realized that I did not define some members of the marching cube. When I define these members I do not get any error message. However, the mesh I generated is totally different. I am trying to figure out the reason. Regards

感谢您的帮助。当我玩代码时,我意识到我没有定义行进立方体的某些成员。当我定义这些成员时,我没有收到任何错误消息。但是,我生成的网格完全不同。我想找出原因。问候