2
2
#include " straight_skeleton_2.h"
3
3
#include < CGAL/Polygon_2.h>
4
4
#include < CGAL/create_straight_skeleton_2.h>
5
+ #include < CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
5
6
6
7
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
7
8
typedef K::Point_2 Point ;
8
9
typedef CGAL::Polygon_2<K> Polygon_2;
10
+ typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes;
9
11
typedef CGAL::Straight_skeleton_2<K> Ss;
10
12
typedef boost::shared_ptr<Ss> SsPtr;
11
13
typedef CGAL::Straight_skeleton_2<K>::Halfedge_const_handle Halfedge_const_handle;
@@ -39,6 +41,50 @@ compas::Edges pmp_create_interior_straight_skeleton(
39
41
return edgelist;
40
42
};
41
43
44
+ compas::Edges pmp_create_interior_straight_skeleton_with_holes (
45
+ Eigen::Ref<const compas::RowMatrixXd> &V,
46
+ std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes)
47
+ {
48
+ Polygon_2 outer;
49
+ for (int i = 0 ; i < V.rows (); i++)
50
+ {
51
+ outer.push_back (Point (V (i, 0 ), V (i, 1 )));
52
+ }
53
+ Polygon_with_holes poly (outer);
54
+
55
+
56
+ for (auto hit : holes)
57
+ {
58
+ compas::RowMatrixXd H = hit;
59
+ Polygon_2 hole;
60
+ for (int i = 0 ; i < H.rows (); i++)
61
+ {
62
+ hole.push_back (Point (H (i, 0 ), H (i, 1 )));
63
+ }
64
+ poly.add_hole (hole);
65
+
66
+ }
67
+
68
+ SsPtr iss = CGAL::create_interior_straight_skeleton_2 (poly);
69
+ compas::Edges edgelist;
70
+ for (auto hit = iss->halfedges_begin (); hit != iss->halfedges_end (); ++hit){
71
+ const Halfedge_const_handle h = hit;
72
+ if (!h->is_bisector ()){
73
+ continue ;
74
+ }
75
+ const Vertex_const_handle& v1 = h->vertex ();
76
+ const Vertex_const_handle& v2 = h->opposite ()->vertex ();
77
+ if (&*v1 < &*v2){
78
+ std::vector<double > s_vec = {v1->point ().x (), v1->point ().y (), 0 };
79
+ std::vector<double > t_vec = {v2->point ().x (), v2->point ().y (), 0 };
80
+ compas::Edge edge = std::make_tuple (s_vec, t_vec);
81
+ edgelist.push_back (edge);
82
+ }
83
+
84
+ }
85
+ return edgelist;
86
+
87
+ }
42
88
43
89
// ===========================================================================
44
90
// PyBind11
@@ -52,4 +98,10 @@ void init_straight_skeleton_2(pybind11::module &m)
52
98
" create_interior_straight_skeleton" ,
53
99
&pmp_create_interior_straight_skeleton,
54
100
pybind11::arg (" V" ).noconvert ());
101
+
102
+ submodule.def (
103
+ " create_interior_straight_skeleton_with_holes" ,
104
+ &pmp_create_interior_straight_skeleton_with_holes,
105
+ pybind11::arg (" V" ).noconvert (),
106
+ pybind11::arg (" holes" ).noconvert ());
55
107
};
0 commit comments