From 14060916576e62654be0db2f614bf8d36f4d2fa6 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Sat, 4 Jan 2025 12:27:00 +0100 Subject: [PATCH 1/5] compatibility with CGAL-6.0 (and 5.6.x) --- src/libslic3r/CutSurface.cpp | 53 +++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 57dfb8560..e39ec9b64 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -4,6 +4,14 @@ ///|/ #include "CutSurface.hpp" +template +auto access_pmap(std::optional opt) -> T { + return opt.value(); +} + +template +auto access_pmap(Pair pair) { return pair.first; } + /// models_input.obj - Check transormation of model to each others /// projection_center.obj - circle representing center of projection with correct distance /// {M} .. model index @@ -31,6 +39,7 @@ using namespace Slic3r; #include #include #include +#include #include #include #include @@ -1021,8 +1030,8 @@ priv::CutMesh priv::to_cgal(const ExPolygons &shapes, if (shapes.empty()) return {}; CutMesh result; - EdgeShapeMap edge_shape_map = result.add_property_map(edge_shape_map_name).first; - FaceShapeMap face_shape_map = result.add_property_map(face_shape_map_name).first; + EdgeShapeMap edge_shape_map = access_pmap((result.add_property_map(edge_shape_map_name))); + FaceShapeMap face_shape_map = access_pmap((result.add_property_map(face_shape_map_name))); std::vector indices; auto insert_contour = [&projection, &indices, &result, @@ -1432,17 +1441,17 @@ priv::CutAOIs priv::cut_from_model(CutMesh &cgal_model, const ExPolygonsIndices &s2i) { // pointer to edge or face shape_map - VertexShapeMap vert_shape_map = cgal_model.add_property_map(vert_shape_map_name, nullptr).first; + VertexShapeMap vert_shape_map = access_pmap((cgal_model.add_property_map(vert_shape_map_name, nullptr))); // detect anomalities in visitor. bool is_valid = true; // NOTE: map are created when convert shapes to cgal model - const EdgeShapeMap& edge_shape_map = cgal_shape.property_map(edge_shape_map_name).first; - const FaceShapeMap& face_shape_map = cgal_shape.property_map(face_shape_map_name).first; + const EdgeShapeMap& edge_shape_map = access_pmap((cgal_shape.property_map(edge_shape_map_name))); + const FaceShapeMap& face_shape_map = access_pmap((cgal_shape.property_map(face_shape_map_name))); Visitor visitor{cgal_model, cgal_shape, edge_shape_map, face_shape_map, vert_shape_map, &is_valid}; // a property map containing the constrained-or-not status of each edge - EdgeBoolMap ecm = cgal_model.add_property_map(is_constrained_edge_name, false).first; + EdgeBoolMap ecm = access_pmap((cgal_model.add_property_map(is_constrained_edge_name, false))); const auto &p = CGAL::parameters::visitor(visitor) .edge_is_constrained_map(ecm) .throw_on_self_intersection(false); @@ -1451,7 +1460,7 @@ priv::CutAOIs priv::cut_from_model(CutMesh &cgal_model, if (!is_valid) return {}; - FaceTypeMap face_type_map = cgal_model.add_property_map(face_type_map_name, FaceType::not_constrained).first; + FaceTypeMap face_type_map = access_pmap((cgal_model.add_property_map(face_type_map_name, FaceType::not_constrained))); // Select inside and outside face in model set_face_type(face_type_map, cgal_model, vert_shape_map, ecm, cgal_shape, s2i); @@ -1587,8 +1596,8 @@ void priv::collect_surface_data(std::queue &process, void priv::create_reduce_map(ReductionMap &reduction_map, const CutMesh &mesh) { - const VertexShapeMap &vert_shape_map = mesh.property_map(vert_shape_map_name).first; - const EdgeBoolMap &ecm = mesh.property_map(is_constrained_edge_name).first; + const VertexShapeMap &vert_shape_map = access_pmap((mesh.property_map(vert_shape_map_name))); + const EdgeBoolMap &ecm = access_pmap((mesh.property_map(is_constrained_edge_name))); // check if vertex was made by edge_2 which is diagonal of quad auto is_reducible_vertex = [&vert_shape_map](VI reduction_from) -> bool { @@ -1773,10 +1782,10 @@ priv::VDistances priv::calc_distances(const SurfacePatches &patches, for (const SurfacePatch &patch : patches) { // map is created during intersection by corefine visitor const VertexShapeMap &vert_shape_map = - models[patch.model_id].property_map(vert_shape_map_name).first; + access_pmap((models[patch.model_id].property_map(vert_shape_map_name))); uint32_t patch_index = &patch - &patches.front(); // map is created during patch creation / dividing - const CvtVI2VI& cvt = patch.mesh.property_map(patch_source_name).first; + const CvtVI2VI& cvt = access_pmap((patch.mesh.property_map(patch_source_name))); // for each point on outline for (const Loop &loop : patch.loops) for (const VI &vi_patch : loop) { @@ -2666,7 +2675,7 @@ priv::SurfacePatch priv::create_surface_patch(const std::vector &fis, /* const */ CutMesh &mesh, const ReductionMap *rmap) { - auto is_counted = mesh.add_property_map("v:is_counted").first; + auto is_counted = access_pmap((mesh.add_property_map("v:is_counted"))); uint32_t count_vertices = 0; if (rmap == nullptr) { for (FI fi : fis) @@ -2696,7 +2705,7 @@ priv::SurfacePatch priv::create_surface_patch(const std::vector &fis, cm.reserve(count_vertices, count_edges, count_faces); // vertex conversion function from mesh VI to result VI - CvtVI2VI mesh2result = mesh.add_property_map("v:mesh2result").first; + CvtVI2VI mesh2result = access_pmap((mesh.add_property_map("v:mesh2result"))); if (rmap == nullptr) { for (FI fi : fis) { @@ -2748,7 +2757,7 @@ priv::SurfacePatch priv::create_surface_patch(const std::vector &fis, assert(count_edges >= cm.edges().size()); // convert VI from this patch to source VI, when exist - CvtVI2VI cvt = cm.add_property_map(patch_source_name).first; + CvtVI2VI cvt = access_pmap((cm.add_property_map(patch_source_name))); // vi_s .. VertexIndex into mesh (source) // vi_d .. new VertexIndex in cm (destination) for (VI vi_s : mesh.vertices()) { @@ -2939,7 +2948,7 @@ bool priv::is_patch_inside_of_model(const SurfacePatch &patch, uint32_t priv::get_shape_point_index(const CutAOI &cut, const CutMesh &model) { // map is created during intersection by corefine visitor - const VertexShapeMap &vert_shape_map = model.property_map(vert_shape_map_name).first; + const VertexShapeMap &vert_shape_map = access_pmap((model.property_map(vert_shape_map_name))); // for each half edge of outline for (HI hi : cut.second) { VI vi = model.source(hi); @@ -2964,7 +2973,7 @@ priv::SurfacePatch priv::separate_patch(const std::vector& fis, patch_new.model_id = patch.model_id; patch_new.shape_id = patch.shape_id; // fix cvt - CvtVI2VI cvt = patch_new.mesh.property_map(patch_source_name).first; + CvtVI2VI cvt = access_pmap((patch_new.mesh.property_map(patch_source_name))); for (VI &vi : cvt) { if (!vi.is_valid()) continue; vi = cvt_from[vi]; @@ -2982,9 +2991,9 @@ void priv::divide_patch(size_t i, SurfacePatchesEx &patches) CutMesh& cm = patch.mesh; assert(!cm.faces().empty()); std::string patch_number_name = "f:patch_number"; - CutMesh::Property_map is_processed = cm.add_property_map(patch_number_name, false).first; + CutMesh::Property_map is_processed = access_pmap((cm.add_property_map(patch_number_name, false))); - const CvtVI2VI& cvt_from = patch.mesh.property_map(patch_source_name).first; + const CvtVI2VI& cvt_from = access_pmap((patch.mesh.property_map(patch_source_name))); std::vector fis; fis.reserve(cm.faces().size()); @@ -3085,7 +3094,7 @@ priv::SurfacePatches priv::diff_models(VCutAOIs &cuts, CutAOIs &model_cuts = cuts[model_index]; CutMesh &cut_model_ = cut_models[model_index]; const CutMesh &cut_model = cut_model_; - ReductionMap vertex_reduction_map = cut_model_.add_property_map(vertex_reduction_map_name).first; + ReductionMap vertex_reduction_map = access_pmap((cut_model_.add_property_map(vertex_reduction_map_name))); create_reduce_map(vertex_reduction_map, cut_model); for (size_t cut_index = 0; cut_index < model_cuts.size(); ++cut_index, ++index) { @@ -3171,7 +3180,7 @@ bool priv::is_over_whole_expoly(const CutAOI &cutAOI, const CutMesh &mesh) { // NonInterupted contour is without other point and contain all from shape - const VertexShapeMap &vert_shape_map = mesh.property_map(vert_shape_map_name).first; + const VertexShapeMap &vert_shape_map = access_pmap((mesh.property_map(vert_shape_map_name))); for (HI hi : cutAOI.second) { const IntersectingElement *ie_s = vert_shape_map[mesh.source(hi)]; const IntersectingElement *ie_t = vert_shape_map[mesh.target(hi)]; @@ -3708,7 +3717,7 @@ void priv::store(const CutMesh &mesh, const FaceTypeMap &face_type_map, const st } CutMesh &mesh_ = const_cast(mesh); - auto face_colors = mesh_.add_property_map("f:color").first; + auto face_colors = access_pmap((mesh_.add_property_map("f:color"))); for (FI fi : mesh.faces()) { auto &color = face_colors[fi]; switch (face_type_map[fi]) { @@ -3734,7 +3743,7 @@ void priv::store(const CutMesh &mesh, const ReductionMap &reduction_map, const s std::string off_file = dir + "model" + std::to_string(reduction_order++) + ".off"; CutMesh &mesh_ = const_cast(mesh); - auto vertex_colors = mesh_.add_property_map("v:color").first; + auto vertex_colors = access_pmap((mesh_.add_property_map("v:color"))); // initialize to gray color for (VI vi: mesh.vertices()) vertex_colors[vi] = CGAL::Color{127, 127, 127}; -- 2.48.1 From 0073b6e72d56ab52d4c513917d2055d69cfc0383 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Sat, 13 Jul 2024 01:24:10 +0200 Subject: [PATCH 2/5] missing include --- src/libslic3r/CutSurface.cpp | 8 ++++++++ src/slic3r/GUI/UserAccountCommunication.cpp | 1 + 2 files changed, 9 insertions(+) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index e39ec9b64..9e3b74293 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -12,6 +12,14 @@ auto access_pmap(std::optional opt) -> T { template auto access_pmap(Pair pair) { return pair.first; } +template +auto access_pmap(std::optional opt) -> T { + return opt.value(); +} + +template +auto access_pmap(Pair pair) { return pair.first; } + /// models_input.obj - Check transormation of model to each others /// projection_center.obj - circle representing center of projection with correct distance /// {M} .. model index diff --git a/src/slic3r/GUI/UserAccountCommunication.cpp b/src/slic3r/GUI/UserAccountCommunication.cpp index ba736891c..8f51f9f0c 100644 --- a/src/slic3r/GUI/UserAccountCommunication.cpp +++ b/src/slic3r/GUI/UserAccountCommunication.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include -- 2.48.1 From 4cc656a9841a672282bf423d8e85413b552d1ba2 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 30 Sep 2024 11:05:55 +0200 Subject: [PATCH 3/5] Update src/libslic3r/CutSurface.cpp Co-authored-by: Gregor Riepl --- src/libslic3r/CutSurface.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 9e3b74293..4bc183747 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -12,13 +12,6 @@ auto access_pmap(std::optional opt) -> T { template auto access_pmap(Pair pair) { return pair.first; } -template -auto access_pmap(std::optional opt) -> T { - return opt.value(); -} - -template -auto access_pmap(Pair pair) { return pair.first; } /// models_input.obj - Check transormation of model to each others /// projection_center.obj - circle representing center of projection with correct distance -- 2.48.1 From 25130451ca9466ffaac96032602d4f6bde5c6e6e Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Sat, 4 Jan 2025 12:57:19 +0100 Subject: [PATCH 4/5] use std::optional::value_or (according to review) --- src/libslic3r/CutSurface.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 4bc183747..b21ed0e0c 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -6,13 +6,12 @@ template auto access_pmap(std::optional opt) -> T { - return opt.value(); + return opt.value_or(T{}); } template auto access_pmap(Pair pair) { return pair.first; } - /// models_input.obj - Check transormation of model to each others /// projection_center.obj - circle representing center of projection with correct distance /// {M} .. model index @@ -3719,7 +3718,7 @@ void priv::store(const CutMesh &mesh, const FaceTypeMap &face_type_map, const st CutMesh &mesh_ = const_cast(mesh); auto face_colors = access_pmap((mesh_.add_property_map("f:color"))); - for (FI fi : mesh.faces()) { + for (FI fi : mesh.faces()) { auto &color = face_colors[fi]; switch (face_type_map[fi]) { case FaceType::inside: color = CGAL::Color{100, 250, 100}; break; // light green -- 2.48.1 From 9e8d79b990f06032b68d17d0aa4cd6111e47d273 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 6 Feb 2025 12:44:51 +0100 Subject: [PATCH 5/5] Fix test_emboss with CGAL 6.0 --- tests/libslic3r/test_emboss.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 40f448f73..5b0750830 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -9,6 +9,14 @@ #include using namespace Slic3r; +template +auto access_pmap(std::optional opt) -> T { + return opt.value(); +} + +template +auto access_pmap(Pair pair) { return pair.first; } + namespace Private{ // calculate multiplication of ray dir to intersect - inspired by @@ -906,8 +914,8 @@ TEST_CASE("Emboss extrude cut", "[Emboss-Cut]") // identify glyph for intersected vertex std::string vert_shape_map_name = "v:glyph_id"; MyMesh cgal_object = MeshBoolean::cgal2::to_cgal(cube, face_map_name); - auto face_map = cgal_object.property_map(face_map_name).first; - auto vert_shape_map = cgal_object.add_property_map(vert_shape_map_name).first; + auto face_map = access_pmap(cgal_object.property_map(face_map_name)); + auto vert_shape_map = access_pmap(cgal_object.add_property_map(vert_shape_map_name)); std::string edge_shape_map_name = "e:glyph_id"; std::string face_shape_map_name = "f:glyph_id"; @@ -915,8 +923,8 @@ TEST_CASE("Emboss extrude cut", "[Emboss-Cut]") MyMesh cgal_shape = MeshBoolean::cgal2::to_cgal(shape, projection, 0, edge_shape_map_name, face_shape_map_name, glyph_contours); - auto edge_shape_map = cgal_shape.property_map(edge_shape_map_name).first; - auto face_shape_map = cgal_shape.property_map(face_shape_map_name).first; + auto edge_shape_map = access_pmap(cgal_shape.property_map(edge_shape_map_name)); + auto face_shape_map = access_pmap(cgal_shape.property_map(face_shape_map_name)); // bool map for affected edge using d_prop_bool = CGAL::dynamic_edge_property_t; -- 2.48.1