TriangleMesh::slice() now accepts a vector of floats instead of doubles for consistency with mesh coordinates

This commit is contained in:
Alessandro Ranellucci 2014-01-12 23:56:07 +01:00
parent 69f1f65a8b
commit 3637ca39df
4 changed files with 21 additions and 13 deletions

View File

@ -165,7 +165,7 @@ void TriangleMesh::rotate(double angle, Point* center)
}
void
TriangleMesh::slice(const std::vector<double> &z, std::vector<Polygons>* layers)
TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
{
/*
This method gets called with a list of unscaled Z coordinates and outputs
@ -190,6 +190,9 @@ TriangleMesh::slice(const std::vector<double> &z, std::vector<Polygons>* 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<double> &z, std::vector<Polygons>* 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<double> &z, std::vector<Polygons>* layers)
}
// find layer extents
std::vector<double>::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<float>::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<double>::const_iterator it = min_layer; it != max_layer + 1; ++it) {
std::vector<double>::size_type layer_idx = it - z.begin();
double slice_z = *it / SCALING_FACTOR;
for (std::vector<float>::const_iterator it = min_layer; it != max_layer + 1; ++it) {
std::vector<float>::size_type layer_idx = it - z.begin();
float slice_z = *it / SCALING_FACTOR;
std::vector<IntersectionPoint> points;
std::vector< std::vector<IntersectionPoint>::size_type > points_on_layer;
bool found_horizontal_edge = false;
@ -521,7 +524,7 @@ class _area_comp {
};
void
TriangleMesh::slice(const std::vector<double> &z, std::vector<ExPolygons>* layers)
TriangleMesh::slice(const std::vector<float> &z, std::vector<ExPolygons>* layers)
{
std::vector<Polygons> layers_p;
this->slice(z, &layers_p);

View File

@ -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<double> &z, std::vector<Polygons>* layers);
void slice(const std::vector<double> &z, std::vector<ExPolygons>* layers);
void slice(const std::vector<float> &z, std::vector<Polygons>* layers);
void slice(const std::vector<float> &z, std::vector<ExPolygons>* layers);
TriangleMeshPtrs split() const;
void merge(const TriangleMesh* mesh);
void horizontal_projection(ExPolygons &retval) const;

View File

@ -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;

View File

@ -137,8 +137,12 @@ SV*
TriangleMesh::slice(z)
std::vector<double>* z
CODE:
// convert doubles to floats
std::vector<float> z_f(z->begin(), z->end());
delete z;
std::vector<ExPolygons> layers;
THIS->slice(*z, &layers);
THIS->slice(z_f, &layers);
AV* layers_av = newAV();
av_extend(layers_av, layers.size()-1);