环境:
一些代码如下:
// Greedy Projection triangulation
pcl::PolygonMesh triangulationGreedyProjection(pcl::PointCloud<pcl::PointXYZ>::Ptr xyzCloud) {
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normalEstimation;
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
tree->setInputCloud(xyzCloud);
normalEstimation.setInputCloud(xyzCloud);
normalEstimation.setSearchMethod(tree);
normalEstimation.setKSearch(20);
normalEstimation.compute(*normals);
pcl::PointCloud<pcl::PointNormal>::Ptr cloudWithNormals(new pcl::PointCloud<pcl::PointNormal>);
// 将已获得的点数据和法向数据拼接
pcl::concatenateFields(*xyzCloud, *normals, *cloudWithNormals);
// another kd-tree for reconstruction
pcl::search::KdTree<pcl::PointNormal>::Ptr tree2(new pcl::search::KdTree<pcl::PointNormal>);
tree2->setInputCloud(cloudWithNormals);
// reconstruction
pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
pcl::PolygonMesh mesh;
// options
gp3.setSearchRadius(25);
gp3.setMu(2.5);
gp3.setMaximumNearestNeighbors(100);
gp3.setMaximumSurfaceAngle(M_PI / 2);
gp3.setMinimumAngle(M_PI / 18);
gp3.setMaximumAngle(2 * M_PI / 3);
gp3.setNormalConsistency(false);
gp3.setInputCloud(cloudWithNormals);
gp3.setSearchMethod(tree2);
gp3.reconstruct(mesh);
return mesh;
}
但是,在执行“gp3.reconstruct(mesh);”时,代码崩溃和断点显示“Memory.h”中的“std::free(ptr)”为流:
EIGEN_DEVICE_FUNC inline void aligned_free(void *ptr)
{
#if (EIGEN_DEFAULT_ALIGN_BYTES==0) || EIGEN_MALLOC_ALREADY_ALIGNED
std::free(ptr);
#else
handmade_aligned_free(ptr);
#endif
}
结果如下:
最佳答案
您可以设置gp3
作为全局指针并在最终退出时让程序释放它。
这不是一个明智的方法,但可以解决您的问题。
auto* gp3 = new pcl::GreedyProjectionTriangulation<pcl::PointNormal>;
gp3->reconstruct(mesh);
// don't use delete
// delete gp3;
关于c++ - 当使用 pcl.1.8.0 显示一些示例时,但在运行 "triangulationGreedyProjection "的代码时出错并在 “Memory.h” 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69233303/