在CGAL中,Mesh有很多种数据结构,诸如Surface_mesh、Polyhedron_3等等。

Surface_mesh

  1. typedef CGAL::Simple_cartesian<double> Kernel;
  2. typedef CGAL::Surface_mesh<Kernel::Point_3> PolygonMesh;

Polyhedron_3

  1. typedef CGAL::Simple_cartesian<double> Kernel;
  2. typedef CGAL::Polyhedron_3<Kernel> Polyhedron3;

处理

Mesh的遍历

但它们都是模板类,这模板类的方法都类似,所以可以统一处理。
例如:Mesh的遍历

  • 适用于Surface_mesh、Polyhedron_3数据结构

    1. template<class PolygonMesh>
    2. Status toGeometry(PolygonMesh& polyhedron, AbstractGeometryPtr& geometry)
    3. {
    4. //点
    5. for (auto vertexIt = polyhedron.vertices_begin(); vertexIt != polyhedron.vertices_end(); ++vertexIt)
    6. {
    7. double x = vertexIt->point().x();
    8. double y = vertexIt->point().y();
    9. double z = vertexIt->point().z();
    10. geometry->addVertex(x, y, z); //直接添加,未去重
    11. }
    12. //面
    13. for (auto i = polyhedron.facets_begin(); i != polyhedron.facets_end(); ++i)
    14. {
    15. PrimitiveIndices indices; //面索引
    16. auto j = i->facet_begin();
    17. // Facets in polyhedral surfaces are at least triangles.
    18. auto pntNum = CGAL::circulator_size(j);
    19. do
    20. {
    21. std::size_t index = std::distance(polyhedron.vertices_begin(), j->vertex());
    22. indices.push_back(index);
    23. } while (++j != i->facet_begin());
    24. geometry->addPrimitiveIndices(indices);
    25. }
    26. return kSuccess;
    27. }