mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-07 23:17:35 -06:00
ENH: add wipe tower into conflict check
Change-Id: I9684ec17ccbfdea39deae6e5089b74ce3124d57b (cherry picked from commit f6ee82b4ecf8bf9de91d0043b514cdabb7284b7e)
This commit is contained in:
parent
60c444f627
commit
b5b7264e99
5 changed files with 123 additions and 37 deletions
|
@ -89,10 +89,11 @@ inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance
|
||||||
}
|
}
|
||||||
} // namespace RasterizationImpl
|
} // namespace RasterizationImpl
|
||||||
|
|
||||||
void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, PrintObject *objPtr, Point offset)
|
void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset)
|
||||||
{
|
{
|
||||||
auto oldSize = _buckets.capacity();
|
auto oldSize = _buckets.capacity();
|
||||||
_buckets.emplace_back(std::move(paths), objPtr, offset);
|
_buckets.emplace_back(std::move(paths), _objsPtrToId.size(), offset);
|
||||||
|
_objsPtrToId.push_back(objPtr);
|
||||||
_pq.push(&_buckets.back());
|
_pq.push(&_buckets.back());
|
||||||
auto newSize = _buckets.capacity();
|
auto newSize = _buckets.capacity();
|
||||||
if (oldSize != newSize) { // pointers change
|
if (oldSize != newSize) { // pointers change
|
||||||
|
@ -199,10 +200,15 @@ ConflictRet ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRet ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs) // find the first intersection point of lines in different objects
|
ConflictObjName ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs,
|
||||||
|
std::optional<const FakeWipeTower *> wtdptr) // find the first intersection point of lines in different objects
|
||||||
{
|
{
|
||||||
if (objs.size() <= 1) { return {}; }
|
if (objs.size() <= 1) { return {}; }
|
||||||
LinesBucketQueue conflictQueue;
|
LinesBucketQueue conflictQueue;
|
||||||
|
if (wtdptr.has_value()) { // wipe tower at 0 by default
|
||||||
|
auto wtpaths = wtdptr.value()->getFakeExtrusionPathsFromWipeTower();
|
||||||
|
conflictQueue.emplace_back_bucket(std::move(wtpaths), wtdptr.value(), {wtdptr.value()->plate_origin.x(),wtdptr.value()->plate_origin.y()});
|
||||||
|
}
|
||||||
for (PrintObject *obj : objs) {
|
for (PrintObject *obj : objs) {
|
||||||
auto layers = getAllLayersExtrusionPathsFromObject(obj);
|
auto layers = getAllLayersExtrusionPathsFromObject(obj);
|
||||||
conflictQueue.emplace_back_bucket(std::move(layers.first), obj, obj->instances().front().shift);
|
conflictQueue.emplace_back_bucket(std::move(layers.first), obj, obj->instances().front().shift);
|
||||||
|
@ -219,7 +225,7 @@ ConflictRet ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs ob
|
||||||
bool find = false;
|
bool find = false;
|
||||||
tbb::concurrent_vector<ConflictResult> conflict;
|
tbb::concurrent_vector<ConflictResult> conflict;
|
||||||
|
|
||||||
tbb::parallel_for(tbb::blocked_range<size_t>( 0, layersLines.size()), [&](tbb::blocked_range<size_t> range) {
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, layersLines.size()), [&](tbb::blocked_range<size_t> range) {
|
||||||
for (size_t i = range.begin(); i < range.end(); i++) {
|
for (size_t i = range.begin(); i < range.end(); i++) {
|
||||||
auto interRes = find_inter_of_lines(layersLines[i]);
|
auto interRes = find_inter_of_lines(layersLines[i]);
|
||||||
if (interRes.has_value()) {
|
if (interRes.has_value()) {
|
||||||
|
@ -231,21 +237,33 @@ ConflictRet ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs ob
|
||||||
});
|
});
|
||||||
|
|
||||||
if (find) {
|
if (find) {
|
||||||
return {conflict[0]};
|
const void *ptr1 = conflictQueue.idToObjsPtr(conflict[0]._obj1);
|
||||||
|
const void *ptr2 = conflictQueue.idToObjsPtr(conflict[0]._obj2);
|
||||||
|
if (wtdptr.has_value()) {
|
||||||
|
const FakeWipeTower *wtdp = wtdptr.value();
|
||||||
|
if (ptr1 == wtdp || ptr2 == wtdp) {
|
||||||
|
if (ptr2 == wtdp) { std::swap(ptr1, ptr2); }
|
||||||
|
const PrintObject *obj2 = reinterpret_cast<const PrintObject *>(ptr2);
|
||||||
|
return {std::make_pair("WipeTower", obj2->model_object()->name)};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const PrintObject *obj1 = reinterpret_cast<const PrintObject *>(ptr1);
|
||||||
|
const PrintObject *obj2 = reinterpret_cast<const PrintObject *>(ptr2);
|
||||||
|
return {std::make_pair(obj1->model_object()->name, obj2->model_object()->name)};
|
||||||
} else
|
} else
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ConflictRet ConflictChecker::line_intersect(const LineWithID &l1, const LineWithID &l2)
|
ConflictRet ConflictChecker::line_intersect(const LineWithID &l1, const LineWithID &l2)
|
||||||
{
|
{
|
||||||
if (l1._objPtr == l2._objPtr) { return {}; } // return true if lines are from same object
|
if (l1._id == l2._id) { return {}; } // return true if lines are from same object
|
||||||
Point inter;
|
Point inter;
|
||||||
bool intersect = l1._line.intersection(l2._line, &inter);
|
bool intersect = l1._line.intersection(l2._line, &inter);
|
||||||
if (intersect) {
|
if (intersect) {
|
||||||
auto dist1 = std::min(unscale(Point(l1._line.a - inter)).norm(), unscale(Point(l1._line.b - inter)).norm());
|
auto dist1 = std::min(unscale(Point(l1._line.a - inter)).norm(), unscale(Point(l1._line.b - inter)).norm());
|
||||||
auto dist2 = std::min(unscale(Point(l2._line.a - inter)).norm(), unscale(Point(l2._line.b - inter)).norm());
|
auto dist2 = std::min(unscale(Point(l2._line.a - inter)).norm(), unscale(Point(l2._line.b - inter)).norm());
|
||||||
auto dist = std::min(dist1, dist2);
|
auto dist = std::min(dist1, dist2);
|
||||||
if (dist > 0.01) { return std::make_optional<ConflictResult>(l1._objPtr, l2._objPtr); } // the two lines intersects if dist>0.01mm
|
if (dist > 0.01) { return std::make_optional<ConflictResult>(l1._id, l2._id); } // the two lines intersects if dist>0.01mm
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ namespace Slic3r {
|
||||||
struct LineWithID
|
struct LineWithID
|
||||||
{
|
{
|
||||||
Line _line;
|
Line _line;
|
||||||
PrintObject *_objPtr;
|
int _id;
|
||||||
int _role;
|
int _role;
|
||||||
|
|
||||||
LineWithID(const Line &line, PrintObject *objPtr, int role) : _line(line), _objPtr(objPtr), _role(role) {}
|
LineWithID(const Line &line, int id, int role) : _line(line), _id(id), _role(role) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
using LineWithIDs = std::vector<LineWithID>;
|
using LineWithIDs = std::vector<LineWithID>;
|
||||||
|
@ -30,11 +30,11 @@ private:
|
||||||
unsigned _curPileIdx = 0;
|
unsigned _curPileIdx = 0;
|
||||||
|
|
||||||
std::vector<ExtrusionPaths> _piles;
|
std::vector<ExtrusionPaths> _piles;
|
||||||
PrintObject * _objPtr;
|
int _id;
|
||||||
Point _offset;
|
Point _offset;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LinesBucket(std::vector<ExtrusionPaths> &&paths, PrintObject *objPtr, Point offset) : _piles(paths), _objPtr(objPtr), _offset(offset) {}
|
LinesBucket(std::vector<ExtrusionPaths> &&paths, int id, Point offset) : _piles(paths), _id(id), _offset(offset) {}
|
||||||
LinesBucket(LinesBucket &&) = default;
|
LinesBucket(LinesBucket &&) = default;
|
||||||
|
|
||||||
bool valid() const { return _curPileIdx < _piles.size(); }
|
bool valid() const { return _curPileIdx < _piles.size(); }
|
||||||
|
@ -52,9 +52,9 @@ public:
|
||||||
for (const ExtrusionPath &path : _piles[_curPileIdx]) {
|
for (const ExtrusionPath &path : _piles[_curPileIdx]) {
|
||||||
if (path.is_force_no_extrusion() == false) {
|
if (path.is_force_no_extrusion() == false) {
|
||||||
Polyline check_polyline = path.polyline;
|
Polyline check_polyline = path.polyline;
|
||||||
if (path.role() != ExtrusionRole::erBrim) { check_polyline.translate(_offset); }
|
check_polyline.translate(_offset);
|
||||||
Lines tmpLines = check_polyline.lines();
|
Lines tmpLines = check_polyline.lines();
|
||||||
for (const Line &line : tmpLines) { lines.emplace_back(line, _objPtr, path.role()); }
|
for (const Line &line : tmpLines) { lines.emplace_back(line, _id, path.role()); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
|
@ -75,11 +75,18 @@ class LinesBucketQueue
|
||||||
private:
|
private:
|
||||||
std::vector<LinesBucket> _buckets;
|
std::vector<LinesBucket> _buckets;
|
||||||
std::priority_queue<LinesBucket *, std::vector<LinesBucket *>, LinesBucketPtrComp> _pq;
|
std::priority_queue<LinesBucket *, std::vector<LinesBucket *>, LinesBucketPtrComp> _pq;
|
||||||
|
std::vector<const void *> _objsPtrToId;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, PrintObject *objPtr, Point offset);
|
void emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset);
|
||||||
bool valid() const { return _pq.empty() == false; }
|
bool valid() const { return _pq.empty() == false; }
|
||||||
|
const void *idToObjsPtr(int id)
|
||||||
|
{
|
||||||
|
if (id >= 0 && id < _objsPtrToId.size()) {
|
||||||
|
return _objsPtrToId[id];
|
||||||
|
} else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
void removeLowests();
|
void removeLowests();
|
||||||
LineWithIDs getCurLines() const;
|
LineWithIDs getCurLines() const;
|
||||||
};
|
};
|
||||||
|
@ -94,19 +101,19 @@ std::pair<std::vector<ExtrusionPaths>, std::vector<ExtrusionPaths>> getAllLayers
|
||||||
|
|
||||||
struct ConflictResult
|
struct ConflictResult
|
||||||
{
|
{
|
||||||
PrintObject *_obj1;
|
int _obj1;
|
||||||
PrintObject *_obj2;
|
int _obj2;
|
||||||
ConflictResult(PrintObject *obj1, PrintObject *obj2) : _obj1(obj1), _obj2(obj2) {}
|
ConflictResult(int obj1, int obj2) : _obj1(obj1), _obj2(obj2) {}
|
||||||
ConflictResult() = default;
|
ConflictResult() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_trivial<ConflictResult>::value, "atomic value requires to be trival.");
|
|
||||||
|
|
||||||
using ConflictRet = std::optional<ConflictResult>;
|
using ConflictRet = std::optional<ConflictResult>;
|
||||||
|
|
||||||
|
using ConflictObjName = std::optional<std::pair<std::string, std::string>>;
|
||||||
|
|
||||||
struct ConflictChecker
|
struct ConflictChecker
|
||||||
{
|
{
|
||||||
static ConflictRet find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs);
|
static ConflictObjName find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs, std::optional<const FakeWipeTower *> wtdptr);
|
||||||
static ConflictRet find_inter_of_lines(const LineWithIDs &lines);
|
static ConflictRet find_inter_of_lines(const LineWithIDs &lines);
|
||||||
static ConflictRet line_intersect(const LineWithID &l1, const LineWithID &l2);
|
static ConflictRet line_intersect(const LineWithID &l1, const LineWithID &l2);
|
||||||
};
|
};
|
||||||
|
|
|
@ -156,6 +156,8 @@ public:
|
||||||
|
|
||||||
float get_depth() const { return m_wipe_tower_depth; }
|
float get_depth() const { return m_wipe_tower_depth; }
|
||||||
float get_brim_width() const { return m_wipe_tower_brim_width_real; }
|
float get_brim_width() const { return m_wipe_tower_brim_width_real; }
|
||||||
|
float get_height() const { return m_wipe_tower_height; }
|
||||||
|
float get_layer_height() const { return m_layer_height; }
|
||||||
|
|
||||||
void set_last_layer_extruder_fill(bool extruder_fill) {
|
void set_last_layer_extruder_fill(bool extruder_fill) {
|
||||||
if (!m_plan.empty()) {
|
if (!m_plan.empty()) {
|
||||||
|
|
|
@ -1679,15 +1679,18 @@ void Print::process(bool use_cache)
|
||||||
{
|
{
|
||||||
using Clock = std::chrono::high_resolution_clock;
|
using Clock = std::chrono::high_resolution_clock;
|
||||||
auto startTime = Clock::now();
|
auto startTime = Clock::now();
|
||||||
auto conflictRes = ConflictChecker::find_inter_of_lines_in_diff_objs(m_objects);
|
std::optional<const FakeWipeTower *> wipe_tower_opt = {};
|
||||||
|
if (this->has_wipe_tower()) {
|
||||||
|
m_fake_wipe_tower.set_pos({m_config.wipe_tower_x.get_at(m_plate_index), m_config.wipe_tower_y.get_at(m_plate_index)});
|
||||||
|
wipe_tower_opt = std::make_optional<const FakeWipeTower *>(&m_fake_wipe_tower);
|
||||||
|
}
|
||||||
|
auto conflictRes = ConflictChecker::find_inter_of_lines_in_diff_objs(m_objects, wipe_tower_opt);
|
||||||
auto endTime = Clock::now();
|
auto endTime = Clock::now();
|
||||||
volatile double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / (double) 1000;
|
volatile double seconds = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() / (double) 1000;
|
||||||
BOOST_LOG_TRIVIAL(info) << "gcode path conflicts check takes " << seconds << " secs.";
|
BOOST_LOG_TRIVIAL(info) << "gcode path conflicts check takes " << seconds << " secs.";
|
||||||
|
|
||||||
if (conflictRes.has_value()) {
|
if (conflictRes.has_value()) {
|
||||||
m_conflict_result.set(conflictRes.value()._obj1, conflictRes.value()._obj2);
|
m_conflict_result.set(conflictRes.value().first, conflictRes.value().second);
|
||||||
auto objName1 = conflictRes.value()._obj1->m_model_object->name;
|
|
||||||
auto objName2 = conflictRes.value()._obj2->m_model_object->name;
|
|
||||||
} else {
|
} else {
|
||||||
m_conflict_result.reset();
|
m_conflict_result.reset();
|
||||||
}
|
}
|
||||||
|
@ -1723,7 +1726,7 @@ std::string Print::export_gcode(const std::string& path_template, GCodeProcessor
|
||||||
gcode.do_export(this, path.c_str(), result, thumbnail_cb);
|
gcode.do_export(this, path.c_str(), result, thumbnail_cb);
|
||||||
//BBS
|
//BBS
|
||||||
if (m_conflict_result.conflicted) {
|
if (m_conflict_result.conflicted) {
|
||||||
result->conflict_result.set(m_conflict_result.obj1->m_model_object->name, m_conflict_result.obj2->m_model_object->name);
|
result->conflict_result.set(m_conflict_result.obj1, m_conflict_result.obj2);
|
||||||
} else {
|
} else {
|
||||||
result->conflict_result.reset();
|
result->conflict_result.reset();
|
||||||
}
|
}
|
||||||
|
@ -2154,6 +2157,9 @@ void Print::_make_wipe_tower()
|
||||||
|
|
||||||
m_wipe_tower_data.used_filament = wipe_tower.get_used_filament();
|
m_wipe_tower_data.used_filament = wipe_tower.get_used_filament();
|
||||||
m_wipe_tower_data.number_of_toolchanges = wipe_tower.get_number_of_toolchanges();
|
m_wipe_tower_data.number_of_toolchanges = wipe_tower.get_number_of_toolchanges();
|
||||||
|
const Vec3d origin = this->get_plate_origin();
|
||||||
|
m_fake_wipe_tower.set_fake_extrusion_data(wipe_tower.position(), wipe_tower.width(), wipe_tower.get_height(), wipe_tower.get_layer_height(), m_wipe_tower_data.depth,
|
||||||
|
m_wipe_tower_data.brim_width, {scale_(origin.x()), scale_(origin.y())});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a recommended G-code output file name based on the format template, default extension, and template parameters
|
// Generate a recommended G-code output file name based on the format template, default extension, and template parameters
|
||||||
|
|
|
@ -510,6 +510,58 @@ private:
|
||||||
static bool infill_only_where_needed;
|
static bool infill_only_where_needed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct FakeWipeTower
|
||||||
|
{
|
||||||
|
// generate fake extrusion
|
||||||
|
Vec2f pos;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
float layer_height;
|
||||||
|
float depth;
|
||||||
|
float brim_width;
|
||||||
|
Vec2d plate_origin;
|
||||||
|
|
||||||
|
void set_fake_extrusion_data(Vec2f p, float w, float h, float lh, float d, float bd, Vec2d o)
|
||||||
|
{
|
||||||
|
pos = p;
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
layer_height = lh;
|
||||||
|
depth = d;
|
||||||
|
brim_width = bd;
|
||||||
|
plate_origin = o;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_pos(Vec2f p) { pos = p; }
|
||||||
|
|
||||||
|
std::vector<ExtrusionPaths> getFakeExtrusionPathsFromWipeTower() const
|
||||||
|
{
|
||||||
|
float h = height;
|
||||||
|
float lh = layer_height;
|
||||||
|
int d = scale_(depth);
|
||||||
|
int w = scale_(width);
|
||||||
|
int bd = scale_(brim_width);
|
||||||
|
Point minCorner = {scale_(pos.x()), scale_(pos.y())};
|
||||||
|
Point maxCorner = {minCorner.x() + w, minCorner.y() + d};
|
||||||
|
|
||||||
|
std::vector<ExtrusionPaths> paths;
|
||||||
|
for (float hh = 0.f; hh < h; hh += lh) {
|
||||||
|
ExtrusionPath path(ExtrusionRole::erWipeTower, 0.0, 0.0, lh);
|
||||||
|
path.polyline = {minCorner, {maxCorner.x(), minCorner.y()}, maxCorner, {minCorner.x(), maxCorner.y()}, minCorner};
|
||||||
|
paths.push_back({path});
|
||||||
|
|
||||||
|
if (hh == 0.f) { // add brim
|
||||||
|
ExtrusionPath fakeBrim(ExtrusionRole::erBrim, 0.0, 0.0, lh);
|
||||||
|
Point wtbminCorner = {minCorner - Point{bd, bd}};
|
||||||
|
Point wtbmaxCorner = {maxCorner + Point{bd, bd}};
|
||||||
|
fakeBrim.polyline = {wtbminCorner, {wtbmaxCorner.x(), wtbminCorner.y()}, wtbmaxCorner, {wtbminCorner.x(), wtbmaxCorner.y()}, wtbminCorner};
|
||||||
|
paths.back().push_back(fakeBrim);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct WipeTowerData
|
struct WipeTowerData
|
||||||
{
|
{
|
||||||
// Following section will be consumed by the GCodeGenerator.
|
// Following section will be consumed by the GCodeGenerator.
|
||||||
|
@ -779,12 +831,12 @@ private:
|
||||||
struct ConflictResult
|
struct ConflictResult
|
||||||
{
|
{
|
||||||
bool conflicted;
|
bool conflicted;
|
||||||
PrintObject *obj1;
|
std::string obj1;
|
||||||
PrintObject *obj2;
|
std::string obj2;
|
||||||
//TODO
|
//TODO
|
||||||
//the actual loaction
|
//the actual loaction
|
||||||
|
|
||||||
void set(PrintObject *o1, PrintObject *o2)
|
void set(const std::string& o1, const std::string& o2)
|
||||||
{
|
{
|
||||||
conflicted = true;
|
conflicted = true;
|
||||||
obj1 = o1;
|
obj1 = o1;
|
||||||
|
@ -793,10 +845,11 @@ private:
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
conflicted = false;
|
conflicted = false;
|
||||||
obj1 = nullptr;
|
obj1.clear();
|
||||||
obj2 = nullptr;
|
obj2.clear();
|
||||||
}
|
}
|
||||||
}m_conflict_result;
|
}m_conflict_result;
|
||||||
|
FakeWipeTower m_fake_wipe_tower;
|
||||||
|
|
||||||
// To allow GCode to set the Print's GCodeExport step status.
|
// To allow GCode to set the Print's GCodeExport step status.
|
||||||
friend class GCode;
|
friend class GCode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue