Some refactoring related to sequential print clearance contours

This commit is contained in:
enricoturri1966 2023-03-15 13:33:46 +01:00
parent 5cc1359c05
commit 2dba40789f
4 changed files with 47 additions and 62 deletions

View File

@ -880,7 +880,7 @@ void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas
ImGui::PopStyleVar(2); ImGui::PopStyleVar(2);
} }
void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& contours) void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& contours, bool generate_fill)
{ {
m_contours.clear(); m_contours.clear();
m_instances.clear(); m_instances.clear();
@ -889,7 +889,7 @@ void GLCanvas3D::SequentialPrintClearance::set_contours(const ContoursList& cont
if (contours.empty()) if (contours.empty())
return; return;
if (m_render_fill) { if (generate_fill) {
GLModel::Geometry fill_data; GLModel::Geometry fill_data;
fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 }; fill_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3 };
fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f }; fill_data.color = { 0.3333f, 0.0f, 0.0f, 0.5f };
@ -966,7 +966,6 @@ void GLCanvas3D::SequentialPrintClearance::render()
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
if (m_render_fill)
m_fill.render(); m_fill.render();
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
@ -991,7 +990,7 @@ void GLCanvas3D::SequentialPrintClearance::render()
for (const auto& [id, trafo] : m_instances) { for (const auto& [id, trafo] : m_instances) {
shader->set_uniform("view_model_matrix", camera.get_view_matrix() * trafo); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * trafo);
assert(id < m_contours.size()); assert(id < m_contours.size());
m_contours[id].set_color(m_render_fill ? FILL_COLOR : m_evaluating ? NO_FILL_EVALUATING_COLOR : NO_FILL_COLOR); m_contours[id].set_color(m_fill.is_initialized() ? FILL_COLOR : m_evaluating ? NO_FILL_EVALUATING_COLOR : NO_FILL_COLOR);
m_contours[id].render(); m_contours[id].render();
} }
@ -3487,17 +3486,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
// Not only detection of some modifiers !!! // Not only detection of some modifiers !!!
if (evt.Dragging()) { if (evt.Dragging()) {
GLGizmosManager::EType c = m_gizmos.get_current_type(); GLGizmosManager::EType c = m_gizmos.get_current_type();
if (current_printer_technology() == ptFFF &&
fff_print()->config().complete_objects){
if (c == GLGizmosManager::EType::Move || if (c == GLGizmosManager::EType::Move ||
c == GLGizmosManager::EType::Scale || c == GLGizmosManager::EType::Scale ||
c == GLGizmosManager::EType::Rotate) c == GLGizmosManager::EType::Rotate) {
update_sequential_clearance(true);
} else {
if (c == GLGizmosManager::EType::Move ||
c == GLGizmosManager::EType::Scale ||
c == GLGizmosManager::EType::Rotate)
show_sinking_contours(); show_sinking_contours();
if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects)
update_sequential_clearance(true);
} }
} }
else if (evt.LeftUp() && else if (evt.LeftUp() &&
@ -4005,7 +3999,7 @@ void GLCanvas3D::do_move(const std::string& snapshot_type)
if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) {
update_sequential_clearance(true); update_sequential_clearance(true);
m_sequential_print_clearance.set_evaluating(true); m_sequential_print_clearance.m_evaluating = true;
} }
m_dirty = true; m_dirty = true;
@ -4093,7 +4087,7 @@ void GLCanvas3D::do_rotate(const std::string& snapshot_type)
if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) {
update_sequential_clearance(true); update_sequential_clearance(true);
m_sequential_print_clearance.set_evaluating(true); m_sequential_print_clearance.m_evaluating = true;
} }
m_dirty = true; m_dirty = true;
@ -4170,7 +4164,7 @@ void GLCanvas3D::do_scale(const std::string& snapshot_type)
if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) { if (current_printer_technology() == ptFFF && fff_print()->config().complete_objects) {
update_sequential_clearance(true); update_sequential_clearance(true);
m_sequential_print_clearance.set_evaluating(true); m_sequential_print_clearance.m_evaluating = true;
} }
m_dirty = true; m_dirty = true;
@ -4475,6 +4469,9 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation)
// second: fill temporary cache with data from volumes // second: fill temporary cache with data from volumes
for (const GLVolume* v : m_volumes.volumes) { for (const GLVolume* v : m_volumes.volumes) {
if (v->is_wipe_tower)
continue;
const int object_idx = v->object_idx(); const int object_idx = v->object_idx();
const int instance_idx = v->instance_idx(); const int instance_idx = v->instance_idx();
auto& transform = instance_transforms[object_idx][instance_idx]; auto& transform = instance_transforms[object_idx][instance_idx];
@ -4490,12 +4487,11 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation)
Geometry::rotation_transform(Geometry::rotation_diff_z(hull_trafo, inst_trafo.get_matrix()) * Vec3d::UnitZ()); Geometry::rotation_transform(Geometry::rotation_diff_z(hull_trafo, inst_trafo.get_matrix()) * Vec3d::UnitZ());
}; };
set_sequential_print_clearance_render_fill(false);
// calculates objects 2d hulls (see also: Print::sequential_print_horizontal_clearance_valid()) // calculates objects 2d hulls (see also: Print::sequential_print_horizontal_clearance_valid())
// this is done only the first time this method is called while moving the mouse, // this is done only the first time this method is called while moving the mouse,
// the results are then cached for following displacements // the results are then cached for following displacements
if (force_contours_generation || m_sequential_print_clearance_first_displacement) { if (force_contours_generation || m_sequential_print_clearance_first_displacement) {
m_sequential_print_clearance.m_evaluating = false;
m_sequential_print_clearance.m_hulls_2d_cache.clear(); m_sequential_print_clearance.m_hulls_2d_cache.clear();
const float shrink_factor = static_cast<float>(scale_(0.5 * fff_print()->config().extruder_clearance_radius.value - EPSILON)); const float shrink_factor = static_cast<float>(scale_(0.5 * fff_print()->config().extruder_clearance_radius.value - EPSILON));
const double mitter_limit = scale_(0.1); const double mitter_limit = scale_(0.1);
@ -4537,7 +4533,7 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation)
} }
} }
set_sequential_print_clearance_contours(contours); set_sequential_print_clearance_contours(contours, false);
m_sequential_print_clearance_first_displacement = false; m_sequential_print_clearance_first_displacement = false;
} }
else { else {
@ -4554,9 +4550,6 @@ void GLCanvas3D::update_sequential_clearance(bool force_contours_generation)
m_sequential_print_clearance.update_instances_trafos(trafos); m_sequential_print_clearance.update_instances_trafos(trafos);
} }
} }
// sends instances 2d hulls to be rendered
set_sequential_print_clearance_visible(true);
} }
bool GLCanvas3D::is_object_sinking(int object_idx) const bool GLCanvas3D::is_object_sinking(int object_idx) const

View File

@ -638,18 +638,13 @@ private:
std::vector<GLModel> m_contours; std::vector<GLModel> m_contours;
// list of transforms used to render the contours // list of transforms used to render the contours
std::vector<std::pair<size_t, Transform3d>> m_instances; std::vector<std::pair<size_t, Transform3d>> m_instances;
bool m_render_fill{ true };
bool m_visible{ false };
bool m_evaluating{ false }; bool m_evaluating{ false };
std::vector<std::pair<Pointf3s, Transform3d>> m_hulls_2d_cache; std::vector<std::pair<Pointf3s, Transform3d>> m_hulls_2d_cache;
public: public:
void set_contours(const ContoursList& contours); void set_contours(const ContoursList& contours, bool generate_fill);
void update_instances_trafos(const std::vector<Transform3d>& trafos); void update_instances_trafos(const std::vector<Transform3d>& trafos);
void set_render_fill(bool render_fill) { m_render_fill = render_fill; }
void set_visible(bool visible) { m_visible = visible; }
void set_evaluating(bool evaluating) { m_evaluating = evaluating; }
void render(); void render();
bool empty() const { return m_contours.empty(); } bool empty() const { return m_contours.empty(); }
@ -975,25 +970,20 @@ public:
} }
void reset_sequential_print_clearance() { void reset_sequential_print_clearance() {
m_sequential_print_clearance.set_visible(false); m_sequential_print_clearance.m_evaluating = false;
m_sequential_print_clearance.set_render_fill(false); m_sequential_print_clearance.set_contours(ContoursList(), false);
m_sequential_print_clearance.set_contours(ContoursList());
} }
void set_sequential_print_clearance_visible(bool visible) { void set_sequential_print_clearance_contours(const ContoursList& contours, bool generate_fill) {
m_sequential_print_clearance.set_visible(visible); m_sequential_print_clearance.set_contours(contours, generate_fill);
} }
void set_sequential_print_clearance_render_fill(bool render_fill) { bool is_sequential_print_clearance_empty() const {
m_sequential_print_clearance.set_render_fill(render_fill); return m_sequential_print_clearance.empty();
} }
void set_sequential_print_clearance_contours(const ContoursList& contours) { bool is_sequential_print_clearance_evaluating() const {
m_sequential_print_clearance.set_contours(contours); return m_sequential_print_clearance.m_evaluating;
}
void set_sequential_print_clearance_evaluating(bool evaluating) {
m_sequential_print_clearance.set_evaluating(evaluating);
} }
void update_sequential_clearance(bool force_contours_generation); void update_sequential_clearance(bool force_contours_generation);

View File

@ -3294,9 +3294,12 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
// or hide the old one. // or hide the old one.
process_validation_warning(warning); process_validation_warning(warning);
if (printer_technology == ptFFF) { if (printer_technology == ptFFF) {
view3D->get_canvas3d()->reset_sequential_print_clearance(); GLCanvas3D* canvas = view3D->get_canvas3d();
view3D->get_canvas3d()->set_as_dirty(); if (canvas->is_sequential_print_clearance_evaluating()) {
view3D->get_canvas3d()->request_extra_frame(); canvas->reset_sequential_print_clearance();
canvas->set_as_dirty();
canvas->request_extra_frame();
}
} }
} }
else { else {
@ -3305,13 +3308,12 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
notification_manager->push_validate_error_notification(err); notification_manager->push_validate_error_notification(err);
return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; return_state |= UPDATE_BACKGROUND_PROCESS_INVALID;
if (printer_technology == ptFFF) { if (printer_technology == ptFFF) {
const Print* print = background_process.fff_print(); GLCanvas3D* canvas = view3D->get_canvas3d();
if (canvas->is_sequential_print_clearance_empty() || canvas->is_sequential_print_clearance_evaluating()) {
GLCanvas3D::ContoursList contours; GLCanvas3D::ContoursList contours;
contours.contours = print->get_sequential_print_clearance_contours(); contours.contours = background_process.fff_print()->get_sequential_print_clearance_contours();
view3D->get_canvas3d()->set_sequential_print_clearance_visible(!contours.empty()); canvas->set_sequential_print_clearance_contours(contours, true);
view3D->get_canvas3d()->set_sequential_print_clearance_render_fill(!contours.empty()); }
view3D->get_canvas3d()->set_sequential_print_clearance_contours(contours);
view3D->get_canvas3d()->set_sequential_print_clearance_evaluating(false);
} }
} }
} }