2013-07-15 10:14:22 +00:00
|
|
|
#ifndef slic3r_ExtrusionEntity_hpp_
|
|
|
|
#define slic3r_ExtrusionEntity_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-15 10:14:22 +00:00
|
|
|
#include "Polygon.hpp"
|
|
|
|
#include "Polyline.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
class ExPolygonCollection;
|
|
|
|
class ExtrusionEntityCollection;
|
2014-04-07 23:43:02 +00:00
|
|
|
class Extruder;
|
2013-11-21 16:53:50 +00:00
|
|
|
|
2014-05-12 19:49:17 +00:00
|
|
|
/* Each ExtrusionRole value identifies a distinct set of { extruder, speed } */
|
2013-07-15 10:14:22 +00:00
|
|
|
enum ExtrusionRole {
|
2015-07-02 12:29:20 +00:00
|
|
|
erNone,
|
2013-07-15 10:14:22 +00:00
|
|
|
erPerimeter,
|
|
|
|
erExternalPerimeter,
|
|
|
|
erOverhangPerimeter,
|
2014-05-12 19:49:17 +00:00
|
|
|
erInternalInfill,
|
|
|
|
erSolidInfill,
|
|
|
|
erTopSolidInfill,
|
|
|
|
erBridgeInfill,
|
|
|
|
erGapFill,
|
2013-07-15 10:14:22 +00:00
|
|
|
erSkirt,
|
|
|
|
erSupportMaterial,
|
2014-05-12 20:59:49 +00:00
|
|
|
erSupportMaterialInterface,
|
2014-05-12 19:49:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Special flags describing loop */
|
|
|
|
enum ExtrusionLoopRole {
|
|
|
|
elrDefault,
|
|
|
|
elrContourInternalPerimeter,
|
2015-12-21 14:02:39 +00:00
|
|
|
elrSkirt,
|
2013-07-15 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExtrusionEntity
|
|
|
|
{
|
2016-11-03 09:24:32 +00:00
|
|
|
public:
|
|
|
|
virtual bool is_collection() const { return false; }
|
|
|
|
virtual bool is_loop() const { return false; }
|
|
|
|
virtual bool can_reverse() const { return true; }
|
2013-08-29 09:47:59 +00:00
|
|
|
virtual ExtrusionEntity* clone() const = 0;
|
2013-07-18 17:09:07 +00:00
|
|
|
virtual ~ExtrusionEntity() {};
|
2013-08-29 09:47:59 +00:00
|
|
|
virtual void reverse() = 0;
|
2014-04-24 14:40:10 +00:00
|
|
|
virtual Point first_point() const = 0;
|
|
|
|
virtual Point last_point() const = 0;
|
2016-11-03 23:10:35 +00:00
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
virtual void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const = 0;
|
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion spacing.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
// Useful to calculate area of an infill, which has been really filled in by a 100% rectilinear infill.
|
|
|
|
virtual void polygons_covered_by_spacing(Polygons &out, const float scaled_epsilon) const = 0;
|
|
|
|
Polygons polygons_covered_by_width(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_width(out, scaled_epsilon); return out; }
|
|
|
|
Polygons polygons_covered_by_spacing(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_spacing(out, scaled_epsilon); return out; }
|
2016-11-03 09:24:32 +00:00
|
|
|
// Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm.
|
2015-05-31 20:04:32 +00:00
|
|
|
virtual double min_mm3_per_mm() const = 0;
|
2015-07-06 23:17:31 +00:00
|
|
|
virtual Polyline as_polyline() const = 0;
|
2016-11-03 23:10:35 +00:00
|
|
|
virtual double length() const = 0;
|
2013-07-15 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
2013-07-18 17:09:07 +00:00
|
|
|
typedef std::vector<ExtrusionEntity*> ExtrusionEntitiesPtr;
|
|
|
|
|
2013-07-15 10:14:22 +00:00
|
|
|
class ExtrusionPath : public ExtrusionEntity
|
|
|
|
{
|
2016-11-03 09:24:32 +00:00
|
|
|
public:
|
2013-07-15 10:14:22 +00:00
|
|
|
Polyline polyline;
|
2014-05-08 09:07:37 +00:00
|
|
|
ExtrusionRole role;
|
2016-11-23 14:51:47 +00:00
|
|
|
// Volumetric velocity. mm^3 of plastic per mm of linear head motion. Used by the G-code generator.
|
2016-11-03 09:24:32 +00:00
|
|
|
double mm3_per_mm;
|
2016-11-23 14:51:47 +00:00
|
|
|
// Width of the extrusion, used for visualization purposes.
|
2014-05-08 09:07:37 +00:00
|
|
|
float width;
|
2016-11-23 14:51:47 +00:00
|
|
|
// Height of the extrusion, used for visualization purposed.
|
2014-05-08 09:07:37 +00:00
|
|
|
float height;
|
|
|
|
|
2014-05-12 19:49:17 +00:00
|
|
|
ExtrusionPath(ExtrusionRole role) : role(role), mm3_per_mm(-1), width(-1), height(-1) {};
|
2016-11-03 09:24:32 +00:00
|
|
|
ExtrusionPath(ExtrusionRole role, double mm3_per_mm, float width, float height) : role(role), mm3_per_mm(mm3_per_mm), width(width), height(height) {};
|
|
|
|
// ExtrusionPath(ExtrusionRole role, const Flow &flow) : role(role), mm3_per_mm(flow.mm3_per_mm()), width(flow.width), height(flow.height) {};
|
|
|
|
ExtrusionPath* clone() const { return new ExtrusionPath (*this); }
|
|
|
|
void reverse() { this->polyline.reverse(); }
|
|
|
|
Point first_point() const { return this->polyline.points.front(); }
|
|
|
|
Point last_point() const { return this->polyline.points.back(); }
|
|
|
|
// Produce a list of extrusion paths into retval by clipping this path by ExPolygonCollection.
|
|
|
|
// Currently not used.
|
2014-03-09 19:19:30 +00:00
|
|
|
void intersect_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const;
|
2016-11-03 09:24:32 +00:00
|
|
|
// Produce a list of extrusion paths into retval by removing parts of this path by ExPolygonCollection.
|
|
|
|
// Currently not used.
|
2014-03-09 19:19:30 +00:00
|
|
|
void subtract_expolygons(const ExPolygonCollection &collection, ExtrusionEntityCollection* retval) const;
|
2013-11-21 17:03:40 +00:00
|
|
|
void clip_end(double distance);
|
2013-11-21 19:25:24 +00:00
|
|
|
void simplify(double tolerance);
|
2016-03-19 18:40:11 +00:00
|
|
|
virtual double length() const;
|
2016-11-03 09:24:32 +00:00
|
|
|
bool is_perimeter() const {
|
|
|
|
return this->role == erPerimeter
|
|
|
|
|| this->role == erExternalPerimeter
|
|
|
|
|| this->role == erOverhangPerimeter;
|
|
|
|
}
|
|
|
|
bool is_infill() const {
|
|
|
|
return this->role == erBridgeInfill
|
|
|
|
|| this->role == erInternalInfill
|
|
|
|
|| this->role == erSolidInfill
|
|
|
|
|| this->role == erTopSolidInfill;
|
|
|
|
}
|
|
|
|
bool is_solid_infill() const {
|
|
|
|
return this->role == erBridgeInfill
|
|
|
|
|| this->role == erSolidInfill
|
|
|
|
|| this->role == erTopSolidInfill;
|
|
|
|
}
|
|
|
|
bool is_bridge() const {
|
|
|
|
return this->role == erBridgeInfill
|
|
|
|
|| this->role == erOverhangPerimeter;
|
|
|
|
}
|
2016-11-03 23:10:35 +00:00
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const;
|
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion spacing.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
// Useful to calculate area of an infill, which has been really filled in by a 100% rectilinear infill.
|
|
|
|
void polygons_covered_by_spacing(Polygons &out, const float scaled_epsilon) const;
|
|
|
|
Polygons polygons_covered_by_width(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_width(out, scaled_epsilon); return out; }
|
|
|
|
Polygons polygons_covered_by_spacing(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_spacing(out, scaled_epsilon); return out; }
|
2016-11-03 09:24:32 +00:00
|
|
|
// Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm.
|
|
|
|
double min_mm3_per_mm() const { return this->mm3_per_mm; }
|
|
|
|
Polyline as_polyline() const { return this->polyline; }
|
2014-05-08 09:07:37 +00:00
|
|
|
|
2013-11-21 16:53:50 +00:00
|
|
|
private:
|
2014-03-09 19:19:30 +00:00
|
|
|
void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const;
|
2013-07-15 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
2014-05-08 09:07:37 +00:00
|
|
|
typedef std::vector<ExtrusionPath> ExtrusionPaths;
|
|
|
|
|
2013-07-15 10:14:22 +00:00
|
|
|
class ExtrusionLoop : public ExtrusionEntity
|
|
|
|
{
|
|
|
|
public:
|
2014-05-08 09:07:37 +00:00
|
|
|
ExtrusionPaths paths;
|
2014-05-12 19:49:17 +00:00
|
|
|
ExtrusionLoopRole role;
|
2014-05-07 10:02:09 +00:00
|
|
|
|
2014-05-12 19:49:17 +00:00
|
|
|
ExtrusionLoop(ExtrusionLoopRole role = elrDefault) : role(role) {};
|
2015-07-06 23:17:31 +00:00
|
|
|
ExtrusionLoop(const ExtrusionPaths &paths, ExtrusionLoopRole role = elrDefault)
|
|
|
|
: paths(paths), role(role) {};
|
2016-03-19 14:33:58 +00:00
|
|
|
ExtrusionLoop(const ExtrusionPath &path, ExtrusionLoopRole role = elrDefault)
|
|
|
|
: role(role) {
|
|
|
|
this->paths.push_back(path);
|
|
|
|
};
|
2016-11-03 09:24:32 +00:00
|
|
|
bool is_loop() const { return true; }
|
|
|
|
bool can_reverse() const { return false; }
|
|
|
|
ExtrusionLoop* clone() const { return new ExtrusionLoop (*this); }
|
2014-05-08 09:07:37 +00:00
|
|
|
bool make_clockwise();
|
2013-08-28 23:40:42 +00:00
|
|
|
bool make_counter_clockwise();
|
2013-08-29 09:47:59 +00:00
|
|
|
void reverse();
|
2016-11-03 09:24:32 +00:00
|
|
|
Point first_point() const { return this->paths.front().polyline.points.front(); }
|
|
|
|
Point last_point() const { assert(first_point() == this->paths.back().polyline.points.back()); return first_point(); }
|
2015-01-25 14:21:45 +00:00
|
|
|
Polygon polygon() const;
|
2016-03-19 18:40:11 +00:00
|
|
|
virtual double length() const;
|
2014-11-08 11:56:14 +00:00
|
|
|
bool split_at_vertex(const Point &point);
|
2014-05-08 09:07:37 +00:00
|
|
|
void split_at(const Point &point);
|
|
|
|
void clip_end(double distance, ExtrusionPaths* paths) const;
|
2016-11-03 09:24:32 +00:00
|
|
|
// Test, whether the point is extruded by a bridging flow.
|
|
|
|
// This used to be used to avoid placing seams on overhangs, but now the EdgeGrid is used instead.
|
2014-05-08 09:07:37 +00:00
|
|
|
bool has_overhang_point(const Point &point) const;
|
2016-11-03 09:24:32 +00:00
|
|
|
bool is_perimeter() const {
|
|
|
|
return this->paths.front().role == erPerimeter
|
|
|
|
|| this->paths.front().role == erExternalPerimeter
|
|
|
|
|| this->paths.front().role == erOverhangPerimeter;
|
|
|
|
}
|
|
|
|
bool is_infill() const {
|
|
|
|
return this->paths.front().role == erBridgeInfill
|
|
|
|
|| this->paths.front().role == erInternalInfill
|
|
|
|
|| this->paths.front().role == erSolidInfill
|
|
|
|
|| this->paths.front().role == erTopSolidInfill;
|
|
|
|
}
|
|
|
|
bool is_solid_infill() const {
|
|
|
|
return this->paths.front().role == erBridgeInfill
|
|
|
|
|| this->paths.front().role == erSolidInfill
|
|
|
|
|| this->paths.front().role == erTopSolidInfill;
|
|
|
|
}
|
2016-11-03 23:10:35 +00:00
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const;
|
|
|
|
// Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion spacing.
|
|
|
|
// Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps.
|
|
|
|
// Useful to calculate area of an infill, which has been really filled in by a 100% rectilinear infill.
|
|
|
|
void polygons_covered_by_spacing(Polygons &out, const float scaled_epsilon) const;
|
|
|
|
Polygons polygons_covered_by_width(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_width(out, scaled_epsilon); return out; }
|
|
|
|
Polygons polygons_covered_by_spacing(const float scaled_epsilon = 0.f) const
|
|
|
|
{ Polygons out; this->polygons_covered_by_spacing(out, scaled_epsilon); return out; }
|
2016-11-03 09:24:32 +00:00
|
|
|
// Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm.
|
2015-05-31 20:04:32 +00:00
|
|
|
double min_mm3_per_mm() const;
|
2016-11-03 09:24:32 +00:00
|
|
|
Polyline as_polyline() const { return this->polygon().split_at_first_point(); }
|
2013-07-15 10:14:22 +00:00
|
|
|
};
|
|
|
|
|
2016-11-23 14:51:47 +00:00
|
|
|
inline void extrusion_entities_append_paths(ExtrusionEntitiesPtr &dst, Polylines &polylines, ExtrusionRole role, double mm3_per_mm, float width, float height)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + polylines.size());
|
|
|
|
for (Polylines::const_iterator it_polyline = polylines.begin(); it_polyline != polylines.end(); ++ it_polyline) {
|
|
|
|
ExtrusionPath *extrusion_path = new ExtrusionPath(role, mm3_per_mm, width, height);
|
|
|
|
dst.push_back(extrusion_path);
|
|
|
|
extrusion_path->polyline = *it_polyline;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SLIC3R_CPPVER >= 11
|
|
|
|
inline void extrusion_entities_append_paths(ExtrusionEntitiesPtr &dst, Polylines &&polylines, ExtrusionRole role, double mm3_per_mm, float width, float height)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + polylines.size());
|
|
|
|
for (Polylines::const_iterator it_polyline = polylines.begin(); it_polyline != polylines.end(); ++ it_polyline) {
|
|
|
|
ExtrusionPath *extrusion_path = new ExtrusionPath(role, mm3_per_mm, width, height);
|
|
|
|
dst.push_back(extrusion_path);
|
|
|
|
extrusion_path->polyline = std::move(*it_polyline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SLIC3R_CPPVER >= 11
|
|
|
|
|
2013-07-15 10:14:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|