11#include " mapping.hpp"
2- #include < algorithm>
3- #include < iostream>
4- #include < iomanip>
5- #include < cmath>
6- #include < unordered_set>
72
83// Custom hash function for tuple
94struct TupleHash {
@@ -99,7 +94,7 @@ std::vector<std::vector<int>> map_mesh_cropped(
9994 }
10095
10196 // Update pattern vertex position through barycentric interpolation, comment this out if you keep 2D pattern
102- // pattern_v.row(id) = A * L(0, 0) + B * L(0, 1) + C * L(0, 2);
97+ pattern_v.row (id) = A * L (0 , 0 ) + B * L (0 , 1 ) + C * L (0 , 2 );
10398
10499 // If normals are requested, interpolate them using the same barycentric coordinates
105100 if (compute_normals) {
@@ -177,9 +172,18 @@ std::tuple<compas::RowMatrixXd, std::vector<std::vector<int>>, std::vector<bool>
177172 const std::vector<std::vector<int >>& pattern_f,
178173 bool clip_boundaries,
179174 bool simplify_borders,
175+ std::vector<int >& fixed_points,
180176 double tolerance
181177)
182178{
179+
180+ // //////////////////////////////////////////////////////////////////////////////////////
181+ // Fixed points
182+ // //////////////////////////////////////////////////////////////////////////////////////
183+ Clipper2Lib::PathD fixed;
184+ for (const auto &point_id : fixed_points){
185+ fixed.emplace_back (Clipper2Lib::PointD (flattned_target_uv (point_id, 0 ), flattned_target_uv (point_id, 1 )));
186+ }
183187
184188 // //////////////////////////////////////////////////////////////////////////////////////
185189 // Get Boundary polygon of a Mesh as Clipper Path.
@@ -302,6 +306,7 @@ std::tuple<compas::RowMatrixXd, std::vector<std::vector<int>>, std::vector<bool>
302306 simplified_paths[0 ].reserve (subject[0 ].size ());
303307
304308 for (const auto &p : solution[0 ]){ // iterate the points of the intersection polygon
309+
305310 // First check if point is close to any vertex (corner)
306311 bool point_added = false ;
307312 for (size_t i = 0 ; i < subject[0 ].size (); i++){
@@ -313,6 +318,19 @@ std::tuple<compas::RowMatrixXd, std::vector<std::vector<int>>, std::vector<bool>
313318 break ;
314319 }
315320 }
321+
322+ // Check if point is close to any fixed point
323+ for (size_t i = 0 ; i < fixed.size (); i++){
324+ double fx = fixed[i].x ;
325+ double fy = fixed[i].y ;
326+ double dx = p.x - fx;
327+ double dy = p.y - fy;
328+ if (dx*dx + dy*dy < tolerance*tolerance){
329+ simplified_paths[0 ].push_back (p);
330+ point_added = true ;
331+ break ;
332+ }
333+ }
316334
317335 // If not close to a vertex, check if close to any edge
318336 if (!point_added) {
@@ -431,46 +449,20 @@ std::tuple<compas::RowMatrixXd, std::vector<std::vector<int>>, compas::RowMatrix
431449 const std::vector<std::vector<int >>& pattern_f,
432450 bool clip_boundaries,
433451 bool simplify_borders,
452+ std::vector<int >& fixed_points,
434453 double tolerance)
435454{
436455
437456
457+
458+
438459 // Compute target mesh UV parameterization using LSCM
439460 Eigen::MatrixXd target_uv;
440461
441462 // Find the open boundary
442463 Eigen::VectorXi B;
443464 igl::boundary_loop (target_f, B);
444465
445- // Get Boundary vertices
446- std::vector<Eigen::Vector3d> corner_vertex_coords;
447-
448- std::vector<std::vector<int >> VV;
449- igl::adjacency_list (target_f, VV);
450-
451- // Create a set of boundary vertices for faster lookup
452- std::unordered_set<int > boundary_set;
453- for (int i = 0 ; i < B.size (); i++) {
454- boundary_set.insert (B (i));
455- }
456-
457- for (int i = 0 ; i < B.size (); i++) {
458- int v = B (i);
459- int boundary_valence = 0 ;
460- for (int neighbor : VV[v])
461- if (boundary_set.count (neighbor) > 0 )
462- boundary_valence++;
463-
464- if (boundary_valence < 2 ) {
465- Eigen::Vector3d vertex_pos (target_v (v, 0 ), target_v (v, 1 ), target_v (v, 2 ));
466- corner_vertex_coords.push_back (vertex_pos);
467- std::cout << " Corner vertex " << v << " at position ("
468- << target_v (v, 0 ) << " , "
469- << target_v (v, 1 ) << " , "
470- << target_v (v, 2 ) << " )" << std::endl;
471- }
472- }
473-
474466 // Fix two points on the boundary
475467 Eigen::VectorXi fixed (2 , 1 );
476468 fixed (0 ) = B (0 );
@@ -494,7 +486,7 @@ std::tuple<compas::RowMatrixXd, std::vector<std::vector<int>>, compas::RowMatrix
494486
495487
496488 // Clip the pattern
497- auto [clipped_pattern_v, clipped_pattern_f, clipped_pattern_is_boundary, clipped_pattern_groups] = eigen_to_clipper (target_uv, target_f, pattern_v, pattern_f, clip_boundaries, simplify_borders, tolerance);
489+ auto [clipped_pattern_v, clipped_pattern_f, clipped_pattern_is_boundary, clipped_pattern_groups] = eigen_to_clipper (target_uv, target_f, pattern_v, pattern_f, clip_boundaries, simplify_borders, fixed_points, tolerance);
498490
499491 Eigen::MatrixXd clipped_pattern_uv;
500492 clipped_pattern_uv.setZero ();
@@ -531,6 +523,7 @@ NB_MODULE(_mapping, m)
531523 " pattern_f" _a,
532524 " clip_boundaries" _a,
533525 " simplify_borders" _a,
526+ " fixed_points" _a,
534527 " tolerance" _a
535528 );
536529}
0 commit comments