Fix non thread-safe data flow between plater and hollowing gizmo.

This commit is contained in:
tamasmeszaros 2019-11-11 17:27:32 +01:00
parent 98e2327a9f
commit a69e80b987
4 changed files with 30 additions and 33 deletions

View file

@ -3,7 +3,6 @@
#include <libslic3r/SLA/Hollowing.hpp>
#include <libslic3r/SLA/Contour3D.hpp>
//#include <openvdb/tools/Filter.h>
#include <boost/log/trivial.hpp>
#include <libslic3r/MTUtils.hpp>
@ -87,9 +86,6 @@ remove_cvref_t<Mesh> _generate_interior(Mesh &&mesh,
if (ctl.stopcondition()) return {};
else ctl.statuscb(70, L("Hollowing"));
// openvdb::tools::Filter<openvdb::FloatGrid> filt{*gridptr};
// filt.offset(float(offset + D));
double iso_surface = D;
double adaptivity = 0.;
auto omesh = _grid_to_mesh<MMesh>(*gridptr, iso_surface, adaptivity);

View file

@ -571,24 +571,11 @@ std::pair<const TriangleMesh *, sla::HollowingConfig> GLGizmoHollow::get_hollowi
return std::make_pair(m_mesh, sla::HollowingConfig{double(m_offset), double(m_accuracy), double(m_closing_d)});
}
void GLGizmoHollow::set_hollowing_result(std::unique_ptr<TriangleMesh> mesh)
void GLGizmoHollow::update_mesh_raycaster(std::unique_ptr<MeshRaycaster> &&rc)
{
// Called from Plater when the UI job finishes
m_cavity_mesh = std::move(mesh);
m_mesh_raycaster.reset(new MeshRaycaster(*m_cavity_mesh.get()));
m_mesh_raycaster = std::move(rc);
m_object_clipper.reset();
m_volume_with_cavity.reset();
if(m_cavity_mesh) {// create a new GLVolume that only has the cavity inside
Geometry::Transformation volume_trafo = m_model_object->volumes.front()->get_transformation();
volume_trafo.set_offset(volume_trafo.get_offset() + Vec3d(0., 0., m_z_shift));
m_volume_with_cavity.reset(new GLVolume(1.f, 0.f, 0.f, 0.5f));
m_volume_with_cavity->indexed_vertex_array.load_mesh(*m_cavity_mesh.get());
m_volume_with_cavity->set_volume_transformation(volume_trafo);
m_volume_with_cavity->set_instance_transformation(m_model_object->instances[size_t(m_active_instance)]->get_transformation());
}
}
void GLGizmoHollow::hollow_mesh()
@ -597,9 +584,21 @@ void GLGizmoHollow::hollow_mesh()
wxGetApp().plater()->hollow();
}
void GLGizmoHollow::update_hollowed_mesh()
void GLGizmoHollow::update_hollowed_mesh(std::unique_ptr<TriangleMesh> &&mesh)
{
if (m_volume_with_cavity) m_volume_with_cavity->finalize_geometry(true);
// Called from Plater when the UI job finishes
m_cavity_mesh = std::move(mesh);
if(m_cavity_mesh) {// create a new GLVolume that only has the cavity inside
Geometry::Transformation volume_trafo = m_model_object->volumes.front()->get_transformation();
volume_trafo.set_offset(volume_trafo.get_offset() + Vec3d(0., 0., m_z_shift));
m_volume_with_cavity.reset(new GLVolume(1.f, 0.f, 0.f, 0.5f));
m_volume_with_cavity->indexed_vertex_array.load_mesh(*m_cavity_mesh.get());
m_volume_with_cavity->finalize_geometry(true);
m_volume_with_cavity->set_volume_transformation(volume_trafo);
m_volume_with_cavity->set_instance_transformation(m_model_object->instances[size_t(m_active_instance)]->get_transformation());
}
m_parent.toggle_model_objects_visibility(! m_cavity_mesh, m_model_object, m_active_instance);
}

View file

@ -79,8 +79,8 @@ public:
std::pair<const TriangleMesh *, sla::HollowingConfig> get_hollowing_parameters() const;
void set_hollowing_result(std::unique_ptr<TriangleMesh> mesh);
void update_hollowed_mesh();
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(); }

View file

@ -1717,7 +1717,8 @@ struct Plater::priv
GLGizmoHollow * get_gizmo();
const GLGizmoHollow * get_gizmo() const;
std::unique_ptr<TriangleMesh> m_output;
std::unique_ptr<TriangleMesh> m_output_mesh;
std::unique_ptr<MeshRaycaster> m_output_raycaster;
const TriangleMesh* m_object_mesh = nullptr;
sla::HollowingConfig m_cfg;
};
@ -2870,7 +2871,7 @@ void Plater::priv::HollowJob::prepare()
auto hlw_data = gizmo_hollow->get_hollowing_parameters();
m_object_mesh = hlw_data.first;
m_cfg = hlw_data.second;
m_output.reset();
m_output_mesh.reset();
}
void Plater::priv::HollowJob::process()
@ -2884,14 +2885,13 @@ void Plater::priv::HollowJob::process()
TriangleMesh omesh = sla::generate_interior(*m_object_mesh, m_cfg, ctl);
if (!omesh.empty()) {
m_output.reset(new TriangleMesh{*m_object_mesh});
m_output->merge(omesh);
m_output->require_shared_vertices();
m_output_mesh.reset(new TriangleMesh{*m_object_mesh});
m_output_mesh->merge(omesh);
m_output_mesh->require_shared_vertices();
update_status(90, "Rendering hollowed object");
update_status(90, _(L("Indexing hollowed object")));
auto gizmo = get_gizmo();
if (gizmo) gizmo->set_hollowing_result(std::move(m_output));
m_output_raycaster.reset(new MeshRaycaster(*m_output_mesh));
update_status(100, was_canceled() ? _(L("Hollowing cancelled.")) :
_(L("Hollowing done.")));
@ -2902,8 +2902,10 @@ void Plater::priv::HollowJob::process()
void Plater::priv::HollowJob::finalize()
{
auto gizmo = get_gizmo();
if (gizmo) gizmo->update_hollowed_mesh();
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()