Merge branch 'lm_drilling_backend'

This commit is contained in:
Lukas Matena 2020-01-24 10:56:40 +01:00
commit cf391383a8
9 changed files with 103 additions and 64 deletions

View File

@ -123,6 +123,7 @@ Contour3D DrainHole::to_mesh() const
Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d{0., 0., 1.}, normal.cast<double>());
for(auto& p : hole.points) p = q * p + pos.cast<double>();
return hole;
}
@ -251,15 +252,8 @@ void cut_drainholes(std::vector<ExPolygons> & obj_slices,
std::function<void(void)> thr)
{
TriangleMesh mesh;
for (const sla::DrainHole &holept : holes) {
auto r = double(holept.radius);
auto h = double(holept.height);
sla::Contour3D hole = sla::cylinder(r, h);
Eigen::Quaterniond q;
q.setFromTwoVectors(Vec3d{0., 0., 1.}, holept.normal.cast<double>());
for(auto& p : hole.points) p = q * p + holept.pos.cast<double>();
mesh.merge(sla::to_triangle_mesh(hole));
}
for (const sla::DrainHole &holept : holes)
mesh.merge(sla::to_triangle_mesh(holept.to_mesh()));
if (mesh.empty()) return;

View File

@ -1119,6 +1119,10 @@ TriangleMesh SLAPrintObject::get_mesh(SLAPrintObjectStep step) const
return this->support_mesh();
case slaposPad:
return this->pad_mesh();
case slaposHollowing:
if (m_hollowing_data)
return m_hollowing_data->hollow_mesh_with_holes;
[[fallthrough]];
default:
return TriangleMesh();
}
@ -1182,11 +1186,18 @@ sla::DrainHoles SLAPrintObject::transformed_drainhole_points() const
assert(m_model_object != nullptr);
auto pts = m_model_object->sla_drain_holes;
auto tr = trafo().cast<float>();
auto sc = m_model_object->instances.front()->get_scaling_factor().cast<float>();
for (sla::DrainHole &hl : pts) {
hl.pos = tr * hl.pos;
hl.normal = tr * hl.normal - tr.translation();
// The normal scales as a covector (and we must also
// undo the damage already done).
hl.normal = Vec3f(hl.normal(0)/(sc(0)*sc(0)),
hl.normal(1)/(sc(1)*sc(1)),
hl.normal(2)/(sc(2)*sc(2)));
}
return pts;
}

View File

@ -80,6 +80,12 @@ public:
// Ready after this->is_step_done(slaposHollowing) is true
const TriangleMesh& hollowed_interior_mesh() const;
// Get the mesh that is going to be printed with all the modifications
// like hollowing and drilled holes.
const TriangleMesh & get_mesh_to_print() const {
return m_hollowing_data ? m_hollowing_data->hollow_mesh_with_holes : transformed_mesh();
}
// This will return the transformed mesh which is cached
const TriangleMesh& transformed_mesh() const;
@ -318,7 +324,7 @@ private:
public:
TriangleMesh interior;
// std::vector<drillpoints>
mutable TriangleMesh hollow_mesh_with_holes; // caching the complete hollowed mesh
};
std::unique_ptr<HollowingData> m_hollowing_data;

View File

@ -1,5 +1,5 @@
#include <libslic3r/SLAPrintSteps.hpp>
#include <libslic3r/MeshBoolean.hpp>
// Need the cylinder method for the the drainholes in hollowing step
#include <libslic3r/SLA/SupportTreeBuilder.hpp>
@ -38,7 +38,7 @@ const std::array<unsigned, slaposCount> OBJ_STEP_LEVELS = {
std::string OBJ_STEP_LABELS(size_t idx)
{
switch (idx) {
case slaposHollowing: return L("Hollowing out the model");
case slaposHollowing: return L("Hollowing and drilling holes");
case slaposObjectSlice: return L("Slicing model");
case slaposDrillHolesIfHollowed: return L("Drilling holes into hollowed model.");
case slaposSupportPoints: return L("Generating support points");
@ -79,26 +79,56 @@ SLAPrint::Steps::Steps(SLAPrint *print)
void SLAPrint::Steps::hollow_model(SLAPrintObject &po)
{
if (!po.m_config.hollowing_enable.getBool()) {
BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!";
po.m_hollowing_data.reset();
return;
} else {
po.m_hollowing_data.reset();
if (! po.m_config.hollowing_enable.getBool())
BOOST_LOG_TRIVIAL(info) << "Skipping hollowing step!";
else {
BOOST_LOG_TRIVIAL(info) << "Performing hollowing step!";
double thickness = po.m_config.hollowing_min_thickness.getFloat();
double quality = po.m_config.hollowing_quality.getFloat();
double closing_d = po.m_config.hollowing_closing_distance.getFloat();
sla::HollowingConfig hlwcfg{thickness, quality, closing_d};
auto meshptr = generate_interior(po.transformed_mesh(), hlwcfg);
if (meshptr->empty())
BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!";
else {
po.m_hollowing_data.reset(new SLAPrintObject::HollowingData());
po.m_hollowing_data->interior = *meshptr;
auto &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes;
hollowed_mesh = po.transformed_mesh();
hollowed_mesh.merge(po.m_hollowing_data->interior);
hollowed_mesh.require_shared_vertices();
}
}
// Drill holes into the hollowed/original mesh.
if (po.m_model_object->sla_drain_holes.empty())
BOOST_LOG_TRIVIAL(info) << "Drilling skipped (no holes).";
else {
BOOST_LOG_TRIVIAL(info) << "Drilling drainage holes.";
sla::DrainHoles drainholes = po.transformed_drainhole_points();
TriangleMesh holes_mesh;
for (const sla::DrainHole &holept : drainholes)
holes_mesh.merge(sla::to_triangle_mesh(holept.to_mesh()));
holes_mesh.require_shared_vertices();
MeshBoolean::self_union(holes_mesh); //FIXME-fix and use the cgal version
// If there is no hollowed mesh yet, copy the original mesh.
if (! po.m_hollowing_data) {
po.m_hollowing_data.reset(new SLAPrintObject::HollowingData());
po.m_hollowing_data->hollow_mesh_with_holes = po.transformed_mesh();
}
TriangleMesh &hollowed_mesh = po.m_hollowing_data->hollow_mesh_with_holes;
hollowed_mesh = po.get_mesh_to_print();
MeshBoolean::cgal::minus(hollowed_mesh, holes_mesh);
hollowed_mesh.require_shared_vertices();
}
if (!po.m_hollowing_data)
po.m_hollowing_data.reset(new SLAPrintObject::HollowingData());
double thickness = po.m_config.hollowing_min_thickness.getFloat();
double quality = po.m_config.hollowing_quality.getFloat();
double closing_d = po.m_config.hollowing_closing_distance.getFloat();
sla::HollowingConfig hlwcfg{thickness, quality, closing_d};
auto meshptr = generate_interior(po.transformed_mesh(), hlwcfg);
if (meshptr) po.m_hollowing_data->interior = *meshptr;
if (po.m_hollowing_data->interior.empty())
BOOST_LOG_TRIVIAL(warning) << "Hollowed interior is empty!";
}
// The slicing will be performed on an imaginary 1D grid which starts from
@ -111,18 +141,8 @@ void SLAPrint::Steps::hollow_model(SLAPrintObject &po)
// same imaginary grid (the height vector argument to TriangleMeshSlicer).
void SLAPrint::Steps::slice_model(SLAPrintObject &po)
{
TriangleMesh hollowed_mesh;
bool is_hollowing = po.m_config.hollowing_enable.getBool() && po.m_hollowing_data;
if (is_hollowing) {
hollowed_mesh = po.transformed_mesh();
hollowed_mesh.merge(po.m_hollowing_data->interior);
hollowed_mesh.require_shared_vertices();
}
const TriangleMesh &mesh = is_hollowing ? hollowed_mesh : po.transformed_mesh();
const TriangleMesh &mesh = po.get_mesh_to_print();
// We need to prepare the slice index...
double lhd = m_print->m_objects.front()->m_config.layer_height.getFloat();
@ -168,8 +188,8 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
auto &slice_grid = po.m_model_height_levels;
slicer.slice(slice_grid, closing_r, &po.m_model_slices, thr);
sla::DrainHoles drainholes = po.transformed_drainhole_points();
cut_drainholes(po.m_model_slices, slice_grid, closing_r, drainholes, thr);
// sla::DrainHoles drainholes = po.transformed_drainhole_points();
// cut_drainholes(po.m_model_slices, slice_grid, closing_r, drainholes, thr);
auto mit = slindex_it;
double doffs = m_print->m_printer_config.absolute_correction.getFloat();
@ -199,16 +219,7 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po)
// If supports are disabled, we can skip the model scan.
if(!po.m_config.supports_enable.getBool()) return;
bool is_hollowing = po.m_config.hollowing_enable.getBool() && po.m_hollowing_data;
TriangleMesh hollowed_mesh;
if (is_hollowing) {
hollowed_mesh = po.transformed_mesh();
hollowed_mesh.merge(po.m_hollowing_data->interior);
hollowed_mesh.require_shared_vertices();
}
const TriangleMesh &mesh = is_hollowing ? hollowed_mesh : po.transformed_mesh();
const TriangleMesh &mesh = po.get_mesh_to_print();
if (!po.m_supportdata)
po.m_supportdata.reset(new SLAPrintObject::SupportData(mesh));
@ -229,7 +240,7 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po)
// Tell the mesh where drain holes are. Although the points are
// calculated on slices, the algorithm then raycasts the points
// so they actually lie on the mesh.
po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points());
// po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points());
throw_if_canceled();
sla::SupportPointGenerator::Config config;
@ -298,7 +309,7 @@ void SLAPrint::Steps::support_tree(SLAPrintObject &po)
po.m_supportdata->emesh.ground_level_offset(pcfg.wall_thickness_mm);
po.m_supportdata->cfg = make_support_cfg(po.m_config);
po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points());
// po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points());
// scaling for the sub operations
double d = objectstep_scale * OBJ_STEP_LEVELS[slaposSupportTree] / 100.0;

View File

@ -6060,9 +6060,9 @@ void GLCanvas3D::_load_sla_shells()
if (obj->is_step_done(slaposSliceSupports)) {
unsigned int initial_volumes_count = (unsigned int)m_volumes.volumes.size();
for (const SLAPrintObject::Instance& instance : obj->instances()) {
add_volume(*obj, 0, instance, obj->transformed_mesh(), GLVolume::MODEL_COLOR[0], true);
if (! obj->hollowed_interior_mesh().empty())
add_volume(*obj, -int(slaposHollowing), instance, obj->hollowed_interior_mesh(), GLVolume::MODEL_COLOR[0], false);
add_volume(*obj, 0, instance, obj->get_mesh_to_print(), GLVolume::MODEL_COLOR[0], true);
// if (! obj->hollowed_interior_mesh().empty())
// add_volume(*obj, -int(slaposHollowing), instance, obj->hollowed_interior_mesh(), GLVolume::MODEL_COLOR[0], false);
// Set the extruder_id and volume_id to achieve the same color as in the 3D scene when
// through the update_volumes_colors_by_extruder() call.
m_volumes.volumes.back()->extruder_id = obj->model_object()->volumes.front()->extruder_id();

View File

@ -608,10 +608,14 @@ void GLGizmoHollow::update_mesh_raycaster(std::unique_ptr<MeshRaycaster> &&rc)
m_c->m_volume_with_cavity.reset();
}
void GLGizmoHollow::hollow_mesh()
void GLGizmoHollow::hollow_mesh(bool postpone_error_messages)
{
// Trigger a UI job to hollow the mesh.
wxGetApp().plater()->hollow();
// wxGetApp().plater()->hollow();
wxGetApp().CallAfter([this, postpone_error_messages]() {
wxGetApp().plater()->reslice_SLA_hollowing(*m_c->m_model_object, postpone_error_messages);
});
}

View File

@ -55,7 +55,7 @@ private:
void render_hollowed_mesh() const;
bool is_mesh_update_necessary() const;
void update_mesh();
void hollow_mesh();
void hollow_mesh(bool postpone_error_messages = false);
bool unsaved_changes() const;
bool m_show_supports = true;

View File

@ -5099,6 +5099,16 @@ void Plater::reslice()
}
void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages)
{
reslice_SLA_until_step(slaposPad, object, postpone_error_messages);
}
void Plater::reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages)
{
reslice_SLA_until_step(slaposHollowing, object, postpone_error_messages);
}
void Plater::reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages)
{
//FIXME Don't reslice if export of G-code or sending to OctoPrint is running.
// bitmask of UpdateBackgroundProcessReturnState
@ -5117,7 +5127,7 @@ void Plater::reslice_SLA_supports(const ModelObject &object, bool postpone_error
// Otherwise calculate everything, but start with the provided object.
if (!this->p->background_processing_enabled()) {
task.single_model_instance_only = true;
task.to_object_step = slaposPad;
task.to_object_step = step;
}
this->p->background_process.set_task(task);
// and let the background processing start.

View File

@ -26,6 +26,7 @@ class Model;
class ModelObject;
class Print;
class SLAPrint;
enum SLAPrintObjectStep : unsigned int;
namespace UndoRedo {
class Stack;
@ -197,6 +198,8 @@ public:
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);
void reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages = false);
void changed_object(int obj_idx);
void changed_objects(const std::vector<size_t>& object_idxs);
void schedule_background_process(bool schedule = true);