Skip to content

Commit 0b247c2

Browse files
committed
finder control over triangulations
1 parent 4ba6897 commit 0b247c2

File tree

7 files changed

+478
-125
lines changed

7 files changed

+478
-125
lines changed

docs/examples/triangulation.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import numpy as np
22

33
from compas_plotters import Plotter
4-
from compas.geometry import Polygon, Translation
4+
from compas.geometry import Point, Polygon, Translation
55
from compas.datastructures import Mesh
6-
from compas_cgal.triangulation import constrained_delaunay_triangulation
6+
from compas_cgal.triangulation import conforming_delaunay_triangulation as cdt
77

88
# ==============================================================================
99
# Constraints
1010
# ==============================================================================
1111

12-
boundary = Polygon.from_sides_and_radius_xy(4, 10)
12+
boundary = Polygon.from_sides_and_radius_xy(12, 10)
1313
boundary = np.array(boundary, dtype=np.float64)
1414

15-
hole = Polygon.from_sides_and_radius_xy(8, 2)
15+
hole = Polygon.from_sides_and_radius_xy(12, 2)
1616

1717
hole1 = hole.transformed(Translation.from_vector([4, 0, 0]))
1818
hole2 = hole.transformed(Translation.from_vector([-4, 0, 0]))
@@ -21,11 +21,13 @@
2121

2222
holes = [hole1, hole2, hole3, hole4]
2323

24+
points = [Point(4, 0, 0), Point(-4, 0, 0), Point(0, 4, 0), Point(0, -4, 0)]
25+
2426
# ==============================================================================
2527
# Triangulation
2628
# ==============================================================================
2729

28-
V, F = constrained_delaunay_triangulation(boundary, holes, maxlength=1.0)
30+
V, F = cdt(boundary, points=points, holes=holes)
2931

3032
mesh = Mesh.from_vertices_and_faces(V, F)
3133

@@ -35,5 +37,7 @@
3537

3638
plotter = Plotter(figsize=(8, 8))
3739
plotter.add(mesh, sizepolicy='absolute', vertexsize=5)
40+
for point in points:
41+
plotter.add(point, size=10, color=(1, 0, 0))
3842
plotter.zoom_extents()
3943
plotter.show()

docs/examples/triangulation2.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import numpy as np
2+
3+
from compas_plotters import Plotter
4+
from compas.geometry import Point, Polygon, Translation
5+
from compas.datastructures import Mesh
6+
from compas_cgal.triangulation import refined_delaunay_mesh as cdt
7+
8+
# ==============================================================================
9+
# Constraints
10+
# ==============================================================================
11+
12+
boundary = Polygon.from_sides_and_radius_xy(12, 10)
13+
boundary = np.array(boundary, dtype=np.float64)
14+
15+
hole = Polygon.from_sides_and_radius_xy(12, 2)
16+
17+
hole1 = hole.transformed(Translation.from_vector([4, 0, 0]))
18+
hole2 = hole.transformed(Translation.from_vector([-4, 0, 0]))
19+
hole3 = hole.transformed(Translation.from_vector([0, 4, 0]))
20+
hole4 = hole.transformed(Translation.from_vector([0, -4, 0]))
21+
22+
holes = [hole1, hole2, hole3, hole4]
23+
24+
points = [Point(4, 0, 0), Point(-4, 0, 0), Point(0, 4, 0), Point(0, -4, 0)]
25+
26+
# ==============================================================================
27+
# Triangulation
28+
# ==============================================================================
29+
30+
V, F = cdt(boundary, points=points, holes=holes, maxlength=1.0, is_optimized=True)
31+
32+
mesh = Mesh.from_vertices_and_faces(V, F)
33+
34+
# ==============================================================================
35+
# Viz
36+
# ==============================================================================
37+
38+
plotter = Plotter(figsize=(8, 8))
39+
plotter.add(mesh, sizepolicy='absolute', vertexsize=5)
40+
for point in points:
41+
plotter.add(point, size=10, color=(1, 0, 0))
42+
plotter.zoom_extents()
43+
plotter.show()

