From e6838f7e187c8932d58e94b32407939a2624985a Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Tue, 22 Mar 2022 15:47:34 +0100 Subject: [PATCH] add new cgal as technology --- src/libslic3r/CutSurface.cpp | 57 ++++++++++++++++++------------ src/libslic3r/Technologies.hpp | 5 +-- tests/libslic3r/test_emboss.cpp | 62 ++++++++++++++++++--------------- 3 files changed, 71 insertions(+), 53 deletions(-) diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 69fb939d9..d2dc1897b 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -1,5 +1,37 @@ #include "CutSurface.hpp" +using namespace Slic3r; + +void Slic3r::append(SurfaceCut &sc, SurfaceCut &&sc_add) +{ + if (sc.empty()) { + sc = std::move(sc_add); + return; + } + + if (!sc_add.cut.empty()) { + SurfaceCut::Index offset = static_cast( + sc.vertices.size()); + size_t require = sc.cut.size() + sc_add.cut.size(); + if (sc.cut.capacity() < require) sc.cut.reserve(require); + for (std::vector &cut : sc_add.cut) + for (SurfaceCut::Index &i : cut) i += offset; + append(sc.cut, std::move(sc_add.cut)); + } + its_merge(sc, std::move(sc_add)); +} + +#if !ENABLE_NEW_CGAL + +SurfaceCuts Slic3r::cut_surface(const indexed_triangle_set &model, + const ExPolygons &shapes, + const Emboss::IProject &projection) +{ + return {}; +} + +#else + #include #include #include @@ -9,8 +41,6 @@ #include "TriangleMesh.hpp" // its_merge #include "Utils.hpp" // next_highest_power_of_2 -using namespace Slic3r; - namespace priv { using EpicKernel = CGAL::Exact_predicates_inexact_constructions_kernel; @@ -336,25 +366,6 @@ void store(CutMesh &mesh, const ReductionMap &reduction_map, const std::string & void store(const SurfaceCuts &cut, const std::string &file_prefix); } // namespace privat -void Slic3r::append(SurfaceCut &sc, SurfaceCut &&sc_add) -{ - if (sc.empty()) { - sc = std::move(sc_add); - return; - } - - if (!sc_add.cut.empty()) { - SurfaceCut::Index offset = static_cast( - sc.vertices.size()); - size_t require = sc.cut.size() + sc_add.cut.size(); - if (sc.cut.capacity() < require) sc.cut.reserve(require); - for (std::vector &cut : sc_add.cut) - for (SurfaceCut::Index &i : cut) i += offset; - append(sc.cut, std::move(sc_add.cut)); - } - its_merge(sc, std::move(sc_add)); -} - SurfaceCuts Slic3r::cut_surface(const indexed_triangle_set &model, const ExPolygons &shapes, const Emboss::IProject &projection) @@ -1055,4 +1066,6 @@ void priv::store(const SurfaceCuts &cut, const std::string &file_prefix) { std::string file = file_prefix + std::to_string(index) + ".obj"; its_write_obj(c, file.c_str()); } -} \ No newline at end of file +} + +#endif // ENABLE_NEW_CGAL diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index cb721792b..82ff4380d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -58,7 +58,7 @@ // Enable using vertex attributes and matrices in shaders #define ENABLE_GL_SHADERS_ATTRIBUTES (1 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable rendering imgui using shaders -#define ENABLE_GL_IMGUI_SHADERS (1 && ENABLE_GL_SHADERS_ATTRIBUTES) +#define ENABLE_GL_IMGUI_SHADERS (0 && ENABLE_GL_SHADERS_ATTRIBUTES) // Shows an imgui dialog with GLModel statistics data #define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) // Enable show non-manifold edges @@ -87,6 +87,7 @@ #define ENABLE_WORLD_COORDINATE_SHOW_AXES (1 && ENABLE_WORLD_COORDINATE) // Enable alternate implementation of manipulating scale for instances and volumes #define ENABLE_WORLD_COORDINATE_SCALE_REVISITED (1 && ENABLE_WORLD_COORDINATE) - +// Enable using of new CGAL for emboss text +#define ENABLE_NEW_CGAL (0 && ENABLE_2_5_0_ALPHA1) #endif // _prusaslicer_technologies_h_ diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 281862751..88c81d02c 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -216,35 +216,6 @@ TEST_CASE("triangle intersection", "[]") CHECK(abs(i.y() - 1.) < std::numeric_limits::epsilon()); } -#include "libslic3r/CutSurface.hpp" -TEST_CASE("Cut surface", "[]") -{ - std::string font_path = get_font_filepath(); - char letter = '%'; - float flatness = 2.; - - auto font = Emboss::create_font_file(font_path.c_str()); - REQUIRE(font != nullptr); - - std::optional glyph = Emboss::letter2glyph(*font, letter, flatness); - REQUIRE(glyph.has_value()); - - ExPolygons shape = glyph->shape; - REQUIRE(!shape.empty()); - - float z_depth = 50.f; - Emboss::ProjectZ projection(z_depth); - - auto object = its_make_cube(782 - 49 + 50, 724 + 10 + 50, 5); - its_translate(object, Vec3f(49 - 25, -10 - 25, 2.5)); - auto cube2 = object; // copy - its_translate(cube2, Vec3f(100, -40, 40)); - its_merge(object, std::move(cube2)); - - auto surfaces = cut_surface(object, shape, projection); - CHECK(!surfaces.empty()); -} - #ifndef __APPLE__ #include #include @@ -295,6 +266,38 @@ TEST_CASE("Italic check", "[Emboss]") } #endif // not __APPLE__ +#if ENABLE_NEW_CGAL +#include "libslic3r/CutSurface.hpp" +TEST_CASE("Cut surface", "[]") +{ + std::string font_path = get_font_filepath(); + char letter = '%'; + float flatness = 2.; + + auto font = Emboss::create_font_file(font_path.c_str()); + REQUIRE(font != nullptr); + + std::optional glyph = Emboss::letter2glyph(*font, letter, + flatness); + REQUIRE(glyph.has_value()); + + ExPolygons shape = glyph->shape; + REQUIRE(!shape.empty()); + + float z_depth = 50.f; + Emboss::ProjectZ projection(z_depth); + + auto object = its_make_cube(782 - 49 + 50, 724 + 10 + 50, 5); + its_translate(object, Vec3f(49 - 25, -10 - 25, 2.5)); + auto cube2 = object; // copy + its_translate(cube2, Vec3f(100, -40, 40)); + its_merge(object, std::move(cube2)); + + auto surfaces = cut_surface(object, shape, projection); + CHECK(!surfaces.empty()); +} + + #include #include #include @@ -1045,3 +1048,4 @@ TEST_CASE("Emboss extrude cut", "[Emboss-Cut]") // REQUIRE(!MeshBoolean::cgal::does_self_intersect(cube)); } +#endif // ENABLE_NEW_CGAL