mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 17:27:52 -06:00
Debugging visualization of the gap fills into a SVG format, if SLIC3R_DEBUG is set.
This commit is contained in:
parent
9576973b57
commit
4156b51c18
4 changed files with 573 additions and 27 deletions
|
@ -19,18 +19,54 @@ SVG::SVG(const char* filename)
|
|||
);
|
||||
}
|
||||
|
||||
SVG::SVG(const char* filename, const BoundingBox &bbox)
|
||||
: arrows(false), fill("grey"), stroke("black"), filename(filename), origin(bbox.min)
|
||||
{
|
||||
this->f = fopen(filename, "w");
|
||||
float w = COORD(bbox.max.x - bbox.min.x);
|
||||
float h = COORD(bbox.max.y - bbox.min.y);
|
||||
fprintf(this->f,
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
|
||||
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">\n"
|
||||
"<svg height=\"%f\" width=\"%f\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"
|
||||
" <marker id=\"endArrow\" markerHeight=\"8\" markerUnits=\"strokeWidth\" markerWidth=\"10\" orient=\"auto\" refX=\"1\" refY=\"5\" viewBox=\"0 0 10 10\">\n"
|
||||
" <polyline fill=\"darkblue\" points=\"0,0 10,5 0,10 1,5\" />\n"
|
||||
" </marker>\n",
|
||||
h, w);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Line &line, std::string stroke)
|
||||
SVG::draw(const Line &line, std::string stroke, coord_t stroke_width)
|
||||
{
|
||||
fprintf(this->f,
|
||||
" <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: 1\"",
|
||||
COORD(line.a.x), COORD(line.a.y), COORD(line.b.x), COORD(line.b.y), stroke.c_str()
|
||||
);
|
||||
" <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: %s; stroke-width: %f\"",
|
||||
COORD(line.a.x - origin.x), COORD(line.a.y - origin.y), COORD(line.b.x - origin.x), COORD(line.b.y - origin.y), stroke.c_str(), (stroke_width == 0) ? 1.f : COORD(stroke_width));
|
||||
if (this->arrows)
|
||||
fprintf(this->f, " marker-end=\"url(#endArrow)\"");
|
||||
fprintf(this->f, "/>\n");
|
||||
}
|
||||
|
||||
void SVG::draw(const ThickLine &line, const std::string &fill, const std::string &stroke, coord_t stroke_width)
|
||||
{
|
||||
Pointf dir(line.b.x-line.a.x, line.b.y-line.a.y);
|
||||
Pointf perp(-dir.y, dir.x);
|
||||
coordf_t len = sqrt(perp.x*perp.x + perp.y*perp.y);
|
||||
coordf_t da = coordf_t(0.5)*line.a_width/len;
|
||||
coordf_t db = coordf_t(0.5)*line.b_width/len;
|
||||
fprintf(this->f,
|
||||
" <polygon points=\"%f,%f %f,%f %f,%f %f,%f\" style=\"fill:%s; stroke: %s; stroke-width: %f\"/>\n",
|
||||
COORD(line.a.x-da*perp.x-origin.x),
|
||||
COORD(line.a.y-da*perp.y-origin.y),
|
||||
COORD(line.b.x-db*perp.x-origin.x),
|
||||
COORD(line.b.y-db*perp.y-origin.y),
|
||||
COORD(line.b.x+db*perp.x-origin.x),
|
||||
COORD(line.b.y+db*perp.y-origin.y),
|
||||
COORD(line.a.x+da*perp.x-origin.x),
|
||||
COORD(line.a.y+da*perp.y-origin.y),
|
||||
fill.c_str(), stroke.c_str(),
|
||||
(stroke_width == 0) ? 1.f : COORD(stroke_width));
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Lines &lines, std::string stroke)
|
||||
{
|
||||
|
@ -80,31 +116,45 @@ SVG::draw(const Polygons &polygons, std::string fill)
|
|||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Polyline &polyline, std::string stroke)
|
||||
SVG::draw(const Polyline &polyline, std::string stroke, coord_t stroke_width)
|
||||
{
|
||||
this->stroke = stroke;
|
||||
this->path(this->get_path_d(polyline, false), false);
|
||||
this->path(this->get_path_d(polyline, false), false, stroke_width);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Polylines &polylines, std::string stroke)
|
||||
SVG::draw(const Polylines &polylines, std::string stroke, coord_t stroke_width)
|
||||
{
|
||||
for (Polylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it)
|
||||
this->draw(*it, stroke);
|
||||
this->draw(*it, fill, stroke_width);
|
||||
}
|
||||
|
||||
void SVG::draw(const ThickLines &thicklines, const std::string &fill, const std::string &stroke, coord_t stroke_width)
|
||||
{
|
||||
for (ThickLines::const_iterator it = thicklines.begin(); it != thicklines.end(); ++it)
|
||||
this->draw(*it, fill, stroke, stroke_width);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const ThickPolylines &polylines, std::string stroke)
|
||||
SVG::draw(const ThickPolylines &polylines, const std::string &stroke, coord_t stroke_width)
|
||||
{
|
||||
for (ThickPolylines::const_iterator it = polylines.begin(); it != polylines.end(); ++it)
|
||||
this->draw((Polyline)*it, stroke);
|
||||
this->draw((Polyline)*it, stroke, stroke_width);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const ThickPolylines &thickpolylines, const std::string &fill, const std::string &stroke, coord_t stroke_width)
|
||||
{
|
||||
for (ThickPolylines::const_iterator it = thickpolylines.begin(); it != thickpolylines.end(); ++ it)
|
||||
draw(it->thicklines(), fill, stroke, stroke_width);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Point &point, std::string fill, unsigned int radius)
|
||||
SVG::draw(const Point &point, std::string fill, coord_t iradius)
|
||||
{
|
||||
float radius = (iradius == 0) ? 3.f : COORD(iradius);
|
||||
std::ostringstream svg;
|
||||
svg << " <circle cx=\"" << COORD(point.x) << "\" cy=\"" << COORD(point.y)
|
||||
svg << " <circle cx=\"" << COORD(point.x - origin.x) << "\" cy=\"" << COORD(point.y - origin.y)
|
||||
<< "\" r=\"" << radius << "\" "
|
||||
<< "style=\"stroke: none; fill: " << fill << "\" />";
|
||||
|
||||
|
@ -112,22 +162,26 @@ SVG::draw(const Point &point, std::string fill, unsigned int radius)
|
|||
}
|
||||
|
||||
void
|
||||
SVG::draw(const Points &points, std::string fill, unsigned int radius)
|
||||
SVG::draw(const Points &points, std::string fill, coord_t radius)
|
||||
{
|
||||
for (Points::const_iterator it = points.begin(); it != points.end(); ++it)
|
||||
this->draw(*it, fill, radius);
|
||||
}
|
||||
|
||||
void
|
||||
SVG::path(const std::string &d, bool fill)
|
||||
SVG::path(const std::string &d, bool fill, coord_t stroke_width)
|
||||
{
|
||||
float lineWidth = 0.f;
|
||||
if (! fill)
|
||||
lineWidth = (stroke_width == 0) ? 2.f : COORD(stroke_width);
|
||||
|
||||
fprintf(
|
||||
this->f,
|
||||
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %s; fill-type: evenodd\" %s />\n",
|
||||
" <path d=\"%s\" style=\"fill: %s; stroke: %s; stroke-width: %f; fill-type: evenodd\" %s />\n",
|
||||
d.c_str(),
|
||||
fill ? this->fill.c_str() : "none",
|
||||
this->stroke.c_str(),
|
||||
fill ? "0" : "2",
|
||||
lineWidth,
|
||||
(this->arrows && !fill) ? " marker-end=\"url(#endArrow)\"" : ""
|
||||
);
|
||||
}
|
||||
|
@ -138,8 +192,8 @@ SVG::get_path_d(const MultiPoint &mp, bool closed) const
|
|||
std::ostringstream d;
|
||||
d << "M ";
|
||||
for (Points::const_iterator p = mp.points.begin(); p != mp.points.end(); ++p) {
|
||||
d << COORD(p->x) << " ";
|
||||
d << COORD(p->y) << " ";
|
||||
d << COORD(p->x - origin.x) << " ";
|
||||
d << COORD(p->y - origin.y) << " ";
|
||||
}
|
||||
if (closed) d << "z";
|
||||
return d.str();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue