Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2013-10-13 17:59:38 +0400
committerAlessandro Ranellucci <aar@cpan.org>2013-10-13 17:59:38 +0400
commitac93e15c98e685d6fdd67e8b416d6b2253c1a5b5 (patch)
tree6dc2e606feffd6b866a29c3f401e1531f26f8caa /xs
parent9918c1e97d37b932b9992c46a7999b11e9f9c0ca (diff)
New class for generating SVG from XS. Includes some minor refactoring to TriangleMesh
Diffstat (limited to 'xs')
-rw-r--r--xs/MANIFEST2
-rw-r--r--xs/src/SVG.cpp34
-rw-r--r--xs/src/SVG.hpp21
-rw-r--r--xs/src/TriangleMesh.cpp34
-rw-r--r--xs/src/myinit.h2
5 files changed, 71 insertions, 22 deletions
diff --git a/xs/MANIFEST b/xs/MANIFEST
index 9514db695..541ad30d5 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 000000000..a8337283a
--- /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,
+ "<?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=\"2000\" width=\"2000\" 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"
+ );
+}
+
+void
+SVG::AddLine(const Line &line)
+{
+ fprintf(this->f,
+ " <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" style=\"stroke: black; stroke-width: 2\" marker-end=\"url(#endArrow)\"/>\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, "</svg>\n");
+ fclose(this->f);
+}
+
+}
diff --git a/xs/src/SVG.hpp b/xs/src/SVG.hpp
new file mode 100644
index 000000000..2a22ed97e
--- /dev/null
+++ b/xs/src/SVG.hpp
@@ -0,0 +1,21 @@
+#ifndef slic3r_SVG_hpp_
+#define slic3r_SVG_hpp_
+
+#include <myinit.h>
+#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 c512757c2..d2c134aa4 100644
--- a/xs/src/TriangleMesh.cpp
+++ b/xs/src/TriangleMesh.cpp
@@ -9,6 +9,10 @@
#include <math.h>
#include <assert.h>
+#ifdef SLIC3R_DEBUG
+#include "SVG.hpp"
+#endif
+
namespace Slic3r {
TriangleMesh::TriangleMesh()
@@ -281,9 +285,6 @@ TriangleMesh::slice(const std::vector<double> &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<double> &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<double> &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<double> &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<double> &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 fcd7d60e1..d1659823e 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;