Tech ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS - Enable detection of collision with circular printbed for toolpaths

This commit is contained in:
enricoturri1966 2021-09-30 12:08:05 +02:00
parent 448911df9f
commit 7cfe082621
4 changed files with 79 additions and 41 deletions

View file

@ -5011,9 +5011,25 @@ void GLCanvas3D::_render_background() const
if (!m_volumes.empty())
use_error_color &= _is_any_volume_outside();
else {
#if ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
const ConfigOptionPoints* opt = dynamic_cast<const ConfigOptionPoints*>(m_config->option("bed_shape"));
if (opt != nullptr) {
const Polygon bed_poly = offset(Polygon::new_scale(opt->values), static_cast<float>(scale_(BedEpsilon))).front();
const float bed_height = m_config->opt_float("max_print_height");
const BoundingBoxf3& paths_volume = m_gcode_viewer.get_paths_bounding_box();
Polygon paths_hull_2d;
paths_hull_2d.append({ scale_(paths_volume.min.x()), scale_(paths_volume.min.y()) });
paths_hull_2d.append({ scale_(paths_volume.max.x()), scale_(paths_volume.min.y()) });
paths_hull_2d.append({ scale_(paths_volume.max.x()), scale_(paths_volume.max.y()) });
paths_hull_2d.append({ scale_(paths_volume.min.x()), scale_(paths_volume.max.y()) });
const ModelInstanceEPrintVolumeState state = printbed_collision_state(bed_poly, bed_height, paths_hull_2d, paths_volume.min.z(), paths_volume.max.z());
use_error_color &= state != ModelInstancePVS_Inside;
}
#else
const BoundingBoxf3 test_volume = (m_config != nullptr) ? print_volume(*m_config) : BoundingBoxf3();
const BoundingBoxf3& paths_volume = m_gcode_viewer.get_paths_bounding_box();
use_error_color &= (test_volume.radius() > 0.0 && paths_volume.radius() > 0.0) ? !test_volume.contains(paths_volume) : false;
#endif // ENABLE_OUT_OF_BED_DETECTION_IMPROVEMENTS
}
}