diff --git a/xs/MANIFEST b/xs/MANIFEST index 9514db695c..541ad30d53 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -37,6 +37,8 @@ src/ppport.h src/Surface.cpp src/Surface.hpp src/SurfaceCollection.hpp +src/SVG.cpp +src/SVG.hpp src/TriangleMesh.cpp src/TriangleMesh.hpp src/utils.cpp diff --git a/xs/src/SVG.cpp b/xs/src/SVG.cpp new file mode 100644 index 0000000000..a8337283a9 --- /dev/null +++ b/xs/src/SVG.cpp @@ -0,0 +1,34 @@ +#include "SVG.hpp" + +namespace Slic3r { + +SVG::SVG(const char* filename) +{ + this->f = fopen(filename, "w"); + fprintf(this->f, + "\n" + "\n" + "\n" + " \n" + " \n" + " \n" + ); +} + +void +SVG::AddLine(const Line &line) +{ + fprintf(this->f, + " \n", + (float)unscale(line.a.x)*10, (float)unscale(line.a.y)*10, (float)unscale(line.b.x)*10, (float)unscale(line.b.y)*10 + ); +} + +void +SVG::Close() +{ + fprintf(this->f, "\n"); + fclose(this->f); +} + +} diff --git a/xs/src/SVG.hpp b/xs/src/SVG.hpp new file mode 100644 index 0000000000..2a22ed97e6 --- /dev/null +++ b/xs/src/SVG.hpp @@ -0,0 +1,21 @@ +#ifndef slic3r_SVG_hpp_ +#define slic3r_SVG_hpp_ + +#include +#include "Line.hpp" + +namespace Slic3r { + +class SVG +{ + private: + FILE* f; + public: + SVG(const char* filename); + void AddLine(const Line &line); + void Close(); +}; + +} + +#endif diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index c512757c24..d2c134aa4a 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -9,6 +9,10 @@ #include #include +#ifdef SLIC3R_DEBUG +#include "SVG.hpp" +#endif + namespace Slic3r { TriangleMesh::TriangleMesh() @@ -281,9 +285,6 @@ TriangleMesh::slice(const std::vector &z) if (a->z == b->z && a->z == slice_z) { // edge is horizontal and belongs to the current layer - #ifdef SLIC3R_DEBUG - printf("Edge is horizontal!\n"); - #endif /* We assume that this method is never being called for horizontal facets, so no other edge is going to be on this layer. */ @@ -308,10 +309,6 @@ TriangleMesh::slice(const std::vector &z) found_horizontal_edge = true; break; } else if (a->z == slice_z) { - #ifdef SLIC3R_DEBUG - printf("A point on plane!\n"); - #endif - IntersectionPoint point; point.x = a->x; point.y = a->y; @@ -319,10 +316,6 @@ TriangleMesh::slice(const std::vector &z) points.push_back(point); points_on_layer.push_back(points.size()-1); } else if (b->z == slice_z) { - #ifdef SLIC3R_DEBUG - printf("B point on plane!\n"); - #endif - IntersectionPoint point; point.x = b->x; point.y = b->y; @@ -331,9 +324,6 @@ TriangleMesh::slice(const std::vector &z) points_on_layer.push_back(points.size()-1); } else if ((a->z < slice_z && b->z > slice_z) || (b->z < slice_z && a->z > slice_z)) { // edge intersects the current layer; calculate intersection - #ifdef SLIC3R_DEBUG - printf("Intersects!\n"); - #endif IntersectionPoint point; point.x = b->x + (a->x - b->x) * (slice_z - b->z) / (a->z - b->z); @@ -345,14 +335,14 @@ TriangleMesh::slice(const std::vector &z) } if (found_horizontal_edge) continue; - if (points_on_layer.size() == 2) { - if (intersection_points.size() == 1) { - points.erase( points.begin() + points_on_layer[1] ); - } else if (intersection_points.empty()) { - if (points[ points_on_layer[0] ].coincides_with(&points[ points_on_layer[1] ])) { - continue; - } - } + if (!points_on_layer.empty()) { + // we can't have only one point on layer because each vertex gets detected + // twice (once for each edge), and we can't have three points on layer because + // we assume this code is not getting called for horizontal facets + assert(points_on_layer.size() == 2); + assert( points[ points_on_layer[0] ].point_id == points[ points_on_layer[1] ].point_id ); + points.erase( points.begin() + points_on_layer[1] ); + if (intersection_points.empty()) continue; } if (!points.empty()) { diff --git a/xs/src/myinit.h b/xs/src/myinit.h index fcd7d60e1f..d1659823e4 100644 --- a/xs/src/myinit.h +++ b/xs/src/myinit.h @@ -19,6 +19,8 @@ extern "C" { #endif #define EPSILON 1e-4 +#define SCALING_FACTOR 0.000001 +#define unscale(val) (val * SCALING_FACTOR) namespace Slic3r {} using namespace Slic3r;