mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-01-11 10:23:06 -07:00
* 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>
70 lines
2 KiB
C++
70 lines
2 KiB
C++
#ifndef SRC_LIBSLIC3R_ALGORITHM_LINE_SPLIT_HPP_
|
|
#define SRC_LIBSLIC3R_ALGORITHM_LINE_SPLIT_HPP_
|
|
|
|
#include "ClipperZUtils.hpp"
|
|
|
|
namespace Slic3r {
|
|
namespace Algorithm {
|
|
|
|
struct SplitLineJunction
|
|
{
|
|
Point p;
|
|
|
|
// true if the line between this point and the next point is inside the clip polygon (or on the edge of the clip polygon)
|
|
bool clipped;
|
|
|
|
// Index from the original input.
|
|
// - If this junction is presented in the source polygon/polyline, this is the index of the point with in the source;
|
|
// - if this point in a new point that caused by the intersection, this will be -(1+index of the first point of the source line involved in this intersection);
|
|
// - if this junction came from the clip polygon, it will be treated as new point.
|
|
int64_t src_idx;
|
|
|
|
SplitLineJunction(const Point& p, bool clipped, int64_t src_idx)
|
|
: p(p)
|
|
, clipped(clipped)
|
|
, src_idx(src_idx) {}
|
|
|
|
bool is_src() const { return src_idx >= 0; }
|
|
size_t get_src_index() const
|
|
{
|
|
if (is_src()) {
|
|
return src_idx;
|
|
} else {
|
|
return -src_idx - 1;
|
|
}
|
|
}
|
|
};
|
|
|
|
using SplittedLine = std::vector<SplitLineJunction>;
|
|
|
|
SplittedLine do_split_line(const ClipperZUtils::ZPath& path, const ExPolygons& clip, bool closed);
|
|
|
|
// Return the splitted line, or empty if no intersection found
|
|
template<class PathType>
|
|
SplittedLine split_line(const PathType& path, const ExPolygons& clip, bool closed)
|
|
{
|
|
if (path.empty()) {
|
|
return {};
|
|
}
|
|
|
|
// Convert the input path into an open ZPath
|
|
ClipperZUtils::ZPath p;
|
|
p.reserve(path.size() + closed ? 1 : 0);
|
|
ClipperLib_Z::cInt z = 0;
|
|
for (const auto& point : path) {
|
|
p.emplace_back(point.x(), point.y(), z);
|
|
z++;
|
|
}
|
|
if (closed) {
|
|
// duplicate the first point at the end to make a closed path open
|
|
p.emplace_back(p.front());
|
|
p.back().z() = z;
|
|
}
|
|
|
|
return do_split_line(p, clip, closed);
|
|
}
|
|
|
|
} // Algorithm
|
|
} // Slic3r
|
|
|
|
#endif /* SRC_LIBSLIC3R_ALGORITHM_LINE_SPLIT_HPP_ */
|