setup.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ def get_library_dirs():
5454
'compas_cgal._cgal',
5555
sorted([
5656
'src/compas_cgal.cpp',
57-
'src/compas.cpp',
58-
'src/meshing.cpp',
59-
'src/booleans.cpp',
60-
'src/slicer.cpp',
61-
'src/intersections.cpp',
62-
'src/measure.cpp',
57+
# 'src/compas.cpp',
58+
# 'src/meshing.cpp',
59+
# 'src/booleans.cpp',
60+
# 'src/slicer.cpp',
61+
# 'src/intersections.cpp',
62+
# 'src/measure.cpp',
6363
'src/triangulations.cpp',
6464
]),
6565
include_dirs=[

src/compas_cgal.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace py = pybind11;
55

6-
void init_meshing(py::module&);
7-
void init_booleans(py::module&);
8-
void init_slicer(py::module&);
9-
void init_intersections(py::module&);
10-
void init_measure(py::module&);
6+
// void init_meshing(py::module&);
7+
// void init_booleans(py::module&);
8+
// void init_slicer(py::module&);
9+
// void init_intersections(py::module&);
10+
// void init_measure(py::module&);
1111
void init_triangulations(py::module&);
1212

1313
PYBIND11_MODULE(_cgal, m) {
@@ -17,10 +17,10 @@ PYBIND11_MODULE(_cgal, m) {
1717
.def_readonly("vertices", &compas::Result::vertices)
1818
.def_readonly("faces", &compas::Result::faces);
1919

20-
init_meshing(m);
21-
init_booleans(m);
22-
init_slicer(m);
23-
init_intersections(m);
24-
init_measure(m);
20+
// init_meshing(m);
21+
// init_booleans(m);
22+
// init_slicer(m);
23+
// init_intersections(m);
24+
// init_measure(m);
2525
init_triangulations(m);
2626
}

src/compas_cgal/triangulation.py

Lines changed: 119 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,129 @@
22
from compas_cgal._cgal import triangulations
33

44

5-
def constrained_delaunay_triangulation(boundary, holes=None, curves=None, maxlength=None):
6-
"""Construct a constrained Delaunay triangulation.
5+
def delaunay_triangulation(vertices):
6+
"""Construct a Delaunay triangulation.
7+
8+
Parameters
9+
----------
10+
vertices : list of :class:`compas.geometry.Point`
11+
Vertices of the triangulation.
12+
13+
Returns
14+
-------
15+
list
16+
The faces of the triangulation.
17+
18+
Notes
19+
-----
20+
...
21+
22+
"""
23+
vertices = np.asarray(vertices, dtype=np.float64)
24+
return triangulations.delaunay_triangulation(vertices)
25+
26+
27+
def constrained_delaunay_triangulation(boundary, points=None, holes=None, curves=None):
28+
"""Construct a Constrained Delaunay triangulation.
29+
30+
Parameters
31+
----------
32+
boundary : :class:`compas.geometry.Polygon`
33+
The boundary of the triangulation.
34+
points : list of :class:`compas.geometry.Point`, optional
35+
Additional internal points.
36+
holes : list of :class:`compas.geometry.Polygon`, optional
37+
Internal boundary polygons.
38+
curves : list of :class:`compas.geometry.Polyline`, optional
39+
Internal constraint curves.
40+
41+
Returns
42+
-------
43+
list
44+
The vertices and faces of the triangulation.
45+
46+
Notes
47+
-----
48+
...
49+
50+
"""
51+
boundary = np.asarray(boundary, dtype=np.float64)
52+
53+
points = points or []
54+
points = np.asarray(points, dtype=np.float64)
55+
56+
if holes:
57+
holes = [np.asarray(hole, dtype=np.float64) for hole in holes]
58+
else:
59+
holes = []
60+
61+
if curves:
62+
curves = [np.asarray(curve, dtype=np.float64) for curve in curves]
63+
else:
64+
curves = []
65+
66+
return triangulations.constrained_delaunay_triangulation(boundary, points, holes, curves, is_conforming=False)
67+
68+
69+
def conforming_delaunay_triangulation(boundary, points=None, holes=None, curves=None):
70+
"""Construct a Conforming Delaunay triangulation.
71+
72+
Parameters
73+
----------
74+
boundary : :class:`compas.geometry.Polygon`
75+
The boundary of the triangulation.
76+
points : list of :class:`compas.geometry.Point`, optional
77+
Additional internal points.
78+
holes : list of :class:`compas.geometry.Polygon`, optional
79+
Internal boundary polygons.
80+
curves : list of :class:`compas.geometry.Polyline`, optional
81+
Internal constraint curves.
82+
83+
Returns
84+
-------
85+
list
86+
The vertices and faces of the triangulation.
87+
88+
Notes
89+
-----
90+
...
91+
92+
"""
93+
boundary = np.asarray(boundary, dtype=np.float64)
94+
95+
points = points or []
96+
points = np.asarray(points, dtype=np.float64)
97+
98+
if holes:
99+
holes = [np.asarray(hole, dtype=np.float64) for hole in holes]
100+
else:
101+
holes = []
102+
103+
if curves:
104+
curves = [np.asarray(curve, dtype=np.float64) for curve in curves]
105+
else:
106+
curves = []
107+
108+
return triangulations.constrained_delaunay_triangulation(boundary, points, holes, curves, is_conforming=True)
109+
110+
111+
def refined_delaunay_mesh(boundary, points=None, holes=None, curves=None, maxlength=None, is_optimized=False):
112+
"""Construct a refined Delaunay mesh.
7113
8114
Parameters
9115
----------
10116
boundary : :class:`compas.geometry.Polygon`
11117
The boundary of the triangulation.
118+
points : list of :class:`compas.geometry.Point`, optional
119+
Additional internal points.
12120
holes : list of :class:`compas.geometry.Polygon`, optional
13121
Internal boundary polygons.
14122
curves : list of :class:`compas.geometry.Polyline`, optional
15123
Internal constraint curves.
16124
maxlength : float, optional
17125
The maximum length of the triangle edges.
126+
is_optimized : bool, optional
127+
Apply LLoyd's optimisation.
18128
19129
Returns
20130
-------
@@ -26,18 +136,21 @@ def constrained_delaunay_triangulation(boundary, holes=None, curves=None, maxlen
26136
...
27137
28138
"""
29-
boundary = np.array(boundary, dtype=np.float64)
139+
boundary = np.asarray(boundary, dtype=np.float64)
140+
141+
points = points or []
142+
points = np.asarray(points, dtype=np.float64)
30143

31144
if holes:
32-
holes = [np.array(hole, dtype=np.float64) for hole in holes]
145+
holes = [np.asarray(hole, dtype=np.float64) for hole in holes]
33146
else:
34147
holes = []
35148

36149
if curves:
37-
curves = [np.array(curve, dtype=np.float64) for curve in curves]
150+
curves = [np.asarray(curve, dtype=np.float64) for curve in curves]
38151
else:
39152
curves = []
40153

41154
maxlength = maxlength or 0.0
42155

43-
return triangulations.constrained_delaunay_triangulation(boundary, holes, curves, maxlength=maxlength)
156+
return triangulations.refined_delaunay_mesh(boundary, points, holes, curves, maxlength=maxlength, is_optimized=is_optimized)

0 commit comments

Comments
 (0)