mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
ENH: show the layer and height of conflict position
Change-Id: If80e81b5556f5afc3228a00edc2593bd8cfe63e4 (cherry picked from commit 895e0f2ecf8e259cfdb7c27081b767bfbaa3ffb6)
This commit is contained in:
parent
98f3aaa4bf
commit
87eb0f3665
9 changed files with 99 additions and 90 deletions
|
@ -92,8 +92,11 @@ inline Grids line_rasterization(const Line &line, int64_t xdist = RasteXDistance
|
|||
void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths, const void *objPtr, Point offset)
|
||||
{
|
||||
auto oldSize = _buckets.capacity();
|
||||
_buckets.emplace_back(std::move(paths), _objsPtrToId.size(), offset);
|
||||
_objsPtrToId.push_back(objPtr);
|
||||
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);
|
||||
_pq.push(&_buckets.back());
|
||||
auto newSize = _buckets.capacity();
|
||||
if (oldSize != newSize) { // pointers change
|
||||
|
@ -103,11 +106,11 @@ void LinesBucketQueue::emplace_back_bucket(std::vector<ExtrusionPaths> &&paths,
|
|||
}
|
||||
}
|
||||
|
||||
void LinesBucketQueue::removeLowests()
|
||||
double LinesBucketQueue::removeLowests()
|
||||
{
|
||||
auto lowest = _pq.top();
|
||||
_pq.pop();
|
||||
|
||||
double curHeight = lowest->curHeight();
|
||||
std::vector<LinesBucket *> lowests;
|
||||
lowests.push_back(lowest);
|
||||
|
||||
|
@ -120,6 +123,7 @@ void LinesBucketQueue::removeLowests()
|
|||
bp->raise();
|
||||
if (bp->valid()) { _pq.push(bp); }
|
||||
}
|
||||
return curHeight;
|
||||
}
|
||||
|
||||
LineWithIDs LinesBucketQueue::getCurLines() const
|
||||
|
@ -180,7 +184,7 @@ std::pair<std::vector<ExtrusionPaths>, std::vector<ExtrusionPaths>> getAllLayers
|
|||
return {std::move(objPaths), std::move(supportPaths)};
|
||||
}
|
||||
|
||||
ConflictRet ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
||||
ConflictComputeOpt ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
||||
{
|
||||
using namespace RasterizationImpl;
|
||||
std::map<IndexPair, std::vector<int>> indexToLine;
|
||||
|
@ -200,7 +204,7 @@ ConflictRet ConflictChecker::find_inter_of_lines(const LineWithIDs &lines)
|
|||
return {};
|
||||
}
|
||||
|
||||
ConflictObjName ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtrs objs,
|
||||
ConflictResultOpt 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 {}; }
|
||||
|
@ -216,45 +220,48 @@ ConflictObjName ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectPtr
|
|||
}
|
||||
|
||||
std::vector<LineWithIDs> layersLines;
|
||||
std::vector<double> heights;
|
||||
while (conflictQueue.valid()) {
|
||||
LineWithIDs lines = conflictQueue.getCurLines();
|
||||
conflictQueue.removeLowests();
|
||||
LineWithIDs lines = conflictQueue.getCurLines();
|
||||
double curHeight = conflictQueue.removeLowests();
|
||||
heights.push_back(curHeight);
|
||||
layersLines.push_back(std::move(lines));
|
||||
}
|
||||
|
||||
bool find = false;
|
||||
tbb::concurrent_vector<ConflictResult> conflict;
|
||||
tbb::concurrent_vector<std::pair<ConflictComputeResult,double>> conflict;
|
||||
|
||||
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++) {
|
||||
auto interRes = find_inter_of_lines(layersLines[i]);
|
||||
if (interRes.has_value()) {
|
||||
find = true;
|
||||
conflict.emplace_back(interRes.value());
|
||||
conflict.emplace_back(interRes.value(),heights[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (find) {
|
||||
const void *ptr1 = conflictQueue.idToObjsPtr(conflict[0]._obj1);
|
||||
const void *ptr2 = conflictQueue.idToObjsPtr(conflict[0]._obj2);
|
||||
const void *ptr1 = conflictQueue.idToObjsPtr(conflict[0].first._obj1);
|
||||
const void *ptr2 = conflictQueue.idToObjsPtr(conflict[0].first._obj2);
|
||||
double conflictHeight = conflict[0].second;
|
||||
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)};
|
||||
return std::make_optional<ConflictResult>("WipeTower", obj2->model_object()->name, conflictHeight, nullptr, ptr2);
|
||||
}
|
||||
}
|
||||
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)};
|
||||
return std::make_optional<ConflictResult>(obj1->model_object()->name, obj2->model_object()->name, conflictHeight, ptr1, ptr2);
|
||||
} else
|
||||
return {};
|
||||
}
|
||||
|
||||
ConflictRet ConflictChecker::line_intersect(const LineWithID &l1, const LineWithID &l2)
|
||||
ConflictComputeOpt ConflictChecker::line_intersect(const LineWithID &l1, const LineWithID &l2)
|
||||
{
|
||||
if (l1._id == l2._id) { return {}; } // return true if lines are from same object
|
||||
Point inter;
|
||||
|
@ -263,7 +270,7 @@ ConflictRet ConflictChecker::line_intersect(const LineWithID &l1, const LineWith
|
|||
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 dist = std::min(dist1, dist2);
|
||||
if (dist > 0.01) { return std::make_optional<ConflictResult>(l1._id, l2._id); } // the two lines intersects if dist>0.01mm
|
||||
if (dist > 0.01) { return std::make_optional<ConflictComputeResult>(l1._id, l2._id); } // the two lines intersects if dist>0.01mm
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue