From 6918f111004adea10314e5eac3368d42784f8ac2 Mon Sep 17 00:00:00 2001 From: Lukas Matena <lukasmatena@seznam.cz> Date: Sat, 29 Feb 2020 11:39:54 +0100 Subject: [PATCH] Removed SLA unused code Mostly the dead-ends that were tried when hollowing was being implemented --- src/libslic3r/SLA/EigenMesh3D.hpp | 3 + src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp | 114 ------------------- src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp | 6 - src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 30 ----- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp | 1 - src/slic3r/GUI/Plater.cpp | 97 +--------------- src/slic3r/GUI/Plater.hpp | 1 - 7 files changed, 5 insertions(+), 247 deletions(-) diff --git a/src/libslic3r/SLA/EigenMesh3D.hpp b/src/libslic3r/SLA/EigenMesh3D.hpp index e8b869bb4..bcf94ec16 100644 --- a/src/libslic3r/SLA/EigenMesh3D.hpp +++ b/src/libslic3r/SLA/EigenMesh3D.hpp @@ -101,6 +101,9 @@ public: // Iterates over hits and holes and returns the true hit, possibly // on the inside of a hole. + // This function is currently not used anywhere, it was written when the + // holes were subtracted on slices, that is, before we started using CGAL + // to actually cut the holes into the mesh. hit_result filter_hits(const std::vector<EigenMesh3D::hit_result>& obj_hits) const; class si_result { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp index 0027fb8be..0a3a6f898 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.cpp @@ -100,16 +100,11 @@ void GLGizmoHollow::on_render() const return; } - // !!! is it necessary? - //const_cast<GLGizmoHollow*>(this)->m_c->update_from_backend(m_parent, m_c->m_model_object); - glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_DEPTH_TEST)); m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); - render_hollowed_mesh(); - if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); @@ -121,28 +116,6 @@ void GLGizmoHollow::on_render() const -void GLGizmoHollow::render_hollowed_mesh() const -{ - /*if (m_c->m_volume_with_cavity) { - m_c->m_volume_with_cavity->set_sla_shift_z(m_z_shift); - m_parent.get_shader().start_using(); - - GLint current_program_id; - glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); - GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; - GLint print_box_detection_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1; - GLint print_box_worldmatrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1; - glcheck(); - m_c->m_volume_with_cavity->set_render_color(); - const Geometry::Transformation& volume_trafo = m_c->m_model_object->volumes.front()->get_transformation(); - m_c->m_volume_with_cavity->set_volume_transformation(volume_trafo); - m_c->m_volume_with_cavity->set_instance_transformation(m_c->m_model_object->instances[size_t(m_c->m_active_instance)]->get_transformation()); - m_c->m_volume_with_cavity->render(color_id, print_box_detection_id, print_box_worldmatrix_id); - m_parent.get_shader().stop_using(); - }*/ -} - - void GLGizmoHollow::render_clipping_plane(const Selection& selection) const { if (m_c->m_clipping_plane_distance == 0.f) @@ -170,11 +143,6 @@ void GLGizmoHollow::render_clipping_plane(const Selection& selection) const m_c->m_object_clipper->set_plane(*m_c->m_clipping_plane); m_c->m_object_clipper->set_transformation(trafo); - - // Next, ask the backend if supports are already calculated. If so, we are gonna cut them too. - //if (m_c->m_print_object_idx < 0) - // m_c->update_from_backend(m_parent, m_c->m_model_object); - if (m_c->m_print_object_idx >= 0) { const SLAPrintObject* print_object = m_parent.sla_print()->objects()[m_c->m_print_object_idx]; @@ -230,7 +198,6 @@ void GLGizmoHollow::on_render_for_picking() const glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); - render_hollowed_mesh(); } void GLGizmoHollow::render_points(const Selection& selection, bool picking) const @@ -344,10 +311,6 @@ bool GLGizmoHollow::unproject_on_mesh(const Vec2d& mouse_pos, std::pair<Vec3f, V if (! m_c->m_mesh_raycaster) return false; - // if the gizmo doesn't have the V, F structures for igl, calculate them first: - // !!! is it really necessary? - //m_c->update_from_backend(m_parent, m_c->m_model_object); - const Camera& camera = m_parent.get_camera(); const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); @@ -562,87 +525,15 @@ void GLGizmoHollow::on_update(const UpdateData& data) } } -std::pair<const TriangleMesh *, sla::HollowingConfig> GLGizmoHollow::get_hollowing_parameters() const -{ - // FIXME this function is probably obsolete, caller could - // get the data from model config himself - auto opts = get_config_options({"hollowing_min_thickness", "hollowing_quality", "hollowing_closing_distance"}); - double offset = static_cast<const ConfigOptionFloat*>(opts[0].first)->value; - double quality = static_cast<const ConfigOptionFloat*>(opts[1].first)->value; - double closing_d = static_cast<const ConfigOptionFloat*>(opts[2].first)->value; - return std::make_pair(m_c->m_mesh, sla::HollowingConfig{offset, quality, closing_d}); -} - -void GLGizmoHollow::update_mesh_raycaster(std::unique_ptr<MeshRaycaster> &&rc) -{ - m_c->m_mesh_raycaster = std::move(rc); - m_c->m_object_clipper.reset(); - //m_c->m_volume_with_cavity.reset(); -} void GLGizmoHollow::hollow_mesh(bool postpone_error_messages) { - // Trigger a UI job to hollow the mesh. - // wxGetApp().plater()->hollow(); - wxGetApp().CallAfter([this, postpone_error_messages]() { wxGetApp().plater()->reslice_SLA_hollowing(*m_c->m_model_object, postpone_error_messages); }); } -void GLGizmoHollow::update_hollowed_mesh(std::unique_ptr<TriangleMesh> &&mesh) -{ - // Called from Plater when the UI job finishes - /*m_c->m_cavity_mesh = std::move(mesh); - - if(m_c->m_cavity_mesh) { - // First subtract the holes: - if (! m_c->m_model_object->sla_drain_holes.empty()) { - TriangleMesh holes_mesh; - for (const sla::DrainHole& hole : m_c->m_model_object->sla_drain_holes) { - TriangleMesh hole_mesh = make_cylinder(hole.radius, hole.height, 2*M_PI/32); - - Vec3d scaling = m_c->m_model_object->instances[m_c->m_active_instance]->get_scaling_factor(); - Vec3d normal_transformed = Vec3d(hole.normal(0)/scaling(0), hole.normal(1)/scaling(1), hole.normal(2)/scaling(2)); - normal_transformed.normalize(); - - // Rotate the cylinder appropriately - Eigen::Quaterniond q; - Transform3d m = Transform3d::Identity(); - m.matrix().block(0, 0, 3, 3) = q.setFromTwoVectors(Vec3d::UnitZ(), normal_transformed).toRotationMatrix(); - hole_mesh.transform(m); - - // If the instance is scaled, undo the scaling of the hole - hole_mesh.scale(Vec3d(1/scaling(0), 1/scaling(1), 1/scaling(2))); - - // Translate the hole into position and merge with the others - hole_mesh.translate(hole.pos); - holes_mesh.merge(hole_mesh); - holes_mesh.repair(); - } - MeshBoolean::minus(*m_c->m_cavity_mesh.get(), holes_mesh); - } - - // create a new GLVolume that only has the cavity inside - m_c->m_volume_with_cavity.reset(new GLVolume(GLVolume::MODEL_COLOR[2])); - m_c->m_volume_with_cavity->indexed_vertex_array.load_mesh(*m_c->m_cavity_mesh.get()); - m_c->m_volume_with_cavity->finalize_geometry(true); - m_c->m_volume_with_cavity->force_transparent = false; - - m_parent.toggle_model_objects_visibility(false, m_c->m_model_object, m_c->m_active_instance); - m_parent.toggle_sla_auxiliaries_visibility(true, m_c->m_model_object, m_c->m_active_instance); - - // Reset raycaster so it works with the new mesh: - m_c->m_mesh_raycaster.reset(new MeshRaycaster(*m_c->mesh())); - } - - if (m_c->m_clipping_plane_distance == 0.f) { - m_c->m_clipping_plane_distance = 0.5f; - update_clipping_plane(); - }*/ -} - std::vector<std::pair<const ConfigOption*, const ConfigOptionDef*>> GLGizmoHollow::get_config_options(const std::vector<std::string>& keys) const { std::vector<std::pair<const ConfigOption*, const ConfigOptionDef*>> out; @@ -830,7 +721,6 @@ RENDER_AGAIN: bool remove_selected = false; bool remove_all = false; - // m_imgui->text(" "); // vertical gap ImGui::Separator(); float diameter_upper_cap = 15.; @@ -1014,10 +904,6 @@ void GLGizmoHollow::on_set_state() m_parent.toggle_model_objects_visibility(true, m_c->m_model_object, m_c->m_active_instance); m_parent.toggle_sla_auxiliaries_visibility(m_show_supports, m_c->m_model_object, m_c->m_active_instance); } - - // Set default head diameter from config. - //const DynamicPrintConfig& cfg = wxGetApp().preset_bundle->sla_prints.get_edited_preset().config; - //m_new_hole_radius = static_cast<const ConfigOptionFloat*>(cfg.option("support_head_front_diameter"))->value; } if (m_state == Off && m_old_state != Off) { // the gizmo was just turned Off //Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("SLA gizmo turned off"))); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp index bc4549a0e..3aafcbf55 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoHollow.hpp @@ -36,11 +36,6 @@ public: void delete_selected_points(); ClippingPlane get_sla_clipping_plane() const; - - std::pair<const TriangleMesh *, sla::HollowingConfig> get_hollowing_parameters() const; - void update_mesh_raycaster(std::unique_ptr<MeshRaycaster> &&rc); - void update_hollowed_mesh(std::unique_ptr<TriangleMesh> &&mesh); - bool is_selection_rectangle_dragging() const { return m_selection_rectangle.is_dragging(); } void update_clipping_plane(bool keep_normal = false) const; void set_common_data_ptr(CommonGizmosData* ptr) { m_c = ptr; } @@ -53,7 +48,6 @@ private: void render_points(const Selection& selection, bool picking = false) const; void render_clipping_plane(const Selection& selection) const; - void render_hollowed_mesh() const; void hollow_mesh(bool postpone_error_messages = false); bool unsaved_changes() const; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index fa8de30ca..ab0b9b5d6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -107,8 +107,6 @@ void GLGizmoSlaSupports::on_render() const m_z_shift = selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z(); - render_hollowed_mesh(); - if (m_quadric != nullptr && selection.is_from_single_instance()) render_points(selection, false); @@ -120,29 +118,6 @@ void GLGizmoSlaSupports::on_render() const -void GLGizmoSlaSupports::render_hollowed_mesh() const -{ - /*if (m_c->m_volume_with_cavity) { - m_c->m_volume_with_cavity->set_sla_shift_z(m_z_shift); - m_parent.get_shader().start_using(); - - GLint current_program_id; - glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); - GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; - GLint print_box_detection_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1; - GLint print_box_worldmatrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1; - glcheck(); - m_c->m_volume_with_cavity->set_render_color(); - const Geometry::Transformation& volume_trafo = m_c->m_model_object->volumes.front()->get_transformation(); - m_c->m_volume_with_cavity->set_volume_transformation(volume_trafo); - m_c->m_volume_with_cavity->set_instance_transformation(m_c->m_model_object->instances[size_t(m_c->m_active_instance)]->get_transformation()); - m_c->m_volume_with_cavity->render(color_id, print_box_detection_id, print_box_worldmatrix_id); - m_parent.get_shader().stop_using(); - }*/ -} - - - void GLGizmoSlaSupports::render_clipping_plane(const Selection& selection) const { if (m_c->m_clipping_plane_distance == 0.f || m_c->m_mesh->empty()) @@ -239,7 +214,6 @@ void GLGizmoSlaSupports::on_render_for_picking() const glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); - render_hollowed_mesh(); } void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) const @@ -628,8 +602,6 @@ void GLGizmoSlaSupports::delete_selected_points(bool force) } select_point(NoPoints); - - //m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); } void GLGizmoSlaSupports::on_update(const UpdateData& data) @@ -644,8 +616,6 @@ void GLGizmoSlaSupports::on_update(const UpdateData& data) m_editing_cache[m_hover_id].support_point.pos = pos_and_normal.first; m_editing_cache[m_hover_id].support_point.is_new_island = false; m_editing_cache[m_hover_id].normal = pos_and_normal.second; - // Do not update immediately, wait until the mouse is released. - // m_parent.post_event(SimpleEvent(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS)); } } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp index deddabe5f..bd48ecd65 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.hpp @@ -93,7 +93,6 @@ private: //void render_selection_rectangle() const; void render_points(const Selection& selection, bool picking = false) const; void render_clipping_plane(const Selection& selection) const; - void render_hollowed_mesh() const; bool unsaved_changes() const; bool m_lock_unique_islands = false; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6fc6ab86c..ed400bab8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -86,8 +86,6 @@ #include "WipeTowerDialog.hpp" #include "libslic3r/CustomGCode.hpp" -#include "Gizmos/GLGizmoHollow.hpp" - using boost::optional; namespace fs = boost::filesystem; using Slic3r::_3DScene; @@ -1555,8 +1553,7 @@ struct Plater::priv enum class Jobs : size_t { Arrange, - Rotoptimize, - Hollow + Rotoptimize }; class ArrangeJob : public PlaterJob @@ -1700,23 +1697,6 @@ struct Plater::priv void process() override; }; - // FIXME: This should be removed, as well as the #include of the gizmo - class HollowJob : public PlaterJob - { - public: - using PlaterJob::PlaterJob; - void prepare() override; - void process() override; - void finalize() override; - private: - GLGizmoHollow * get_gizmo(); - const GLGizmoHollow * get_gizmo() const; - - std::unique_ptr<TriangleMesh> m_output_mesh; - std::unique_ptr<MeshRaycaster> m_output_raycaster; - const TriangleMesh* m_object_mesh = nullptr; - sla::HollowingConfig m_cfg; - }; // Jobs defined inside the group class will be managed so that only one can // run at a time. Also, the background process will be stopped if a job is @@ -1729,7 +1709,6 @@ struct Plater::priv ArrangeJob arrange_job{m_plater}; RotoptimizeJob rotoptimize_job{m_plater}; - HollowJob hollow_job{m_plater}; // To create a new job, just define a new subclass of Job, implement // the process and the optional prepare() and finalize() methods @@ -1737,8 +1716,7 @@ struct Plater::priv // if it cannot run concurrently with other jobs in this group std::vector<std::reference_wrapper<Job>> m_jobs{arrange_job, - rotoptimize_job, - hollow_job}; + rotoptimize_job}; public: ExclusiveJobGroup(priv *_plater) : m_plater(_plater) {} @@ -1841,7 +1819,6 @@ struct Plater::priv void reset(); void mirror(Axis axis); void arrange(); - void hollow(); void sla_optimize_rotation(); void split_object(); void split_volume(); @@ -2757,11 +2734,6 @@ void Plater::priv::arrange() m_ui_jobs.start(Jobs::Arrange); } -void Plater::priv::hollow() -{ - this->take_snapshot(_(L("Hollow"))); - m_ui_jobs.start(Jobs::Hollow); -} // This method will find an optimal orientation for the currently selected item // Very similar in nature to the arrange method above... @@ -2894,67 +2866,6 @@ void Plater::priv::RotoptimizeJob::process() : _(L("Orientation found."))); } -void Plater::priv::HollowJob::prepare() -{ - const GLGizmosManager& gizmo_manager = plater().q->canvas3D()->get_gizmos_manager(); - const GLGizmoHollow* gizmo_hollow = dynamic_cast<const GLGizmoHollow*>(gizmo_manager.get_current()); - assert(gizmo_hollow); - auto hlw_data = gizmo_hollow->get_hollowing_parameters(); - m_object_mesh = hlw_data.first; - m_cfg = hlw_data.second; - m_output_mesh.reset(); -} - -void Plater::priv::HollowJob::process() -{ - sla::JobController ctl; - ctl.stopcondition = [this]{ return was_canceled(); }; - ctl.statuscb = [this](unsigned st, const std::string &s) { - if (st < 100) update_status(int(st), s); - }; - - std::unique_ptr<TriangleMesh> omesh = - sla::generate_interior(*m_object_mesh, m_cfg, ctl); - - if (omesh && !omesh->empty()) { - m_output_mesh.reset(new TriangleMesh{*m_object_mesh}); - m_output_mesh->merge(*omesh); - m_output_mesh->require_shared_vertices(); - - update_status(90, _(L("Indexing hollowed object"))); - - m_output_raycaster.reset(new MeshRaycaster(*m_output_mesh)); - - update_status(100, was_canceled() ? _(L("Hollowing cancelled.")) : - _(L("Hollowing done."))); - } else { - update_status(100, _(L("Hollowing failed."))); - } -} - -void Plater::priv::HollowJob::finalize() -{ - if (auto gizmo = get_gizmo()) { - gizmo->update_mesh_raycaster(std::move(m_output_raycaster)); - gizmo->update_hollowed_mesh(std::move(m_output_mesh)); - } -} - -GLGizmoHollow *Plater::priv::HollowJob::get_gizmo() -{ - const GLGizmosManager& gizmo_manager = plater().q->canvas3D()->get_gizmos_manager(); - auto ret = dynamic_cast<GLGizmoHollow*>(gizmo_manager.get_current()); - assert(ret); - return ret; -} - -const GLGizmoHollow *Plater::priv::HollowJob::get_gizmo() const -{ - const GLGizmosManager& gizmo_manager = plater().q->canvas3D()->get_gizmos_manager(); - auto ret = dynamic_cast<const GLGizmoHollow*>(gizmo_manager.get_current()); - assert(ret); - return ret; -} void Plater::priv::split_object() { @@ -5074,10 +4985,6 @@ void Plater::export_toolpaths_to_obj() const p->preview->get_canvas3d()->export_toolpaths_to_obj(into_u8(path).c_str()); } -void Plater::hollow() -{ - p->hollow(); -} void Plater::reslice() { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 754a2a720..f3b0181a0 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -198,7 +198,6 @@ public: void reload_all_from_disk(); bool has_toolpaths_to_export() const; void export_toolpaths_to_obj() const; - void hollow(); void reslice(); void reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages = false); void reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages = false);