diff --git a/xs/src/TriangleMesh.cpp b/xs/src/TriangleMesh.cpp index 246d94a6d..dcdf75807 100644 --- a/xs/src/TriangleMesh.cpp +++ b/xs/src/TriangleMesh.cpp @@ -165,7 +165,7 @@ void TriangleMesh::rotate(double angle, Point* center) } void -TriangleMesh::slice(const std::vector &z, std::vector* layers) +TriangleMesh::slice(const std::vector &z, std::vector* layers) { /* This method gets called with a list of unscaled Z coordinates and outputs @@ -190,6 +190,9 @@ TriangleMesh::slice(const std::vector &z, std::vector* layers) At the end, we free the tables generated by analyze() as we don't need them anymore. FUTURE: parallelize slice_facet() and make_loops() + + NOTE: this method accepts a vector of floats because the mesh coordinate + type is float. */ // build a table to map a facet_idx to its three edge indices @@ -256,8 +259,8 @@ TriangleMesh::slice(const std::vector &z, std::vector* layers) stl_facet* facet = &this->stl.facet_start[facet_idx]; // find facet extents - double min_z = fminf(facet->vertex[0].z, fminf(facet->vertex[1].z, facet->vertex[2].z)); - double max_z = fmaxf(facet->vertex[0].z, fmaxf(facet->vertex[1].z, facet->vertex[2].z)); + float min_z = fminf(facet->vertex[0].z, fminf(facet->vertex[1].z, facet->vertex[2].z)); + float max_z = fmaxf(facet->vertex[0].z, fmaxf(facet->vertex[1].z, facet->vertex[2].z)); #ifdef SLIC3R_DEBUG printf("\n==> FACET %d (%f,%f,%f - %f,%f,%f - %f,%f,%f):\n", facet_idx, @@ -275,16 +278,16 @@ TriangleMesh::slice(const std::vector &z, std::vector* layers) } // find layer extents - std::vector::const_iterator min_layer, max_layer; - min_layer = std::lower_bound(z.begin(), z.end(), min_z - EPSILON); // first layer whose slice_z is >= min_z - max_layer = std::upper_bound(z.begin() + (min_layer - z.begin()), z.end(), max_z + EPSILON) - 1; // last layer whose slice_z is <= max_z + std::vector::const_iterator min_layer, max_layer; + min_layer = std::lower_bound(z.begin(), z.end(), min_z); // first layer whose slice_z is >= min_z + max_layer = std::upper_bound(z.begin() + (min_layer - z.begin()), z.end(), max_z) - 1; // last layer whose slice_z is <= max_z #ifdef SLIC3R_DEBUG printf("layers: min = %d, max = %d\n", (int)(min_layer - z.begin()), (int)(max_layer - z.begin())); #endif - for (std::vector::const_iterator it = min_layer; it != max_layer + 1; ++it) { - std::vector::size_type layer_idx = it - z.begin(); - double slice_z = *it / SCALING_FACTOR; + for (std::vector::const_iterator it = min_layer; it != max_layer + 1; ++it) { + std::vector::size_type layer_idx = it - z.begin(); + float slice_z = *it / SCALING_FACTOR; std::vector points; std::vector< std::vector::size_type > points_on_layer; bool found_horizontal_edge = false; @@ -521,7 +524,7 @@ class _area_comp { }; void -TriangleMesh::slice(const std::vector &z, std::vector* layers) +TriangleMesh::slice(const std::vector &z, std::vector* layers) { std::vector layers_p; this->slice(z, &layers_p); diff --git a/xs/src/TriangleMesh.hpp b/xs/src/TriangleMesh.hpp index 055817739..f20340b42 100644 --- a/xs/src/TriangleMesh.hpp +++ b/xs/src/TriangleMesh.hpp @@ -30,8 +30,8 @@ class TriangleMesh void translate(float x, float y, float z); void align_to_origin(); void rotate(double angle, Point* center); - void slice(const std::vector &z, std::vector* layers); - void slice(const std::vector &z, std::vector* layers); + void slice(const std::vector &z, std::vector* layers); + void slice(const std::vector &z, std::vector* layers); TriangleMeshPtrs split() const; void merge(const TriangleMesh* mesh); void horizontal_projection(ExPolygons &retval) const; diff --git a/xs/src/myinit.h b/xs/src/myinit.h index 0156f64dc..14e25fd43 100644 --- a/xs/src/myinit.h +++ b/xs/src/myinit.h @@ -23,6 +23,7 @@ extern "C" { #define PI 3.141592653589793238 #define scale_(val) (val / SCALING_FACTOR) #define unscale(val) (val * SCALING_FACTOR) +#define SCALED_EPSILON scale_(EPSILON) typedef long coord_t; typedef double coordf_t; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index f026390c4..26670a1db 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -137,8 +137,12 @@ SV* TriangleMesh::slice(z) std::vector* z CODE: + // convert doubles to floats + std::vector z_f(z->begin(), z->end()); + delete z; + std::vector layers; - THIS->slice(*z, &layers); + THIS->slice(z_f, &layers); AV* layers_av = newAV(); av_extend(layers_av, layers.size()-1);