OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp} Namespace Reference

Classes

struct  SegmentIntersection

Functions

double boundary_epsilon ()
bool line_intersection_t (const Point &a, const Point &b, const Point &c, const Point &d, double &t, Point &intersection)
template<typename Fn>
void for_each_expolygon_contour (const ExPolygon &expolygon, Fn &&fn)
void add_unique_param (std::vector< double > &params, double t)
std::vector< SegmentIntersection > contour_intersections (const Point &a, const Point &b, const Polygon &polygon)
bool point_in_expolygons (const ExPolygons &expolygons, const Point &point, bool border_result)
bool point_on_expolygon_boundary (const ExPolygon &expolygon, const Point &point)
bool point_on_expolygons_boundary (const ExPolygons &expolygons, const Point &point)
bool point_in_expolygons_interior (const ExPolygons &expolygons, const Point &point)
std::vector< double > boundary_params_for_segment (const Point &a, const Point &b, const ExPolygons &expolygons)
Point interpolate (const Point &a, const Point &b, double t)
bool segment_enters_expolygons_interior (const Point &a, const Point &b, const ExPolygons &expolygons)
std::optional< double > first_interior_param_for_segment (const Point &a, const Point &b, const ExPolygons &expolygons)
bool segment_inside_bed (const Point &a, const Point &b, const ExPolygons &valid_bed)
double polyline_length (const Polyline &polyline)
bool points_near (const Point &lhs, const Point &rhs)
bool replacement_matches_original_segment (const Polyline &replacement, const Point &a, const Point &b)
void append_point (Points &points, const Point &point)
Polyline make_forward_detour (const Point &a, const Point &b, const Polygon &contour, const SegmentIntersection &entry, const SegmentIntersection &exit)
Polyline make_backward_detour (const Point &a, const Point &b, const Polygon &contour, const SegmentIntersection &entry, const SegmentIntersection &exit)
bool routed_polyline_inside_bed (const Polyline &polyline, const ExPolygons &valid_bed, const bool allow_start_outside, const bool allow_end_outside)
bool polyline_intersects_obstacles (const Polyline &polyline, const ExPolygons &obstacles)
std::optional< size_t > first_intersected_obstacle (const Point &a, const Point &b, const ExPolygons &obstacles)
std::optional< Polyline > detour_around_obstacle (const Point &a, const Point &b, const ExPolygon &obstacle, const ExPolygons &obstacles, const ExPolygons &valid_bed, const bool allow_start_outside, const bool allow_end_outside)
void replace_segment (Polyline &path, size_t segment_idx, const Polyline &replacement)
Polyline simplify_path (const Polyline &path, const ExPolygons &obstacles, const ExPolygons &valid_bed)

Variables

constexpr double T_EPSILON = 1e-9
constexpr size_t MAX_REROUTE_ITERATIONS = 16

Class Documentation

◆ Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection

struct Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection
Collaboration diagram for Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection:
Class Members
size_t edge_idx { 0 }
Point point
double t { 0.0 }

Function Documentation

◆ add_unique_param()

void Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::add_unique_param ( std::vector< double > & params,
double t )
76{
77 const double clamped = std::clamp(t, 0.0, 1.0);
78 if (std::none_of(params.begin(), params.end(), [clamped](double value) {
79 return std::abs(value - clamped) < T_EPSILON;
80 }))
81 params.emplace_back(clamped);
82}

References add_unique_param().

Referenced by add_unique_param(), and boundary_params_for_segment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_point()

void Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::append_point ( Points & points,
const Point & point )
248{
249 if (points.empty() || points.back() != point)
250 points.emplace_back(point);
251}

References append_point().

Referenced by append_point(), make_backward_detour(), make_forward_detour(), replace_segment(), and simplify_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boundary_epsilon()

double Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::boundary_epsilon ( )
35{
36 return std::max<double>(SCALED_EPSILON, scale_(0.005));
37}
#define SCALED_EPSILON
Definition libslic3r.h:109
#define scale_(val)
Definition libslic3r.h:106

