2013-07-14 11:05:55 +00:00
|
|
|
#ifndef slic3r_Surface_hpp_
|
|
|
|
#define slic3r_Surface_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2013-07-14 11:05:55 +00:00
|
|
|
#include "ExPolygon.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2016-10-13 14:00:22 +00:00
|
|
|
enum SurfaceType {
|
|
|
|
// Top horizontal surface, visible from the top.
|
|
|
|
stTop,
|
|
|
|
// Bottom horizontal surface, visible from the bottom, printed with a normal extrusion flow.
|
|
|
|
stBottom,
|
|
|
|
// Bottom horizontal surface, visible from the bottom, unsupported, printed with a bridging extrusion flow.
|
|
|
|
stBottomBridge,
|
|
|
|
// Normal sparse infill.
|
|
|
|
stInternal,
|
|
|
|
// Full infill, supporting the top surfaces and/or defining the verticall wall thickness.
|
|
|
|
stInternalSolid,
|
|
|
|
// 1st layer of dense infill over sparse infill, printed with a bridging extrusion flow.
|
|
|
|
stInternalBridge,
|
|
|
|
// stInternal turns into void surfaces if the sparse infill is used for supports only,
|
|
|
|
// or if sparse infill layers get combined into a single layer.
|
|
|
|
stInternalVoid,
|
|
|
|
// Inner/outer perimeters.
|
2017-03-02 15:42:26 +00:00
|
|
|
stPerimeter,
|
2019-09-04 14:11:16 +00:00
|
|
|
// Number of SurfaceType enums.
|
|
|
|
stCount,
|
2016-10-13 14:00:22 +00:00
|
|
|
};
|
2013-07-14 11:05:55 +00:00
|
|
|
|
|
|
|
class Surface
|
|
|
|
{
|
2016-10-13 14:00:22 +00:00
|
|
|
public:
|
2013-07-14 11:05:55 +00:00
|
|
|
SurfaceType surface_type;
|
2014-11-09 15:23:50 +00:00
|
|
|
ExPolygon expolygon;
|
2013-07-14 11:05:55 +00:00
|
|
|
double thickness; // in mm
|
|
|
|
unsigned short thickness_layers; // in layers
|
2014-04-21 21:21:15 +00:00
|
|
|
double bridge_angle; // in radians, ccw, 0 = East, only 0+ (negative means undefined)
|
2013-07-14 11:05:55 +00:00
|
|
|
unsigned short extra_perimeters;
|
2014-11-09 15:23:50 +00:00
|
|
|
|
2017-03-08 13:22:49 +00:00
|
|
|
Surface(const Slic3r::Surface &rhs)
|
|
|
|
: surface_type(rhs.surface_type), expolygon(rhs.expolygon),
|
|
|
|
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
|
|
|
|
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
|
|
|
|
{};
|
|
|
|
|
2014-11-09 15:23:50 +00:00
|
|
|
Surface(SurfaceType _surface_type, const ExPolygon &_expolygon)
|
|
|
|
: surface_type(_surface_type), expolygon(_expolygon),
|
|
|
|
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0)
|
|
|
|
{};
|
2016-11-02 09:47:00 +00:00
|
|
|
Surface(const Surface &other, const ExPolygon &_expolygon)
|
|
|
|
: surface_type(other.surface_type), expolygon(_expolygon),
|
2017-03-08 12:43:49 +00:00
|
|
|
thickness(other.thickness), thickness_layers(other.thickness_layers),
|
|
|
|
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
|
|
|
{};
|
|
|
|
Surface(Surface &&rhs)
|
|
|
|
: surface_type(rhs.surface_type), expolygon(std::move(rhs.expolygon)),
|
|
|
|
thickness(rhs.thickness), thickness_layers(rhs.thickness_layers),
|
|
|
|
bridge_angle(rhs.bridge_angle), extra_perimeters(rhs.extra_perimeters)
|
2016-11-02 09:47:00 +00:00
|
|
|
{};
|
|
|
|
Surface(SurfaceType _surface_type, const ExPolygon &&_expolygon)
|
|
|
|
: surface_type(_surface_type), expolygon(std::move(_expolygon)),
|
|
|
|
thickness(-1), thickness_layers(1), bridge_angle(-1), extra_perimeters(0)
|
|
|
|
{};
|
|
|
|
Surface(const Surface &other, const ExPolygon &&_expolygon)
|
|
|
|
: surface_type(other.surface_type), expolygon(std::move(_expolygon)),
|
2017-03-08 12:43:49 +00:00
|
|
|
thickness(other.thickness), thickness_layers(other.thickness_layers),
|
|
|
|
bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
2016-11-02 09:47:00 +00:00
|
|
|
{};
|
2017-03-08 12:43:49 +00:00
|
|
|
|
2017-03-08 13:22:49 +00:00
|
|
|
Surface& operator=(const Surface &rhs)
|
|
|
|
{
|
|
|
|
surface_type = rhs.surface_type;
|
|
|
|
expolygon = rhs.expolygon;
|
|
|
|
thickness = rhs.thickness;
|
|
|
|
thickness_layers = rhs.thickness_layers;
|
|
|
|
bridge_angle = rhs.bridge_angle;
|
|
|
|
extra_perimeters = rhs.extra_perimeters;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2017-03-08 12:43:49 +00:00
|
|
|
Surface& operator=(Surface &&rhs)
|
|
|
|
{
|
|
|
|
surface_type = rhs.surface_type;
|
|
|
|
expolygon = std::move(rhs.expolygon);
|
|
|
|
thickness = rhs.thickness;
|
|
|
|
thickness_layers = rhs.thickness_layers;
|
|
|
|
bridge_angle = rhs.bridge_angle;
|
|
|
|
extra_perimeters = rhs.extra_perimeters;
|
2017-03-08 13:22:49 +00:00
|
|
|
return *this;
|
2017-03-08 12:43:49 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 13:03:49 +00:00
|
|
|
operator Polygons() const { return this->expolygon; }
|
|
|
|
double area() const { return this->expolygon.area(); }
|
|
|
|
bool empty() const { return expolygon.empty(); }
|
|
|
|
void clear() { expolygon.clear(); }
|
|
|
|
|
|
|
|
// The following methods do not test for stPerimeter.
|
|
|
|
bool is_top() const { return this->surface_type == stTop; }
|
|
|
|
bool is_bottom() const { return this->surface_type == stBottom || this->surface_type == stBottomBridge; }
|
|
|
|
bool is_bridge() const { return this->surface_type == stBottomBridge || this->surface_type == stInternalBridge; }
|
|
|
|
bool is_external() const { return this->is_top() || this->is_bottom(); }
|
|
|
|
bool is_internal() const { return ! this->is_external(); }
|
|
|
|
bool is_solid() const { return this->is_external() || this->surface_type == stInternalSolid || this->surface_type == stInternalBridge; }
|
2013-07-14 11:05:55 +00:00
|
|
|
};
|
|
|
|
|
2013-07-18 17:09:07 +00:00
|
|
|
typedef std::vector<Surface> Surfaces;
|
2013-11-23 17:15:59 +00:00
|
|
|
typedef std::vector<Surface*> SurfacesPtr;
|
2013-07-18 17:09:07 +00:00
|
|
|
|
2016-11-02 09:47:00 +00:00
|
|
|
inline Polygons to_polygons(const Surfaces &src)
|
|
|
|
{
|
|
|
|
size_t num = 0;
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it)
|
|
|
|
num += it->expolygon.holes.size() + 1;
|
|
|
|
Polygons polygons;
|
|
|
|
polygons.reserve(num);
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
polygons.emplace_back(it->expolygon.contour);
|
2016-11-02 09:47:00 +00:00
|
|
|
for (Polygons::const_iterator ith = it->expolygon.holes.begin(); ith != it->expolygon.holes.end(); ++ith)
|
2017-03-08 12:43:49 +00:00
|
|
|
polygons.emplace_back(*ith);
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
}
|
|
|
|
|
2016-09-26 10:42:44 +00:00
|
|
|
inline Polygons to_polygons(const SurfacesPtr &src)
|
|
|
|
{
|
2016-11-02 09:47:00 +00:00
|
|
|
size_t num = 0;
|
|
|
|
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it)
|
|
|
|
num += (*it)->expolygon.holes.size() + 1;
|
2016-09-26 10:42:44 +00:00
|
|
|
Polygons polygons;
|
2016-11-02 09:47:00 +00:00
|
|
|
polygons.reserve(num);
|
2016-09-26 10:42:44 +00:00
|
|
|
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
polygons.emplace_back((*it)->expolygon.contour);
|
2016-11-02 09:47:00 +00:00
|
|
|
for (Polygons::const_iterator ith = (*it)->expolygon.holes.begin(); ith != (*it)->expolygon.holes.end(); ++ith)
|
2017-03-08 12:43:49 +00:00
|
|
|
polygons.emplace_back(*ith);
|
2016-09-26 10:42:44 +00:00
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
}
|
|
|
|
|
2016-11-17 22:22:59 +00:00
|
|
|
inline ExPolygons to_expolygons(const Surfaces &src)
|
|
|
|
{
|
|
|
|
ExPolygons expolygons;
|
|
|
|
expolygons.reserve(src.size());
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it)
|
2017-03-08 12:43:49 +00:00
|
|
|
expolygons.emplace_back(it->expolygon);
|
2016-11-17 22:22:59 +00:00
|
|
|
return expolygons;
|
|
|
|
}
|
|
|
|
|
2017-02-14 11:36:04 +00:00
|
|
|
inline ExPolygons to_expolygons(Surfaces &&src)
|
|
|
|
{
|
|
|
|
ExPolygons expolygons;
|
|
|
|
expolygons.reserve(src.size());
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++it)
|
|
|
|
expolygons.emplace_back(ExPolygon(std::move(it->expolygon)));
|
|
|
|
src.clear();
|
|
|
|
return expolygons;
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:13:36 +00:00
|
|
|
inline ExPolygons to_expolygons(const SurfacesPtr &src)
|
|
|
|
{
|
|
|
|
ExPolygons expolygons;
|
|
|
|
expolygons.reserve(src.size());
|
|
|
|
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++it)
|
2017-03-08 12:43:49 +00:00
|
|
|
expolygons.emplace_back((*it)->expolygon);
|
2016-11-11 10:13:36 +00:00
|
|
|
return expolygons;
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:47:00 +00:00
|
|
|
// Count a nuber of polygons stored inside the vector of expolygons.
|
|
|
|
// Useful for allocating space for polygons when converting expolygons to polygons.
|
|
|
|
inline size_t number_polygons(const Surfaces &surfaces)
|
|
|
|
{
|
|
|
|
size_t n_polygons = 0;
|
|
|
|
for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
|
|
|
|
n_polygons += it->expolygon.holes.size() + 1;
|
|
|
|
return n_polygons;
|
|
|
|
}
|
|
|
|
inline size_t number_polygons(const SurfacesPtr &surfaces)
|
|
|
|
{
|
|
|
|
size_t n_polygons = 0;
|
|
|
|
for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
|
|
|
|
n_polygons += (*it)->expolygon.holes.size() + 1;
|
|
|
|
return n_polygons;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append a vector of Surfaces at the end of another vector of polygons.
|
|
|
|
inline void polygons_append(Polygons &dst, const Surfaces &src)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
dst.emplace_back(it->expolygon.contour);
|
2016-11-02 09:47:00 +00:00
|
|
|
dst.insert(dst.end(), it->expolygon.holes.begin(), it->expolygon.holes.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void polygons_append(Polygons &dst, Surfaces &&src)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
2017-01-20 13:39:44 +00:00
|
|
|
for (Surfaces::iterator it = src.begin(); it != src.end(); ++ it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
dst.emplace_back(std::move(it->expolygon.contour));
|
2016-11-02 20:29:59 +00:00
|
|
|
std::move(std::begin(it->expolygon.holes), std::end(it->expolygon.holes), std::back_inserter(dst));
|
2017-01-20 13:39:44 +00:00
|
|
|
it->expolygon.holes.clear();
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append a vector of Surfaces at the end of another vector of polygons.
|
|
|
|
inline void polygons_append(Polygons &dst, const SurfacesPtr &src)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
dst.emplace_back((*it)->expolygon.contour);
|
2016-11-02 09:47:00 +00:00
|
|
|
dst.insert(dst.end(), (*it)->expolygon.holes.begin(), (*it)->expolygon.holes.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void polygons_append(Polygons &dst, SurfacesPtr &&src)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (SurfacesPtr::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
2017-03-08 12:43:49 +00:00
|
|
|
dst.emplace_back(std::move((*it)->expolygon.contour));
|
2016-11-02 20:29:59 +00:00
|
|
|
std::move(std::begin((*it)->expolygon.holes), std::end((*it)->expolygon.holes), std::back_inserter(dst));
|
2017-01-20 13:39:44 +00:00
|
|
|
(*it)->expolygon.holes.clear();
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append a vector of Surfaces at the end of another vector of polygons.
|
|
|
|
inline void surfaces_append(Surfaces &dst, const ExPolygons &src, SurfaceType surfaceType)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + src.size());
|
2017-03-08 12:43:49 +00:00
|
|
|
for (const ExPolygon &expoly : src)
|
|
|
|
dst.emplace_back(Surface(surfaceType, expoly));
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
|
|
|
inline void surfaces_append(Surfaces &dst, const ExPolygons &src, const Surface &surfaceTempl)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
2017-03-08 12:43:49 +00:00
|
|
|
for (const ExPolygon &expoly : src)
|
|
|
|
dst.emplace_back(Surface(surfaceTempl, expoly));
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
2016-11-07 21:49:11 +00:00
|
|
|
inline void surfaces_append(Surfaces &dst, const Surfaces &src)
|
|
|
|
{
|
|
|
|
dst.insert(dst.end(), src.begin(), src.end());
|
|
|
|
}
|
2016-11-02 09:47:00 +00:00
|
|
|
|
|
|
|
inline void surfaces_append(Surfaces &dst, ExPolygons &&src, SurfaceType surfaceType)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + src.size());
|
2017-03-08 12:43:49 +00:00
|
|
|
for (ExPolygon &expoly : src)
|
|
|
|
dst.emplace_back(Surface(surfaceType, std::move(expoly)));
|
2017-01-20 13:39:44 +00:00
|
|
|
src.clear();
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
2017-01-20 13:39:44 +00:00
|
|
|
|
2016-11-02 09:47:00 +00:00
|
|
|
inline void surfaces_append(Surfaces &dst, ExPolygons &&src, const Surface &surfaceTempl)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
2017-03-08 12:43:49 +00:00
|
|
|
dst.emplace_back(Surface(surfaceTempl, std::move(*it)));
|
2017-01-20 13:39:44 +00:00
|
|
|
src.clear();
|
2016-11-02 09:47:00 +00:00
|
|
|
}
|
2017-03-08 12:43:49 +00:00
|
|
|
|
2016-11-07 21:49:11 +00:00
|
|
|
inline void surfaces_append(Surfaces &dst, Surfaces &&src)
|
|
|
|
{
|
2017-01-20 13:39:44 +00:00
|
|
|
if (dst.empty()) {
|
2016-11-07 21:49:11 +00:00
|
|
|
dst = std::move(src);
|
2017-01-20 13:39:44 +00:00
|
|
|
} else {
|
2016-11-07 21:49:11 +00:00
|
|
|
std::move(std::begin(src), std::end(src), std::back_inserter(dst));
|
2017-01-20 13:39:44 +00:00
|
|
|
src.clear();
|
|
|
|
}
|
2016-11-07 21:49:11 +00:00
|
|
|
}
|
2016-11-02 09:47:00 +00:00
|
|
|
|
2016-09-13 11:30:00 +00:00
|
|
|
extern BoundingBox get_extents(const Surface &surface);
|
|
|
|
extern BoundingBox get_extents(const Surfaces &surfaces);
|
|
|
|
extern BoundingBox get_extents(const SurfacesPtr &surfaces);
|
|
|
|
|
2016-11-07 21:49:11 +00:00
|
|
|
inline bool surfaces_could_merge(const Surface &s1, const Surface &s2)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
s1.surface_type == s2.surface_type &&
|
|
|
|
s1.thickness == s2.thickness &&
|
|
|
|
s1.thickness_layers == s2.thickness_layers &&
|
|
|
|
s1.bridge_angle == s2.bridge_angle;
|
|
|
|
}
|
|
|
|
|
2016-09-26 10:42:44 +00:00
|
|
|
class SVG;
|
|
|
|
|
|
|
|
extern const char* surface_type_to_color_name(const SurfaceType surface_type);
|
|
|
|
extern void export_surface_type_legend_to_svg(SVG &svg, const Point &pos);
|
|
|
|
extern Point export_surface_type_legend_to_svg_box_size();
|
|
|
|
extern bool export_to_svg(const char *path, const Surfaces &surfaces, const float transparency = 1.f);
|
|
|
|
|
2013-07-14 11:05:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|