Hollowed mesh tracker implementation

The class tracks state of the backend calculation and if there is a hollowed/drilled mesh, it can provide a pointer to it
This commit is contained in:
Lukas Matena 2020-04-06 09:56:00 +02:00
parent 7e797eaaf8
commit 81dba7677b
2 changed files with 92 additions and 13 deletions

View File

@ -3,6 +3,7 @@
#include <cassert> #include <cassert>
#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLCanvas3D.hpp"
#include "libslic3r/SLAPrint.hpp"
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
@ -15,7 +16,7 @@ CommonGizmosDataPool::CommonGizmosDataPool(GLCanvas3D* canvas)
using c = CommonGizmosDataID; using c = CommonGizmosDataID;
m_data[c::SelectionInfo].reset( new SelectionInfo(this)); m_data[c::SelectionInfo].reset( new SelectionInfo(this));
m_data[c::InstancesHider].reset( new InstancesHider(this)); m_data[c::InstancesHider].reset( new InstancesHider(this));
//m_data[c::HollowedMesh].reset( new HollowedMesh(this)); m_data[c::HollowedMesh].reset( new HollowedMesh(this));
//m_data[c::ClippingPlaneWrapper].reset(new ClippingPlaneWrapper(this)); //m_data[c::ClippingPlaneWrapper].reset(new ClippingPlaneWrapper(this));
//m_data[c::SupportsClipper].reset( new SupportsClipper(this)); //m_data[c::SupportsClipper].reset( new SupportsClipper(this));
//m_data[c::MeshRaycaster].reset( new Raycaster(this)); //m_data[c::MeshRaycaster].reset( new Raycaster(this));
@ -38,8 +39,15 @@ void CommonGizmosDataPool::update(CommonGizmosDataID required)
SelectionInfo* CommonGizmosDataPool::selection_info() SelectionInfo* CommonGizmosDataPool::selection_info()
{ {
SelectionInfo* sel_info = dynamic_cast<SelectionInfo*>(m_data[CommonGizmosDataID::SelectionInfo].get()); SelectionInfo* sel_info = dynamic_cast<SelectionInfo*>(m_data[CommonGizmosDataID::SelectionInfo].get());
assert(sel_info->is_valid()); assert(sel_info);
return sel_info; return sel_info->is_valid() ? sel_info : nullptr;
}
HollowedMesh* CommonGizmosDataPool::hollowed_mesh()
{
HollowedMesh* hol_mesh = dynamic_cast<HollowedMesh*>(m_data[CommonGizmosDataID::HollowedMesh].get());
assert(hol_mesh);
return hol_mesh->is_valid() ? hol_mesh : nullptr;
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -113,5 +121,64 @@ void InstancesHider::on_release()
void HollowedMesh::on_update()
{
const ModelObject* mo = get_pool()->selection_info()->model_object();
if (! mo)
return;
const GLCanvas3D* canvas = get_pool()->get_canvas();
const PrintObjects& print_objects = canvas->sla_print()->objects();
const SLAPrintObject* print_object = m_print_object_idx != -1
? print_objects[m_print_object_idx]
: nullptr;
// Find the respective SLAPrintObject.
if (m_print_object_idx < 0 || m_print_objects_count != int(print_objects.size())) {
m_print_objects_count = print_objects.size();
m_print_object_idx = -1;
for (const SLAPrintObject* po : print_objects) {
++m_print_object_idx;
if (po->model_object()->id() == mo->id()) {
print_object = po;
break;
}
}
}
// If there is a valid SLAPrintObject, check state of Hollowing step.
if (print_object) {
if (print_object->is_step_done(slaposDrillHoles) && print_object->has_mesh(slaposDrillHoles)) {
size_t timestamp = print_object->step_state_with_timestamp(slaposDrillHoles).timestamp;
if (timestamp > m_old_hollowing_timestamp) {
const TriangleMesh& backend_mesh = print_object->get_mesh_to_print();
m_hollowed_mesh_transformed.reset(new TriangleMesh(backend_mesh));
Transform3d trafo_inv = canvas->sla_print()->sla_trafo(*mo).inverse();
m_hollowed_mesh_transformed->transform(trafo_inv);
m_old_hollowing_timestamp = timestamp;
}
}
else {
m_hollowed_mesh_transformed.reset(nullptr);
m_old_hollowing_timestamp = 0;
}
}
}
void HollowedMesh::on_release()
{
m_hollowed_mesh_transformed.reset();
m_old_hollowing_timestamp = 0;
m_print_object_idx = -1;
}
const TriangleMesh* HollowedMesh::get_hollowed_mesh() const
{
return m_hollowed_mesh_transformed.get();
}
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View File

@ -7,6 +7,7 @@
namespace Slic3r { namespace Slic3r {
class ModelObject; class ModelObject;
class TriangleMesh;
namespace GUI { namespace GUI {
@ -16,6 +17,8 @@ class GLCanvas3D;
class CommonGizmosDataBase; class CommonGizmosDataBase;
namespace CommonGizmosDataObjects { namespace CommonGizmosDataObjects {
class SelectionInfo; class SelectionInfo;
class InstancesHider;
class HollowedMesh;
} }
// Some of the gizmos use the same data that need to be updated ocassionally. // Some of the gizmos use the same data that need to be updated ocassionally.
@ -50,6 +53,8 @@ public:
// Getters for the data that need to be accessed from the gizmos directly. // Getters for the data that need to be accessed from the gizmos directly.
CommonGizmosDataObjects::SelectionInfo* selection_info(); CommonGizmosDataObjects::SelectionInfo* selection_info();
CommonGizmosDataObjects::HollowedMesh* hollowed_mesh();
GLCanvas3D* get_canvas() const { return m_canvas; } GLCanvas3D* get_canvas() const { return m_canvas; }
@ -129,6 +134,7 @@ private:
}; };
class InstancesHider : public CommonGizmosDataBase class InstancesHider : public CommonGizmosDataBase
{ {
public: public:
@ -145,23 +151,29 @@ protected:
/*
class HollowedMesh : public CommonGizmosDataBase class HollowedMesh : public CommonGizmosDataBase
{ {
public: public:
explicit HollowedMesh(CommonGizmosDataPool* cgdp) explicit HollowedMesh(CommonGizmosDataPool* cgdp)
: CommonGizmosDataBase(cgdp) {} : CommonGizmosDataBase(cgdp) {}
void update(bool required) override; #ifndef NDEBUG
CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; }
#endif // NDEBUG
const TriangleMesh* get_hollowed_mesh() const;
protected:
void on_update() override;
void on_release() override;
private:
std::unique_ptr<TriangleMesh> m_hollowed_mesh_transformed;
size_t m_old_hollowing_timestamp = 0;
int m_print_object_idx = -1;
int m_print_objects_count = 0;
}; };
/*
class ClippingPlaneWrapper : public CommonGizmosDataBase class ClippingPlaneWrapper : public CommonGizmosDataBase
{ {