References boundary_epsilon(), scale_, and SCALED_EPSILON.

Referenced by boundary_epsilon(), point_on_expolygon_boundary(), and points_near().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ boundary_params_for_segment()

std::vector< double > Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::boundary_params_for_segment ( const Point & a,
const Point & b,
const ExPolygons & expolygons )
146{
147 std::vector<double> params { 0.0, 1.0 };
148 for (const ExPolygon &expolygon : expolygons) {
149 for_each_expolygon_contour(expolygon, [&](const Polygon &contour) {
152 });
153 }
154 std::sort(params.begin(), params.end());
155 return params;
156}
Definition ExPolygon.hpp:23
Definition Polygon.hpp:31
void add_unique_param(std::vector< double > &params, double t)
Definition ExclusionVolumeTravelAvoidance.cpp:75
std::vector< SegmentIntersection > contour_intersections(const Point &a, const Point &b, const Polygon &polygon)
Definition ExclusionVolumeTravelAvoidance.cpp:84
void for_each_expolygon_contour(const ExPolygon &expolygon, Fn &&fn)
Definition ExclusionVolumeTravelAvoidance.cpp:68
Slic3r::Polygons intersection(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:769
const Polygon & contour(const ExPolygon &p)
Definition AGGRaster.hpp:30
Definition FillRectilinear.cpp:138

References add_unique_param(), boundary_params_for_segment(), Slic3r::contour(), contour_intersections(), for_each_expolygon_contour(), and Slic3r::intersection().

Referenced by boundary_params_for_segment(), first_interior_param_for_segment(), segment_enters_expolygons_interior(), and segment_inside_bed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ contour_intersections()

std::vector< SegmentIntersection > Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::contour_intersections ( const Point & a,
const Point & b,
const Polygon & polygon )
88{
89 std::vector<SegmentIntersection> intersections;
90 if (polygon.points.size() < 2)
91 return intersections;
92
93 intersections.reserve(4);
94 for (size_t edge_idx = 0; edge_idx < polygon.points.size(); ++edge_idx) {
95 const Point &c = polygon.points[edge_idx];
96 const Point &d = polygon.points[(edge_idx + 1) % polygon.points.size()];
97 double t = 0.0;
98 Point point;
99 if (line_intersection_t(a, b, c, d, t, point) &&
100 std::none_of(intersections.begin(), intersections.end(), [t](const SegmentIntersection &other) {
101 return std::abs(other.t - t) < T_EPSILON;
102 }))
103 intersections.push_back({ t, point, edge_idx });
104 }
105
106 std::sort(intersections.begin(), intersections.end(), [](const SegmentIntersection &lhs, const SegmentIntersection &rhs) {
107 return lhs.t < rhs.t;
108 });
109 return intersections;
110}
Points points
Definition MultiPoint.hpp:22
Definition Point.hpp:199
bool line_intersection_t(const Point &a, const Point &b, const Point &c, const Point &d, double &t, Point &intersection)
Definition ExclusionVolumeTravelAvoidance.cpp:39

References contour_intersections(), line_intersection_t(), and Slic3r::MultiPoint::points.

Referenced by boundary_params_for_segment(), contour_intersections(), and detour_around_obstacle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ detour_around_obstacle()

std::optional< Polyline > Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::detour_around_obstacle ( const Point & a,
const Point & b,
const ExPolygon & obstacle,
const ExPolygons & obstacles,
const ExPolygons & valid_bed,
const bool allow_start_outside,
const bool allow_end_outside )
359{
360 const std::vector<SegmentIntersection> intersections = contour_intersections(a, b, obstacle.contour);
361 if (intersections.size() < 2)
362 return std::nullopt;
363
364 const SegmentIntersection &entry = intersections.front();
365 const SegmentIntersection &exit = intersections.back();
366 const Polyline forward = make_forward_detour(a, b, obstacle.contour, entry, exit);
367 const Polyline backward = make_backward_detour(a, b, obstacle.contour, entry, exit);
368
369 const bool forward_bed_valid = routed_polyline_inside_bed(
370 forward, valid_bed, allow_start_outside, allow_end_outside);
371 const bool backward_bed_valid = routed_polyline_inside_bed(
372 backward, valid_bed, allow_start_outside, allow_end_outside);
373 const bool forward_clear = forward_bed_valid && !polyline_intersects_obstacles(forward, obstacles);
374 const bool backward_clear = backward_bed_valid && !polyline_intersects_obstacles(backward, obstacles);
375
376 if (forward_clear || backward_clear) {
377 if (forward_clear && !backward_clear)
378 return forward;
379 if (!forward_clear && backward_clear)
380 return backward;
381 return polyline_length(forward) <= polyline_length(backward) ? forward : backward;
382 }
383
384 // If another obstacle blocks both immediate choices, retain the valid local
385 // detour and let the outer repair loop address the next crossing.
386 if (!forward_bed_valid && !backward_bed_valid)
387 return std::nullopt;
388 if (forward_bed_valid && !backward_bed_valid)
389 return forward;
390 if (!forward_bed_valid && backward_bed_valid)
391 return backward;
392 return polyline_length(forward) <= polyline_length(backward) ? forward : backward;
393}
Polygon contour
Definition ExPolygon.hpp:42
Definition Polyline.hpp:25
double polyline_length(const Polyline &polyline)
Definition ExclusionVolumeTravelAvoidance.cpp:227
Polyline make_backward_detour(const Point &a, const Point &b, const Polygon &contour, const SegmentIntersection &entry, const SegmentIntersection &exit)
Definition ExclusionVolumeTravelAvoidance.cpp:273
bool polyline_intersects_obstacles(const Polyline &polyline, const ExPolygons &obstacles)
Definition ExclusionVolumeTravelAvoidance.cpp:326
bool routed_polyline_inside_bed(const Polyline &polyline, const ExPolygons &valid_bed, const bool allow_start_outside, const bool allow_end_outside)
Definition ExclusionVolumeTravelAvoidance.cpp:297
Polyline make_forward_detour(const Point &a, const Point &b, const Polygon &contour, const SegmentIntersection &entry, const SegmentIntersection &exit)
Definition ExclusionVolumeTravelAvoidance.cpp:253

References Slic3r::ExPolygon::contour, contour_intersections(), detour_around_obstacle(), make_backward_detour(), make_forward_detour(), polyline_intersects_obstacles(), polyline_length(), and routed_polyline_inside_bed().

Referenced by detour_around_obstacle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_interior_param_for_segment()

std::optional< double > Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::first_interior_param_for_segment ( const Point & a,
const Point & b,
const ExPolygons & expolygons )
189{
190 if (expolygons.empty())
191 return std::nullopt;
192 if (point_in_expolygons_interior(expolygons, a))
193 return 0.0;
194
195 const std::vector<double> params = boundary_params_for_segment(a, b, expolygons);
196 for (size_t idx = 1; idx < params.size(); ++idx) {
197 const double low = params[idx - 1];
198 const double high = params[idx];
199 if (high - low < T_EPSILON)
200 continue;
201 if (point_in_expolygons_interior(expolygons, interpolate(a, b, 0.5 * (low + high))))
202 return low;
203 }
204
205 return point_in_expolygons_interior(expolygons, b) ? std::optional<double>(1.0) : std::nullopt;
206}
constexpr double T_EPSILON
Definition ExclusionVolumeTravelAvoidance.cpp:24
Point interpolate(const Point &a, const Point &b, double t)
Definition ExclusionVolumeTravelAvoidance.cpp:158
std::vector< double > boundary_params_for_segment(const Point &a, const Point &b, const ExPolygons &expolygons)
Definition ExclusionVolumeTravelAvoidance.cpp:142
bool point_in_expolygons_interior(const ExPolygons &expolygons, const Point &point)
Definition ExclusionVolumeTravelAvoidance.cpp:136
STL namespace.

References boundary_params_for_segment(), first_interior_param_for_segment(), interpolate(), point_in_expolygons_interior(), and T_EPSILON.

Referenced by first_interior_param_for_segment(), and first_intersected_obstacle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ first_intersected_obstacle()

std::optional< size_t > Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::first_intersected_obstacle ( const Point & a,
const Point & b,
const ExPolygons & obstacles )
338{
339 std::optional<size_t> best_idx;
340 double best_t = std::numeric_limits<double>::infinity();
341 for (size_t idx = 0; idx < obstacles.size(); ++idx) {
342 const ExPolygons single { obstacles[idx] };
343 if (const std::optional<double> t = first_interior_param_for_segment(a, b, single); t && *t < best_t) {
344 best_t = *t;
345 best_idx = idx;
346 }
347 }
348 return best_idx;
349}
std::optional< double > first_interior_param_for_segment(const Point &a, const Point &b, const ExPolygons &expolygons)
Definition ExclusionVolumeTravelAvoidance.cpp:185
std::vector< ExPolygon > ExPolygons
Definition ExPolygon.hpp:20

References first_interior_param_for_segment(), and first_intersected_obstacle().

Referenced by first_intersected_obstacle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ for_each_expolygon_contour()

template<typename Fn>
void Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::for_each_expolygon_contour ( const ExPolygon & expolygon,
Fn && fn )
69{
70 fn(expolygon.contour);
71 for (const Polygon &hole : expolygon.holes)
72 fn(hole);
73}
Polygons holes
Definition ExPolygon.hpp:43

References Slic3r::ExPolygon::contour, for_each_expolygon_contour(), and Slic3r::ExPolygon::holes.

Referenced by boundary_params_for_segment(), and for_each_expolygon_contour().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interpolate()

Point Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::interpolate ( const Point & a,
const Point & b,
double t )
159{
160 return (a.cast<double>() + t * (b - a).cast<double>()).cast<coord_t>();
161}
int64_t coord_t
Definition libslic3r.h:48

References interpolate().

Referenced by first_interior_param_for_segment(), interpolate(), segment_enters_expolygons_interior(), and segment_inside_bed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ line_intersection_t()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::line_intersection_t ( const Point & a,
const Point & b,
const Point & c,
const Point & d,
double & t,
Point & intersection )
46{
47 const Vec2d p = a.cast<double>();
48 const Vec2d r = (b - a).cast<double>();
49 const Vec2d q = c.cast<double>();
50 const Vec2d s = (d - c).cast<double>();
51 const double denominator = cross2(r, s);
52 if (std::abs(denominator) < T_EPSILON)
53 return false;
54
55 const Vec2d qp = q - p;
56 const double candidate_t = cross2(qp, s) / denominator;
57 const double u = cross2(qp, r) / denominator;
58 if (candidate_t < -T_EPSILON || candidate_t > 1.0 + T_EPSILON ||
59 u < -T_EPSILON || u > 1.0 + T_EPSILON)
60 return false;
61
62 t = std::clamp(candidate_t, 0.0, 1.0);
63 intersection = (p + t * r).cast<coord_t>();
64 return true;
65}
int32_t cross2(const Eigen::MatrixBase< Eigen::Matrix< int32_t, 2, 1, Options > > &v1, const Eigen::MatrixBase< Eigen::Matrix< int32_t, 2, 1, Options > > &v2)=delete
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
auto cast(const BoundingBoxBase< Tin > &b)
Definition BoundingBox.hpp:299

References Slic3r::cast(), Slic3r::cross2(), Slic3r::intersection(), line_intersection_t(), and T_EPSILON.

Referenced by contour_intersections(), and line_intersection_t().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_backward_detour()

Polyline Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::make_backward_detour ( const Point & a,
const Point & b,
const Polygon & contour,
const SegmentIntersection & entry,
const SegmentIntersection & exit )
279{
280 Points points;
281 append_point(points, a);
282 append_point(points, entry.point);
283
284 const size_t count = contour.points.size();
285 const size_t last_vertex = (exit.edge_idx + 1) % count;
286 for (size_t idx = entry.edge_idx;; idx = idx == 0 ? count - 1 : idx - 1) {
287 append_point(points, contour.points[idx]);
288 if (idx == last_vertex)
289 break;
290 }
291
292 append_point(points, exit.point);
293 append_point(points, b);
294 return Polyline(std::move(points));
295}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
size_t edge_idx
Definition ExclusionVolumeTravelAvoidance.cpp:31
void append_point(Points &points, const Point &point)
Definition ExclusionVolumeTravelAvoidance.cpp:247
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:73

References append_point(), Slic3r::contour(), count, Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection::edge_idx, make_backward_detour(), and Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection::point.

Referenced by detour_around_obstacle(), and make_backward_detour().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_forward_detour()

Polyline Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::make_forward_detour ( const Point & a,
const Point & b,
const Polygon & contour,
const SegmentIntersection & entry,
const SegmentIntersection & exit )
259{
260 Points points;
261 append_point(points, a);
262 append_point(points, entry.point);
263
264 const size_t count = contour.points.size();
265 for (size_t idx = (entry.edge_idx + 1) % count; idx != (exit.edge_idx + 1) % count; idx = (idx + 1) % count)
266 append_point(points, contour.points[idx]);
267
268 append_point(points, exit.point);
269 append_point(points, b);
270 return Polyline(std::move(points));
271}

References append_point(), Slic3r::contour(), count, Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection::edge_idx, make_forward_detour(), and Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::SegmentIntersection::point.

Referenced by detour_around_obstacle(), and make_forward_detour().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ point_in_expolygons()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::point_in_expolygons ( const ExPolygons & expolygons,
const Point & point,
bool border_result )
113{
114 return std::any_of(expolygons.begin(), expolygons.end(), [&point, border_result](const ExPolygon &expolygon) {
115 return expolygon.contains(point, border_result);
116 });
117}

References point_in_expolygons().

Referenced by point_in_expolygons(), point_in_expolygons_interior(), routed_polyline_inside_bed(), and segment_inside_bed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ point_in_expolygons_interior()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::point_in_expolygons_interior ( const ExPolygons & expolygons,
const Point & point )
137{
138 return point_in_expolygons(expolygons, point, false) &&
139 !point_on_expolygons_boundary(expolygons, point);
140}
bool point_in_expolygons(const ExPolygons &expolygons, const Point &point, bool border_result)
Definition ExclusionVolumeTravelAvoidance.cpp:112
bool point_on_expolygons_boundary(const ExPolygons &expolygons, const Point &point)
Definition ExclusionVolumeTravelAvoidance.cpp:129

References point_in_expolygons(), point_in_expolygons_interior(), and point_on_expolygons_boundary().

Referenced by first_interior_param_for_segment(), point_in_expolygons_interior(), and segment_enters_expolygons_interior().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ point_on_expolygon_boundary()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::point_on_expolygon_boundary ( const ExPolygon & expolygon,
const Point & point )
120{
121 const double epsilon = boundary_epsilon();
122 if (expolygon.contour.on_boundary(point, epsilon))
123 return true;
124 return std::any_of(expolygon.holes.begin(), expolygon.holes.end(), [&point, epsilon](const Polygon &hole) {
125 return hole.on_boundary(point, epsilon);
126 });
127}
bool on_boundary(const Point &point, double eps) const
Definition Polygon.hpp:75
double boundary_epsilon()
Definition ExclusionVolumeTravelAvoidance.cpp:34

References boundary_epsilon(), Slic3r::ExPolygon::contour, Slic3r::ExPolygon::holes, Slic3r::Polygon::on_boundary(), and point_on_expolygon_boundary().

Referenced by point_on_expolygon_boundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ point_on_expolygons_boundary()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::point_on_expolygons_boundary ( const ExPolygons & expolygons,
const Point & point )
130{
131 return std::any_of(expolygons.begin(), expolygons.end(), [&point](const ExPolygon &expolygon) {
132 return point_on_expolygon_boundary(expolygon, point);
133 });
134}

References point_on_expolygons_boundary().

Referenced by point_in_expolygons_interior(), and point_on_expolygons_boundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ points_near()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::points_near ( const Point & lhs,
const Point & rhs )
236{
237 const double epsilon = boundary_epsilon();
238 return (lhs - rhs).cast<double>().squaredNorm() <= epsilon * epsilon;
239}

References boundary_epsilon(), and points_near().

Referenced by points_near(), and replacement_matches_original_segment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ polyline_intersects_obstacles()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::polyline_intersects_obstacles ( const Polyline & polyline,
const ExPolygons & obstacles )
327{
328 for (size_t idx = 1; idx < polyline.points.size(); ++idx)
329 if (segment_enters_expolygons_interior(polyline.points[idx - 1], polyline.points[idx], obstacles))
330 return true;
331 return false;
332}
bool segment_enters_expolygons_interior(const Point &a, const Point &b, const ExPolygons &expolygons)
Definition ExclusionVolumeTravelAvoidance.cpp:163

References Slic3r::MultiPoint::points, polyline_intersects_obstacles(), and segment_enters_expolygons_interior().

Referenced by detour_around_obstacle(), and polyline_intersects_obstacles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ polyline_length()

double Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::polyline_length ( const Polyline & polyline)
228{
229 double length = 0.0;
230 for (size_t idx = 1; idx < polyline.points.size(); ++idx)
231 length += (polyline.points[idx] - polyline.points[idx - 1]).cast<double>().norm();
232 return length;
233}
double length(const Points &pts)
Definition MultiPoint.hpp:181

References Slic3r::length(), Slic3r::MultiPoint::points, and polyline_length().

Referenced by detour_around_obstacle(), and polyline_length().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_segment()

void Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::replace_segment ( Polyline & path,
size_t segment_idx,
const Polyline & replacement )
396{
397 Points points;
398 points.reserve(path.points.size() + replacement.points.size());
399 for (size_t idx = 0; idx < segment_idx; ++idx)
400 append_point(points, path.points[idx]);
401 for (const Point &point : replacement.points)
402 append_point(points, point);
403 for (size_t idx = segment_idx + 2; idx < path.points.size(); ++idx)
404 append_point(points, path.points[idx]);
405 path.points = std::move(points);
406}

References append_point(), Slic3r::MultiPoint::points, and replace_segment().

Referenced by replace_segment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replacement_matches_original_segment()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::replacement_matches_original_segment ( const Polyline & replacement,
const Point & a,
const Point & b )
242{
243 return replacement.points.size() == 2 &&
244 points_near(replacement.points.front(), a) && points_near(replacement.points.back(), b);
245}
bool points_near(const Point &lhs, const Point &rhs)
Definition ExclusionVolumeTravelAvoidance.cpp:235

References Slic3r::MultiPoint::points, points_near(), and replacement_matches_original_segment().

Referenced by replacement_matches_original_segment().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ routed_polyline_inside_bed()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::routed_polyline_inside_bed ( const Polyline & polyline,
const ExPolygons & valid_bed,
const bool allow_start_outside,
const bool allow_end_outside )
302{
303 if (valid_bed.empty())
304 return true;
305
306 const size_t last_idx = polyline.points.size() - 1;
307 for (size_t idx = 0; idx < polyline.points.size(); ++idx) {
308 if ((idx == 0 && allow_start_outside) || (idx == last_idx && allow_end_outside))
309 continue;
310 if (!point_in_expolygons(valid_bed, polyline.points[idx], true))
311 return false;
312 }
313
314 for (size_t idx = 1; idx < polyline.points.size(); ++idx) {
315 // A start or end produced by machine G-code may legitimately lie on
316 // or beyond the printable boundary. Constrain only the route vertices
317 // Orca adds; the firmware-defined transition to the bed remains intact.
318 if ((idx == 1 && allow_start_outside) || (idx == last_idx && allow_end_outside))
319 continue;
320 if (!segment_inside_bed(polyline.points[idx - 1], polyline.points[idx], valid_bed))
321 return false;
322 }
323 return true;
324}
bool segment_inside_bed(const Point &a, const Point &b, const ExPolygons &valid_bed)
Definition ExclusionVolumeTravelAvoidance.cpp:208

References point_in_expolygons(), Slic3r::MultiPoint::points, routed_polyline_inside_bed(), and segment_inside_bed().

Referenced by detour_around_obstacle(), and routed_polyline_inside_bed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ segment_enters_expolygons_interior()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::segment_enters_expolygons_interior ( const Point & a,
const Point & b,
const ExPolygons & expolygons )
167{
168 if (expolygons.empty())
169 return false;
170 if (point_in_expolygons_interior(expolygons, a) || point_in_expolygons_interior(expolygons, b))
171 return true;
172
173 const std::vector<double> params = boundary_params_for_segment(a, b, expolygons);
174 for (size_t idx = 1; idx < params.size(); ++idx) {
175 const double low = params[idx - 1];
176 const double high = params[idx];
177 if (high - low < T_EPSILON)
178 continue;
179 if (point_in_expolygons_interior(expolygons, interpolate(a, b, 0.5 * (low + high))))
180 return true;
181 }
182 return false;
183}

References boundary_params_for_segment(), interpolate(), point_in_expolygons_interior(), segment_enters_expolygons_interior(), and T_EPSILON.

Referenced by polyline_intersects_obstacles(), segment_enters_expolygons_interior(), and simplify_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ segment_inside_bed()

bool Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::segment_inside_bed ( const Point & a,
const Point & b,
const ExPolygons & valid_bed )
209{
210 if (valid_bed.empty())
211 return true;
212 if (!point_in_expolygons(valid_bed, a, true) || !point_in_expolygons(valid_bed, b, true))
213 return false;
214
215 const std::vector<double> params = boundary_params_for_segment(a, b, valid_bed);
216 for (size_t idx = 1; idx < params.size(); ++idx) {
217 const double low = params[idx - 1];
218 const double high = params[idx];
219 if (high - low < T_EPSILON)
220 continue;
221 if (!point_in_expolygons(valid_bed, interpolate(a, b, 0.5 * (low + high)), false))
222 return false;
223 }
224 return true;
225}

References boundary_params_for_segment(), interpolate(), point_in_expolygons(), segment_inside_bed(), and T_EPSILON.

Referenced by routed_polyline_inside_bed(), segment_inside_bed(), and simplify_path().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ simplify_path()

Polyline Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::simplify_path ( const Polyline & path,
const ExPolygons & obstacles,
const ExPolygons & valid_bed )
409{
410 if (path.points.size() <= 2)
411 return path;
412
413 Points simplified;
414 simplified.reserve(path.points.size());
415 size_t current = 0;
416 append_point(simplified, path.points.front());
417 while (current + 1 < path.points.size()) {
418 size_t next = path.points.size() - 1;
419 for (; next > current + 1; --next) {
420 if (segment_inside_bed(path.points[current], path.points[next], valid_bed) &&
421 !segment_enters_expolygons_interior(path.points[current], path.points[next], obstacles))
422 break;
423 }
424 append_point(simplified, path.points[next]);
425 current = next;
426 }
427 return Polyline(std::move(simplified));
428}

References append_point(), Slic3r::MultiPoint::points, segment_enters_expolygons_interior(), segment_inside_bed(), and simplify_path().

Referenced by simplify_path().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ MAX_REROUTE_ITERATIONS

size_t Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::MAX_REROUTE_ITERATIONS = 16
constexpr

◆ T_EPSILON

double Slic3r::anonymous_namespace{ExclusionVolumeTravelAvoidance.cpp}::T_EPSILON = 1e-9
constexpr