Search code examples
cgal

How do I extract the output from CGAL::poisson_surface_reconstruction_delaunay?


I am trying to convert a point cloud to a trimesh using CGAL::poisson_surface_reconstruction_delaunay() and extract the data inside the trimesh to an OpenGL friendly format:

// The function below should set vertices and indices so that: 
// triangle 0: (vertices[indices[0]],vertices[indices[1]],vertices[indices[2]]), 
// triangle 1: (vertices[indices[3]],vertices[indices[4]],vertices[indices[5]]) 
// ...
// triangle n - 1
void reconstructPointsToSurfaceInOpenGLFormat(const& std::list<std::pair<Kernel::Point_3, Kernel::Vector_3>> points, // input: points and normals
    std::vector<glm::vec3>& vertices, // output
    std::vector<unsigned int>& indices) { // output
   
    CGAL::Surface_mesh<Kernel::Point_3> trimesh;

    double spacing = 10;

    bool ok = CGAL::poisson_surface_reconstruction_delaunay(points.begin(), points.end(),
        CGAL::First_of_pair_property_map<std::pair<Kernel::Point_3, Kernel::Vector_3>>(),
        CGAL::Second_of_pair_property_map<std::pair<Kernel::Point_3, Kernel::Vector_3>>(),
        trimesh, spacing);

    // How do I set the vertices and indices values?
}

Please help me on iterating trough the triangles in trimesh and setting the vertices and indices in the code above.


Solution

  • The class Polyhedron_3 is not indexed based so you need to provide a item class with ids like Polyhedron_items_with_id_3. You will then need to call CGAL::set_halfedgeds_items_id(trimesh) to init the ids. If you can't modify the Polyhedron type, then you can use dynamic properties and will need to init the ids.

    Note that Surface_mesh is indexed based and no particular handling is needed to get indices.