diff --git a/src/libslic3r/CMakeLists.txt b/src/libslic3r/CMakeLists.txt index 0a0062a75..443c81b48 100644 --- a/src/libslic3r/CMakeLists.txt +++ b/src/libslic3r/CMakeLists.txt @@ -201,6 +201,8 @@ set(SLIC3R_SOURCES Point.hpp Polygon.cpp Polygon.hpp + PolygonPointTest.cpp + PolygonPointTest.hpp MutablePolygon.cpp MutablePolygon.hpp PolygonTrimmer.cpp diff --git a/src/libslic3r/PolygonPointTest.cpp b/src/libslic3r/PolygonPointTest.cpp new file mode 100644 index 000000000..dcab9e87e --- /dev/null +++ b/src/libslic3r/PolygonPointTest.cpp @@ -0,0 +1 @@ +#include "PolygonPointTest.hpp" diff --git a/src/libslic3r/PolygonPointTest.hpp b/src/libslic3r/PolygonPointTest.hpp new file mode 100644 index 000000000..79e6b4ab5 --- /dev/null +++ b/src/libslic3r/PolygonPointTest.hpp @@ -0,0 +1,73 @@ +#ifndef SRC_LIBSLIC3R_POLYGONPOINTTEST_HPP_ +#define SRC_LIBSLIC3R_POLYGONPOINTTEST_HPP_ + +#include "libslic3r/Point.hpp" +#include "libslic3r/EdgeGrid.hpp" + +namespace Slic3r { + +struct EdgeGridWrapper { + EdgeGridWrapper(coord_t resolution, ExPolygons ex_polys) : + ex_polys(ex_polys) { + + grid.create(this->ex_polys, resolution); + grid.calculate_sdf(); + } + + bool signed_distance(const Point &point, coordf_t point_width, coordf_t &dist_out) const { + coordf_t tmp_dist_out; + bool found = grid.signed_distance(point, point_width, tmp_dist_out); + // decrease the distance by half of edge width of previous layer and half of flow width of current layer + dist_out = tmp_dist_out - point_width / 2; + return found; + + } + + EdgeGrid::Grid grid; + ExPolygons ex_polys; +}; + +class PolygonPointTest { +public: + PolygonPointTest(const ExPolygons &ex_polygons) { + std::vector lines; + for (const auto &exp : ex_polygons) { + Lines contour = exp.contour.lines(); + lines.insert(lines.end(), contour.begin(), contour.end()); + for (const auto &hole : exp.holes) { + Lines hole_lines = hole.lines(); + for (Line &line : hole_lines) { + line.reverse(); // reverse hole lines, so that we can use normal to deduce where the object is + } + lines.insert(lines.end(), hole_lines.begin(), hole_lines.end()); + } + } + + std::vector> sweeping_data(lines.size()); + sweeping_data.reserve(lines.size() * 2); + for (int line_index = 0; line_index < lines.size(); ++line_index) { + sweeping_data[line_index].first = line_index; + sweeping_data[line_index].second = true; + } + + const auto data_comparator = [&lines](const std::pair &left, + const std::pair &right) { + return std::min(lines[left.first].a.x(), lines[left.first].b.x()) + < std::min(lines[right.first].a.x(), lines[right.first].b.x()); + }; + + std::make_heap(sweeping_data.begin(), sweeping_data.end(), data_comparator); + std::set active_lines; + + //TODO continue + + + + + } + +}; + +} + +#endif /* SRC_LIBSLIC3R_POLYGONPOINTTEST_HPP_ */ diff --git a/src/libslic3r/SupportableIssuesSearch.cpp b/src/libslic3r/SupportableIssuesSearch.cpp index 6510c3546..39ded7648 100644 --- a/src/libslic3r/SupportableIssuesSearch.cpp +++ b/src/libslic3r/SupportableIssuesSearch.cpp @@ -8,8 +8,8 @@ #include #include "libslic3r/Layer.hpp" -#include "libslic3r/EdgeGrid.hpp" #include "libslic3r/ClipperUtils.hpp" +#include "PolygonPointTest.hpp" #define DEBUG_FILES @@ -33,28 +33,6 @@ bool Issues::empty() const { namespace Impl { -struct EdgeGridWrapper { - EdgeGridWrapper(coord_t edge_width, ExPolygons ex_polys) : - ex_polys(ex_polys), edge_width(edge_width) { - - grid.create(this->ex_polys, edge_width); - grid.calculate_sdf(); - } - - bool signed_distance(const Point &point, coordf_t point_width, coordf_t &dist_out) const { - coordf_t tmp_dist_out; - bool found = grid.signed_distance(point, edge_width, tmp_dist_out); - // decrease the distance by half of edge width of previous layer and half of flow width of current layer - dist_out = tmp_dist_out - edge_width / 2 - point_width / 2; - return found; - - } - - EdgeGrid::Grid grid; - ExPolygons ex_polys; - coord_t edge_width; -}; - #ifdef DEBUG_FILES void debug_export(Issues issues, std::string file_name) { Slic3r::CNumericLocalesSetter locales_setter; @@ -194,7 +172,7 @@ Issues check_extrusion_entity_stability(const ExtrusionEntity *entity, } if (dist_from_prev_layer > max_allowed_dist_from_prev_layer) { //extrusion point is unsupported - unsupported_distance += (fpoint - prev_fpoint).norm(); // for algortihm simplicity, expect that the whole line between prev and current point is unsupported + unsupported_distance += (fpoint - prev_fpoint).norm(); // for algorithm simplicity, expect that the whole line between prev and current point is unsupported if (!points.empty()) { const Vec2f v1 = (fpoint - prev_fpoint).head<2>();