Tech ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS - Faster printbed collision detection using the new function Geometry::intersect()

This commit is contained in:
enricoturri1966 2021-10-04 14:07:45 +02:00
parent 5739178306
commit 4521945bb3
2 changed files with 13 additions and 15 deletions

View file

@ -29,20 +29,18 @@ namespace Slic3r {
#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS #if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
ModelInstanceEPrintVolumeState printbed_collision_state(const Polygon& printbed_shape, double print_volume_height, const Polygon& obj_hull_2d, double obj_min_z, double obj_max_z) ModelInstanceEPrintVolumeState printbed_collision_state(const Polygon& printbed_shape, double print_volume_height, const Polygon& obj_hull_2d, double obj_min_z, double obj_max_z)
{ {
static const double Z_TOLERANCE = -1e10; if (!Geometry::intersects(printbed_shape, obj_hull_2d))
return ModelInstancePVS_Fully_Outside;
const Polygons intersection_polys = intersection(printbed_shape, obj_hull_2d); bool contained_xy = true;
const bool contained_xy = !intersection_polys.empty() && Geometry::are_approx(intersection_polys.front(), obj_hull_2d); for (const Point& p : obj_hull_2d) {
const bool contained_z = Z_TOLERANCE < obj_min_z && obj_max_z < print_volume_height; if (!printbed_shape.contains(p)) {
if (contained_xy && contained_z) contained_xy = false;
return ModelInstancePVS_Inside; break;
}
const bool intersects_xy = !contained_xy && !intersection_polys.empty(); }
const bool intersects_z = !contained_z && obj_min_z < print_volume_height&& Z_TOLERANCE < obj_max_z; const bool contained_z = -1e10 < obj_min_z && obj_max_z < print_volume_height;
if (intersects_xy || intersects_z) return (contained_xy && contained_z) ? ModelInstancePVS_Inside : ModelInstancePVS_Partly_Outside;
return ModelInstancePVS_Partly_Outside;
return ModelInstancePVS_Fully_Outside;
} }
ModelInstanceEPrintVolumeState printbed_collision_state(const Polygon& printbed_shape, double print_volume_height, const BoundingBoxf3& box) ModelInstanceEPrintVolumeState printbed_collision_state(const Polygon& printbed_shape, double print_volume_height, const BoundingBoxf3& box)

View file

@ -1083,8 +1083,8 @@ bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, M
} }
} }
else { else {
const indexed_triangle_set& its = GUI::wxGetApp().plater()->model().objects[volume->object_idx()]->volumes[volume->volume_idx()]->mesh().its; const TriangleMesh* mesh = volume->is_sinking() ? &GUI::wxGetApp().plater()->model().objects[volume->object_idx()]->volumes[volume->volume_idx()]->mesh() : volume->convex_hull();
const Polygon volume_hull_2d = its_convex_hull_2d_above(its, volume->world_matrix().cast<float>(), 0.0f); const Polygon volume_hull_2d = its_convex_hull_2d_above(mesh->its, volume->world_matrix().cast<float>(), 0.0f);
volume_state = printbed_collision_state(bed_poly, bed_height, volume_hull_2d, bb.min.z(), bb.max.z()); volume_state = printbed_collision_state(bed_poly, bed_height, volume_hull_2d, bb.min.z(), bb.max.z());
} }
contained = (volume_state == ModelInstancePVS_Inside); contained = (volume_state == ModelInstancePVS_Inside);