在CGAL中,Mesh有很多种数据结构,诸如Surface_mesh、Polyhedron_3等等。
Surface_mesh
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Surface_mesh<Kernel::Point_3> PolygonMesh;
Polyhedron_3
typedef CGAL::Simple_cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron3;
处理
Mesh的遍历
但它们都是模板类,这模板类的方法都类似,所以可以统一处理。
例如:Mesh的遍历
适用于Surface_mesh、Polyhedron_3数据结构
template<class PolygonMesh>
Status toGeometry(PolygonMesh& polyhedron, AbstractGeometryPtr& geometry)
{
//点
for (auto vertexIt = polyhedron.vertices_begin(); vertexIt != polyhedron.vertices_end(); ++vertexIt)
{
double x = vertexIt->point().x();
double y = vertexIt->point().y();
double z = vertexIt->point().z();
geometry->addVertex(x, y, z); //直接添加,未去重
}
//面
for (auto i = polyhedron.facets_begin(); i != polyhedron.facets_end(); ++i)
{
PrimitiveIndices indices; //面索引
auto j = i->facet_begin();
// Facets in polyhedral surfaces are at least triangles.
auto pntNum = CGAL::circulator_size(j);
do
{
std::size_t index = std::distance(polyhedron.vertices_begin(), j->vertex());
indices.push_back(index);
} while (++j != i->facet_begin());
geometry->addPrimitiveIndices(indices);
}
return kSuccess;
}