From b0bef4eeb4e15cc95421a23d8c387cfbb9f46854 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 3 May 2023 15:28:46 +0200 Subject: [PATCH] Conflict checker: first steps to extend it so it takes instances into account --- src/libslic3r/GCode/ConflictChecker.cpp | 17 +++++++++++------ src/libslic3r/GCode/ConflictChecker.hpp | 17 ++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/libslic3r/GCode/ConflictChecker.cpp b/src/libslic3r/GCode/ConflictChecker.cpp index f3d3f49fe..3ac65663b 100644 --- a/src/libslic3r/GCode/ConflictChecker.cpp +++ b/src/libslic3r/GCode/ConflictChecker.cpp @@ -89,18 +89,18 @@ inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance } } // namespace RasterizationImpl -void LinesBucketQueue::emplace_back_bucket(std::vector &&paths, const void *objPtr, Point offset) +void LinesBucketQueue::emplace_back_bucket(std::vector &&paths, const void *objPtr, Points offsets) { if (_objsPtrToId.find(objPtr) == _objsPtrToId.end()) { _objsPtrToId.insert({objPtr, _objsPtrToId.size()}); _idToObjsPtr.insert({_objsPtrToId.size() - 1, objPtr}); } - _buckets.emplace_back(std::move(paths), _objsPtrToId[objPtr], offset); + _buckets.emplace_back(std::move(paths), _objsPtrToId[objPtr], offsets); } void LinesBucketQueue::build_queue() { - assert(_pq.empty); + assert(_pq.empty()); for (LinesBucket &bucket : _buckets) _pq.push(&bucket); } @@ -210,12 +210,17 @@ ConflictResultOpt ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectP LinesBucketQueue conflictQueue; if (wtdptr.has_value()) { // wipe tower at 0 by default auto wtpaths = (*wtdptr)->getFakeExtrusionPathsFromWipeTower(); - conflictQueue.emplace_back_bucket(std::move(wtpaths), *wtdptr, { (*wtdptr)->plate_origin.x(), (*wtdptr)->plate_origin.y() }); + conflictQueue.emplace_back_bucket(std::move(wtpaths), *wtdptr, Points{Point((*wtdptr)->plate_origin)}); } for (PrintObject *obj : objs) { auto layers = getAllLayersExtrusionPathsFromObject(obj); - conflictQueue.emplace_back_bucket(std::move(layers.first), obj, obj->instances().front().shift); - conflictQueue.emplace_back_bucket(std::move(layers.second), obj, obj->instances().front().shift); + + Points instances_shifts; + for (const PrintInstance& inst : obj->instances()) + instances_shifts.emplace_back(inst.shift); + + conflictQueue.emplace_back_bucket(std::move(layers.first), obj, instances_shifts); + conflictQueue.emplace_back_bucket(std::move(layers.second), obj, instances_shifts); } conflictQueue.build_queue(); diff --git a/src/libslic3r/GCode/ConflictChecker.hpp b/src/libslic3r/GCode/ConflictChecker.hpp index 069e553b4..ce57fdcfb 100644 --- a/src/libslic3r/GCode/ConflictChecker.hpp +++ b/src/libslic3r/GCode/ConflictChecker.hpp @@ -31,10 +31,10 @@ private: std::vector _piles; int _id; - Point _offset; + Points _offsets; public: - LinesBucket(std::vector &&paths, int id, Point offset) : _piles(paths), _id(id), _offset(offset) {} + LinesBucket(std::vector &&paths, int id, Points offsets) : _piles(paths), _id(id), _offsets(offsets) {} LinesBucket(LinesBucket &&) = default; bool valid() const { return _curPileIdx < _piles.size(); } @@ -50,10 +50,13 @@ public: { LineWithIDs lines; for (const ExtrusionPath &path : _piles[_curPileIdx]) { - Polyline check_polyline = path.polyline; - check_polyline.translate(_offset); - Lines tmpLines = check_polyline.lines(); - for (const Line &line : tmpLines) { lines.emplace_back(line, _id, path.role()); } + Polyline check_polyline; + for (const Point& offset : _offsets) { + check_polyline = path.polyline; + check_polyline.translate(offset); + Lines tmpLines = check_polyline.lines(); + for (const Line &line : tmpLines) { lines.emplace_back(line, _id, path.role()); } + } } return lines; } @@ -77,7 +80,7 @@ private: std::map _objsPtrToId; public: - void emplace_back_bucket(std::vector &&paths, const void *objPtr, Point offset); + void emplace_back_bucket(std::vector &&paths, const void *objPtr, Points offset); void build_queue(); bool valid() const { return _pq.empty() == false; } const void *idToObjsPtr(int id)