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.
|
|
|
|
stPerimeter
|
|
|
|
};
|
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
|
|
|
|
|
|
|
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),
|
|
|
|
thickness(other.thickness), thickness_layers(other.thickness_layers), bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
|
|
|
{};
|
|
|
|
#if SLIC3R_CPPVER >= 11
|
|
|
|
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)),
|
|
|
|
thickness(other.thickness), thickness_layers(other.thickness_layers), bridge_angle(other.bridge_angle), extra_perimeters(other.extra_perimeters)
|
|
|
|
{};
|
|
|
|
#endif
|
2015-10-26 22:23:03 +00:00
|
|
|
operator Polygons() const;
|
2013-09-06 16:36:38 +00:00
|
|
|
double area() const;
|
2013-11-22 23:07:04 +00:00
|
|
|
bool is_solid() const;
|
2014-02-10 12:19:44 +00:00
|
|
|
bool is_external() const;
|
2014-12-09 00:08:58 +00:00
|
|
|
bool is_internal() const;
|
2014-03-25 00:11:28 +00:00
|
|
|
bool is_bottom() const;
|
2013-11-22 23:07:04 +00:00
|
|
|
bool is_bridge() const;
|
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) {
|
|
|
|
polygons.push_back(it->expolygon.contour);
|
|
|
|
for (Polygons::const_iterator ith = it->expolygon.holes.begin(); ith != it->expolygon.holes.end(); ++ith)
|
|
|
|
polygons.push_back(*ith);
|
|
|
|
}
|
|
|
|
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) {
|
|
|
|
polygons.push_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)
|
2016-09-26 10:42:44 +00:00
|
|
|
polygons.push_back(*ith);
|
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:47:00 +00:00
|
|
|
#if SLIC3R_CPPVER >= 11
|
2016-09-26 10:42:44 +00:00
|
|
|
inline Polygons to_polygons(SurfacesPtr &&src)
|
|
|
|
{
|
2016-11-02 09:47:00 +00:00
|
|
|
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 (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++it) {
|
|
|
|
polygons.push_back(std::move((*it)->expolygon.contour));
|
|
|
|
for (Polygons::const_iterator ith = (*it)->expolygon.holes.begin(); ith != (*it)->expolygon.holes.end(); ++ith) {
|
|
|
|
polygons.push_back(std::move(*ith));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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) {
|
|
|
|
dst.push_back(it->expolygon.contour);
|
|
|
|
dst.insert(dst.end(), it->expolygon.holes.begin(), it->expolygon.holes.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SLIC3R_CPPVER >= 11
|
|
|
|
inline void polygons_append(Polygons &dst, Surfaces &&src)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (Surfaces::const_iterator it = src.begin(); it != src.end(); ++ it) {
|
|
|
|
dst.push_back(std::move(it->expolygon.contour));
|
|
|
|
std::move(std::begin(it->expolygon.contour), std::end(it->expolygon.contour), std::back_inserter(dst));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
dst.push_back((*it)->expolygon.contour);
|
|
|
|
dst.insert(dst.end(), (*it)->expolygon.holes.begin(), (*it)->expolygon.holes.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SLIC3R_CPPVER >= 11
|
|
|
|
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) {
|
|
|
|
dst.push_back(std::move((*it)->expolygon.contour));
|
|
|
|
std::move(std::begin((*it)->expolygon.contour), std::end((*it)->expolygon.contour), std::back_inserter(dst));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
|
|
|
dst.push_back(Surface(surfaceType, *it));
|
|
|
|
}
|
|
|
|
inline void surfaces_append(Surfaces &dst, const ExPolygons &src, const Surface &surfaceTempl)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + number_polygons(src));
|
|
|
|
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
|
|
|
dst.push_back(Surface(surfaceTempl, *it));
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SLIC3R_CPPVER >= 11
|
|
|
|
inline void surfaces_append(Surfaces &dst, ExPolygons &&src, SurfaceType surfaceType)
|
|
|
|
{
|
|
|
|
dst.reserve(dst.size() + src.size());
|
|
|
|
for (ExPolygons::const_iterator it = src.begin(); it != src.end(); ++ it)
|
|
|
|
dst.push_back(Surface(surfaceType, std::move(*it)));
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
dst.push_back(Surface(surfaceTempl, std::move(*it)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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-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
|