New routines for debugging visualization of surfaces & infills.

This commit is contained in:
bubnikv 2016-09-26 12:45:23 +02:00
parent 4046552dd1
commit edc70e27d9
2 changed files with 120 additions and 14 deletions

View File

@ -82,7 +82,7 @@ SVG::draw(const IntersectionLines &lines, std::string stroke)
} }
void void
SVG::draw(const ExPolygon &expolygon, std::string fill) SVG::draw(const ExPolygon &expolygon, std::string fill, const float fill_opacity)
{ {
this->fill = fill; this->fill = fill;
@ -91,21 +91,77 @@ SVG::draw(const ExPolygon &expolygon, std::string fill)
for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) { for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
d += this->get_path_d(*p, true) + " "; d += this->get_path_d(*p, true) + " ";
} }
this->path(d, true, 0); this->path(d, true, 0, fill_opacity);
} }
void void
SVG::draw(const ExPolygons &expolygons, std::string fill) SVG::draw_outline(const ExPolygon &expolygon, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
draw_outline(expolygon.contour, stroke_outer, stroke_width);
for (Polygons::const_iterator it = expolygon.holes.begin(); it != expolygon.holes.end(); ++ it) {
draw_outline(*it, stroke_holes, stroke_width);
}
}
void
SVG::draw(const ExPolygons &expolygons, std::string fill, const float fill_opacity)
{ {
for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++it) for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++it)
this->draw(*it, fill); this->draw(*it, fill, fill_opacity);
}
void
SVG::draw_outline(const ExPolygons &expolygons, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
for (ExPolygons::const_iterator it = expolygons.begin(); it != expolygons.end(); ++ it)
draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
}
void
SVG::draw(const Surface &surface, std::string fill, const float fill_opacity)
{
draw(surface.expolygon, fill, fill_opacity);
}
void
SVG::draw_outline(const Surface &surface, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
draw_outline(surface.expolygon, stroke_outer, stroke_holes, stroke_width);
}
void
SVG::draw(const Surfaces &surfaces, std::string fill, const float fill_opacity)
{
for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
this->draw(*it, fill, fill_opacity);
}
void
SVG::draw_outline(const Surfaces &surfaces, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
for (Surfaces::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
draw_outline(*it, stroke_outer, stroke_holes, stroke_width);
}
void
SVG::draw(const SurfacesPtr &surfaces, std::string fill, const float fill_opacity)
{
for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
this->draw(*(*it), fill, fill_opacity);
}
void
SVG::draw_outline(const SurfacesPtr &surfaces, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
for (SurfacesPtr::const_iterator it = surfaces.begin(); it != surfaces.end(); ++ it)
draw_outline(*(*it), stroke_outer, stroke_holes, stroke_width);
} }
void void
SVG::draw(const Polygon &polygon, std::string fill) SVG::draw(const Polygon &polygon, std::string fill)
{ {
this->fill = fill; this->fill = fill;
this->path(this->get_path_d(polygon, true), !fill.empty(), 0); this->path(this->get_path_d(polygon, true), !fill.empty(), 0, 1.f);
} }
void void
@ -119,7 +175,7 @@ void
SVG::draw(const Polyline &polyline, std::string stroke, coordf_t stroke_width) SVG::draw(const Polyline &polyline, std::string stroke, coordf_t stroke_width)
{ {
this->stroke = stroke; this->stroke = stroke;
this->path(this->get_path_d(polyline, false), false, stroke_width); this->path(this->get_path_d(polyline, false), false, stroke_width, 1.f);
} }
void void
@ -172,7 +228,7 @@ void
SVG::draw(const ClipperLib::Path &polygon, double scale, std::string stroke, coordf_t stroke_width) SVG::draw(const ClipperLib::Path &polygon, double scale, std::string stroke, coordf_t stroke_width)
{ {
this->stroke = stroke; this->stroke = stroke;
this->path(this->get_path_d(polygon, scale, true), false, stroke_width); this->path(this->get_path_d(polygon, scale, true), false, stroke_width, 1.f);
} }
void void
@ -186,7 +242,7 @@ void
SVG::draw_outline(const Polygon &polygon, std::string stroke, coordf_t stroke_width) SVG::draw_outline(const Polygon &polygon, std::string stroke, coordf_t stroke_width)
{ {
this->stroke = stroke; this->stroke = stroke;
this->path(this->get_path_d(polygon, true), false, stroke_width); this->path(this->get_path_d(polygon, true), false, stroke_width, 1.f);
} }
void void
@ -197,7 +253,7 @@ SVG::draw_outline(const Polygons &polygons, std::string stroke, coordf_t stroke_
} }
void void
SVG::path(const std::string &d, bool fill, coordf_t stroke_width) SVG::path(const std::string &d, bool fill, coordf_t stroke_width, const float fill_opacity)
{ {
float lineWidth = 0.f; float lineWidth = 0.f;
if (! fill) if (! fill)
@ -205,12 +261,13 @@ SVG::path(const std::string &d, bool fill, coordf_t stroke_width)
fprintf( fprintf(
this->f, this->f,
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %f; fill-type: evenodd\" %s />\n", " <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %f; fill-type: evenodd\" %s fill-opacity=\"%f\" />\n",
d.c_str(), d.c_str(),
fill ? this->fill.c_str() : "none", fill ? this->fill.c_str() : "none",
this->stroke.c_str(), this->stroke.c_str(),
lineWidth, lineWidth,
(this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : "" (this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : "",
fill_opacity
); );
} }
@ -240,6 +297,29 @@ SVG::get_path_d(const ClipperLib::Path &path, double scale, bool closed) const
return d.str(); return d.str();
} }
void SVG::draw_text(const Point &pt, const char *text, const char *color)
{
fprintf(this->f,
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"20px\" fill=\"%s\">%s</text>",
COORD(pt.x-origin.x),
COORD(pt.y-origin.y),
color, text);
}
void SVG::draw_legend(const Point &pt, const char *text, const char *color)
{
fprintf(this->f,
"<circle cx=\"%f\" cy=\"%f\" r=\"10\" fill=\"%s\"/>",
COORD(pt.x-origin.x),
COORD(pt.y-origin.y),
color);
fprintf(this->f,
"<text x=\"%f\" y=\"%f\" font-family=\"sans-serif\" font-size=\"10px\" fill=\"%s\">%s</text>",
COORD(pt.x-origin.x) + 20.f,
COORD(pt.y-origin.y),
"black", text);
}
void void
SVG::Close() SVG::Close()
{ {
@ -249,4 +329,12 @@ SVG::Close()
printf("SVG written to %s\n", this->filename.c_str()); printf("SVG written to %s\n", this->filename.c_str());
} }
void SVG::export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer, std::string stroke_holes, coordf_t stroke_width)
{
SVG svg(path, bbox);
svg.draw(expolygons);
svg.draw_outline(expolygons, stroke_outer, stroke_holes, stroke_width);
svg.Close();
}
} }

