#include "SVGExport.hpp" #include "SVG.hpp" #include #include #define COORD(x) ((float)unscale(x)*10) namespace Slic3r { SVGExport::SVGExport(TriangleMesh &t, float layerheight, float firstlayerheight) :t(&t), sliced(false) { if(layerheight>0){ for(float f=firstlayerheight;f<=t.stl.stats.max.z;f+=layerheight){ heights.push_back(f); } TriangleMeshSlicer(&t).slice(heights,&layers); sliced=true; } } // void SVGExport::writeSVG(const std::string &outputfile){ if(sliced){ FILE* f = fopen(outputfile.c_str(), "w"); fprintf(f, "\n" "\n" "\n" "\n" ,t->stl.stats.max.x*10,t->stl.stats.max.y*10,SLIC3R_VERSION); for (int i=0;i\n",i,heights[i]); for (ExPolygons::const_iterator it = layers[i].begin(); it != layers[i].end(); ++it){ std::string pd; Polygons pp = *it; for (Polygons::const_iterator mp = pp.begin(); mp != pp.end(); ++mp) { 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 << "z"; pd += d.str() + " "; } fprintf(f,"\t\t\n", pd.c_str(),"white","black","0" ); } fprintf(f,"\t\n"); } fprintf(f,"\n"); } } }