initial works on EdgeGrid alternative

This commit is contained in:
PavelMikus 2022-04-14 17:21:14 +02:00
parent c14b4a5d2e
commit a46e1dc79c
4 changed files with 78 additions and 24 deletions

View File

@ -201,6 +201,8 @@ set(SLIC3R_SOURCES
Point.hpp
Polygon.cpp
Polygon.hpp
PolygonPointTest.cpp
PolygonPointTest.hpp
MutablePolygon.cpp
MutablePolygon.hpp
PolygonTrimmer.cpp

View File

@ -0,0 +1 @@
#include "PolygonPointTest.hpp"

View File

@ -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<Line> 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<std::pair<size_t, bool>> 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<size_t, bool> &left,
const std::pair<size_t, bool> &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<size_t> active_lines;
//TODO continue
}
};
}
#endif /* SRC_LIBSLIC3R_POLYGONPOINTTEST_HPP_ */

View File

@ -8,8 +8,8 @@
#include <stack>
#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>();