假设我有一个受约束的Delaunay三角剖分,其中facet与某些'label'(一些抽象属性)相关联。我想从约束中删除入射到共享相同标签的构面的边。有什么方法可以做到这一点,以及如何确保在约束被删除后获得的构面保持其标签?
以下是CGAL示例中的一段代码,用于说明我的目的:
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_face_base_with_info_2.h>
#include <CGAL/Polygon_2.h>
#include <iostream>
struct FaceInfo2
{
FaceInfo2(){}
int label;
};
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Triangulation_face_base_with_info_2<FaceInfo2,K> Fbb;
typedef CGAL::Constrained_triangulation_face_base_2<K,Fbb> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> TDS;
typedef CGAL::Exact_predicates_tag Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> CDT;
typedef CDT::Point Point;
typedef CGAL::Polygon_2<K> Polygon_2;
void insert_polygon(CDT& cdt,const Polygon_2& polygon)
{
if ( polygon.is_empty() ) return;
CDT::Vertex_handle v_prev=cdt.insert(*CGAL::cpp11::prev(polygon.vertices_end()));
for (Polygon_2::Vertex_iterator vit=polygon.vertices_begin();
vit!=polygon.vertices_end();++vit)
{
CDT::Vertex_handle vh=cdt.insert(*vit);
cdt.insert_constraint(vh,v_prev);
v_prev=vh;
}
}
void compute_labels(CDT& cdt)
{
// Do stuff and set the 'label' of each facet according to some property
}
int main( )
{
// Insert some polyons into a constrained triangulation
CDT cdt;
insert_polygon(cdt,polygon1);
insert_polygon(cdt,polygon2); // ...
// Mark facets according to an arbitrary property
compute_labels(cdt);
int count=0;
for (CDT::Finite_edges_iterator eit=cdt.finite_edges_begin();
eit!=cdt.finite_edges_end();++eit)
{
// This will not do, because the iterator may get invalidated
if ( eit->first->info().label == eit->first->neighbor(eit->second)->info().label )
cdt.remove_constrained_edge(eit->first, eit->second);
}
return 0;
}
我从那里看到了几个可能性:
cdt.remove_constrained_edge(fh, i, out)
来恢复可能受约束删除影响的构面,并相应地对待它们(但它仍然会使迭代器的问题失效)。set
而不是queue
/ stack
,因此我可以从facet中删除我需要访问处理到删除约束的facets(删除之前) ),因为删除后它们可能会失效(如果发生翻转)。那么,StackOverflow对此有何看法?