Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConflictChecker Struct Reference

#include <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
187{
188 using namespace RasterizationImpl;
189 std::map<IndexPair, std::vector<int>> indexToLine;
190
191 for (int i = 0; i < (int)lines.size(); ++i) {
192 const LineWithID &l1 = lines[i];
193 auto indexes = line_rasterization(l1._line);
194 for (auto index : indexes) {
195 const auto &possibleIntersectIdxs = indexToLine[index];
196 for (auto possibleIntersectIdx : possibleIntersectIdxs) {
197 const LineWithID &l2 = lines[possibleIntersectIdx];
198 if (auto interRes = line_intersect(l1, l2); interRes.has_value()) { return interRes; }
199 }
200 indexToLine[index].push_back(i);
201 }
202 }
203 return {};
204}
Grids line_rasterization(const Line &line, int64_t xdist=RasteXDistance, int64_t ydist=RasteYDistance)
Definition ConflictChecker.cpp:29
T l2(const boost::geometry::model::d2::point_xy< T > &v)
Definition ExtrusionSimulator.cpp:166
static ConflictComputeOpt line_intersect(const LineWithID &l1, const LineWithID &l2)
Definition ConflictChecker.cpp:274

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
208{
209 if (objs.empty() || (objs.size() == 1 && objs.front()->instances().size() == 1)) { return {}; }
210
211 LinesBucketQueue conflictQueue;
212 if (wtdptr.has_value()) { // wipe tower at 0 by default
213 std::vector<ExtrusionPaths> wtpaths = (*wtdptr)->getFakeExtrusionPathsFromWipeTower();
214 conflictQueue.emplace_back_bucket(std::move(wtpaths), *wtdptr, Points{Point((*wtdptr)->plate_origin)});
215 }
216 for (PrintObject *obj : objs) {
217 std::pair<std::vector<ExtrusionPaths>, std::vector<ExtrusionPaths>> layers = getAllLayersExtrusionPathsFromObject(obj);
218
219 Points instances_shifts;
220 for (const PrintInstance& inst : obj->instances())
221 instances_shifts.emplace_back(inst.shift);
222
223 conflictQueue.emplace_back_bucket(std::move(layers.first), obj, instances_shifts);
224 conflictQueue.emplace_back_bucket(std::move(layers.second), obj, instances_shifts);
225 }
226 conflictQueue.build_queue();
227
228 std::vector<LineWithIDs> layersLines;
229 std::vector<double> heights;
230 while (conflictQueue.valid()) {
231 LineWithIDs lines = conflictQueue.getCurLines();
232 double curHeight = conflictQueue.removeLowests();
233 heights.push_back(curHeight);
234 layersLines.push_back(std::move(lines));
235 }
236
237 bool find = false;
238 tbb::concurrent_vector<std::pair<ConflictComputeResult,double>> conflict;
239
240 tbb::parallel_for(tbb::blocked_range<size_t>(0, layersLines.size()), [&](tbb::blocked_range<size_t> range) {
241 for (size_t i = range.begin(); i < range.end(); i++) {
242 auto interRes = find_inter_of_lines(layersLines[i]);
243 if (interRes.has_value()) {
244 find = true;
245 conflict.emplace_back(*interRes, heights[i]);
246 break;
247 }
248 }
249 });
250
251 if (find) {
252 std::sort(conflict.begin(), conflict.end(), [](const std::pair<ConflictComputeResult, double>& i1, const std::pair<ConflictComputeResult, double>& i2) {
253 return i1.second < i2.second;
254 });
255
256 const void *ptr1 = conflictQueue.idToObjsPtr(conflict[0].first._obj1);
257 const void *ptr2 = conflictQueue.idToObjsPtr(conflict[0].first._obj2);
258 double conflictHeight = conflict[0].second;
259 if (wtdptr.has_value()) {
260 const FakeWipeTower* wtdp = *wtdptr;
261 if (ptr1 == wtdp || ptr2 == wtdp) {
262 if (ptr2 == wtdp) { std::swap(ptr1, ptr2); }
263 const PrintObject *obj2 = reinterpret_cast<const PrintObject *>(ptr2);
264 return std::make_optional<ConflictResult>("WipeTower", obj2->model_object()->name, conflictHeight, nullptr, ptr2);
265 }
266 }
267 const PrintObject *obj1 = reinterpret_cast<const PrintObject *>(ptr1);
268 const PrintObject *obj2 = reinterpret_cast<const PrintObject *>(ptr2);
269 return std::make_optional<ConflictResult>(obj1->model_object()->name, obj2->model_object()->name, conflictHeight, ptr1, ptr2);
270 } else
271 return {};
272}
auto range(Cont &&cont)
Definition libslic3r.h:356
std::pair< std::vector< ExtrusionPaths >, std::vector< ExtrusionPaths > > getAllLayersExtrusionPathsFromObject(PrintObject *obj)
Definition ConflictChecker.cpp:175
std::vector< LineWithID > LineWithIDs
Definition ConflictChecker.hpp:26
std::vector< Point, PointsAllocator< Point > > Points
Definition Point.hpp:58
IGL_INLINE void find(const Eigen::SparseMatrix< T > &X, Eigen::DenseBase< DerivedI > &I, Eigen::DenseBase< DerivedJ > &J, Eigen::DenseBase< DerivedV > &V)
Definition find.cpp:18
Kernel::Point_2 Point
Definition point_areas.cpp:20

References Slic3r::LinesBucketQueue::build_queue(), Slic3r::LinesBucketQueue::emplace_back_bucket(), Slic3r::getAllLayersExtrusionPathsFromObject(), Slic3r::LinesBucketQueue::getCurLines(), Slic3r::range(), Slic3r::LinesBucketQueue::removeLowests(), and Slic3r::LinesBucketQueue::valid().

Referenced by Slic3r::Print::process().

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

◆ line_intersect()

ConflictComputeOpt Slic3r::ConflictChecker::line_intersect ( const LineWithID l1,
const LineWithID l2 
)
static
275{
276 if (l1._obj_id == l2._obj_id && l1._inst_id == l2._inst_id) { return {}; } // lines are from same instance
277
278 Point inter;
279 bool intersect = l1._line.intersection(l2._line, &inter);
280 if (intersect) {
281 auto dist1 = std::min(unscale(Point(l1._line.a - inter)).norm(), unscale(Point(l1._line.b - inter)).norm());
282 auto dist2 = std::min(unscale(Point(l2._line.a - inter)).norm(), unscale(Point(l2._line.b - inter)).norm());
283 auto dist = std::min(dist1, dist2);
284 if (dist > 0.01) { return std::make_optional<ConflictComputeResult>(l1._obj_id, l2._obj_id); } // the two lines intersects if dist>0.01mm
285 }
286 return {};
287}
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
T unscale(Q v)
Definition libslic3r.h:95
IGL_INLINE void intersect(const M &A, const M &B, M &C)
Definition intersect.cpp:10

References Slic3r::LineWithID::_inst_id, Slic3r::LineWithID::_line, Slic3r::LineWithID::_obj_id, Slic3r::Line::a, Slic3r::Line::b, Slic3r::Line::intersection(), Slic3r::l2(), and Slic3r::unscale().

Referenced by find_inter_of_lines().

+ 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: