Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::AvoidCrossingPerimeters Class Reference

#include <src/libslic3r/GCode/AvoidCrossingPerimeters.hpp>

+ Collaboration diagram for Slic3r::AvoidCrossingPerimeters:

Classes

struct  Boundary
 

Public Member Functions

void use_external_mp (bool use=true)
 
void use_external_mp_once ()
 
bool used_external_mp_once ()
 
void disable_once ()
 
bool disabled_once () const
 
void reset_once_modifiers ()
 
void init_layer (const Layer &layer)
 
Polyline travel_to (const GCode &gcodegen, const Point &point)
 
Polyline travel_to (const GCode &gcodegen, const Point &point, bool *could_be_wipe_disabled)
 

Private Attributes

bool m_use_external_mp { false }
 
bool m_use_external_mp_once { false }
 
bool m_disabled_once { true }
 
ExPolygons m_lslices_offset
 
std::vector< BoundingBoxm_lslices_offset_bboxes
 
EdgeGrid::Grid m_grid_lslices_offset
 
Boundary m_internal
 
Boundary m_external
 

Detailed Description

Member Function Documentation

◆ disable_once()

void Slic3r::AvoidCrossingPerimeters::disable_once ( )
inline
22{ m_disabled_once = true; }
bool m_disabled_once
Definition AvoidCrossingPerimeters.hpp:59

References m_disabled_once.

Referenced by Slic3r::GCode::_do_export(), and Slic3r::GCode::process_layer().

+ Here is the caller graph for this function:

◆ disabled_once()

bool Slic3r::AvoidCrossingPerimeters::disabled_once ( ) const
inline
23{ return m_disabled_once; }

References m_disabled_once.

Referenced by Slic3r::GCode::travel_to().

+ Here is the caller graph for this function:

◆ init_layer()

void Slic3r::AvoidCrossingPerimeters::init_layer ( const Layer layer)
1244{
1245 m_internal.clear();
1246 m_external.clear();
1247 m_lslices_offset.clear();
1249
1250 float perimeter_offset = -get_external_perimeter_width(layer) / float(2.);
1251 m_lslices_offset = offset_ex(layer.lslices, perimeter_offset);
1252
1254 for (const ExPolygon &ex_poly : m_lslices_offset)
1255 m_lslices_offset_bboxes.emplace_back(get_extents(ex_poly));
1256
1257 BoundingBox bbox_slice(get_extents(layer.lslices));
1258 bbox_slice.offset(SCALED_EPSILON);
1259
1260 m_grid_lslices_offset.set_bbox(bbox_slice);
1262}
Boundary m_external
Definition AvoidCrossingPerimeters.hpp:69
ExPolygons m_lslices_offset
Definition AvoidCrossingPerimeters.hpp:62
EdgeGrid::Grid m_grid_lslices_offset
Definition AvoidCrossingPerimeters.hpp:65
Boundary m_internal
Definition AvoidCrossingPerimeters.hpp:67
std::vector< BoundingBox > m_lslices_offset_bboxes
Definition AvoidCrossingPerimeters.hpp:63
void create(const std::vector< Points > &polylines_or_polygons, coord_t resolution, bool open)
Definition EdgeGrid.cpp:52
void set_bbox(const BoundingBox &bbox)
Definition EdgeGrid.hpp:97
#define SCALED_EPSILON
Definition libslic3r.h:71
#define scale_(val)
Definition libslic3r.h:69
int32_t coord_t
Definition libslic3r.h:39
static float get_external_perimeter_width(const Layer &layer)
Definition AvoidCrossingPerimeters.cpp:525
Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta, ClipperLib::JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:421
BoundingBox get_extents(const ExPolygon &expolygon)
Definition ExPolygon.cpp:352
void clear()
Definition AvoidCrossingPerimeters.hpp:46

References Slic3r::MultiPoint::clear(), Slic3r::get_extents(), Slic3r::get_external_perimeter_width(), Slic3r::Layer::lslices, Slic3r::BoundingBoxBase< PointType, APointsType >::offset(), Slic3r::offset_ex(), scale_, and SCALED_EPSILON.

Referenced by Slic3r::GCode::process_layer_single_object().

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

◆ reset_once_modifiers()

void Slic3r::AvoidCrossingPerimeters::reset_once_modifiers ( )
inline
24{ m_use_external_mp_once = false; m_disabled_once = false; }
bool m_use_external_mp_once
Definition AvoidCrossingPerimeters.hpp:56

References m_disabled_once, and m_use_external_mp_once.

Referenced by Slic3r::GCode::travel_to().

+ Here is the caller graph for this function:

