Conflict checker: added detection for instances belonging to the same object
This commit is contained in:
parent
b0bef4eeb4
commit
a2ed20d595
@ -206,7 +206,8 @@ ConflictComputeOpt ConflictChecker::find_inter_of_lines(const LineWithIDs &lines
|
|||||||
ConflictResultOpt 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
|
std::optional<const FakeWipeTower *> wtdptr) // find the first intersection point of lines in different objects
|
||||||
{
|
{
|
||||||
if (objs.size() <= 1) { return {}; }
|
if (objs.empty() || (objs.size() == 1 && objs.front()->instances().size() == 1)) { return {}; }
|
||||||
|
|
||||||
LinesBucketQueue conflictQueue;
|
LinesBucketQueue conflictQueue;
|
||||||
if (wtdptr.has_value()) { // wipe tower at 0 by default
|
if (wtdptr.has_value()) { // wipe tower at 0 by default
|
||||||
auto wtpaths = (*wtdptr)->getFakeExtrusionPathsFromWipeTower();
|
auto wtpaths = (*wtdptr)->getFakeExtrusionPathsFromWipeTower();
|
||||||
@ -268,14 +269,15 @@ ConflictResultOpt ConflictChecker::find_inter_of_lines_in_diff_objs(PrintObjectP
|
|||||||
|
|
||||||
ConflictComputeOpt 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
|
if (l1._obj_id == l2._obj_id && l1._inst_id == l2._inst_id) { return {}; } // lines are from same instance
|
||||||
|
|
||||||
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<ConflictComputeResult>(l1._id, l2._id); } // the two lines intersects if dist>0.01mm
|
if (dist > 0.01) { return std::make_optional<ConflictComputeResult>(l1._obj_id, l2._obj_id); } // the two lines intersects if dist>0.01mm
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,12 @@ namespace Slic3r {
|
|||||||
struct LineWithID
|
struct LineWithID
|
||||||
{
|
{
|
||||||
Line _line;
|
Line _line;
|
||||||
int _id;
|
int _obj_id;
|
||||||
|
int _inst_id;
|
||||||
ExtrusionRole _role;
|
ExtrusionRole _role;
|
||||||
|
|
||||||
LineWithID(const Line& line, int id, const ExtrusionRole& role) : _line(line), _id(id), _role(role) {}
|
LineWithID(const Line& line, int obj_id, int inst_id, const ExtrusionRole& role) :
|
||||||
|
_line(line), _obj_id(obj_id), _inst_id(inst_id), _role(role) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
using LineWithIDs = std::vector<LineWithID>;
|
using LineWithIDs = std::vector<LineWithID>;
|
||||||
@ -51,11 +53,11 @@ public:
|
|||||||
LineWithIDs lines;
|
LineWithIDs lines;
|
||||||
for (const ExtrusionPath &path : _piles[_curPileIdx]) {
|
for (const ExtrusionPath &path : _piles[_curPileIdx]) {
|
||||||
Polyline check_polyline;
|
Polyline check_polyline;
|
||||||
for (const Point& offset : _offsets) {
|
for (int i = 0; i < (int)_offsets.size(); ++i) {
|
||||||
check_polyline = path.polyline;
|
check_polyline = path.polyline;
|
||||||
check_polyline.translate(offset);
|
check_polyline.translate(_offsets[i]);
|
||||||
Lines tmpLines = check_polyline.lines();
|
Lines tmpLines = check_polyline.lines();
|
||||||
for (const Line &line : tmpLines) { lines.emplace_back(line, _id, path.role()); }
|
for (const Line& line : tmpLines) { lines.emplace_back(line, _id, i, path.role()); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lines;
|
return lines;
|
||||||
|
Loading…
Reference in New Issue
Block a user