Skip to content

Commit ac729ca

Browse files
committed
clean start for v2
0 parents  commit ac729ca

File tree

4 files changed

+1425
-0
lines changed

4 files changed

+1425
-0
lines changed
+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// Enhanced_constrained_triangulation
2+
//
3+
// Copyright © 2016-2020,
4+
// Ken Arroyo Ohori [email protected]
5+
// All rights reserved.
6+
//
7+
// This program is free software: you can redistribute it and/or modify
8+
// it under the terms of the GNU General Public License as published by
9+
// the Free Software Foundation, either version 3 of the License, or
10+
// (at your option) any later version.
11+
//
12+
// This program is distributed in the hope that it will be useful,
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
// GNU General Public License for more details.
16+
//
17+
// You should have received a copy of the GNU General Public License
18+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
20+
#ifndef ENHANCED_TRIANGULATION_2_H
21+
#define ENHANCED_TRIANGULATION_2_H
22+
23+
template <class T>
24+
class Enhanced_constrained_triangulation_2;
25+
26+
template <class T>
27+
class Is_Delaunay {
28+
public:
29+
typedef T Triangulation;
30+
typedef typename Triangulation::List_edges List_edges;
31+
32+
static void if_Delaunay_make_Delaunay(Enhanced_constrained_triangulation_2<T> &et, List_edges &e) {
33+
std::cout << "Unknown triangulation: cannot make Delaunay" << std::endl;
34+
}
35+
};
36+
37+
template <class K, class TDS, class Itag>
38+
class Is_Delaunay<CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> > {
39+
public:
40+
typedef CGAL::Constrained_Delaunay_triangulation_2<K, TDS, Itag> Triangulation;
41+
typedef typename Triangulation::List_edges List_edges;
42+
43+
static void if_Delaunay_make_Delaunay(Enhanced_constrained_triangulation_2<Triangulation> &et, List_edges &e) {
44+
et.propagating_flip(e);
45+
}
46+
};
47+
48+
template <class K, class TDS, class Itag>
49+
class Is_Delaunay<CGAL::Constrained_triangulation_2<K, TDS, Itag> > {
50+
public:
51+
typedef CGAL::Constrained_triangulation_2<K, TDS, Itag> Triangulation;
52+
typedef typename Triangulation::List_edges List_edges;
53+
54+
static void if_Delaunay_make_Delaunay(Enhanced_constrained_triangulation_2<Triangulation> &et, List_edges &e) {
55+
// Do nothing
56+
}
57+
};
58+
59+
template <class T>
60+
class Enhanced_constrained_triangulation_2 : public T {
61+
public:
62+
typedef typename T::Point Point;
63+
typedef typename T::Vertex Vertex;
64+
typedef typename T::Edge Edge;
65+
typedef typename T::Vertex_handle Vertex_handle;
66+
typedef typename T::Face_handle Face_handle;
67+
typedef typename T::Locate_type Locate_type;
68+
typedef typename T::List_faces List_faces;
69+
typedef typename T::List_edges List_edges;
70+
71+
Vertex_handle insert(const Point &p, Face_handle f = Face_handle()) {
72+
// std::cout << "Enhanced_triangulation_2::insert(const Point &, Face_handle)" << std::endl;
73+
Locate_type location_type;
74+
int location_vertex;
75+
Face_handle location = T::locate(p, location_type, location_vertex, f);
76+
return insert(p, location_type, location, location_vertex);
77+
}
78+
79+
Vertex_handle insert(const Point &p, Locate_type &lt, Face_handle loc, int li) {
80+
// std::cout << "Enhanced_triangulation_2::insert(const Point &, Locate_type &, Face_handle, int)" << std::endl;
81+
// TODO: Read and reset info on faces & edges that are split because of the insertion
82+
return T::insert(p, lt, loc, li);
83+
}
84+
85+
void odd_even_insert_constraint(const Point& a, const Point& b) {
86+
Vertex_handle va = insert(a);
87+
Vertex_handle vb = insert(b);
88+
if (va != vb) odd_even_insert_constraint(va, vb);
89+
}
90+
91+
void odd_even_insert_constraint(Vertex_handle va, Vertex_handle vb) {
92+
CGAL_triangulation_precondition(va != vb);
93+
94+
// std::cout << "Triangulation:" << std::endl;
95+
// for (typename T::All_faces_iterator current_face = T::all_faces_begin(); current_face != T::all_faces_end(); ++current_face) {
96+
// std::cout << "\tTriangle [0]: " << current_face->vertex(0)->point() << " [1]: " << current_face->vertex(1)->point() << " [2]: " << current_face->vertex(2)->point() << std::endl;
97+
// } std::cout.precision(15);
98+
// std::cout << "Adding constraint from " << va->point() << " to " << vb->point() << std::endl;
99+
100+
// If [va, vb] lies on an existing edge
101+
Vertex_handle vertex_on_other_end;
102+
Face_handle incident_face;
103+
int vertex_opposite_to_incident_edge;
104+
if (T::includes_edge(va, vb, vertex_on_other_end, incident_face, vertex_opposite_to_incident_edge)) {
105+
if (T::is_constrained(Edge(incident_face, vertex_opposite_to_incident_edge))) {
106+
T::remove_constrained_edge(incident_face, vertex_opposite_to_incident_edge);
107+
if (T::number_of_faces() == 0) return;
108+
List_edges possibly_non_Delaunay_edges;
109+
possibly_non_Delaunay_edges.push_back(Edge(incident_face, vertex_opposite_to_incident_edge));
110+
Is_Delaunay<T>::if_Delaunay_make_Delaunay(*this, possibly_non_Delaunay_edges);
111+
} else T::mark_constraint(incident_face, vertex_opposite_to_incident_edge);
112+
if (vertex_on_other_end != vb) odd_even_insert_constraint(vertex_on_other_end, vb);
113+
return;
114+
}
115+
116+
// If [va, vb] intersects a constrained edge or an existing vertex
117+
List_faces intersected_faces;
118+
List_edges conflict_boundary_ab, conflict_boundary_ba;
119+
Vertex_handle intersection;
120+
if (T::find_intersected_faces(va, vb, intersected_faces, conflict_boundary_ab, conflict_boundary_ba, intersection)) {
121+
if (intersection != va && intersection != vb) {
122+
odd_even_insert_constraint(va, intersection);
123+
odd_even_insert_constraint(intersection, vb);
124+
} else odd_even_insert_constraint(va, vb);
125+
return;
126+
}
127+
128+
// Otherwise
129+
T::triangulate_hole(intersected_faces, conflict_boundary_ab, conflict_boundary_ba);
130+
if (intersection != vb) {
131+
odd_even_insert_constraint(intersection, vb);
132+
}
133+
}
134+
};
135+
136+
#endif

0 commit comments

Comments
 (0)