From 437e9be32972cbb96867872e471a443a7826ba47 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 9 Jul 2016 15:30:31 +0200 Subject: [PATCH] Fix sizes of SVG output --- src/slic3r.cpp | 6 +----- xs/src/libslic3r/SVGExport.cpp | 24 ++++++++++++++++-------- xs/src/libslic3r/SVGExport.hpp | 6 ++++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/slic3r.cpp b/src/slic3r.cpp index 0b2dbf0ae9..ac888deebe 100644 --- a/src/slic3r.cpp +++ b/src/slic3r.cpp @@ -80,12 +80,8 @@ main(const int argc, const char **argv) } else if (cli_config.export_svg) { std::string outfile = cli_config.output.value; if (outfile.empty()) outfile = model->objects.front()->input_file + ".svg"; - - TriangleMesh mesh = model->mesh(); - mesh.mirror_x(); - mesh.align_to_origin(); - SVGExport svg_export(mesh); + SVGExport svg_export(model->mesh()); svg_export.config.apply(print_config, true); svg_export.writeSVG(outfile); printf("SVG file exported to %s\n", outfile.c_str()); diff --git a/xs/src/libslic3r/SVGExport.cpp b/xs/src/libslic3r/SVGExport.cpp index df2ba5940c..c34b5216ed 100644 --- a/xs/src/libslic3r/SVGExport.cpp +++ b/xs/src/libslic3r/SVGExport.cpp @@ -2,13 +2,23 @@ #include "ClipperUtils.hpp" #include #include -#define COORD(x) ((float)unscale(x)*10) namespace Slic3r { void SVGExport::writeSVG(const std::string &outputfile) { + // align to origin taking raft into account + BoundingBoxf3 bb = this->mesh.bounding_box(); + if (this->config.raft_layers > 0) { + bb.min.x -= this->config.raft_offset.value; + bb.min.y -= this->config.raft_offset.value; + bb.max.x += this->config.raft_offset.value; + bb.max.y += this->config.raft_offset.value; + } + this->mesh.translate(-bb.min.x, -bb.min.y, -bb.min.z); // align to origin + const Sizef3 size = bb.size(); + // if we are generating a raft, first_layer_height will not affect mesh slicing const float lh = this->config.layer_height.value; const float first_lh = this->config.first_layer_height.value; @@ -21,14 +31,14 @@ SVGExport::writeSVG(const std::string &outputfile) slice_z.push_back(first_slice_lh/2); layer_z.push_back(first_slice_lh); } - while (layer_z.back() + lh/2 <= this->mesh->stl.stats.max.z) { + while (layer_z.back() + lh/2 <= this->mesh.stl.stats.max.z) { slice_z.push_back(layer_z.back() + lh/2); layer_z.push_back(layer_z.back() + lh); } // perform the slicing std::vector layers; - TriangleMeshSlicer(this->mesh).slice(slice_z, &layers); + TriangleMeshSlicer(&this->mesh).slice(slice_z, &layers); // generate a solid raft if requested if (this->config.raft_layers > 0) { @@ -49,9 +59,7 @@ SVGExport::writeSVG(const std::string &outputfile) "\n" "\n" "\n" - , this->mesh->stl.stats.max.x*10, this->mesh->stl.stats.max.y*10, SLIC3R_VERSION); - - // + , size.x, size.y, SLIC3R_VERSION); for (size_t i = 0; i < layer_z.size(); ++i) { fprintf(f, "\t\n", i, layer_z[i]); @@ -62,8 +70,8 @@ SVGExport::writeSVG(const std::string &outputfile) 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 << unscale(p->x) << " "; + d << unscale(p->y) << " "; } d << "z"; pd += d.str() + " "; diff --git a/xs/src/libslic3r/SVGExport.hpp b/xs/src/libslic3r/SVGExport.hpp index 3b24d1bd17..b77a21fa88 100644 --- a/xs/src/libslic3r/SVGExport.hpp +++ b/xs/src/libslic3r/SVGExport.hpp @@ -14,11 +14,13 @@ class SVGExport public: SVGExportConfig config; - SVGExport(TriangleMesh &mesh) : mesh(&mesh) {}; + SVGExport(const TriangleMesh &mesh) : mesh(mesh) { + this->mesh.mirror_x(); + }; void writeSVG(const std::string &outputfile); private: - TriangleMesh* mesh; + TriangleMesh mesh; }; }