Search code examples
c++cgal

Accessing property map for surface mesh


I have a CGAL::Surface_mesh<Point_3> to which I added a property map

Mesh::Property_map<Mesh::Face_index, CGAL::Color>
    color_map = tin_colored_mesh.add_property_map<Mesh::Face_index, CGAL::Color>("f:color").first;

I had this map populated.

Afterwards, I try to access this property map again as below:

std::string name = "f:color";
const Mesh::Property_map<Mesh::Face_index, CGAL::Color> ans = tin_colored_mesh.property_map(name).first;

However this raises an error:

/Users/<path to file>:197:82: error: no matching member function for call to 'property_map'
  const Mesh::Property_map<Mesh::Face_index, CGAL::Color> ans = tin_colored_mesh.property_map(name).first;
                                                                
/usr/local/include/CGAL/Surface_mesh/Surface_mesh.h:1974:40: note: candidate template ignored: couldn't infer template argument 'I'
    std::pair<Property_map<I, T>,bool> property_map(const std::string& name) const

I am not sure how to correctly use the templates here.


Solution

  • According to the documentation for CGAL::Surface_mesh the property_map member function is a template just as the add_property_map member function that you use above.

    As the error states, C++ fails to infer the template argument I that the function template CGAL::Surface_mesh::property_map expects. A potential solution would be to supply the required template arguments just as you did for add_property_map:

    const Mesh::Property_map<Mesh::Face_index, CGAL::Color> ans
      = tin_colored_mesh.property_map<Mesh::Face_index, CGAL::Color>(name).first;
    //                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^