mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 03:07:55 -06:00
EdgeGrid refactoring to support both open and closed contours.
Squashed commit of the following: commit 4e13a8fe19abcc9aae39a9bc4c7953a743196504 Merge: 6ae7664096f89da1f3
Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Fri Feb 5 11:19:35 2021 +0100 Merge remote-tracking branch 'remotes/origin/master' into vb_edgegrid_open_lines commit 6ae76640942269993c942861f0444088843e3fa1 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Fri Feb 5 11:14:48 2021 +0100 EdgeGrid enhancement to accept both the open and closed lines. commit 36a5efcd558bd5fd5f46b5f561387a2c73221553 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Fri Feb 5 10:52:14 2021 +0100 EdgeGrid improvements: Documentation, one bug fix after recent refactoring. commit6f89da1f39
Author: tamasmeszaros <meszaros.q@gmail.com> Date: Thu Feb 4 20:31:50 2021 +0100 Disable libicu for boost-regex Should have been disabled from the beginning commit ffc77b1a72a0be9b5622fd33defeebb24bf07b34 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Thu Feb 4 18:40:33 2021 +0100 EdgeGrid: Annotated those methods that do not work with open contours. commit 8039a645b4bf0c46c99b90a9c34e7189d7442f86 Author: Vojtech Bubnik <bubnikv@gmail.com> Date: Thu Feb 4 18:28:21 2021 +0100 Refactoring of EdgeGrid structure to support both closed and open lines.
This commit is contained in:
parent
6f89da1f39
commit
5f86d11c74
6 changed files with 272 additions and 187 deletions
|
@ -596,7 +596,7 @@ static std::vector<float> contour_distance(const EdgeGrid::Grid &grid,
|
|||
{
|
||||
struct Visitor {
|
||||
Visitor(const EdgeGrid::Grid &grid, const size_t contour_idx, const std::vector<float> &polygon_distances, double dist_same_contour_accept, double dist_same_contour_reject) :
|
||||
grid(grid), idx_contour(contour_idx), contour(*grid.contours()[contour_idx]), boundary_parameters(polygon_distances), dist_same_contour_accept(dist_same_contour_accept), dist_same_contour_reject(dist_same_contour_reject) {}
|
||||
grid(grid), idx_contour(contour_idx), contour(grid.contours()[contour_idx]), boundary_parameters(polygon_distances), dist_same_contour_accept(dist_same_contour_accept), dist_same_contour_reject(dist_same_contour_reject) {}
|
||||
|
||||
void init(const Points &contour, const Point &apoint)
|
||||
{
|
||||
|
@ -630,12 +630,12 @@ static std::vector<float> contour_distance(const EdgeGrid::Grid &grid,
|
|||
// Complex case: The closest segment originates from the same contour as the starting point.
|
||||
// Reject the closest point if its distance along the contour is reasonable compared to the current contour bisector
|
||||
// (this->pt, foot).
|
||||
const Slic3r::Points &ipts = *grid.contours()[it_contour_and_segment->first];
|
||||
double param_lo = boundary_parameters[this->idx_point];
|
||||
double param_hi = t * sqrt(l2);
|
||||
double param_end = boundary_parameters.back();
|
||||
const EdgeGrid::Contour &contour = grid.contours()[it_contour_and_segment->first];
|
||||
double param_lo = boundary_parameters[this->idx_point];
|
||||
double param_hi = t * sqrt(l2);
|
||||
double param_end = boundary_parameters.back();
|
||||
const size_t ipt = it_contour_and_segment->second;
|
||||
if (ipt + 1 < ipts.size())
|
||||
if (contour.begin() + ipt + 1 < contour.end())
|
||||
param_hi += boundary_parameters[ipt > 0 ? ipt - 1 : 0];
|
||||
if (param_lo > param_hi)
|
||||
std::swap(param_lo, param_hi);
|
||||
|
@ -649,9 +649,9 @@ static std::vector<float> contour_distance(const EdgeGrid::Grid &grid,
|
|||
// longer than the bisector. That is, the path shall not bulge away from the bisector too much.
|
||||
// Bulge is estimated by 0.6 of the circle circumference drawn around the bisector.
|
||||
// Test whether the contour is convex or concave.
|
||||
bool inside = (t == 0.) ? this->inside_corner(ipts, ipt, this->point) :
|
||||
(t == 1.) ? this->inside_corner(ipts, ipt + 1 == ipts.size() ? 0 : ipt + 1, this->point) :
|
||||
this->left_of_segment(ipts, ipt, this->point);
|
||||
bool inside = (t == 0.) ? this->inside_corner(contour, ipt, this->point) :
|
||||
(t == 1.) ? this->inside_corner(contour, contour.segment_idx_next(ipt), this->point) :
|
||||
this->left_of_segment(contour, ipt, this->point);
|
||||
accept = inside && dist_along_contour > 0.6 * M_PI * dist;
|
||||
}
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ static std::vector<float> contour_distance(const EdgeGrid::Grid &grid,
|
|||
|
||||
const EdgeGrid::Grid &grid;
|
||||
const size_t idx_contour;
|
||||
const Points &contour;
|
||||
const EdgeGrid::Contour &contour;
|
||||
|
||||
const std::vector<float> &boundary_parameters;
|
||||
const double dist_same_contour_accept;
|
||||
|
@ -691,25 +691,27 @@ static std::vector<float> contour_distance(const EdgeGrid::Grid &grid,
|
|||
return Vec2d(-v1.y() - v2.y(), v1.x() + v2.x());
|
||||
}
|
||||
|
||||
static bool inside_corner(const Slic3r::Points &contour, size_t i, const Point &pt_oposite)
|
||||
static bool inside_corner(const EdgeGrid::Contour &contour, size_t i, const Point &pt_oposite)
|
||||
{
|
||||
const Vec2d pt = pt_oposite.cast<double>();
|
||||
size_t iprev = prev_idx_modulo(i, contour);
|
||||
size_t inext = next_idx_modulo(i, contour);
|
||||
Vec2d v1 = (contour[i] - contour[iprev]).cast<double>();
|
||||
Vec2d v2 = (contour[inext] - contour[i]).cast<double>();
|
||||
bool left_of_v1 = cross2(v1, pt - contour[iprev].cast<double>()) > 0.;
|
||||
bool left_of_v2 = cross2(v2, pt - contour[i].cast<double>()) > 0.;
|
||||
const Point &pt_prev = contour.segment_prev(i);
|
||||
const Point &pt_this = contour.segment_start(i);
|
||||
const Point &pt_next = contour.segment_end(i);
|
||||
Vec2d v1 = (pt_this - pt_prev).cast<double>();
|
||||
Vec2d v2 = (pt_next - pt_this).cast<double>();
|
||||
bool left_of_v1 = cross2(v1, pt - pt_prev.cast<double>()) > 0.;
|
||||
bool left_of_v2 = cross2(v2, pt - pt_this.cast<double>()) > 0.;
|
||||
return cross2(v1, v2) > 0 ? left_of_v1 && left_of_v2 : // convex corner
|
||||
left_of_v1 || left_of_v2; // concave corner
|
||||
}
|
||||
|
||||
static bool left_of_segment(const Slic3r::Points &contour, size_t i, const Point &pt_oposite)
|
||||
static bool left_of_segment(const EdgeGrid::Contour &contour, size_t i, const Point &pt_oposite)
|
||||
{
|
||||
const Vec2d pt = pt_oposite.cast<double>();
|
||||
size_t inext = next_idx_modulo(i, contour);
|
||||
Vec2d v = (contour[inext] - contour[i]).cast<double>();
|
||||
return cross2(v, pt - contour[i].cast<double>()) > 0.;
|
||||
const Vec2d pt = pt_oposite.cast<double>();
|
||||
const Point &pt_this = contour.segment_start(i);
|
||||
const Point &pt_next = contour.segment_end(i);
|
||||
Vec2d v = (pt_next - pt_this).cast<double>();
|
||||
return cross2(v, pt - pt_this.cast<double>()) > 0.;
|
||||
}
|
||||
} visitor(grid, contour_idx, poly_distances, 0.5 * compensation * M_PI, search_radius);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue