22#include " straight_skeleton_2.h"
33#include < CGAL/Polygon_2.h>
44#include < CGAL/create_straight_skeleton_2.h>
5+ #include < CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
56
67typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
78typedef K::Point_2 Point;
89typedef CGAL::Polygon_2<K> Polygon_2;
10+ typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes;
911typedef CGAL::Straight_skeleton_2<K> Ss;
1012typedef boost::shared_ptr<Ss> SsPtr;
1113typedef CGAL::Straight_skeleton_2<K>::Halfedge_const_handle Halfedge_const_handle;
@@ -39,6 +41,50 @@ compas::Edges pmp_create_interior_straight_skeleton(
3941 return edgelist;
4042};
4143
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+ }
4288
4389// ===========================================================================
4490// PyBind11
@@ -52,4 +98,10 @@ void init_straight_skeleton_2(pybind11::module &m)
5298 " create_interior_straight_skeleton" ,
5399 &pmp_create_interior_straight_skeleton,
54100 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 ());
55107};
0 commit comments