Bugfix: incomplete slicing when a horizontal surface was tangent to the slicing plane and it shared an edge with an adjacent volume. #1672

issue1834
Alessandro Ranellucci 2014-01-13 00:45:19 +01:00
parent b0a7baa454
commit fcaa3a03c2
2 changed files with 22 additions and 10 deletions

View File

@ -270,13 +270,6 @@ TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
printf("z: min = %.2f, max = %.2f\n", min_z, max_z);
#endif
if (min_z == max_z) {
#ifdef SLIC3R_DEBUG
printf("Facet is horizontal; ignoring\n");
#endif
continue;
}
// find layer extents
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
@ -319,7 +312,9 @@ TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
stl_vertex* v1 = &v_scaled_shared[ this->stl.v_indices[facet_idx].vertex[1] ];
stl_vertex* v2 = &v_scaled_shared[ this->stl.v_indices[facet_idx].vertex[2] ];
IntersectionLine line;
if (v0->z < slice_z || v1->z < slice_z || v2->z < slice_z) {
if (min_z == max_z) {
line.edge_type = feHorizontal;
} else if (v0->z < slice_z || v1->z < slice_z || v2->z < slice_z) {
line.edge_type = feTop;
std::swap(a, b);
std::swap(a_id, b_id);
@ -335,7 +330,10 @@ TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
lines[layer_idx].push_back(line);
found_horizontal_edge = true;
break;
// if this is a top or bottom edge, we can stop looping through edges
// because we won't find anything interesting
if (line.edge_type != feHorizontal) break;
} else if (a->z == slice_z) {
IntersectionPoint point;
point.x = a->x;
@ -398,6 +396,13 @@ TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
printf("Layer %d:\n", layer_idx);
#endif
/*
SVG svg("lines.svg");
for (IntersectionLines::iterator line = it->begin(); line != it->end(); ++line)
svg.AddLine(*line);
svg.Close();
*/
// remove tangent edges
for (IntersectionLines::iterator line = it->begin(); line != it->end(); ++line) {
if (line->skip || line->edge_type == feNone) continue;
@ -421,6 +426,13 @@ TriangleMesh::slice(const std::vector<float> &z, std::vector<Polygons>* layers)
line->skip = true;
break;
}
} else if (line->a_id == line2->b_id && line->b_id == line2->a_id) {
/* if this edge joins two horizontal facets, remove both of them */
if (line->edge_type == feHorizontal && line2->edge_type == feHorizontal) {
line->skip = true;
line2->skip = true;
break;
}
}
}
}

View File

@ -49,7 +49,7 @@ class TriangleMesh
void require_shared_vertices();
};
enum FacetEdgeType { feNone, feTop, feBottom };
enum FacetEdgeType { feNone, feTop, feBottom, feHorizontal };
class IntersectionPoint : public Point
{