◆ travel_to() [1/2]

Polyline Slic3r::AvoidCrossingPerimeters::travel_to ( const GCode gcodegen,
const Point point 
)
inline
29 {
30 bool could_be_wipe_disabled;
31 return this->travel_to(gcodegen, point, &could_be_wipe_disabled);
32 }
Polyline travel_to(const GCode &gcodegen, const Point &point)
Definition AvoidCrossingPerimeters.hpp:28

References travel_to().

Referenced by travel_to(), and Slic3r::GCode::travel_to().

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

◆ travel_to() [2/2]

Polyline Slic3r::AvoidCrossingPerimeters::travel_to ( const GCode gcodegen,
const Point point,
bool *  could_be_wipe_disabled 
)
1171{
1172 // If use_external, then perform the path planning in the world coordinate system (correcting for the gcodegen offset).
1173 // Otherwise perform the path planning in the coordinate system of the active object.
1174 bool use_external = m_use_external_mp || m_use_external_mp_once;
1175 Point scaled_origin = use_external ? Point::new_scale(gcodegen.origin()(0), gcodegen.origin()(1)) : Point(0, 0);
1176 const Point start = gcodegen.last_pos() + scaled_origin;
1177 const Point end = point + scaled_origin;
1178 const Line travel(start, end);
1179
1180 Polyline result_pl;
1181 size_t travel_intersection_count = 0;
1182 Vec2d startf = start.cast<double>();
1183 Vec2d endf = end .cast<double>();
1184
1185 bool is_support_layer = dynamic_cast<const SupportLayer *>(gcodegen.layer()) != nullptr;
1186 if (!use_external && (is_support_layer || (!m_lslices_offset.empty() && !any_expolygon_contains(m_lslices_offset, m_lslices_offset_bboxes, m_grid_lslices_offset, travel)))) {
1187 // Initialize m_internal only when it is necessary.
1188 if (m_internal.boundaries.empty())
1189 init_boundary(&m_internal, to_polygons(get_boundary(*gcodegen.layer())));
1190
1191 // Trim the travel line by the bounding box.
1193 travel_intersection_count = avoid_perimeters(m_internal, startf.cast<coord_t>(), endf.cast<coord_t>(), *gcodegen.layer(), result_pl);
1194 result_pl.points.front() = start;
1195 result_pl.points.back() = end;
1196 }
1197 } else if(use_external) {
1198 // Initialize m_external only when exist any external travel for the current layer.
1199 if (m_external.boundaries.empty())
1200 init_boundary(&m_external, get_boundary_external(*gcodegen.layer()));
1201
1202 // Trim the travel line by the bounding box.
1204 travel_intersection_count = avoid_perimeters(m_external, startf.cast<coord_t>(), endf.cast<coord_t>(), *gcodegen.layer(), result_pl);
1205 result_pl.points.front() = start;
1206 result_pl.points.back() = end;
1207 }
1208 }
1209
1210 if(result_pl.empty()) {
1211 // Travel line is completely outside the bounding box.
1212 result_pl = {start, end};
1213 travel_intersection_count = 0;
1214 }
1215
1216 const ConfigOptionFloatOrPercent &opt_max_detour = gcodegen.config().avoid_crossing_perimeters_max_detour;
1217 bool max_detour_length_exceeded = false;
1218 if (opt_max_detour.value > 0) {
1219 double direct_length = travel.length();
1220 double detour = result_pl.length() - direct_length;
1221 double max_detour_length = opt_max_detour.percent ?
1222 direct_length * 0.01 * opt_max_detour.value :
1223 scale_(opt_max_detour.value);
1224 if (detour > max_detour_length) {
1225 result_pl = {start, end};
1226 max_detour_length_exceeded = true;
1227 }
1228 }
1229
1230 if (use_external) {
1231 result_pl.translate(-scaled_origin);
1232 *could_be_wipe_disabled = false;
1233 } else if (max_detour_length_exceeded) {
1234 *could_be_wipe_disabled = false;
1235 } else
1236 *could_be_wipe_disabled = !need_wipe(gcodegen, m_lslices_offset, m_lslices_offset_bboxes, m_grid_lslices_offset, travel, result_pl, travel_intersection_count);
1237
1238 return result_pl;
1239}
bool m_use_external_mp
Definition AvoidCrossingPerimeters.hpp:54
bool liang_barsky_line_clipping(Eigen::Matrix< T, 2, 1, Eigen::DontAlign > &x0, Eigen::Matrix< T, 2, 1, Eigen::DontAlign > &x1, const BoundingBoxBase< Eigen::Matrix< T, 2, 1, Eigen::DontAlign > > &bbox)
Definition Geometry.hpp:250
static bool need_wipe(const GCode &gcodegen, const ExPolygons &lslices_offset, const std::vector< BoundingBox > &lslices_offset_bboxes, const EdgeGrid::Grid &grid_lslices_offset, const Line &original_travel, const Polyline &result_travel, const size_t intersection_count)
Definition AvoidCrossingPerimeters.cpp:733
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51
static void init_boundary(AvoidCrossingPerimeters::Boundary *boundary, Polygons &&boundary_polygons)
Definition AvoidCrossingPerimeters.cpp:1155
Polygons to_polygons(const ExPolygon &src)
Definition ExPolygon.hpp:281
static size_t avoid_perimeters(const AvoidCrossingPerimeters::Boundary &boundary, const Point &start, const Point &end, const Layer &layer, Polyline &result_out)
Definition AvoidCrossingPerimeters.cpp:657
static ExPolygons get_boundary(const Layer &layer)
Definition AvoidCrossingPerimeters.cpp:1054
static bool any_expolygon_contains(const ExPolygons &lslices_offset, const std::vector< BoundingBox > &lslices_offset_bboxes, const EdgeGrid::Grid &grid_lslices_offset, const Line &travel)
Definition AvoidCrossingPerimeters.cpp:681
static Polygons get_boundary_external(const Layer &layer)
Definition AvoidCrossingPerimeters.cpp:1091
S::iterator end(S &sh, const PathTag &)
Definition geometry_traits.hpp:620
Kernel::Point_2 Point
Definition point_areas.cpp:20
Polygons boundaries
Definition AvoidCrossingPerimeters.hpp:38
BoundingBoxf bbox
Definition AvoidCrossingPerimeters.hpp:40

