OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::ConflictChecker Struct Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/GCode/ConflictChecker.hpp>

Static Public Member Functions

static ConflictResultOpt find_inter_of_lines_in_diff_objs (PrintObjectPtrs objs, std::optional< const FakeWipeTower * > wtdptr)
static ConflictComputeOpt find_inter_of_lines (const LineWithIDs &lines)
static ConflictComputeOpt line_intersect (const LineWithID &l1, const LineWithID &l2)

Detailed Description

Member Function Documentation

◆ find_inter_of_lines()

ConflictComputeOpt Slic3r::ConflictChecker::find_inter_of_lines ( const LineWithIDs & lines)
static
219{
220 using namespace RasterizationImpl;
221 std::map<IndexPair, std::vector<int>> indexToLine;
222
223 for (int i = 0; i < lines.size(); ++i) {
224 const LineWithID &l1 = lines[i];
225 auto indexes = line_rasterization(l1._line);
226 for (auto index : indexes) {
227 const auto &possibleIntersectIdxs = indexToLine[index];
228 for (auto possibleIntersectIdx : possibleIntersectIdxs) {
229 const LineWithID &l2 = lines[possibleIntersectIdx];
230 if (auto interRes = line_intersect(l1, l2); interRes.has_value()) { return interRes; }
231 }
232 indexToLine[index].push_back(i);
233 }
234 }
235 return {};
236}
Grids line_rasterization(const Line &line, int64_t xdist=scale_(1), int64_t ydist=scale_(1))
Definition ConflictChecker.cpp:43
T l2(const boost::geometry::model::d2::point_xy< T > &v)
Definition ExtrusionSimulator.cpp:177
static ConflictComputeOpt line_intersect(const LineWithID &l1, const LineWithID &l2)
Definition ConflictChecker.cpp:326

References Slic3r::LineWithID::_line, Slic3r::l2(), and line_intersect().

Here is the call graph for this function:

◆ find_inter_of_lines_in_diff_objs()

ConflictResultOpt Slic3r::ConflictChecker::find_inter_of_lines_in_diff_objs ( PrintObjectPtrs objs,
std::optional< const FakeWipeTower * > wtdptr )
static
240{
241 if (objs.empty() && !wtdptr) { return {}; }
242
243 // Orca: check if we have enough items to potentially conflict (instances count)
244 size_t total_instances = 0;
245 for (auto obj : objs) total_instances += obj->instances().size();
246 if (total_instances <= 1 && !wtdptr) return {};
247
248 LinesBucketQueue conflictQueue;
249
250 if (wtdptr.has_value()) { // wipe tower at 0 by default
251 //auto wtpaths = wtdptr.value()->getFakeExtrusionPathsFromWipeTower();
252 ExtrusionLayers wtels = wtdptr.value()->getTrueExtrusionLayersFromWipeTower();
253 //wtels.type = ExtrusionLayersType::WIPE_TOWER;
254 //for (int i = 0; i < wtpaths.size(); ++i) { // assume that wipe tower always has same height
255 // ExtrusionLayer el;
256 // el.paths = wtpaths[i];
257 // el.bottom_z = wtpaths[i].front().height * (float) i;
258 // el.layer = nullptr;
259 // wtels.push_back(el);
260 //}
261 conflictQueue.emplace_back_bucket(std::move(wtels), wtdptr.value(), {wtdptr.value()->plate_origin.x(), wtdptr.value()->plate_origin.y()});
262 }
263 for (PrintObject *obj : objs) {
264 auto layers = getAllLayersExtrusionPathsFromObject(obj);
265 // Orca: check for collisions between all instances
266 const auto& instances = obj->instances();
267 for (size_t inst_idx = 0; inst_idx < instances.size(); ++inst_idx) {
268 const PrintInstance& inst = instances[inst_idx];
269 const bool is_last_instance = inst_idx + 1 == instances.size();
270 if (is_last_instance) {
271 conflictQueue.emplace_back_bucket(std::move(layers.perimeters), &inst, inst.shift);
272 conflictQueue.emplace_back_bucket(std::move(layers.support), &inst, inst.shift);
273 } else {
274 conflictQueue.emplace_back_bucket(ExtrusionLayers(layers.perimeters), &inst, inst.shift);
275 conflictQueue.emplace_back_bucket(ExtrusionLayers(layers.support), &inst, inst.shift);
276 }
277 }
278 }
279
280 std::vector<LineWithIDs> layersLines;
281 std::vector<float> bottomZs;
282 while (conflictQueue.valid()) {
283 LineWithIDs lines = conflictQueue.getCurLines();
284 float curBottomZ = conflictQueue.getCurrBottomZ();
285 bottomZs.push_back(curBottomZ);
286 layersLines.push_back(std::move(lines));
287 }
288
289 bool find = false;
290 tbb::concurrent_vector<std::pair<ConflictComputeResult, float>> conflict;
291 tbb::parallel_for(tbb::blocked_range<size_t>(0, layersLines.size()), [&](tbb::blocked_range<size_t> range) {
292 for (size_t i = range.begin(); i < range.end(); i++) {
293 auto interRes = find_inter_of_lines(layersLines[i]);
294 if (interRes.has_value()) {
295 find = true;
296 conflict.emplace_back(interRes.value(), bottomZs[i]);
297 break;
298 }
299 }
300 });
301
302 if (find) {
303 const void *ptr1 = conflict[0].first._obj1;
304 const void *ptr2 = conflict[0].first._obj2;
305 float conflictPrintZ = conflict[0].second;
306 if (wtdptr.has_value()) {
307 const FakeWipeTower *wtdp = wtdptr.value();
308 if (ptr1 == wtdp || ptr2 == wtdp) {
309 if (ptr2 == wtdp) { std::swap(ptr1, ptr2); }
310 // ptr1 is now wipe tower, ptr2 is PrintInstance*
311 const PrintInstance *inst2 = reinterpret_cast<const PrintInstance *>(ptr2);
312 const PrintObject *obj2 = inst2->print_object;
313 return std::make_optional<ConflictResult>("WipeTower", obj2->model_object()->name, conflictPrintZ, nullptr, inst2);
314 }
315 }
316
317 const PrintInstance *inst1 = reinterpret_cast<const PrintInstance *>(ptr1);
318 const PrintInstance *inst2 = reinterpret_cast<const PrintInstance *>(ptr2);
319 const PrintObject *obj1 = inst1->print_object;
320 const PrintObject *obj2 = inst2->print_object;
321 return std::make_optional<ConflictResult>(obj1->model_object()->name, obj2->model_object()->name, conflictPrintZ, inst1, inst2);
322 } else
323 return {};
324}
std::vector< LineWithID > LineWithIDs
Definition ConflictChecker.hpp:33
ObjectExtrusions getAllLayersExtrusionPathsFromObject(PrintObject *obj)
Definition ConflictChecker.cpp:204
auto range(Cont &&cont)
Definition libslic3r.h:405
RaycastManager::TrItems::iterator find(RaycastManager::TrItems &items, const RaycastManager::TrKey &key)
Definition RaycastManager.cpp:298

