2013-07-16 18:09:53 +00:00
|
|
|
#ifndef slic3r_ClipperUtils_hpp_
|
|
|
|
#define slic3r_ClipperUtils_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <libslic3r.h>
|
2013-07-16 18:09:53 +00:00
|
|
|
#include "clipper.hpp"
|
2013-07-16 19:04:14 +00:00
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
#include "Polygon.hpp"
|
2013-11-23 17:29:25 +00:00
|
|
|
#include "Surface.hpp"
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-08-26 23:26:44 +00:00
|
|
|
// import these wherever we're included
|
|
|
|
using ClipperLib::jtMiter;
|
|
|
|
using ClipperLib::jtRound;
|
|
|
|
using ClipperLib::jtSquare;
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
namespace Slic3r {
|
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
// Factor to convert from coord_t (which is int32) to an int64 type used by the Clipper library.
|
|
|
|
//FIXME Vojtech: Better to use a power of 2 coefficient and to use bit shifts for scaling.
|
|
|
|
// How about 2^17=131072?
|
|
|
|
// By the way, is the scalling needed at all? Cura runs all the computation with a fixed point precision of 1um, while Slic3r scales to 1nm,
|
|
|
|
// further scaling by 10e5 brings us to
|
2013-08-26 15:58:37 +00:00
|
|
|
#define CLIPPER_OFFSET_SCALE 100000.0
|
2013-07-16 18:09:53 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------
|
|
|
|
// legacy code from Clipper documentation
|
2013-07-16 19:04:14 +00:00
|
|
|
void AddOuterPolyNodeToExPolygons(ClipperLib::PolyNode& polynode, Slic3r::ExPolygons& expolygons);
|
|
|
|
void PolyTreeToExPolygons(ClipperLib::PolyTree& polytree, Slic3r::ExPolygons& expolygons);
|
2013-07-16 18:09:53 +00:00
|
|
|
//-----------------------------------------------------------
|
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void Slic3rMultiPoint_to_ClipperPath(const Slic3r::MultiPoint &input, ClipperLib::Path* output);
|
2013-11-20 10:35:58 +00:00
|
|
|
template <class T>
|
2014-11-15 22:44:03 +00:00
|
|
|
void Slic3rMultiPoints_to_ClipperPaths(const T &input, ClipperLib::Paths* output);
|
2013-11-21 13:15:38 +00:00
|
|
|
template <class T>
|
2014-11-15 22:44:03 +00:00
|
|
|
void ClipperPath_to_Slic3rMultiPoint(const ClipperLib::Path &input, T* output);
|
2013-11-21 13:15:38 +00:00
|
|
|
template <class T>
|
2014-11-15 22:44:03 +00:00
|
|
|
void ClipperPaths_to_Slic3rMultiPoints(const ClipperLib::Paths &input, T* output);
|
|
|
|
void ClipperPaths_to_Slic3rExPolygons(const ClipperLib::Paths &input, Slic3r::ExPolygons* output);
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-11-20 14:59:19 +00:00
|
|
|
void scaleClipperPolygons(ClipperLib::Paths &polygons, const double scale);
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polygons
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 22:48:29 +00:00
|
|
|
double miterLimit = 3);
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Polygons &polygons, Slic3r::Polygons* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 22:48:29 +00:00
|
|
|
double miterLimit = 3);
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::Polygons &polygons, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-07-23 13:53:02 +00:00
|
|
|
double miterLimit = 3);
|
2013-11-20 10:35:58 +00:00
|
|
|
|
2016-10-20 11:04:23 +00:00
|
|
|
// This is a safe variant of the polygon offset, tailored for a single ExPolygon:
|
|
|
|
// a single polygon with multiple non-overlapping holes.
|
|
|
|
// Each contour and hole is offsetted separately, then the holes are subtracted from the outer contours.
|
|
|
|
void offset(const Slic3r::ExPolygon &expolygon, ClipperLib::Paths* retval, const float delta,
|
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
|
|
|
double miterLimit = 3);
|
2016-11-07 21:49:11 +00:00
|
|
|
void offset(const Slic3r::ExPolygons &expolygons, ClipperLib::Paths* retval, const float delta,
|
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
|
|
|
double miterLimit = 3);
|
2016-10-20 11:04:23 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::ExPolygon &expolygon, const float delta,
|
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
|
|
|
double miterLimit = 3);
|
2016-11-07 21:49:11 +00:00
|
|
|
Slic3r::Polygons offset(const Slic3r::ExPolygons &expolygons, const float delta,
|
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
|
|
|
double miterLimit = 3);
|
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygon &expolygon, const float delta,
|
|
|
|
double scale, ClipperLib::JoinType joinType, double miterLimit);
|
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::ExPolygons &expolygons, const float delta,
|
|
|
|
double scale, ClipperLib::JoinType joinType, double miterLimit);
|
2016-10-20 11:04:23 +00:00
|
|
|
|
2013-11-20 10:35:58 +00:00
|
|
|
// offset Polylines
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Polylines &polylines, ClipperLib::Paths* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtSquare,
|
2013-11-20 10:35:58 +00:00
|
|
|
double miterLimit = 3);
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Polylines &polylines, Slic3r::Polygons* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtSquare,
|
2013-11-20 10:35:58 +00:00
|
|
|
double miterLimit = 3);
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Surface &surface, Slic3r::Surfaces* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtSquare,
|
2013-11-23 17:29:25 +00:00
|
|
|
double miterLimit = 3);
|
2013-11-20 10:35:58 +00:00
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset(const Slic3r::Polygons &polygons, Slic3r::ExPolygons* retval, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 19:04:14 +00:00
|
|
|
double miterLimit = 3);
|
2015-10-26 22:23:03 +00:00
|
|
|
Slic3r::ExPolygons offset_ex(const Slic3r::Polygons &polygons, const float delta,
|
2016-04-10 16:58:12 +00:00
|
|
|
double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-10-26 22:23:03 +00:00
|
|
|
double miterLimit = 3);
|
2013-07-16 18:36:27 +00:00
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset2(const Slic3r::Polygons &polygons, ClipperLib::Paths* retval, const float delta1,
|
2016-04-10 16:58:12 +00:00
|
|
|
const float delta2, double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 22:48:29 +00:00
|
|
|
double miterLimit = 3);
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset2(const Slic3r::Polygons &polygons, Slic3r::Polygons* retval, const float delta1,
|
2016-04-10 16:58:12 +00:00
|
|
|
const float delta2, double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 22:48:29 +00:00
|
|
|
double miterLimit = 3);
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::Polygons offset2(const Slic3r::Polygons &polygons, const float delta1,
|
2016-04-10 16:58:12 +00:00
|
|
|
const float delta2, double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-07-23 13:53:02 +00:00
|
|
|
double miterLimit = 3);
|
2014-11-15 22:44:03 +00:00
|
|
|
void offset2(const Slic3r::Polygons &polygons, Slic3r::ExPolygons* retval, const float delta1,
|
2016-04-10 16:58:12 +00:00
|
|
|
const float delta2, double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2013-07-16 19:04:14 +00:00
|
|
|
double miterLimit = 3);
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::ExPolygons offset2_ex(const Slic3r::Polygons &polygons, const float delta1,
|
2016-04-10 16:58:12 +00:00
|
|
|
const float delta2, double scale = CLIPPER_OFFSET_SCALE, ClipperLib::JoinType joinType = ClipperLib::jtMiter,
|
2015-07-23 13:53:02 +00:00
|
|
|
double miterLimit = 3);
|
2013-07-16 18:36:27 +00:00
|
|
|
|
2013-07-16 23:21:30 +00:00
|
|
|
template <class T>
|
2013-11-21 14:12:06 +00:00
|
|
|
void _clipper_do(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, T* retval, bool safety_offset_);
|
2013-11-21 14:12:06 +00:00
|
|
|
void _clipper_do(ClipperLib::ClipType clipType, const Slic3r::Polylines &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, ClipperLib::Paths* retval, bool safety_offset_);
|
2013-11-21 14:12:06 +00:00
|
|
|
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, Slic3r::Polygons* retval, bool safety_offset_);
|
2013-11-21 14:12:06 +00:00
|
|
|
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polygons &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, Slic3r::ExPolygons* retval, bool safety_offset_);
|
2013-11-21 14:12:06 +00:00
|
|
|
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Polylines &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, Slic3r::Polylines* retval);
|
2014-11-15 21:41:22 +00:00
|
|
|
void _clipper(ClipperLib::ClipType clipType, const Slic3r::Lines &subject,
|
2014-11-15 22:44:03 +00:00
|
|
|
const Slic3r::Polygons &clip, Slic3r::Lines* retval);
|
2013-07-16 23:21:30 +00:00
|
|
|
|
2014-05-08 09:07:37 +00:00
|
|
|
template <class SubjectType, class ResultType>
|
2014-11-15 22:44:03 +00:00
|
|
|
void diff(const SubjectType &subject, const Slic3r::Polygons &clip, ResultType* retval, bool safety_offset_ = false);
|
2013-07-16 23:21:30 +00:00
|
|
|
|
2014-12-24 09:20:55 +00:00
|
|
|
template <class SubjectType, class ResultType>
|
|
|
|
void diff(const SubjectType &subject, const Slic3r::ExPolygons &clip, ResultType* retval, bool safety_offset_ = false);
|
|
|
|
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::Polygons diff(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
2015-10-26 22:23:03 +00:00
|
|
|
|
|
|
|
template <class SubjectType, class ClipType>
|
|
|
|
Slic3r::ExPolygons diff_ex(const SubjectType &subject, const ClipType &clip, bool safety_offset_ = false);
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2014-05-08 09:07:37 +00:00
|
|
|
template <class SubjectType, class ResultType>
|
2014-11-15 22:44:03 +00:00
|
|
|
void intersection(const SubjectType &subject, const Slic3r::Polygons &clip, ResultType* retval, bool safety_offset_ = false);
|
2013-11-21 13:15:38 +00:00
|
|
|
|
2015-12-21 13:46:35 +00:00
|
|
|
template <class SubjectType>
|
|
|
|
SubjectType intersection(const SubjectType &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
|
|
|
|
Slic3r::ExPolygons
|
|
|
|
intersection_ex(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2014-11-09 14:27:34 +00:00
|
|
|
template <class SubjectType>
|
|
|
|
bool intersects(const SubjectType &subject, const Slic3r::Polygons &clip, bool safety_offset_ = false);
|
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void xor_(const Slic3r::Polygons &subject, const Slic3r::Polygons &clip, Slic3r::ExPolygons* retval,
|
2013-08-26 15:58:37 +00:00
|
|
|
bool safety_offset_ = false);
|
2013-07-16 23:21:30 +00:00
|
|
|
|
2013-08-17 10:24:04 +00:00
|
|
|
template <class T>
|
2014-11-15 22:44:03 +00:00
|
|
|
void union_(const Slic3r::Polygons &subject, T* retval, bool safety_offset_ = false);
|
2013-07-16 18:09:53 +00:00
|
|
|
|
2015-07-23 13:53:02 +00:00
|
|
|
Slic3r::Polygons union_(const Slic3r::Polygons &subject, bool safety_offset = false);
|
|
|
|
Slic3r::ExPolygons union_ex(const Slic3r::Polygons &subject, bool safety_offset = false);
|
2015-12-02 18:32:57 +00:00
|
|
|
Slic3r::ExPolygons union_ex(const Slic3r::Surfaces &subject, bool safety_offset = false);
|
2015-07-23 13:53:02 +00:00
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void union_(const Slic3r::Polygons &subject1, const Slic3r::Polygons &subject2, Slic3r::Polygons* retval, bool safety_offset = false);
|
2016-10-24 12:07:38 +00:00
|
|
|
Slic3r::Polygons union_(const Slic3r::ExPolygons &subject1, const Slic3r::ExPolygons &subject2, bool safety_offset = false);
|
2014-11-09 14:27:34 +00:00
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void union_pt(const Slic3r::Polygons &subject, ClipperLib::PolyTree* retval, bool safety_offset_ = false);
|
|
|
|
void union_pt_chained(const Slic3r::Polygons &subject, Slic3r::Polygons* retval, bool safety_offset_ = false);
|
|
|
|
static void traverse_pt(ClipperLib::PolyNodes &nodes, Slic3r::Polygons* retval);
|
2013-08-26 16:37:19 +00:00
|
|
|
|
2014-11-15 22:44:03 +00:00
|
|
|
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::Polygons* retval, bool preserve_collinear = false);
|
|
|
|
void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::ExPolygons* retval, bool preserve_collinear = false);
|
2013-08-08 00:10:34 +00:00
|
|
|
|
2014-05-08 09:07:37 +00:00
|
|
|
void safety_offset(ClipperLib::Paths* paths);
|
2013-08-26 15:58:37 +00:00
|
|
|
|
2016-11-23 14:51:47 +00:00
|
|
|
Polygons top_level_islands(const Slic3r::Polygons &polygons);
|
|
|
|
|
2013-07-16 18:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|