6
6
#include < CGAL/create_offset_polygons_2.h>
7
7
#include < CGAL/create_weighted_offset_polygons_from_polygon_with_holes_2.h>
8
8
#include < CGAL/create_weighted_straight_skeleton_2.h>
9
+ #include < CGAL/create_offset_polygons_from_polygon_with_holes_2.h>
9
10
10
11
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
11
12
typedef K::Point_2 Point ;
@@ -17,6 +18,8 @@ typedef CGAL::Straight_skeleton_2<K>::Halfedge_const_handle Halfedge_const_handl
17
18
typedef CGAL::Straight_skeleton_2<K>::Vertex_const_handle Vertex_const_handle;
18
19
typedef boost::shared_ptr<Polygon_2> PolygonPtr;
19
20
typedef std::vector<PolygonPtr> PolygonPtrVector;
21
+ typedef boost::shared_ptr<Polygon_with_holes> PolygonWithHolesPtr;
22
+ typedef std::vector<PolygonWithHolesPtr> PolygonWithHolesPtrVector;
20
23
21
24
22
25
std::tuple<compas::RowMatrixXd, std::vector<int >, compas::RowMatrixXi, std::vector<int >> mesh_data_from_skeleton (boost::shared_ptr<Ss> &iss){
@@ -62,97 +65,119 @@ std::tuple<compas::RowMatrixXd, std::vector<int>, compas::RowMatrixXi, std::vect
62
65
return result;
63
66
}
64
67
65
- std::tuple<compas::RowMatrixXd, std::vector<int >, compas::RowMatrixXi, std::vector<int >> pmp_create_interior_straight_skeleton (
66
- Eigen::Ref<const compas::RowMatrixXd> &V)
67
- {
68
- Polygon_2 poly;
69
- for (int i = 0 ; i < V.rows (); i++)
70
- {
71
- poly.push_back (Point (V (i, 0 ), V (i, 1 )));
68
+ compas::RowMatrixXd polygon_to_data (Polygon_2 const & poly){
69
+ std::size_t n = poly.size ();
70
+ compas::RowMatrixXd points (n, 3 );
71
+ int j = 0 ;
72
+ for (typename Polygon_2::Vertex_const_iterator vi = poly.vertices_begin () ; vi != poly.vertices_end () ; ++ vi){
73
+ points (j, 0 ) = (double )(*vi).x ();
74
+ points (j, 1 ) = (double )(*vi).y ();
75
+ points (j, 2 ) = 0 ;
76
+ j++;
72
77
}
73
- SsPtr iss = CGAL::create_interior_straight_skeleton_2 (poly.vertices_begin (), poly.vertices_end ());
78
+ return points;
79
+ }
74
80
75
- return mesh_data_from_skeleton (iss);
76
- };
81
+ std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>> polygon_with_holes_to_data (Polygon_with_holes const & polywh){
82
+ std::vector<compas::RowMatrixXd> holes;
83
+ compas::RowMatrixXd points = polygon_to_data (polywh.outer_boundary ());
84
+ for (typename Polygon_with_holes::Hole_const_iterator hi = polywh.holes_begin () ; hi != polywh.holes_end () ; ++ hi){
85
+ compas::RowMatrixXd hole = polygon_to_data (*hi);
86
+ holes.push_back (hole);
87
+ }
88
+ std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>> result = std::make_tuple (points, holes);
89
+ return result;
90
+ }
77
91
78
- std::tuple<compas::RowMatrixXd, std::vector<int >, compas::RowMatrixXi, std::vector<int >> pmp_create_interior_straight_skeleton_with_holes (
79
- Eigen::Ref<const compas::RowMatrixXd> &V,
80
- std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes)
81
- {
82
- Polygon_2 outer;
83
- for (int i = 0 ; i < V.rows (); i++)
84
- {
85
- outer.push_back (Point (V (i, 0 ), V (i, 1 )));
92
+ Polygon_2 data_to_polygon (Eigen::Ref<const compas::RowMatrixXd> &V){
93
+ Polygon_2 poly;
94
+ for (int i = 0 ; i < V.rows (); i++){
95
+ poly.push_back (Point (V (i, 0 ), V (i, 1 )));
86
96
}
87
- Polygon_with_holes poly (outer);
97
+ return poly;
98
+ }
88
99
89
- for (auto hit : holes)
90
- {
100
+ Polygon_with_holes data_to_polygon_with_holes (Eigen::Ref<const compas::RowMatrixXd> &V, std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes){
101
+ Polygon_2 outer = data_to_polygon (V);
102
+ Polygon_with_holes poly (outer);
103
+ for (auto hit : holes){
91
104
compas::RowMatrixXd H = hit;
105
+ // Polygon_2 hole = data_to_polygon(*H); // why does this not work?
92
106
Polygon_2 hole;
93
- for (int i = 0 ; i < H.rows (); i++)
94
- {
107
+ for (int i = 0 ; i < H.rows (); i++){
95
108
hole.push_back (Point (H (i, 0 ), H (i, 1 )));
96
109
}
97
110
poly.add_hole (hole);
98
-
99
111
}
112
+ return poly;
113
+ }
100
114
115
+ std::tuple<compas::RowMatrixXd, std::vector<int >, compas::RowMatrixXi, std::vector<int >> pmp_create_interior_straight_skeleton (
116
+ Eigen::Ref<const compas::RowMatrixXd> &V){
117
+ Polygon_2 poly = data_to_polygon (V);
118
+ SsPtr iss = CGAL::create_interior_straight_skeleton_2 (poly.vertices_begin (), poly.vertices_end ());
119
+ return mesh_data_from_skeleton (iss);
120
+ };
121
+
122
+ std::tuple<compas::RowMatrixXd, std::vector<int >, compas::RowMatrixXi, std::vector<int >> pmp_create_interior_straight_skeleton_with_holes (
123
+ Eigen::Ref<const compas::RowMatrixXd> &V,
124
+ std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes){
125
+ Polygon_with_holes poly = data_to_polygon_with_holes (V, holes);
101
126
SsPtr iss = CGAL::create_interior_straight_skeleton_2 (poly);
102
127
return mesh_data_from_skeleton (iss);
103
128
}
104
129
105
130
std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_inner (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
106
- Polygon_2 poly;
107
- for (int i = 0 ; i < V.rows (); i++){
108
- poly.push_back (Point (V (i, 0 ), V (i, 1 )));
109
- }
131
+ Polygon_2 poly = data_to_polygon (V);
110
132
PolygonPtrVector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2 (offset, poly);
111
133
112
134
std::vector<compas::RowMatrixXd> result;
113
- for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi ){
114
- std::size_t n = (*pi )->size ();
115
- compas::RowMatrixXd points (n, 3 );
116
- int j = 0 ;
117
- for (auto vi = (*pi )->vertices_begin (); vi != (*pi )->vertices_end (); ++vi){
118
- points (j, 0 ) = (double )(*vi).x ();
119
- points (j, 1 ) = (double )(*vi).y ();
120
- points (j, 2 ) = 0 ;
121
- j++;
122
- }
135
+ for (typename PolygonPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
136
+ compas::RowMatrixXd points = polygon_to_data (**pi );
123
137
result.push_back (points);
124
138
}
125
139
return result;
126
140
}
127
141
128
- std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_outer (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
129
- Polygon_2 poly;
130
- for (int i = 0 ; i < V.rows (); i++){
131
- poly.push_back (Point (V (i, 0 ), V (i, 1 )));
142
+ std::vector<std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>>> pmp_create_offset_polygons_2_inner_with_holes (Eigen::Ref<const compas::RowMatrixXd> &V, std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes, double &offset){
143
+
144
+ Polygon_with_holes poly = data_to_polygon_with_holes (V, holes);
145
+ PolygonWithHolesPtrVector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2 (offset, poly);
146
+
147
+ std::vector<std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>>> result;
148
+ for (typename PolygonWithHolesPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
149
+ std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>> polywh_data = polygon_with_holes_to_data (**pi );
150
+ result.push_back (polywh_data);
132
151
}
152
+ return result;
153
+ }
154
+
155
+ std::vector<compas::RowMatrixXd> pmp_create_offset_polygons_2_outer (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset){
156
+ Polygon_2 poly = data_to_polygon (V);
133
157
PolygonPtrVector offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2 (offset, poly);
134
158
135
159
std::vector<compas::RowMatrixXd> result;
136
- for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi ){
137
- std::size_t n = (*pi )->size ();
138
- compas::RowMatrixXd points (n, 3 );
139
- int j = 0 ;
140
- for (auto vi = (*pi )->vertices_begin (); vi != (*pi )->vertices_end (); ++vi){
141
- points (j, 0 ) = (double )(*vi).x ();
142
- points (j, 1 ) = (double )(*vi).y ();
143
- points (j, 2 ) = 0 ;
144
- j++;
145
- }
160
+ for (typename PolygonPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
161
+ compas::RowMatrixXd points = polygon_to_data (**pi );
146
162
result.push_back (points);
147
163
}
148
164
return result;
149
165
}
150
166
151
- std::vector<compas::RowMatrixXd> pmp_create_weighted_offset_polygons_2_inner (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset, Eigen::Ref<const compas::RowMatrixXd> &weights){
152
- Polygon_2 poly;
153
- for (int i = 0 ; i < V.rows (); i++){
154
- poly.push_back (Point (V (i, 0 ), V (i, 1 )));
167
+ std::vector<std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>>> pmp_create_offset_polygons_2_outer_with_holes (Eigen::Ref<const compas::RowMatrixXd> &V, std::vector<Eigen::Ref<const compas::RowMatrixXd>> &holes, double &offset){
168
+ Polygon_with_holes poly = data_to_polygon_with_holes (V, holes);
169
+ PolygonWithHolesPtrVector offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_with_holes_2 (offset, poly);
170
+
171
+ std::vector<std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>>> result;
172
+ for (typename PolygonWithHolesPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
173
+ std::tuple<compas::RowMatrixXd, std::vector<compas::RowMatrixXd>> polywh_data = polygon_with_holes_to_data (**pi );
174
+ result.push_back (polywh_data);
155
175
}
176
+ return result;
177
+ }
178
+
179
+ std::vector<compas::RowMatrixXd> pmp_create_weighted_offset_polygons_2_inner (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset, Eigen::Ref<const compas::RowMatrixXd> &weights){
180
+ Polygon_2 poly = data_to_polygon (V);
156
181
std::vector<double > weights_vec;
157
182
for (int i = 0 ; i < weights.rows (); i++){
158
183
weights_vec.push_back (weights (i, 0 ));
@@ -161,26 +186,15 @@ std::vector<compas::RowMatrixXd> pmp_create_weighted_offset_polygons_2_inner(Eig
161
186
PolygonPtrVector offset_polygons = CGAL::create_offset_polygons_2<Polygon_2>(offset, *iss);
162
187
163
188
std::vector<compas::RowMatrixXd> result;
164
- for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi ){
165
- std::size_t n = (*pi )->size ();
166
- compas::RowMatrixXd points (n, 3 );
167
- int j = 0 ;
168
- for (auto vi = (*pi )->vertices_begin (); vi != (*pi )->vertices_end (); ++vi){
169
- points (j, 0 ) = (double )(*vi).x ();
170
- points (j, 1 ) = (double )(*vi).y ();
171
- points (j, 2 ) = 0 ;
172
- j++;
173
- }
189
+ for (typename PolygonPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
190
+ compas::RowMatrixXd points = polygon_to_data (**pi );
174
191
result.push_back (points);
175
192
}
176
193
return result;
177
194
}
178
195
179
196
std::vector<compas::RowMatrixXd> pmp_create_weighted_offset_polygons_2_outer (Eigen::Ref<const compas::RowMatrixXd> &V, double &offset, Eigen::Ref<const compas::RowMatrixXd> &weights){
180
- Polygon_2 poly;
181
- for (int i = 0 ; i < V.rows (); i++){
182
- poly.push_back (Point (V (i, 0 ), V (i, 1 )));
183
- }
197
+ Polygon_2 poly = data_to_polygon (V);
184
198
std::vector<double > weights_vec;
185
199
for (int i = 0 ; i < weights.rows (); i++){
186
200
weights_vec.push_back (weights (i, 0 ));
@@ -189,16 +203,8 @@ std::vector<compas::RowMatrixXd> pmp_create_weighted_offset_polygons_2_outer(Eig
189
203
PolygonPtrVector offset_polygons = CGAL::create_offset_polygons_2<Polygon_2>(offset, *iss);
190
204
191
205
std::vector<compas::RowMatrixXd> result;
192
- for (auto pi = offset_polygons.begin (); pi != offset_polygons.end (); ++pi ){
193
- std::size_t n = (*pi )->size ();
194
- compas::RowMatrixXd points (n, 3 );
195
- int j = 0 ;
196
- for (auto vi = (*pi )->vertices_begin (); vi != (*pi )->vertices_end (); ++vi){
197
- points (j, 0 ) = (double )(*vi).x ();
198
- points (j, 1 ) = (double )(*vi).y ();
199
- points (j, 2 ) = 0 ;
200
- j++;
201
- }
206
+ for (typename PolygonPtrVector::const_iterator pi = offset_polygons.begin () ; pi != offset_polygons.end () ; ++ pi ){
207
+ compas::RowMatrixXd points = polygon_to_data (**pi );
202
208
result.push_back (points);
203
209
}
204
210
return result;
@@ -229,12 +235,26 @@ void init_straight_skeleton_2(pybind11::module &m)
229
235
pybind11::arg (" V" ).noconvert (),
230
236
pybind11::arg (" offset" ).noconvert ());
231
237
238
+ submodule.def (
239
+ " create_offset_polygons_2_inner_with_holes" ,
240
+ &pmp_create_offset_polygons_2_inner_with_holes,
241
+ pybind11::arg (" V" ).noconvert (),
242
+ pybind11::arg (" holes" ).noconvert (),
243
+ pybind11::arg (" offset" ).noconvert ());
244
+
232
245
submodule.def (
233
246
" create_offset_polygons_2_outer" ,
234
247
&pmp_create_offset_polygons_2_outer,
235
248
pybind11::arg (" V" ).noconvert (),
236
249
pybind11::arg (" offset" ).noconvert ());
237
250
251
+ submodule.def (
252
+ " create_offset_polygons_2_outer_with_holes" ,
253
+ &pmp_create_offset_polygons_2_outer_with_holes,
254
+ pybind11::arg (" V" ).noconvert (),
255
+ pybind11::arg (" holes" ).noconvert (),
256
+ pybind11::arg (" offset" ).noconvert ());
257
+
238
258
submodule.def (
239
259
" create_weighted_offset_polygons_2_inner" ,
240
260
&pmp_create_weighted_offset_polygons_2_inner,
0 commit comments