From 226ab414d968ed88dad352f121af8b921a6043b6 Mon Sep 17 00:00:00 2001 From: Filip Sykala - NTB T15p Date: Wed, 25 Oct 2023 09:59:18 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20warnings:=20../src/libslic3r/Emboss.cpp:8?= =?UTF-8?q?58:13:=20warning:=20=E2=80=98Slic3r::EmbossStyle=20{anonymous}:?= =?UTF-8?q?:create=5Fstyle(const=20wstring&,=20const=20wstring&)=E2=80=99?= =?UTF-8?q?=20defined=20but=20not=20used=20[-Wunused-function]=20../src/li?= =?UTF-8?q?bslic3r/Emboss.cpp:708:6:=20warning:=20=E2=80=98void=20{anonymo?= =?UTF-8?q?us}::remove=5Fsmall=5Fislands(Slic3r::ExPolygons&,=20double)?= =?UTF-8?q?=E2=80=99=20defined=20but=20not=20used=20[-Wunused-function]=20?= =?UTF-8?q?../src/libslic3r/Emboss.cpp:497:6:=20warning:=20=E2=80=98void?= =?UTF-8?q?=20{anonymous}::visualize=5Fheal(const=20string&,=20const=20ExP?= =?UTF-8?q?olygons&)=E2=80=99=20defined=20but=20not=20used=20[-Wunused-fun?= =?UTF-8?q?ction]=20../src/libslic3r/Emboss.cpp:283:8:=20warning:=20?= =?UTF-8?q?=E2=80=98Slic3r::Points=20{anonymous}::collect=5Fclose=5Fpoints?= =?UTF-8?q?(const=20ExPolygons&,=20double)=E2=80=99=20defined=20but=20not?= =?UTF-8?q?=20used=20[-Wunused-function]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libslic3r/Emboss.cpp | 135 ++++++++++----------------- src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp | 2 +- 2 files changed, 49 insertions(+), 88 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index aeb865c98c..4ae153f847 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -43,6 +43,39 @@ using fontinfo_opt = std::optional; // Potentionaly useable for eliminate spike in layer //#define REMOVE_SPIKES +// function to remove useless islands and holes +// #define REMOVE_SMALL_ISLANDS +#ifdef REMOVE_SMALL_ISLANDS +namespace { void remove_small_islands(ExPolygons &shape, double minimal_area);} +#endif //REMOVE_SMALL_ISLANDS + +//#define VISUALIZE_HEAL +#ifdef VISUALIZE_HEAL +namespace { +// for debug purpose only +// NOTE: check scale when store svg !! +#include "libslic3r/SVG.hpp" // for visualize_heal +static std::string visualize_heal_svg_filepath = "C:/data/temp/heal.svg"; +void visualize_heal(const std::string &svg_filepath, const ExPolygons &expolygons) +{ + Points pts = to_points(expolygons); + BoundingBox bb(pts); + // double svg_scale = SHAPE_SCALE / unscale(1.); + // bb.scale(svg_scale); + SVG svg(svg_filepath, bb); + svg.draw(expolygons); + + Points duplicits = collect_duplicates(pts); + int black_size = std::max(bb.size().x(), bb.size().y()) / 20; + svg.draw(duplicits, "black", black_size); + + Slic3r::IntersectionsLines intersections_f = get_intersections(expolygons); + Points intersections = get_unique_intersections(intersections_f); + svg.draw(intersections, "red", black_size * 1.2); +} +} // namespace +#endif // VISUALIZE_HEAL + // do not expose out of this file stbtt_ data types namespace{ using Polygon = Slic3r::Polygon; @@ -54,8 +87,6 @@ std::optional get_glyph(const stbtt_fontinfo &font_info, int unicode_lett const Glyph* get_glyph(int unicode, const FontFile &font, const FontProp &font_prop, Glyphs &cache, fontinfo_opt &font_info_opt); -EmbossStyle create_style(const std::wstring &name, const std::wstring &path); - // scale and convert float to int coordinate Point to_point(const stbtt__point &point); @@ -66,17 +97,9 @@ void remove_bad(ExPolygons &expolygons); // Try to remove self intersection by subtracting rect 2x2 px ExPolygon create_bounding_rect(const ExPolygons &shape); -void remove_small_islands(ExPolygons &shape, double minimal_area); - -// NOTE: expolygons can't contain same_neighbor -Points collect_close_points(const ExPolygons &expolygons, double distance = .6); - // Heal duplicates points and self intersections bool heal_dupl_inter(ExPolygons &shape, unsigned max_iteration); -// for debug purpose -void visualize_heal(const std::string& svg_filepath, const ExPolygons &expolygons); - const Points pts_2x2({Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1)}); const Points pts_3x3({Point(-1, -1), Point(1, -1), Point(1, 1), Point(-1, 1)}); @@ -279,56 +302,6 @@ void remove_bad(ExPolygons &expolygons) { for (ExPolygon &expolygon : expolygons) remove_bad(expolygon.holes); } - -Points collect_close_points(const ExPolygons &expolygons, double distance) { - if (expolygons.empty()) return {}; - if (distance < 0.) return {}; - - // IMPROVE: use int(insted of double) lines and tree - const ExPolygonsIndices ids(expolygons); - const std::vector lines = Slic3r::to_linesf(expolygons, ids.get_count()); - AABBTreeIndirect::Tree<2, double> tree = AABBTreeLines::build_aabb_tree_over_indexed_lines(lines); - // Result close points - Points res; - size_t point_index = 0; - auto collect_close = [&res, &point_index, &lines, &tree, &distance, &ids, &expolygons](const Points &pts) { - for (const Point &p : pts) { - Vec2d p_d = p.cast(); - std::vector close_lines = AABBTreeLines::all_lines_in_radius(lines, tree, p_d, distance); - for (size_t index : close_lines) { - // skip point neighbour lines indices - if (index == point_index) continue; - if (&p != &pts.front()) { - if (index == point_index - 1) continue; - } else if (index == (pts.size()-1)) continue; - - // do not doubled side point of segment - const ExPolygonsIndex id = ids.cvt(index); - const ExPolygon &expoly = expolygons[id.expolygons_index]; - const Polygon &poly = id.is_contour() ? expoly.contour : expoly.holes[id.hole_index()]; - const Points &poly_pts = poly.points; - const Point &line_a = poly_pts[id.point_index]; - const Point &line_b = (!ids.is_last_point(id)) ? poly_pts[id.point_index + 1] : poly_pts.front(); - assert(line_a == lines[index].a.cast()); - assert(line_b == lines[index].b.cast()); - if (p == line_a || p == line_b) continue; - res.push_back(p); - } - ++point_index; - } - }; - for (const ExPolygon &expoly : expolygons) { - collect_close(expoly.contour.points); - for (const Polygon &hole : expoly.holes) - collect_close(hole.points); - } - if (res.empty()) return {}; - std::sort(res.begin(), res.end()); - // only unique points - res.erase(std::unique(res.begin(), res.end()), res.end()); - return res; -} - } // end namespace bool Emboss::divide_segments_for_close_point(ExPolygons &expolygons, double distance) @@ -471,7 +444,6 @@ bool Emboss::heal_expolygons(ExPolygons &shape, unsigned max_iteration) return ::heal_dupl_inter(shape, max_iteration); } -#include "libslic3r/SVG.hpp" // for visualize_heal namespace { Points get_unique_intersections(const Slic3r::IntersectionsLines &intersections) @@ -494,24 +466,6 @@ Points get_unique_intersections(const Slic3r::IntersectionsLines &intersections) return result; } -void visualize_heal(const std::string &svg_filepath, const ExPolygons &expolygons) -{ - Points pts = to_points(expolygons); - BoundingBox bb(pts); - // double svg_scale = SHAPE_SCALE / unscale(1.); - // bb.scale(svg_scale); - SVG svg(svg_filepath, bb); - svg.draw(expolygons); - - Points duplicits = collect_duplicates(pts); - int black_size = std::max(bb.size().x(), bb.size().y()) / 20; - svg.draw(duplicits, "black", black_size); - - Slic3r::IntersectionsLines intersections_f = get_intersections(expolygons); - Points intersections = get_unique_intersections(intersections_f); - svg.draw(intersections, "red", black_size * 1.2); -} - Polygons get_holes_with_points(const Polygons &holes, const Points &points) { Polygons result; @@ -655,8 +609,11 @@ bool heal_dupl_inter(ExPolygons &shape, unsigned max_iteration) // healed in the last loop return true; } - - // visualize_heal("C:/data/temp/heal.svg", shape); + + #ifdef VISUALIZE_HEAL + visualize_heal(visualize_heal_svg_filepath, shape); + #endif // VISUALIZE_HEAL + assert(false); // Can not heal this shape // investigate how to heal better way @@ -705,6 +662,7 @@ ExPolygon create_bounding_rect(const ExPolygons &shape) { return ExPolygon(rect, hole); } +#ifdef REMOVE_SMALL_ISLANDS void remove_small_islands(ExPolygons &expolygons, double minimal_area) { if (expolygons.empty()) return; @@ -722,6 +680,7 @@ void remove_small_islands(ExPolygons &expolygons, double minimal_area) { holes.erase(it, holes.end()); } } +#endif // REMOVE_SMALL_ISLANDS std::optional get_glyph(const stbtt_fontinfo &font_info, int unicode_letter, float flatness) { @@ -855,12 +814,6 @@ const Glyph* get_glyph( return &it->second; } -EmbossStyle create_style(const std::wstring& name, const std::wstring& path) { - return { boost::nowide::narrow(name.c_str()), - boost::nowide::narrow(path.c_str()), - EmbossStyle::Type::file_path, FontProp() }; -} - Point to_point(const stbtt__point &point) { return Point(static_cast(std::round(point.x / SHAPE_SCALE)), static_cast(std::round(point.y / SHAPE_SCALE))); @@ -874,6 +827,14 @@ Point to_point(const stbtt__point &point) { #include #include +namespace { +EmbossStyle create_style(const std::wstring& name, const std::wstring& path) { + return { boost::nowide::narrow(name.c_str()), + boost::nowide::narrow(path.c_str()), + EmbossStyle::Type::file_path, FontProp() }; +} +} // namespace + // Get system font file path std::optional Emboss::get_font_path(const std::wstring &font_face_name) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp index b8fccceeee..2d7b438ff5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSVG.cpp @@ -764,7 +764,7 @@ void draw_side_outline(const ExPolygons &shape, const std::array= data_width || y >= count_lines) + if (x < 0 || y < 0 || static_cast(x) >= data_width || y >= count_lines) return; // out of image size_t offset = get_offset(x, y); bool change_color = false;