References Slic3r::any_expolygon_contains(), Slic3r::avoid_perimeters(), Slic3r::GCode::config(), Slic3r::MultiPoint::empty(), Slic3r::get_boundary(), Slic3r::get_boundary_external(), Slic3r::init_boundary(), Slic3r::GCode::last_pos(), Slic3r::GCode::layer(), Slic3r::Line::length(), Slic3r::Polyline::length(), Slic3r::need_wipe(), Slic3r::GCode::origin(), Slic3r::ConfigOptionFloatOrPercent::percent, Slic3r::MultiPoint::points, scale_, Slic3r::to_polygons(), Slic3r::MultiPoint::translate(), and Slic3r::ConfigOptionSingle< T >::value.

+ Here is the call graph for this function:

◆ use_external_mp()

void Slic3r::AvoidCrossingPerimeters::use_external_mp ( bool  use = true)
inline
19{ m_use_external_mp = use; };

References m_use_external_mp.

Referenced by Slic3r::GCode::process_layer().

+ Here is the caller graph for this function:

◆ use_external_mp_once()

void Slic3r::AvoidCrossingPerimeters::use_external_mp_once ( )
inline
20{ m_use_external_mp_once = true; }

References m_use_external_mp_once.

Referenced by Slic3r::GCode::_do_export(), Slic3r::WipeTowerIntegration::append_tcr(), Slic3r::GCode::process_layer_single_object(), and Slic3r::GCode::travel_to().

+ Here is the caller graph for this function:

◆ used_external_mp_once()

bool Slic3r::AvoidCrossingPerimeters::used_external_mp_once ( )
inline
21{ return m_use_external_mp_once; }

References m_use_external_mp_once.

Referenced by Slic3r::GCode::travel_to().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_disabled_once

bool Slic3r::AvoidCrossingPerimeters::m_disabled_once { true }
private

◆ m_external

Boundary Slic3r::AvoidCrossingPerimeters::m_external
private

◆ m_grid_lslices_offset

EdgeGrid::Grid Slic3r::AvoidCrossingPerimeters::m_grid_lslices_offset
private

◆ m_internal

Boundary Slic3r::AvoidCrossingPerimeters::m_internal
private

◆ m_lslices_offset

ExPolygons Slic3r::AvoidCrossingPerimeters::m_lslices_offset
private

◆ m_lslices_offset_bboxes

std::vector<BoundingBox> Slic3r::AvoidCrossingPerimeters::m_lslices_offset_bboxes
private

◆ m_use_external_mp

bool Slic3r::AvoidCrossingPerimeters::m_use_external_mp { false }
private

Referenced by use_external_mp().

◆ m_use_external_mp_once

bool Slic3r::AvoidCrossingPerimeters::m_use_external_mp_once { false }
private

The documentation for this class was generated from the following files: