0

environment:

  • ubuntu18
  • pcl 1.8.0

some code as follow:

// 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;
}

However, when implement “gp3.reconstruct(mesh);”, the code crash and the break point show "std::free(ptr)" in "Memory.h" as fllow

enter image description here:

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
}

result as fllows:

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Please provide a [mre]. It is quite likely that the real error is in other part of code than the one you've posted. Also, it's far easier to analyse code that compiles than code that is just displayed. – zkoza Sep 25 '21 at 12:33
  • were you able to find a solution here @alimagic? – Akshay Kumar Apr 11 '23 at 20:27

1 Answers1

0

You can set gp3 as a global pointer and let programa free it when finally quit.

It's not a wise method but can solve your problem.

auto* gp3 = new pcl::GreedyProjectionTriangulation<pcl::PointNormal>;

gp3->reconstruct(mesh);

// don't use delete
// delete gp3;