Utility function SVG::export_expolygons() to paint a set of possibly

overlapping ExPolygons with attributes.
This commit is contained in:
bubnikv 2017-03-02 16:32:43 +01:00
parent dff5bda202
commit 07fa15806f
2 changed files with 52 additions and 0 deletions

View file

@ -345,4 +345,28 @@ void SVG::export_expolygons(const char *path, const BoundingBox &bbox, const Sli
svg.Close();
}
void SVG::export_expolygons(const char *path, const std::vector<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &expolygons_with_attributes)
{
if (expolygons_with_attributes.empty())
return;
BoundingBox bbox = get_extents(expolygons_with_attributes.front().first);
for (size_t i = 0; i < expolygons_with_attributes.size(); ++ i)
bbox.merge(get_extents(expolygons_with_attributes[i].first));
SVG svg(path, bbox);
for (const auto &exp_with_attr : expolygons_with_attributes)
svg.draw(exp_with_attr.first, exp_with_attr.second.color_fill, exp_with_attr.second.fill_opacity);
for (const auto &exp_with_attr : expolygons_with_attributes) {
std::string color_contour = exp_with_attr.second.color_contour;
if (color_contour.empty())
color_contour = exp_with_attr.second.color_fill;
std::string color_holes = exp_with_attr.second.color_holes;
if (color_holes.empty())
color_holes = color_contour;
svg.draw_outline(exp_with_attr.first, color_contour, color_holes, exp_with_attr.second.outline_width);
}
svg.Close();
}
}

View file

@ -93,6 +93,34 @@ public:
{ export_expolygons(path, get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); }
static void export_expolygons(const std::string &path, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0)
{ export_expolygons(path.c_str(), get_extents(expolygons), expolygons, stroke_outer, stroke_holes, stroke_width); }
struct ExPolygonAttributes
{
ExPolygonAttributes() : ExPolygonAttributes("gray", "black", "blue") {}
ExPolygonAttributes(const std::string &color) :
ExPolygonAttributes(color, color, color) {}
ExPolygonAttributes(
const std::string &color_fill,
const std::string &color_contour,
const std::string &color_holes,
const coord_t outline_width = scale_(0.05),
const float fill_opacity = 0.5f) :
color_fill (color_fill),
color_contour (color_contour),
color_holes (color_holes),
outline_width (outline_width),
fill_opacity (fill_opacity)
{}
std::string color_fill;
std::string color_contour;
std::string color_holes;
coord_t outline_width;
float fill_opacity;
};
static void export_expolygons(const char *path, const std::vector<std::pair<Slic3r::ExPolygons, ExPolygonAttributes>> &expolygons_with_attributes);
};
}