diff options
author | bubnikv <bubnikv@gmail.com> | 2019-08-25 10:01:01 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2019-08-25 10:01:01 +0300 |
commit | de43f579a9c9e2874eccb94deb1389b9ab371d4f (patch) | |
tree | 5719eca36236bd81a0686c6f7f66fcf6f884911d | |
parent | ceae7b4889342daa6babf0de244e0f9175ef65a3 (diff) |
Refactoring of AvoidCrossingPerimeters::init_external_mp()
-rw-r--r-- | src/libslic3r/GCode.cpp | 16 | ||||
-rw-r--r-- | src/libslic3r/GCode.hpp | 5 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index bfda5a2a6..5ff8c4dce 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -50,7 +50,12 @@ static inline void check_add_eol(std::string &gcode) if (! gcode.empty() && gcode.back() != '\n') gcode += '\n'; } - + +void AvoidCrossingPerimeters::init_external_mp(const Print &print) +{ + m_external_mp = Slic3r::make_unique<MotionPlanner>(union_ex(this->collect_contours_all_layers(print.objects()))); +} + // Plan a travel move while minimizing the number of perimeter crossings. // point is in unscaled coordinates, in the coordinate system of the current active object // (set by gcodegen.set_origin()). @@ -70,7 +75,7 @@ Polyline AvoidCrossingPerimeters::travel_to(const GCode &gcodegen, const Point & // Collect outer contours of all objects over all layers. // Discard objects only containing thin walls (offset would fail on an empty polygon). // Used by avoid crossing perimeters feature. -static Polygons collect_contours_all_layers(const PrintObjectPtrs& objects) +Polygons AvoidCrossingPerimeters::collect_contours_all_layers(const PrintObjectPtrs& objects) { Polygons islands; for (const PrintObject *object : objects) { @@ -80,8 +85,8 @@ static Polygons collect_contours_all_layers(const PrintObjectPtrs& objects) tbb::parallel_for(tbb::blocked_range<size_t>(0, object->layers().size() / 2), [&object, &polygons_per_layer](const tbb::blocked_range<size_t> &range) { for (size_t i = range.begin(); i < range.end(); ++ i) { - const Layer* layer1 = object->layers()[i/2]; - const Layer* layer2 = object->layers()[i/2 + 1]; + const Layer* layer1 = object->layers()[i * 2]; + const Layer* layer2 = object->layers()[i * 2 + 1]; Polygons polys; polys.reserve(layer1->slices.expolygons.size() + layer2->slices.expolygons.size()); for (const ExPolygon &expoly : layer1->slices.expolygons) @@ -1008,8 +1013,7 @@ void GCode::_do_export(Print &print, FILE *file) // Initialize a motion planner for object-to-object travel moves. if (print.config().avoid_crossing_perimeters.value) { - Polygons islands = collect_contours_all_layers(print.objects()); - m_avoid_crossing_perimeters.init_external_mp(union_ex(islands)); + m_avoid_crossing_perimeters.init_external_mp(print); print.throw_if_canceled(); } diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index f2a67f600..4baf000f3 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -45,12 +45,15 @@ public: AvoidCrossingPerimeters() : use_external_mp(false), use_external_mp_once(false), disable_once(true) {} ~AvoidCrossingPerimeters() {} - void init_external_mp(const ExPolygons &islands) { m_external_mp = Slic3r::make_unique<MotionPlanner>(islands); } + void init_external_mp(const Print &print); void init_layer_mp(const ExPolygons &islands) { m_layer_mp = Slic3r::make_unique<MotionPlanner>(islands); } Polyline travel_to(const GCode &gcodegen, const Point &point); private: + // For initializing the regions to avoid. + static Polygons collect_contours_all_layers(const PrintObjectPtrs& objects); + std::unique_ptr<MotionPlanner> m_external_mp; std::unique_ptr<MotionPlanner> m_layer_mp; }; |