From 8343e81053cf271da05d772fa2cbd3d1c72b6526 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 12 Oct 2022 19:26:45 +0200 Subject: [PATCH] Fix test + Comment debug output + Add was_canceled in cut surface --- src/libslic3r/AABBTreeLines.hpp | 19 ++++++++++--------- src/libslic3r/CutSurface.cpp | 6 ++---- src/libslic3r/Emboss.cpp | 5 ++--- src/libslic3r/Emboss.hpp | 11 +++++++++++ src/slic3r/GUI/Jobs/EmbossJob.cpp | 2 +- tests/libslic3r/test_emboss.cpp | 4 ++-- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/libslic3r/AABBTreeLines.hpp b/src/libslic3r/AABBTreeLines.hpp index 771c568d4..e8497c5ac 100644 --- a/src/libslic3r/AABBTreeLines.hpp +++ b/src/libslic3r/AABBTreeLines.hpp @@ -91,18 +91,19 @@ inline AABBTreeIndirect::Tree<2, typename LineType::Scalar> build_aabb_tree_over // Finding a closest line, its closest point and squared distance to the closest point // Returns squared distance to the closest point or -1 if the input is empty. // or no closer point than max_sq_dist -template -inline typename Scalar squared_distance_to_indexed_lines(const std::vector &lines, - const TreeType &tree, - const VectorType &point, - size_t &hit_idx_out, - Eigen::PlainObjectBase &hit_point_out, - Scalar max_sqr_dist = std::numeric_limits::infinity()) +template +inline typename VectorType::Scalar squared_distance_to_indexed_lines( + const std::vector &lines, + const TreeType &tree, + const VectorType &point, + size_t &hit_idx_out, + Eigen::PlainObjectBase &hit_point_out, + typename VectorType::Scalar max_sqr_dist = std::numeric_limits::infinity()) { - if (tree.empty()) return Scalar(-1); + if (tree.empty()) return VectorType::Scalar(-1); auto distancer = detail::IndexedLinesDistancer{lines, tree, point}; return AABBTreeIndirect::detail::squared_distance_to_indexed_primitives_recursive( - distancer, size_t(0), Scalar(0), max_sqr_dist, hit_idx_out, hit_point_out); + distancer, size_t(0), VectorType::Scalar(0), max_sqr_dist, hit_idx_out, hit_point_out); } // Returns all lines within the given radius limit diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index a2b5c4602..5e0f2b052 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -20,7 +20,7 @@ /// patches/patch{O}.off /// result.obj - Merged result its /// result_contours/{O}.obj - visualization of contours for result patches -#define DEBUG_OUTPUT_DIR std::string("C:/data/temp/cutSurface/") +//#define DEBUG_OUTPUT_DIR std::string("C:/data/temp/cutSurface/") using namespace Slic3r; #include "ExPolygonsIndex.hpp" @@ -1058,7 +1058,7 @@ priv::CutMesh priv::to_cgal(const ExPolygons &shapes, for (const Polygon &hole : shape.holes) insert_contour(hole); } - assert(!exist_duplicit_point(result)); + assert(!exist_duplicit_vertex(result)); return result; } @@ -3209,8 +3209,6 @@ std::vector priv::select_patches(const ProjectionDistances &best_distances for (uint32_t patch_index : used_shape_patches) { ExPolygon patch_area = to_expoly(patches[patch_index], projection); //*/ - // add save offset extension to cover numerical mistake made by back projection to 2d - const float extend_delta = 5.f; ExPolygons patch_areas = offset_ex(patch_area, extend_delta); fill.insert(fill.end(), patch_areas.begin(), patch_areas.end()); /*/ diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 5194c8064..16b174517 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -43,7 +43,6 @@ Point to_point(const stbtt__point &point); bool remove_same_neighbor(Slic3r::Points &points); bool remove_same_neighbor(Slic3r::Polygons &polygons); bool remove_same_neighbor(ExPolygons &expolygons); -bool divide_segments_for_close_point(ExPolygons &expolygons, double distance = .6); // NOTE: expolygons can't contain same_neighbor Points collect_close_points(const ExPolygons &expolygons, double distance = .6); @@ -173,13 +172,13 @@ Points priv::collect_close_points(const ExPolygons &expolygons, double distance) return res; } -bool priv::divide_segments_for_close_point(ExPolygons &expolygons, double distance) +bool Emboss::divide_segments_for_close_point(ExPolygons &expolygons, double distance) { if (expolygons.empty()) return false; if (distance < 0.) return false; // ExPolygons can't contain same neigbours - remove_same_neighbor(expolygons); + priv::remove_same_neighbor(expolygons); // IMPROVE: use int(insted of double) lines and tree const ExPolygonsIndices ids(expolygons); diff --git a/src/libslic3r/Emboss.hpp b/src/libslic3r/Emboss.hpp index f2df0257e..83a45a6e6 100644 --- a/src/libslic3r/Emboss.hpp +++ b/src/libslic3r/Emboss.hpp @@ -177,6 +177,17 @@ public: /// True when shapes is good otherwise False static bool heal_shape(ExPolygons &shape, unsigned max_iteration = 10); + /// + /// Divide line segments in place near to point + /// (which could lead to self intersection due to preccision) + /// Remove same neighbors + /// Note: Possible part of heal shape + /// + /// Expolygon to edit + /// (epsilon)Euclidean distance from point to line which divide line + /// True when some division was made otherwise false + static bool divide_segments_for_close_point(ExPolygons &expolygons, double distance); + /// /// Use data from font property to modify transformation /// diff --git a/src/slic3r/GUI/Jobs/EmbossJob.cpp b/src/slic3r/GUI/Jobs/EmbossJob.cpp index 5e78eb838..a486e17e3 100644 --- a/src/slic3r/GUI/Jobs/EmbossJob.cpp +++ b/src/slic3r/GUI/Jobs/EmbossJob.cpp @@ -356,7 +356,7 @@ void UseSurfaceJob::process(Ctl &ctl) { const TextConfiguration &tc = m_input.text_configuration; const char *text = tc.text.c_str(); const FontProp &fp = tc.style.prop; - ExPolygons shapes = Emboss::text2shapes(m_input.font_file, text, fp); + ExPolygons shapes = Emboss::text2shapes(m_input.font_file, text, fp, was_canceled); if (shapes.empty() || shapes.front().contour.empty()) throw priv::EmbossJobException( _u8L("Font doesn't have any shape for given text.").c_str()); diff --git a/tests/libslic3r/test_emboss.cpp b/tests/libslic3r/test_emboss.cpp index 31bb1459a..6a523ed31 100644 --- a/tests/libslic3r/test_emboss.cpp +++ b/tests/libslic3r/test_emboss.cpp @@ -283,9 +283,9 @@ TEST_CASE("Heal of points close to line", "[Emboss]") Polygon polygon = polygons.front(); polygon.points.pop_back();// NSVG put first point as last one when polygon is closed ExPolygons expoly({ExPolygon(polygon)}); - Emboss::heal_shape(expoly); + CHECK(Emboss::divide_segments_for_close_point(expoly, .6)); //{ SVG svg("C:/data/temp/healed.svg"); svg.draw(expoly);} - CHECK(expoly.size() == 3); + CHECK(to_points(expoly).size() >= (to_points(polygon).size() + 2)); } TEST_CASE("Convert text with glyph cache to model", "[Emboss]")