View File

@ -6,6 +6,7 @@
#include "ExPolygon.hpp" #include "ExPolygon.hpp"
#include "Line.hpp" #include "Line.hpp"
#include "TriangleMesh.hpp" #include "TriangleMesh.hpp"
#include "Surface.hpp"
namespace Slic3r { namespace Slic3r {
@ -25,8 +26,19 @@ class SVG
void draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width = 0); void draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coordf_t stroke_width = 0);
void draw(const Lines &lines, std::string stroke = "black", coordf_t stroke_width = 0); void draw(const Lines &lines, std::string stroke = "black", coordf_t stroke_width = 0);
void draw(const IntersectionLines &lines, std::string stroke = "black"); void draw(const IntersectionLines &lines, std::string stroke = "black");
void draw(const ExPolygon &expolygon, std::string fill = "grey");
void draw(const ExPolygons &expolygons, std::string fill = "grey"); void draw(const ExPolygon &expolygon, std::string fill = "grey", const float fill_opacity=1.f);
void draw_outline(const ExPolygon &polygon, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
void draw(const ExPolygons &expolygons, std::string fill = "grey", const float fill_opacity=1.f);
void draw_outline(const ExPolygons &polygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
void draw(const Surface &surface, std::string fill = "grey", const float fill_opacity=1.f);
void draw_outline(const Surface &surface, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
void draw(const Surfaces &surfaces, std::string fill = "grey", const float fill_opacity=1.f);
void draw_outline(const Surfaces &surfaces, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
void draw(const SurfacesPtr &surfaces, std::string fill = "grey", const float fill_opacity=1.f);
void draw_outline(const SurfacesPtr &surfaces, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
void draw(const Polygon &polygon, std::string fill = "grey"); void draw(const Polygon &polygon, std::string fill = "grey");
void draw_outline(const Polygon &polygon, std::string stroke = "black", coordf_t stroke_width = 0); void draw_outline(const Polygon &polygon, std::string stroke = "black", coordf_t stroke_width = 0);
void draw(const Polygons &polygons, std::string fill = "grey"); void draw(const Polygons &polygons, std::string fill = "grey");
@ -43,15 +55,21 @@ class SVG
void draw(const ClipperLib::Path &polygon, double scale, std::string fill = "grey", coordf_t stroke_width = 0); void draw(const ClipperLib::Path &polygon, double scale, std::string fill = "grey", coordf_t stroke_width = 0);
void draw(const ClipperLib::Paths &polygons, double scale, std::string fill = "grey", coordf_t stroke_width = 0); void draw(const ClipperLib::Paths &polygons, double scale, std::string fill = "grey", coordf_t stroke_width = 0);
void draw_text(const Point &pt, const char *text, const char *color);
void draw_legend(const Point &pt, const char *text, const char *color);
void Close(); void Close();
private: private:
std::string filename; std::string filename;
FILE* f; FILE* f;
void path(const std::string &d, bool fill, coordf_t stroke_width); void path(const std::string &d, bool fill, coordf_t stroke_width, const float fill_opacity);
std::string get_path_d(const MultiPoint &mp, bool closed = false) const; std::string get_path_d(const MultiPoint &mp, bool closed = false) const;
std::string get_path_d(const ClipperLib::Path &mp, double scale, bool closed = false) const; std::string get_path_d(const ClipperLib::Path &mp, double scale, bool closed = false) const;
public:
static void export_expolygons(const char *path, const BoundingBox &bbox, const Slic3r::ExPolygons &expolygons, std::string stroke_outer = "black", std::string stroke_holes = "blue", coordf_t stroke_width = 0);
}; };
} }