33#include < CGAL/Polygon_2.h>
44#include < CGAL/create_straight_skeleton_2.h>
55#include < CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
6+ #include < CGAL/create_offset_polygons_2.h>
67
78typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
89typedef K::Point_2 Point;
@@ -12,6 +13,8 @@ typedef CGAL::Straight_skeleton_2<K> Ss;
1213typedef boost::shared_ptr<Ss> SsPtr;
1314typedef CGAL::Straight_skeleton_2<K>::Halfedge_const_handle Halfedge_const_handle;
1415typedef CGAL::Straight_skeleton_2<K>::Vertex_const_handle Vertex_const_handle;
16+ typedef boost::shared_ptr<Polygon_2> PolygonPtr;
17+ typedef std::vector<PolygonPtr> PolygonPtrVector;
1518
1619compas::Edges pmp_create_interior_straight_skeleton (
1720 Eigen::Ref<const compas::RowMatrixXd> &V)
@@ -86,6 +89,52 @@ compas::Edges pmp_create_interior_straight_skeleton_with_holes(
8689
8790}
8891
92+ std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_inner (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
93+ Polygon_2 poly;
94+ for (int i = 0 ; i < V.rows (); i++){
95+ poly.push_back (Point (V (i, 0 ), V (i, 1 )));
96+ }
97+ PolygonPtrVector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2 (offset, poly);
98+
99+ std::vector<compas::RowMatrixXd> result;
100+ for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi){
101+ std::size_t n = (*pi)->size ();
102+ compas::RowMatrixXd points (n, 3 );
103+ int j = 0 ;
104+ for (auto vi = (*pi)->vertices_begin (); vi != (*pi)->vertices_end (); ++vi){
105+ points (j, 0 ) = (double )(*vi).x ();
106+ points (j, 1 ) = (double )(*vi).y ();
107+ points (j, 2 ) = 0 ;
108+ j++;
109+ }
110+ result.push_back (points);
111+ }
112+ return result;
113+ }
114+
115+ std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_outer (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
116+ Polygon_2 poly;
117+ for (int i = 0 ; i < V.rows (); i++){
118+ poly.push_back (Point (V (i, 0 ), V (i, 1 )));
119+ }
120+ PolygonPtrVector offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2 (offset, poly);
121+
122+ std::vector<compas::RowMatrixXd> result;
123+ for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi){
124+ std::size_t n = (*pi)->size ();
125+ compas::RowMatrixXd points (n, 3 );
126+ int j = 0 ;
127+ for (auto vi = (*pi)->vertices_begin (); vi != (*pi)->vertices_end (); ++vi){
128+ points (j, 0 ) = (double )(*vi).x ();
129+ points (j, 1 ) = (double )(*vi).y ();
130+ points (j, 2 ) = 0 ;
131+ j++;
132+ }
133+ result.push_back (points);
134+ }
135+ return result;
136+ }
137+
89138// ===========================================================================
90139// PyBind11
91140// ===========================================================================
@@ -104,4 +153,16 @@ void init_straight_skeleton_2(pybind11::module &m)
104153 &pmp_create_interior_straight_skeleton_with_holes,
105154 pybind11::arg (" V" ).noconvert (),
106155 pybind11::arg (" holes" ).noconvert ());
156+
157+ submodule.def (
158+ " create_offset_polygons_2_inner" ,
159+ &pmp_create_offset_polygons_2_inner,
160+ pybind11::arg (" V" ).noconvert (),
161+ pybind11::arg (" offset" ).noconvert ());
162+
163+ submodule.def (
164+ " create_offset_polygons_2_outer" ,
165+ &pmp_create_offset_polygons_2_outer,
166+ pybind11::arg (" V" ).noconvert (),
167+ pybind11::arg (" offset" ).noconvert ());
107168};
0 commit comments