英文:
Embedding and iterating over custom faces in CGAL Delaunay triangulation
问题
我在我的C++应用程序中使用CGAL库执行Delaunay三角剖分。我想要将自定义的面嵌入到三角剖分中,然后迭代遍历它们,但我不确定如何将它们合并到三角剖分中,以及如何在之后迭代遍历这些自定义面。
最终我希望得到类似于这样的结果:
typedef CGAL::Delaunay_triangulation_2<EPIC> DelaunayTriangulation;
DelaunayTriangulation triangulation;
// ...
for (auto it = triangulation.faces_begin(); it != triangulation.faces_end(); ++it)
{
MyFace& face = static_cast<MyFace&>(*it);
// ...
}
有人能解释一下如何将我的自定义面嵌入到Delaunay三角剖分中吗?
编辑
正如评论中正确指出的,我实际上想要扩展在CGAL中用于Delaunay三角剖分的Face类,以在构造函数中存储额外的信息以供后续重用。
英文:
I'm using the CGAL library for performing Delaunay triangulation in my C++ application. I would like to embed custom faces into the triangulation and then iterate over them, but I'm not sure how to incorporate them into the triangulation and how to iterate over the custom faces afterwards.
At the end I want something like this:
typedef CGAL::Delaunay_triangulation_2<EPIC> DelaunayTriangulation;
DelaunayTriangulation triangulation;
// ...
for (auto it = triangulation.faces_begin(); it != triangulation.faces_end(); ++it)
{
MyFace& face = static_cast<MyFace&>(*it);
// ...
}
Can someone explain how I can embed my custom face into the Delaunay triangulation?
Edit
As correctly pointed out in the comments, I actually want to extend the Face class used during Delaunay triangulation in CGAL to store additional information in the constructor for reuse.
答案1
得分: 1
请查看CGAL::Triangulation_face_base_with_info_2。
您的三角剖分期望其面类型提供特定的API:如果您查看CGAL::Delaunay_triangulation_2的文档,您会发现它希望其面是TriangulationDataStructure_2::Face概念的模型。
默认情况下,CGAL将使用CGAL::Triangulation_data_structure_2
模板化为CGAL::Triangulation_face_base_2
作为模板类,以满足这些要求。您可以通过从CGAL::Triangulation_face_base_2
派生来丰富现有的面基类。例如,在类CGAL::Triangulation_face_base_with_id_2
中就是这样做的,它继承自CGAL::Triangulation_face_base_2
并添加了一个ID成员。
类CGAL::Triangulation_face_base_with_info_2以通用方式提供了这一功能,您可以将任何您想要的信息作为模板参数传递(无论是布尔值还是类本身)。
由于您不再使用默认类,因此您需要指定CGAL::Delaunay_triangulation_2
模板:
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<**YOUR_INFO_TYPE**,K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation;
英文:
Short version: have a look at CGAL::Triangulation_face_base_with_info_2.
Longer version below:
Your triangulation expects its face type to provide it some specific API: if you check the doc of CGAL::Delaunay_triangulation_2, you can see it wants its face to be a model of the concept TriangulationDataStructure_2::Face.
By default, CGAL will use CGAL::Triangulation_data_structure_2
templated with CGAL::Triangulation_face_base_2
as template classes that fit those requirements. You can enrich existing face base classes by deriving from CGAL::Triangulation_face_base_2
. This is what is done for example in the class CGAL::Triangulation_face_base_with_id_2
, which inherits CGAL::Triangulation_face_base_2
and adds an ID member.
The class CGAL::Triangulation_face_base_with_info_2 provides this in a generic way as you can pass whatever info you want as a template parameter (be it a bool or a class itself).
Since you are no longer using the default classes, you will need to specify the CGAL::Delaunay_triangulation_2
templates:
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<**YOUR_INFO_TYPE**,K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论