References Slic3r::LinesBucketQueue::emplace_back_bucket(), Slic3r::getAllLayersExtrusionPathsFromObject(), Slic3r::LinesBucketQueue::getCurLines(), Slic3r::LinesBucketQueue::getCurrBottomZ(), Slic3r::range(), Slic3r::PrintInstance::shift, and Slic3r::LinesBucketQueue::valid().

Here is the call graph for this function:

◆ line_intersect()

ConflictComputeOpt Slic3r::ConflictChecker::line_intersect ( const LineWithID & l1,
const LineWithID & l2 )
static
327{
328 constexpr double SUPPORT_THRESHOLD = 100; // this large almost disables conflict check of supports
329 constexpr double OTHER_THRESHOLD = 0.01;
330 if (l1._id == l2._id) { return {}; } // return true if lines are from same object
331 double overlap_length = 0.;
332 bool overlap = l1._line.overlap(l2._line, overlap_length);
333 if (overlap && overlap_length > scaled(OTHER_THRESHOLD)) return std::make_optional<ConflictComputeResult>(l1._id, l2._id);
334 Point inter;
335 bool intersect = l1._line.intersection(l2._line, &inter);
336
337 if (intersect) {
338 double dist1 = std::min(unscale(Point(l1._line.a - inter)).norm(), unscale(Point(l1._line.b - inter)).norm());
339 double dist2 = std::min(unscale(Point(l2._line.a - inter)).norm(), unscale(Point(l2._line.b - inter)).norm());
340 double dist = std::min(dist1, dist2);
341 ExtrusionRole r1 = l1._role;
342 ExtrusionRole r2 = l2._role;
345 if (dist > (both_support ? SUPPORT_THRESHOLD:OTHER_THRESHOLD)) {
346 // the two lines intersects if dist>0.01mm for regular lines, and if dist>1mm for both supports
347 return std::make_optional<ConflictComputeResult>(l1._id, l2._id);
348 }
349 }
350 return {};
351}
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:298
void intersect(CGALMesh &A, CGALMesh &B)
Definition MeshBoolean.cpp:477
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
BoundingBox scaled(const BoundingBoxf &bb)
Definition BoundingBox.hpp:284
ExtrusionRole
Definition ExtrusionEntity.hpp:26
@ erSupportMaterialInterface
Definition ExtrusionEntity.hpp:42
@ erSupportMaterial
Definition ExtrusionEntity.hpp:41
@ erSupportTransition
Definition ExtrusionEntity.hpp:43
T unscale(Q v)
Definition libslic3r.h:138

References Slic3r::LineWithID::_id, Slic3r::LineWithID::_line, Slic3r::LineWithID::_role, Slic3r::Line::a, Slic3r::Line::b, Slic3r::Geometry::dist(), Slic3r::erSupportMaterial, Slic3r::erSupportMaterialInterface, Slic3r::erSupportTransition, Slic3r::Line::intersection(), Slic3r::l2(), line_intersect(), Slic3r::Line::overlap(), Slic3r::scaled(), and Slic3r::unscale().

Referenced by find_inter_of_lines(), and line_intersect().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this struct was generated from the following files: