New class for generating SVG from XS. Includes some minor refactoring to TriangleMesh
This commit is contained in:
parent
9918c1e97d
commit
ac93e15c98
5 changed files with 71 additions and 22 deletions
|
@ -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
|
||||
|
|
34
xs/src/SVG.cpp
Normal file
34
xs/src/SVG.cpp
Normal file
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
21
xs/src/SVG.hpp
Normal file
21
xs/src/SVG.hpp
Normal file
|
@ -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
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue