在CGAL约束三角剖分中存储额外信息并使用有限面迭代器访问它。

huangapple go评论76阅读模式
英文:

Storing Additional Information in CGAL Constrained Triangulation Face and Accessing it Using Finite Faces Iterator

问题

我正在使用CGAL的Constrained Delaunay Triangulation(Constrained_Delaunay_triangulation_2)执行带约束的三角剖分。我想在约束三角剖分的每个面中存储一些额外的信息,然后在迭代有限面时访问这些信息。

我已经尝试创建一个自定义面基类,该类派生自CGAL::Constrained_triangulation_face_base_2,但我在使用Finite_faces_iterator访问存储在面中的额外信息时遇到了困难。

以下是我的尝试(包括不同类型的转换,如静态、动态等):

class Constrained_triangulation_face_base_with_info_2 : public CGAL::Constrained_triangulation_face_base_2<EPIC> {
	
public:
	std::vector<Point2d> containedPoints;

	Constrained_triangulation_face_base_with_info_2() : containedPoints() {

	}

	virtual ~Constrained_triangulation_face_base_with_info_2() {}
};

// 约束的 Delaunay 三角剖分
typedef CGAL::Triangulation_vertex_base_2<EPIC> VertexBase;
typedef CGAL::Triangulation_data_structure_2<VertexBase, Constrained_triangulation_face_base_with_info_2> TDS;
typedef CGAL::Constrained_Delaunay_triangulation_2<EPIC, TDS> ConstrainedDelaunayTriangulation;
typedef ConstrainedDelaunayTriangulation::Finite_faces_iterator ConstrainedDelaunayFacesIterator;

// ...

for (
	ConstrainedDelaunayFacesIterator fit = 
    constrainedDelaunayTriangulation.finite_faces_begin(), end = 
    constrainedDelaunayTriangulation.finite_faces_end();
	fit != end;
	++fit
	) {

	// 现在如何将/访问从fit派生的自定义面基类的信息?
}

我理解问题可能与类型转换有关,但我不确定如何正确访问Constrained_triangulation_face_base_with_info_2中存储的额外信息。

请问有人能指导我如何在CGAL的约束三角剖分的面中存储和访问额外信息,使用Finite_faces_iterator?任何帮助或代码示例都将不胜感激。谢谢!

英文:

I am using CGAL's Constrained Delaunay Triangulation (Constrained_Delaunay_triangulation_2) to perform triangulation with constraints. I would like to store some additional information in each face of the constrained triangulation and then access this information while iterating over the finite faces.

I have tried to create a custom face base class derived from CGAL::Constrained_triangulation_face_base_2, but I am facing difficulties in accessing the additional information stored in the face using the Finite_faces_iterator.

Here is my attempt (including different types of casts like static, dynamic etc.):

class Constrained_triangulation_face_base_with_info_2 : public CGAL::Constrained_triangulation_face_base_2&lt;EPIC&gt; {
	
public:
	std::vector&lt;Point2d&gt; containedPoints;

	Constrained_triangulation_face_base_with_info_2() : containedPoints() {

	}

	virtual ~Constrained_triangulation_face_base_with_info_2() {}
};

// Constrained (!) Delaunay-Triangulierung
typedef CGAL::Triangulation_vertex_base_2&lt;EPIC&gt; VertexBase;
typedef CGAL::Triangulation_data_structure_2&lt;VertexBase, Constrained_triangulation_face_base_with_info_2&gt; TDS;
typedef CGAL::Constrained_Delaunay_triangulation_2&lt;EPIC, TDS&gt; ConstrainedDelaunayTriangulation;
typedef ConstrainedDelaunayTriangulation::Finite_faces_iterator ConstrainedDelaunayFacesIterator;

// ...

for (
	ConstrainedDelaunayFacesIterator fit = 
    constrainedDelaunayTriangulation.finite_faces_begin(), end = 
    constrainedDelaunayTriangulation.finite_faces_end();
	fit != end;
	++fit
	) {

	// Now how to cast/access the custom face base class derived from fit?!
}

I understand that the issue might be related to type casting, but I am unsure how to correctly access the additional information stored in Constrained_triangulation_face_base_with_info_2.

Could someone please guide me on how to store and access additional information in faces of CGAL's constrained triangulation using Finite_faces_iterator? Any help or code example would be highly appreciated. Thank you!

答案1

得分: 3

正确的方法是您不需要创建新的面类。您可以使用Constrained_triangulation_face_base_2 具有一个模板参数,允许您将现有的类Triangulation_face_base_with_info_2 作为基类:

typedef CGAL::Triangulation_vertex_base_2&lt;EPIC&gt; Vb;
typedef std::vector&lt;Point2d&gt; My_info;
typedef CGAL::Triangulation_face_base_with_info_2&lt;My_info, EPIC&gt; Fbb;
typedef CGAL::Constrained_triangulation_face_base_2&lt;EPIC, Fbb&gt;;
typedef CGAL::Triangulation_data_structure_2&lt;Vb, Fb&gt; Tds;
typedef CGAL::Your_prefered_itag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2&lt;EPIC, Tds, Itag&gt; CDT;

[...]
for(auto fit =  cdt.finite_faces_begin(), end = cdt.finite_faces_end(); fit != end; ++fit) 
{
  fit-&gt;info().push_back(Point2d());
  // etc.
}

只是为了完整起见:如果您想派生自己的顶点/面类(再次强调,在这里您不需要,因为您可以使用现有的CGAL类),那么您必须注意高级的重新绑定机制,参见 https://doc.cgal.org/latest/TDS_2/index.html#title7

英文:

The correct approach is that you don't need to create a new face class. You can use the fact that Constrained_triangulation_face_base_2 has a template parameter allowing you pass the existing class Triangulation_face_base_with_info_2 as a base:

typedef CGAL::Triangulation_vertex_base_2&lt;EPIC&gt; Vb;
typedef std::vector&lt;Point2d&gt; My_info;
typedef CGAL::Triangulation_face_base_with_info_2&lt;My_info, EPIC&gt; Fbb;
typedef CGAL::Constrained_triangulation_face_base_2&lt;EPIC, Fbb&gt;;
typedef CGAL::Triangulation_data_structure_2&lt;Vb, Fb&gt; Tds;
typedef CGAL::Your_prefered_itag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2&lt;EPIC, Tds, Itag&gt; CDT;

[...]
for(auto fit =  cdt.finite_faces_begin(), end = cdt.finite_faces_end(); fit != end; ++fit) 
{
  fit-&gt;info().push_back(Point2d());
  // etc.
}

Just for completeness: if you want to derive your own vertex/face classes (which, again, you don't need here as you can use existing CGAL classes), then you have to take care of the advanced rebinding mechanism, see https://doc.cgal.org/latest/TDS_2/index.html#title7.

huangapple
  • 本文由 发表于 2023年7月20日 16:07:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76727848.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定