OrcaSlicer/src/libslic3r/ShortestPath.hpp
Noisyfox fe4a72ec94
Some checks are pending
Build all / Build All (push) Waiting to run
Build all / Flatpak (push) Waiting to run
Upgrade clipper & improve multi-thread performance (#7177)
* Clipper: Verify range of int32 coordinates on input.

Cherry-picked from prusa3d/PrusaSlicer@fa7debf49d

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* ClipperLib: Optimized PointInPolygon() to calculate cross products
 with int64s instead of doubles.

Cherry-picked from prusa3d/PrusaSlicer@9dca8403fe

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Reworked the ClipperLib / Polygon types to use
the tbb::scallable_allocator to better scale on multiple threads.

Cherry-picked from prusa3d/PrusaSlicer@9cde96993e

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* use tbb::scallable_allocator for Polygons and ExPolygon::holes
to better scale on multiple threads

Cherry-picked from prusa3d/PrusaSlicer@b67ad6434d

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Fixed compilation on GCC and CLang

Cherry-picked from prusa3d/PrusaSlicer@b3b44681a9

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Remove clipper2 which is not used

* Removed shiny profiler from clipperlib

Cherry-picked from prusa3d/PrusaSlicer@7e77048593

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* ClipperLib: Further optimization of memory allocation using scalable_allocator.
ClipperLib: SimplifyPolygon() - changed default winding number to positive,
      added strictly_simple parameter.
ClipperUtlis simplify_polygons() - removed "remove_collinear" parameter

Cherry-picked from prusa3d/PrusaSlicer@a7e17df25f

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* ClipperLib: emplace_back() instead of push_back().

Cherry-picked from prusa3d/PrusaSlicer@2e150795b1

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Fixed issue in a 32bit clipper, where IntersectPoint() checked for
the Y coordinate of the calculated intersection point for validity,
but the Y coordinate was already rounded to 32bits, thus an overflow
may have in rare cases masked invalidity of the result.

Cherry-picked from prusa3d/PrusaSlicer@b39c33414f

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Fixed Vojtech's out of boundary assert in Clipper library.

Cherry-picked from prusa3d/PrusaSlicer@0a202dcff3

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>

* Update clipper to 6.4.2.

Cherry-picked from prusa3d/PrusaSlicer@b8b3cccb40

Co-authored-by: Lukáš Hejl <hejl.lukas@gmail.com>

* Try fix cmake opencv

---------

Co-authored-by: Vojtech Bubnik <bubnikv@gmail.com>
Co-authored-by: Lukáš Hejl <hejl.lukas@gmail.com>
2025-06-18 17:50:44 +08:00

61 lines
2.8 KiB
C++

#ifndef slic3r_ShortestPath_hpp_
#define slic3r_ShortestPath_hpp_
#include "libslic3r.h"
#include "ExtrusionEntity.hpp"
#include "Point.hpp"
#include <utility>
#include <vector>
namespace Slic3r {
namespace ClipperLib {
class PolyNode;
using PolyNodes = std::vector<PolyNode*, PointsAllocator<PolyNode*>>;
}
std::vector<size_t> chain_points(const Points &points, Point *start_near = nullptr);
std::vector<size_t> chain_expolygons(const ExPolygons &input_exploy);
std::vector<std::pair<size_t, bool>> chain_extrusion_entities(std::vector<ExtrusionEntity*> &entities, const Point *start_near = nullptr);
void reorder_extrusion_entities(std::vector<ExtrusionEntity*> &entities, const std::vector<std::pair<size_t, bool>> &chain);
void chain_and_reorder_extrusion_entities(std::vector<ExtrusionEntity*> &entities, const Point *start_near = nullptr);
std::vector<std::pair<size_t, bool>> chain_extrusion_paths(std::vector<ExtrusionPath> &extrusion_paths, const Point *start_near = nullptr);
void reorder_extrusion_paths(std::vector<ExtrusionPath> &extrusion_paths, std::vector<std::pair<size_t, bool>> &chain);
void chain_and_reorder_extrusion_paths(std::vector<ExtrusionPath> &extrusion_paths, const Point *start_near = nullptr);
Polylines chain_polylines(Polylines &&src, const Point *start_near = nullptr);
inline Polylines chain_polylines(const Polylines& src, const Point* start_near = nullptr) { Polylines tmp(src); return chain_polylines(std::move(tmp), start_near); }
template<typename T> inline void reorder_by_shortest_traverse(std::vector<T> &polylines_out)
{
Points start_point;
start_point.reserve(polylines_out.size());
for (const T& contour : polylines_out) start_point.push_back(contour.points.front());
std::vector<Points::size_type> order = chain_points(start_point);
std::vector<T> Temp = polylines_out;
polylines_out.erase(polylines_out.begin(), polylines_out.end());
for (size_t i:order) polylines_out.emplace_back(std::move(Temp[i]));
}
ClipperLib::PolyNodes chain_clipper_polynodes(const Points &points, const ClipperLib::PolyNodes &items);
// Chain instances of print objects by an approximate shortest path.
// Returns pairs of PrintObject idx and instance of that PrintObject.
class Print;
struct PrintInstance;
// BBS
class PrintObject;
std::vector<const PrintInstance*> chain_print_object_instances(const std::vector<const PrintObject*>& print_objects, const Point* start_near);
std::vector<const PrintInstance*> chain_print_object_instances(const Print &print);
// Chain lines into polylines.
Polylines chain_lines(const std::vector<Line> &lines, const double point_distance_epsilon);
} // namespace Slic3r
#endif /* slic3r_ShortestPath_hpp_ */