33 #ifdef OGDF_INCLUDE_CGAL
40 # include <CGAL/Constrained_Delaunay_triangulation_2.h>
41 # include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
42 # include <CGAL/Point_2.h>
43 # include <CGAL/Polygon_2.h>
44 # include <CGAL/Triangulation_face_base_with_info_2.h>
52 template<
typename Kernel>
53 class RestrictedTriangulation {
60 bool in_domain() {
return nesting_level % 2 == 1; }
64 using Vb = CGAL::Triangulation_vertex_base_2<K>;
65 using Fbb = CGAL::Triangulation_face_base_with_info_2<FaceInfo2, K>;
66 using Fb = CGAL::Constrained_triangulation_face_base_2<K, Fbb>;
67 using TDS = CGAL::Triangulation_data_structure_2<Vb, Fb>;
68 using Itag = CGAL::Exact_predicates_tag;
69 using CDT = CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag>;
70 using Point = CGAL::Point_2<K>;
71 using Polygon_2 = CGAL::Polygon_2<K>;
73 void mark_domains(CDT& ct,
typename CDT::Face_handle start,
int index,
74 std::list<typename CDT::Edge>& border) {
75 if (start->info().nesting_level != -1) {
78 std::list<typename CDT::Face_handle> queue;
79 queue.push_back(start);
80 while (!queue.empty()) {
81 typename CDT::Face_handle fh = queue.front();
83 if (fh->info().nesting_level == -1) {
84 fh->info().nesting_level = index;
85 for (
int i = 0; i < 3; i++) {
86 typename CDT::Edge e(fh, i);
87 typename CDT::Face_handle n = fh->neighbor(i);
88 if (n->info().nesting_level == -1) {
89 if (ct.is_constrained(e)) {
106 void mark_domains(CDT& cdt) {
107 for (
typename CDT::All_faces_iterator it = cdt.all_faces_begin(); it != cdt.all_faces_end();
109 it->info().nesting_level = -1;
111 std::list<typename CDT::Edge> border;
112 mark_domains(cdt, cdt.infinite_face(), 0, border);
113 while (!border.empty()) {
114 typename CDT::Edge e = border.front();
116 typename CDT::Face_handle n = e.first->neighbor(e.second);
117 if (n->info().nesting_level == -1) {
118 mark_domains(cdt, n, e.first->info().nesting_level + 1, border);
123 void insert_polygon(CDT& cdt,
const Polygon_2& polygon) {
124 if (polygon.is_empty()) {
127 typename CDT::Vertex_handle v_prev = cdt.insert(*CGAL::cpp11::prev(polygon.vertices_end()));
128 for (
typename Polygon_2::Vertex_iterator vit = polygon.vertices_begin();
129 vit != polygon.vertices_end(); ++vit) {
130 typename CDT::Vertex_handle vh = cdt.insert(*vit);
131 cdt.insert_constraint(vh, v_prev);
137 CDT run(
const Polygon_t<Kernel>& polygon) {
139 insert_polygon(cdt, polygon);