2018-11-08 19:18:40 +00:00
|
|
|
#include "SLAPrint.hpp"
|
2018-11-09 17:32:35 +00:00
|
|
|
#include "SLA/SLASupportTree.hpp"
|
2018-11-15 17:05:47 +00:00
|
|
|
#include "SLA/SLABasePool.hpp"
|
2018-12-14 15:15:59 +00:00
|
|
|
#include "SLA/SLAAutoSupports.hpp"
|
2019-02-21 14:46:04 +00:00
|
|
|
#include "ClipperUtils.hpp"
|
2018-11-22 12:42:52 +00:00
|
|
|
#include "MTUtils.hpp"
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2018-11-21 17:03:24 +00:00
|
|
|
#include <unordered_set>
|
2018-11-22 17:13:34 +00:00
|
|
|
#include <numeric>
|
2018-11-21 17:03:24 +00:00
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
#include <tbb/parallel_for.h>
|
2019-02-13 07:44:42 +00:00
|
|
|
#include <boost/filesystem/path.hpp>
|
2018-11-20 15:12:04 +00:00
|
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
//#include <tbb/spin_mutex.h>//#include "tbb/mutex.h"
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
#include "I18N.hpp"
|
|
|
|
|
|
|
|
//! macro used to mark string used at localization,
|
|
|
|
//! return same string
|
|
|
|
#define L(s) Slic3r::I18N::translate(s)
|
2018-11-08 19:18:40 +00:00
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
using SupportTreePtr = std::unique_ptr<sla::SLASupportTree>;
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
class SLAPrintObject::SupportData {
|
|
|
|
public:
|
2018-11-13 16:33:03 +00:00
|
|
|
sla::EigenMesh3D emesh; // index-triangle representation
|
2019-02-17 12:05:22 +00:00
|
|
|
std::vector<sla::SupportPoint> support_points; // all the support points (manual/auto)
|
2018-11-13 16:33:03 +00:00
|
|
|
SupportTreePtr support_tree_ptr; // the supports
|
|
|
|
SlicedSupports support_slices; // sliced supports
|
2019-01-29 14:10:07 +00:00
|
|
|
|
|
|
|
inline SupportData(const TriangleMesh& trmesh): emesh(trmesh) {}
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2018-11-22 11:13:58 +00:00
|
|
|
// should add up to 100 (%)
|
2018-11-09 17:32:35 +00:00
|
|
|
const std::array<unsigned, slaposCount> OBJ_STEP_LEVELS =
|
|
|
|
{
|
2018-11-22 11:13:58 +00:00
|
|
|
10, // slaposObjectSlice,
|
2018-12-14 15:15:59 +00:00
|
|
|
30, // slaposSupportPoints,
|
2018-11-22 11:13:58 +00:00
|
|
|
25, // slaposSupportTree,
|
|
|
|
25, // slaposBasePool,
|
2018-11-26 13:43:28 +00:00
|
|
|
5, // slaposSliceSupports,
|
|
|
|
5 // slaposIndexSlices
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const std::array<std::string, slaposCount> OBJ_STEP_LABELS =
|
|
|
|
{
|
|
|
|
L("Slicing model"), // slaposObjectSlice,
|
2018-12-14 15:15:59 +00:00
|
|
|
L("Generating support points"), // slaposSupportPoints,
|
2018-11-09 17:32:35 +00:00
|
|
|
L("Generating support tree"), // slaposSupportTree,
|
2019-02-21 07:44:07 +00:00
|
|
|
L("Generating pad"), // slaposBasePool,
|
2018-11-26 13:43:28 +00:00
|
|
|
L("Slicing supports"), // slaposSliceSupports,
|
|
|
|
L("Slicing supports") // slaposIndexSlices,
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-22 11:13:58 +00:00
|
|
|
// Should also add up to 100 (%)
|
2018-11-09 17:32:35 +00:00
|
|
|
const std::array<unsigned, slapsCount> PRINT_STEP_LEVELS =
|
|
|
|
{
|
2019-03-26 17:04:04 +00:00
|
|
|
5, // slapsStats
|
|
|
|
94, // slapsRasterize
|
|
|
|
1, // slapsValidate
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const std::array<std::string, slapsCount> PRINT_STEP_LABELS =
|
|
|
|
{
|
2019-03-26 17:04:04 +00:00
|
|
|
L("Calculating statistics"), // slapsStats
|
2018-11-09 17:32:35 +00:00
|
|
|
L("Rasterizing layers"), // slapsRasterize
|
|
|
|
L("Validating"), // slapsValidate
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:18:40 +00:00
|
|
|
void SLAPrint::clear()
|
|
|
|
{
|
2018-11-27 12:52:42 +00:00
|
|
|
tbb::mutex::scoped_lock lock(this->state_mutex());
|
2018-11-09 11:02:42 +00:00
|
|
|
// The following call should stop background processing if it is running.
|
|
|
|
this->invalidate_all_steps();
|
2018-12-03 15:25:21 +00:00
|
|
|
for (SLAPrintObject *object : m_objects)
|
|
|
|
delete object;
|
2018-11-27 12:52:42 +00:00
|
|
|
m_objects.clear();
|
2018-12-03 15:25:21 +00:00
|
|
|
m_model.clear_objects();
|
2018-11-08 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// Transformation without rotation around Z and without a shift by X and Y.
|
|
|
|
static Transform3d sla_trafo(const ModelObject &model_object)
|
|
|
|
{
|
|
|
|
ModelInstance &model_instance = *model_object.instances.front();
|
|
|
|
Vec3d offset = model_instance.get_offset();
|
|
|
|
Vec3d rotation = model_instance.get_rotation();
|
|
|
|
offset(0) = 0.;
|
|
|
|
offset(1) = 0.;
|
|
|
|
rotation(2) = 0.;
|
|
|
|
return Geometry::assemble_transform(offset, rotation, model_instance.get_scaling_factor(), model_instance.get_mirror());
|
|
|
|
}
|
|
|
|
|
|
|
|
// List of instances, where the ModelInstance transformation is a composite of sla_trafo and the transformation defined by SLAPrintObject::Instance.
|
|
|
|
static std::vector<SLAPrintObject::Instance> sla_instances(const ModelObject &model_object)
|
|
|
|
{
|
|
|
|
std::vector<SLAPrintObject::Instance> instances;
|
|
|
|
for (ModelInstance *model_instance : model_object.instances)
|
|
|
|
if (model_instance->is_printable()) {
|
|
|
|
instances.emplace_back(SLAPrintObject::Instance(
|
2018-11-27 12:52:42 +00:00
|
|
|
model_instance->id(),
|
2018-11-21 16:35:35 +00:00
|
|
|
Point::new_scale(model_instance->get_offset(X), model_instance->get_offset(Y)),
|
|
|
|
float(model_instance->get_rotation(Z))));
|
|
|
|
}
|
|
|
|
return instances;
|
|
|
|
}
|
|
|
|
|
2018-12-03 12:14:28 +00:00
|
|
|
SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, const DynamicPrintConfig &config_in)
|
2018-11-08 19:18:40 +00:00
|
|
|
{
|
2018-11-21 16:35:35 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
check_model_ids_validity(model);
|
|
|
|
#endif /* _DEBUG */
|
2018-11-09 11:02:42 +00:00
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// Make a copy of the config, normalize it.
|
2018-11-14 17:04:43 +00:00
|
|
|
DynamicPrintConfig config(config_in);
|
2019-03-14 17:47:26 +00:00
|
|
|
config.option("sla_print_settings_id", true);
|
|
|
|
config.option("sla_material_settings_id", true);
|
|
|
|
config.option("printer_settings_id", true);
|
2018-11-14 17:04:43 +00:00
|
|
|
config.normalize();
|
2018-11-21 16:35:35 +00:00
|
|
|
// Collect changes to print config.
|
2018-12-03 12:14:28 +00:00
|
|
|
t_config_option_keys print_diff = m_print_config.diff(config);
|
2018-11-21 16:35:35 +00:00
|
|
|
t_config_option_keys printer_diff = m_printer_config.diff(config);
|
|
|
|
t_config_option_keys material_diff = m_material_config.diff(config);
|
|
|
|
t_config_option_keys object_diff = m_default_object_config.diff(config);
|
2018-12-03 12:14:28 +00:00
|
|
|
t_config_option_keys placeholder_parser_diff = this->placeholder_parser().config_diff(config);
|
2018-11-21 16:35:35 +00:00
|
|
|
|
2018-11-27 12:52:42 +00:00
|
|
|
// Do not use the ApplyStatus as we will use the max function when updating apply_status.
|
2018-11-21 16:35:35 +00:00
|
|
|
unsigned int apply_status = APPLY_STATUS_UNCHANGED;
|
|
|
|
auto update_apply_status = [&apply_status](bool invalidated)
|
|
|
|
{ apply_status = std::max<unsigned int>(apply_status, invalidated ? APPLY_STATUS_INVALIDATED : APPLY_STATUS_CHANGED); };
|
2018-12-03 12:14:28 +00:00
|
|
|
if (! (print_diff.empty() && printer_diff.empty() && material_diff.empty() && object_diff.empty()))
|
2018-11-21 16:35:35 +00:00
|
|
|
update_apply_status(false);
|
2018-11-14 17:04:43 +00:00
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// Grab the lock for the Print / PrintObject milestones.
|
2018-11-27 12:52:42 +00:00
|
|
|
tbb::mutex::scoped_lock lock(this->state_mutex());
|
2018-11-21 16:35:35 +00:00
|
|
|
|
|
|
|
// The following call may stop the background processing.
|
2018-12-03 12:14:28 +00:00
|
|
|
if (! print_diff.empty())
|
|
|
|
update_apply_status(this->invalidate_state_by_config_options(print_diff));
|
2018-11-27 12:52:42 +00:00
|
|
|
if (! printer_diff.empty())
|
|
|
|
update_apply_status(this->invalidate_state_by_config_options(printer_diff));
|
|
|
|
if (! material_diff.empty())
|
|
|
|
update_apply_status(this->invalidate_state_by_config_options(material_diff));
|
2018-11-21 16:35:35 +00:00
|
|
|
|
2018-12-03 12:14:28 +00:00
|
|
|
// Apply variables to placeholder parser. The placeholder parser is currently used
|
|
|
|
// only to generate the output file name.
|
|
|
|
if (! placeholder_parser_diff.empty()) {
|
|
|
|
// update_apply_status(this->invalidate_step(slapsRasterize));
|
|
|
|
PlaceholderParser &pp = this->placeholder_parser();
|
|
|
|
pp.apply_config(config);
|
|
|
|
// Set the profile aliases for the PrintBase::output_filename()
|
2019-03-14 17:47:26 +00:00
|
|
|
pp.set("print_preset", config.option("sla_print_settings_id")->clone());
|
|
|
|
pp.set("material_preset", config.option("sla_material_settings_id")->clone());
|
|
|
|
pp.set("printer_preset", config.option("printer_settings_id")->clone());
|
2018-12-03 12:14:28 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// It is also safe to change m_config now after this->invalidate_state_by_config_options() call.
|
2018-12-03 12:14:28 +00:00
|
|
|
m_print_config.apply_only(config, print_diff, true);
|
2018-11-27 12:52:42 +00:00
|
|
|
m_printer_config.apply_only(config, printer_diff, true);
|
2018-11-21 16:35:35 +00:00
|
|
|
// Handle changes to material config.
|
|
|
|
m_material_config.apply_only(config, material_diff, true);
|
|
|
|
// Handle changes to object config defaults
|
|
|
|
m_default_object_config.apply_only(config, object_diff, true);
|
|
|
|
|
|
|
|
struct ModelObjectStatus {
|
|
|
|
enum Status {
|
|
|
|
Unknown,
|
|
|
|
Old,
|
|
|
|
New,
|
|
|
|
Moved,
|
|
|
|
Deleted,
|
|
|
|
};
|
|
|
|
ModelObjectStatus(ModelID id, Status status = Unknown) : id(id), status(status) {}
|
|
|
|
ModelID id;
|
|
|
|
Status status;
|
|
|
|
// Search by id.
|
|
|
|
bool operator<(const ModelObjectStatus &rhs) const { return id < rhs.id; }
|
|
|
|
};
|
|
|
|
std::set<ModelObjectStatus> model_object_status;
|
|
|
|
|
|
|
|
// 1) Synchronize model objects.
|
|
|
|
if (model.id() != m_model.id()) {
|
|
|
|
// Kill everything, initialize from scratch.
|
|
|
|
// Stop background processing.
|
2019-02-21 11:39:38 +00:00
|
|
|
this->call_cancel_callback();
|
2018-11-21 16:35:35 +00:00
|
|
|
update_apply_status(this->invalidate_all_steps());
|
|
|
|
for (SLAPrintObject *object : m_objects) {
|
|
|
|
model_object_status.emplace(object->model_object()->id(), ModelObjectStatus::Deleted);
|
2018-12-22 09:02:42 +00:00
|
|
|
update_apply_status(object->invalidate_all_steps());
|
2018-11-21 16:35:35 +00:00
|
|
|
delete object;
|
|
|
|
}
|
|
|
|
m_objects.clear();
|
2018-11-09 11:02:42 +00:00
|
|
|
m_model.assign_copy(model);
|
2018-11-21 16:35:35 +00:00
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::New);
|
|
|
|
} else {
|
|
|
|
if (model_object_list_equal(m_model, model)) {
|
|
|
|
// The object list did not change.
|
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Old);
|
|
|
|
} else if (model_object_list_extended(m_model, model)) {
|
|
|
|
// Add new objects. Their volumes and configs will be synchronized later.
|
|
|
|
update_apply_status(this->invalidate_step(slapsRasterize));
|
|
|
|
for (const ModelObject *model_object : m_model.objects)
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Old);
|
|
|
|
for (size_t i = m_model.objects.size(); i < model.objects.size(); ++ i) {
|
|
|
|
model_object_status.emplace(model.objects[i]->id(), ModelObjectStatus::New);
|
|
|
|
m_model.objects.emplace_back(ModelObject::new_copy(*model.objects[i]));
|
|
|
|
m_model.objects.back()->set_model(&m_model);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Reorder the objects, add new objects.
|
|
|
|
// First stop background processing before shuffling or deleting the PrintObjects in the object list.
|
2019-02-21 11:39:38 +00:00
|
|
|
this->call_cancel_callback();
|
2018-11-21 16:35:35 +00:00
|
|
|
update_apply_status(this->invalidate_step(slapsRasterize));
|
|
|
|
// Second create a new list of objects.
|
|
|
|
std::vector<ModelObject*> model_objects_old(std::move(m_model.objects));
|
|
|
|
m_model.objects.clear();
|
|
|
|
m_model.objects.reserve(model.objects.size());
|
|
|
|
auto by_id_lower = [](const ModelObject *lhs, const ModelObject *rhs){ return lhs->id() < rhs->id(); };
|
|
|
|
std::sort(model_objects_old.begin(), model_objects_old.end(), by_id_lower);
|
|
|
|
for (const ModelObject *mobj : model.objects) {
|
|
|
|
auto it = std::lower_bound(model_objects_old.begin(), model_objects_old.end(), mobj, by_id_lower);
|
|
|
|
if (it == model_objects_old.end() || (*it)->id() != mobj->id()) {
|
|
|
|
// New ModelObject added.
|
|
|
|
m_model.objects.emplace_back(ModelObject::new_copy(*mobj));
|
|
|
|
m_model.objects.back()->set_model(&m_model);
|
|
|
|
model_object_status.emplace(mobj->id(), ModelObjectStatus::New);
|
|
|
|
} else {
|
|
|
|
// Existing ModelObject re-added (possibly moved in the list).
|
|
|
|
m_model.objects.emplace_back(*it);
|
|
|
|
model_object_status.emplace(mobj->id(), ModelObjectStatus::Moved);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool deleted_any = false;
|
|
|
|
for (ModelObject *&model_object : model_objects_old) {
|
|
|
|
if (model_object_status.find(ModelObjectStatus(model_object->id())) == model_object_status.end()) {
|
|
|
|
model_object_status.emplace(model_object->id(), ModelObjectStatus::Deleted);
|
|
|
|
deleted_any = true;
|
|
|
|
} else
|
|
|
|
// Do not delete this ModelObject instance.
|
|
|
|
model_object = nullptr;
|
|
|
|
}
|
|
|
|
if (deleted_any) {
|
|
|
|
// Delete PrintObjects of the deleted ModelObjects.
|
|
|
|
std::vector<SLAPrintObject*> print_objects_old = std::move(m_objects);
|
|
|
|
m_objects.clear();
|
|
|
|
m_objects.reserve(print_objects_old.size());
|
|
|
|
for (SLAPrintObject *print_object : print_objects_old) {
|
|
|
|
auto it_status = model_object_status.find(ModelObjectStatus(print_object->model_object()->id()));
|
|
|
|
assert(it_status != model_object_status.end());
|
|
|
|
if (it_status->status == ModelObjectStatus::Deleted) {
|
|
|
|
update_apply_status(print_object->invalidate_all_steps());
|
|
|
|
delete print_object;
|
|
|
|
} else
|
|
|
|
m_objects.emplace_back(print_object);
|
|
|
|
}
|
|
|
|
for (ModelObject *model_object : model_objects_old)
|
|
|
|
delete model_object;
|
2018-11-13 16:33:03 +00:00
|
|
|
}
|
2018-11-09 11:02:42 +00:00
|
|
|
}
|
2018-11-12 10:46:38 +00:00
|
|
|
}
|
2018-11-09 11:02:42 +00:00
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// 2) Map print objects including their transformation matrices.
|
|
|
|
struct PrintObjectStatus {
|
|
|
|
enum Status {
|
|
|
|
Unknown,
|
|
|
|
Deleted,
|
|
|
|
Reused,
|
|
|
|
New
|
|
|
|
};
|
2018-11-27 12:52:42 +00:00
|
|
|
PrintObjectStatus(SLAPrintObject *print_object, Status status = Unknown) :
|
2018-11-21 16:35:35 +00:00
|
|
|
id(print_object->model_object()->id()),
|
|
|
|
print_object(print_object),
|
|
|
|
trafo(print_object->trafo()),
|
|
|
|
status(status) {}
|
|
|
|
PrintObjectStatus(ModelID id) : id(id), print_object(nullptr), trafo(Transform3d::Identity()), status(Unknown) {}
|
|
|
|
// ID of the ModelObject & PrintObject
|
|
|
|
ModelID id;
|
|
|
|
// Pointer to the old PrintObject
|
|
|
|
SLAPrintObject *print_object;
|
2018-11-27 12:52:42 +00:00
|
|
|
// Trafo generated with model_object->world_matrix(true)
|
2018-11-21 16:35:35 +00:00
|
|
|
Transform3d trafo;
|
|
|
|
Status status;
|
|
|
|
// Search by id.
|
|
|
|
bool operator<(const PrintObjectStatus &rhs) const { return id < rhs.id; }
|
|
|
|
};
|
|
|
|
std::multiset<PrintObjectStatus> print_object_status;
|
|
|
|
for (SLAPrintObject *print_object : m_objects)
|
|
|
|
print_object_status.emplace(PrintObjectStatus(print_object));
|
|
|
|
|
|
|
|
// 3) Synchronize ModelObjects & PrintObjects.
|
|
|
|
std::vector<SLAPrintObject*> print_objects_new;
|
|
|
|
print_objects_new.reserve(std::max(m_objects.size(), m_model.objects.size()));
|
|
|
|
bool new_objects = false;
|
|
|
|
for (size_t idx_model_object = 0; idx_model_object < model.objects.size(); ++ idx_model_object) {
|
|
|
|
ModelObject &model_object = *m_model.objects[idx_model_object];
|
|
|
|
auto it_status = model_object_status.find(ModelObjectStatus(model_object.id()));
|
|
|
|
assert(it_status != model_object_status.end());
|
|
|
|
assert(it_status->status != ModelObjectStatus::Deleted);
|
2019-03-13 14:44:50 +00:00
|
|
|
// PrintObject for this ModelObject, if it exists.
|
|
|
|
auto it_print_object_status = print_object_status.end();
|
|
|
|
if (it_status->status != ModelObjectStatus::New) {
|
|
|
|
// Update the ModelObject instance, possibly invalidate the linked PrintObjects.
|
|
|
|
assert(it_status->status == ModelObjectStatus::Old || it_status->status == ModelObjectStatus::Moved);
|
|
|
|
const ModelObject &model_object_new = *model.objects[idx_model_object];
|
2019-03-14 11:10:10 +00:00
|
|
|
it_print_object_status = print_object_status.lower_bound(PrintObjectStatus(model_object.id()));
|
2019-03-13 14:44:50 +00:00
|
|
|
if (it_print_object_status != print_object_status.end() && it_print_object_status->id != model_object.id())
|
|
|
|
it_print_object_status = print_object_status.end();
|
|
|
|
// Check whether a model part volume was added or removed, their transformations or order changed.
|
|
|
|
bool model_parts_differ = model_volume_list_changed(model_object, model_object_new, ModelVolumeType::MODEL_PART);
|
|
|
|
bool sla_trafo_differs = model_object.instances.empty() != model_object_new.instances.empty() ||
|
|
|
|
(! model_object.instances.empty() && ! sla_trafo(model_object).isApprox(sla_trafo(model_object_new)));
|
|
|
|
if (model_parts_differ || sla_trafo_differs) {
|
|
|
|
// The very first step (the slicing step) is invalidated. One may freely remove all associated PrintObjects.
|
|
|
|
if (it_print_object_status != print_object_status.end()) {
|
|
|
|
update_apply_status(it_print_object_status->print_object->invalidate_all_steps());
|
|
|
|
const_cast<PrintObjectStatus&>(*it_print_object_status).status = PrintObjectStatus::Deleted;
|
|
|
|
}
|
|
|
|
// Copy content of the ModelObject including its ID, do not change the parent.
|
|
|
|
model_object.assign_copy(model_object_new);
|
|
|
|
} else {
|
|
|
|
// Synchronize Object's config.
|
|
|
|
bool object_config_changed = model_object.config != model_object_new.config;
|
|
|
|
if (object_config_changed)
|
|
|
|
model_object.config = model_object_new.config;
|
|
|
|
if (! object_diff.empty() || object_config_changed) {
|
|
|
|
SLAPrintObjectConfig new_config = m_default_object_config;
|
|
|
|
normalize_and_apply_config(new_config, model_object.config);
|
|
|
|
if (it_print_object_status != print_object_status.end()) {
|
|
|
|
t_config_option_keys diff = it_print_object_status->print_object->config().diff(new_config);
|
|
|
|
if (! diff.empty()) {
|
|
|
|
update_apply_status(it_print_object_status->print_object->invalidate_state_by_config_options(diff));
|
|
|
|
it_print_object_status->print_object->config_apply_only(new_config, diff, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*if (model_object.sla_support_points != model_object_new.sla_support_points) {
|
|
|
|
model_object.sla_support_points = model_object_new.sla_support_points;
|
|
|
|
if (it_print_object_status != print_object_status.end())
|
|
|
|
update_apply_status(it_print_object_status->print_object->invalidate_step(slaposSupportPoints));
|
|
|
|
}
|
|
|
|
if (model_object.sla_points_status != model_object_new.sla_points_status) {
|
|
|
|
// Change of this status should invalidate support points. The points themselves are not enough, there are none
|
|
|
|
// in case that nothing was generated OR that points were autogenerated already and not copied to the front-end.
|
|
|
|
// These cases can only be differentiated by checking the status change. However, changing from 'Generating' should NOT
|
|
|
|
// invalidate - that would keep stopping the background processing without a reason.
|
|
|
|
if (model_object.sla_points_status != sla::PointsStatus::Generating)
|
|
|
|
if (it_print_object_status != print_object_status.end())
|
|
|
|
update_apply_status(it_print_object_status->print_object->invalidate_step(slaposSupportPoints));
|
|
|
|
model_object.sla_points_status = model_object_new.sla_points_status;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
bool old_user_modified = model_object.sla_points_status == sla::PointsStatus::UserModified;
|
|
|
|
bool new_user_modified = model_object_new.sla_points_status == sla::PointsStatus::UserModified;
|
|
|
|
if ((old_user_modified && ! new_user_modified) || // switching to automatic supports from manual supports
|
|
|
|
(! old_user_modified && new_user_modified) || // switching to manual supports from automatic supports
|
|
|
|
(new_user_modified && model_object.sla_support_points != model_object_new.sla_support_points)) {
|
|
|
|
if (it_print_object_status != print_object_status.end())
|
|
|
|
update_apply_status(it_print_object_status->print_object->invalidate_step(slaposSupportPoints));
|
|
|
|
|
|
|
|
model_object.sla_points_status = model_object_new.sla_points_status;
|
|
|
|
model_object.sla_support_points = model_object_new.sla_support_points;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the ModelObject name, input_file and instances. The instances will compared against PrintObject instances in the next step.
|
|
|
|
model_object.name = model_object_new.name;
|
|
|
|
model_object.input_file = model_object_new.input_file;
|
|
|
|
model_object.clear_instances();
|
|
|
|
model_object.instances.reserve(model_object_new.instances.size());
|
|
|
|
for (const ModelInstance *model_instance : model_object_new.instances) {
|
|
|
|
model_object.instances.emplace_back(new ModelInstance(*model_instance));
|
|
|
|
model_object.instances.back()->set_model_object(&model_object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-21 16:35:35 +00:00
|
|
|
|
|
|
|
std::vector<SLAPrintObject::Instance> new_instances = sla_instances(model_object);
|
|
|
|
if (it_print_object_status != print_object_status.end() && it_print_object_status->status != PrintObjectStatus::Deleted) {
|
|
|
|
// The SLAPrintObject is already there.
|
2019-02-20 11:21:22 +00:00
|
|
|
if (new_instances.empty()) {
|
|
|
|
const_cast<PrintObjectStatus&>(*it_print_object_status).status = PrintObjectStatus::Deleted;
|
|
|
|
} else {
|
|
|
|
if (new_instances != it_print_object_status->print_object->instances()) {
|
|
|
|
// Instances changed.
|
|
|
|
it_print_object_status->print_object->set_instances(new_instances);
|
|
|
|
update_apply_status(this->invalidate_step(slapsRasterize));
|
|
|
|
}
|
|
|
|
print_objects_new.emplace_back(it_print_object_status->print_object);
|
|
|
|
const_cast<PrintObjectStatus&>(*it_print_object_status).status = PrintObjectStatus::Reused;
|
|
|
|
}
|
|
|
|
} else if (! new_instances.empty()) {
|
2018-11-21 16:35:35 +00:00
|
|
|
auto print_object = new SLAPrintObject(this, &model_object);
|
2019-02-05 14:57:19 +00:00
|
|
|
|
|
|
|
// FIXME: this invalidates the transformed mesh in SLAPrintObject
|
|
|
|
// which is expensive to calculate (especially the raw_mesh() call)
|
2018-11-21 16:35:35 +00:00
|
|
|
print_object->set_trafo(sla_trafo(model_object));
|
2019-02-05 14:57:19 +00:00
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
print_object->set_instances(new_instances);
|
|
|
|
print_object->config_apply(config, true);
|
|
|
|
print_objects_new.emplace_back(print_object);
|
|
|
|
new_objects = true;
|
|
|
|
}
|
2018-11-12 10:46:38 +00:00
|
|
|
}
|
2018-11-09 11:02:42 +00:00
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
if (m_objects != print_objects_new) {
|
2019-02-21 11:39:38 +00:00
|
|
|
this->call_cancel_callback();
|
2018-11-21 16:35:35 +00:00
|
|
|
update_apply_status(this->invalidate_all_steps());
|
|
|
|
m_objects = print_objects_new;
|
|
|
|
// Delete the PrintObjects marked as Unknown or Deleted.
|
|
|
|
bool deleted_objects = false;
|
|
|
|
for (auto &pos : print_object_status)
|
|
|
|
if (pos.status == PrintObjectStatus::Unknown || pos.status == PrintObjectStatus::Deleted) {
|
2018-12-22 09:02:42 +00:00
|
|
|
update_apply_status(pos.print_object->invalidate_all_steps());
|
2018-11-21 16:35:35 +00:00
|
|
|
delete pos.print_object;
|
|
|
|
deleted_objects = true;
|
|
|
|
}
|
2018-12-22 09:02:42 +00:00
|
|
|
if (new_objects)
|
|
|
|
update_apply_status(false);
|
2018-11-21 16:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
check_model_ids_equal(m_model, model);
|
|
|
|
#endif /* _DEBUG */
|
|
|
|
|
|
|
|
return static_cast<ApplyStatus>(apply_status);
|
2018-11-08 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 10:40:56 +00:00
|
|
|
// After calling the apply() function, set_task() may be called to limit the task to be processed by process().
|
2019-02-21 07:44:07 +00:00
|
|
|
void SLAPrint::set_task(const TaskParams ¶ms)
|
|
|
|
{
|
|
|
|
// Grab the lock for the Print / PrintObject milestones.
|
|
|
|
tbb::mutex::scoped_lock lock(this->state_mutex());
|
|
|
|
|
2019-02-21 10:40:56 +00:00
|
|
|
int n_object_steps = int(params.to_object_step) + 1;
|
|
|
|
if (n_object_steps == 0)
|
2019-02-21 07:44:07 +00:00
|
|
|
n_object_steps = (int)slaposCount;
|
|
|
|
|
|
|
|
if (params.single_model_object.valid()) {
|
2019-02-25 09:21:12 +00:00
|
|
|
// Find the print object to be processed with priority.
|
2019-02-21 07:44:07 +00:00
|
|
|
SLAPrintObject *print_object = nullptr;
|
|
|
|
size_t idx_print_object = 0;
|
2019-02-25 09:21:12 +00:00
|
|
|
for (; idx_print_object < m_objects.size(); ++ idx_print_object)
|
2019-02-21 07:44:07 +00:00
|
|
|
if (m_objects[idx_print_object]->model_object()->id() == params.single_model_object) {
|
|
|
|
print_object = m_objects[idx_print_object];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(print_object != nullptr);
|
2019-02-25 09:21:12 +00:00
|
|
|
// Find out whether the priority print object is being currently processed.
|
|
|
|
bool running = false;
|
|
|
|
for (int istep = 0; istep < n_object_steps; ++ istep) {
|
|
|
|
if (! print_object->m_stepmask[istep])
|
|
|
|
// Step was skipped, cancel.
|
|
|
|
break;
|
|
|
|
if (print_object->is_step_started_unguarded(SLAPrintObjectStep(istep))) {
|
|
|
|
// No step was skipped, and a wanted step is being processed. Don't cancel.
|
|
|
|
running = true;
|
2019-02-21 07:44:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 09:21:12 +00:00
|
|
|
if (! running)
|
2019-02-21 11:39:38 +00:00
|
|
|
this->call_cancel_callback();
|
2019-02-21 07:44:07 +00:00
|
|
|
|
|
|
|
// Now the background process is either stopped, or it is inside one of the print object steps to be calculated anyway.
|
|
|
|
if (params.single_model_instance_only) {
|
|
|
|
// Suppress all the steps of other instances.
|
|
|
|
for (SLAPrintObject *po : m_objects)
|
2019-02-25 09:21:12 +00:00
|
|
|
for (int istep = 0; istep < (int)slaposCount; ++ istep)
|
2019-02-21 10:40:56 +00:00
|
|
|
po->m_stepmask[istep] = false;
|
2019-02-25 09:21:12 +00:00
|
|
|
} else if (! running) {
|
2019-02-21 07:44:07 +00:00
|
|
|
// Swap the print objects, so that the selected print_object is first in the row.
|
|
|
|
// At this point the background processing must be stopped, so it is safe to shuffle print objects.
|
|
|
|
if (idx_print_object != 0)
|
|
|
|
std::swap(m_objects.front(), m_objects[idx_print_object]);
|
|
|
|
}
|
2019-02-25 09:21:12 +00:00
|
|
|
// and set the steps for the current object.
|
2019-02-21 07:44:07 +00:00
|
|
|
for (int istep = 0; istep < n_object_steps; ++ istep)
|
|
|
|
print_object->m_stepmask[istep] = true;
|
2019-02-25 09:21:12 +00:00
|
|
|
for (int istep = n_object_steps; istep < (int)slaposCount; ++ istep)
|
2019-02-21 07:44:07 +00:00
|
|
|
print_object->m_stepmask[istep] = false;
|
2019-02-25 09:21:12 +00:00
|
|
|
} else {
|
|
|
|
// Slicing all objects.
|
|
|
|
bool running = false;
|
|
|
|
for (SLAPrintObject *print_object : m_objects)
|
|
|
|
for (int istep = 0; istep < n_object_steps; ++ istep) {
|
|
|
|
if (! print_object->m_stepmask[istep]) {
|
|
|
|
// Step may have been skipped. Restart.
|
|
|
|
goto loop_end;
|
|
|
|
}
|
|
|
|
if (print_object->is_step_started_unguarded(SLAPrintObjectStep(istep))) {
|
|
|
|
// This step is running, and the state cannot be changed due to the this->state_mutex() being locked.
|
|
|
|
// It is safe to manipulate m_stepmask of other SLAPrintObjects and SLAPrint now.
|
|
|
|
running = true;
|
|
|
|
goto loop_end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loop_end:
|
|
|
|
if (! running)
|
|
|
|
this->call_cancel_callback();
|
|
|
|
for (SLAPrintObject *po : m_objects) {
|
|
|
|
for (int istep = 0; istep < n_object_steps; ++ istep)
|
|
|
|
po->m_stepmask[istep] = true;
|
|
|
|
for (int istep = n_object_steps; istep < (int)slaposCount; ++ istep)
|
|
|
|
po->m_stepmask[istep] = false;
|
|
|
|
}
|
|
|
|
}
|
2019-02-21 10:40:56 +00:00
|
|
|
|
|
|
|
if (params.to_object_step != -1 || params.to_print_step != -1) {
|
|
|
|
// Limit the print steps.
|
|
|
|
size_t istep = (params.to_object_step != -1) ? 0 : size_t(params.to_print_step) + 1;
|
|
|
|
for (; istep < m_stepmask.size(); ++ istep)
|
|
|
|
m_stepmask[istep] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up after process() finished, either with success, error or if canceled.
|
|
|
|
// The adjustments on the SLAPrint / SLAPrintObject data due to set_task() are to be reverted here.
|
|
|
|
void SLAPrint::finalize()
|
|
|
|
{
|
|
|
|
for (SLAPrintObject *po : m_objects)
|
|
|
|
for (int istep = 0; istep < (int)slaposCount; ++ istep)
|
|
|
|
po->m_stepmask[istep] = true;
|
|
|
|
for (int istep = 0; istep < (int)slapsCount; ++ istep)
|
|
|
|
m_stepmask[istep] = true;
|
2019-02-21 07:44:07 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 14:46:04 +00:00
|
|
|
// Generate a recommended output file name based on the format template, default extension, and template parameters
|
|
|
|
// (timestamps, object placeholders derived from the model, current placeholder prameters and print statistics.
|
|
|
|
// Use the final print statistics if available, or just keep the print statistics placeholders if not available yet (before the output is finalized).
|
|
|
|
std::string SLAPrint::output_filename() const
|
|
|
|
{
|
|
|
|
DynamicConfig config = this->finished() ? this->print_statistics().config() : this->print_statistics().placeholders();
|
2019-02-25 14:01:39 +00:00
|
|
|
return this->PrintBase::output_filename(m_print_config.output_filename_format.value, "sl1", &config);
|
2019-02-21 14:46:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 12:03:07 +00:00
|
|
|
namespace {
|
|
|
|
// Compile the argument for support creation from the static print config.
|
|
|
|
sla::SupportConfig make_support_cfg(const SLAPrintObjectConfig& c) {
|
|
|
|
sla::SupportConfig scfg;
|
|
|
|
|
|
|
|
scfg.head_front_radius_mm = 0.5*c.support_head_front_diameter.getFloat();
|
|
|
|
scfg.head_back_radius_mm = 0.5*c.support_pillar_diameter.getFloat();
|
|
|
|
scfg.head_penetration_mm = c.support_head_penetration.getFloat();
|
|
|
|
scfg.head_width_mm = c.support_head_width.getFloat();
|
|
|
|
scfg.object_elevation_mm = c.support_object_elevation.getFloat();
|
2019-02-27 10:39:02 +00:00
|
|
|
scfg.bridge_slope = c.support_critical_angle.getFloat() * PI / 180.0 ;
|
2018-11-23 12:03:07 +00:00
|
|
|
scfg.max_bridge_length_mm = c.support_max_bridge_length.getFloat();
|
2019-03-08 10:39:34 +00:00
|
|
|
scfg.max_pillar_link_distance_mm = c.support_max_pillar_link_distance.getFloat();
|
2019-01-09 11:21:43 +00:00
|
|
|
switch(c.support_pillar_connection_mode.getInt()) {
|
|
|
|
case slapcmZigZag:
|
|
|
|
scfg.pillar_connection_mode = sla::PillarConnectionMode::zigzag; break;
|
|
|
|
case slapcmCross:
|
|
|
|
scfg.pillar_connection_mode = sla::PillarConnectionMode::cross; break;
|
|
|
|
case slapcmDynamic:
|
|
|
|
scfg.pillar_connection_mode = sla::PillarConnectionMode::dynamic; break;
|
|
|
|
}
|
2019-02-05 10:16:03 +00:00
|
|
|
scfg.ground_facing_only = c.support_buildplate_only.getBool();
|
2018-11-23 12:03:07 +00:00
|
|
|
scfg.pillar_widening_factor = c.support_pillar_widening_factor.getFloat();
|
|
|
|
scfg.base_radius_mm = 0.5*c.support_base_diameter.getFloat();
|
|
|
|
scfg.base_height_mm = c.support_base_height.getFloat();
|
|
|
|
|
|
|
|
return scfg;
|
|
|
|
}
|
2018-12-13 11:42:45 +00:00
|
|
|
|
2019-03-20 17:03:11 +00:00
|
|
|
sla::PoolConfig make_pool_config(const SLAPrintObjectConfig& c) {
|
|
|
|
sla::PoolConfig pcfg;
|
|
|
|
|
|
|
|
pcfg.min_wall_thickness_mm = c.pad_wall_thickness.getFloat();
|
|
|
|
pcfg.wall_slope = c.pad_wall_slope.getFloat();
|
|
|
|
pcfg.edge_radius_mm = c.pad_edge_radius.getFloat();
|
|
|
|
pcfg.max_merge_distance_mm = c.pad_max_merge_distance.getFloat();
|
|
|
|
pcfg.min_wall_height_mm = c.pad_wall_height.getFloat();
|
|
|
|
|
|
|
|
return pcfg;
|
|
|
|
}
|
|
|
|
|
2018-12-13 11:42:45 +00:00
|
|
|
void swapXY(ExPolygon& expoly) {
|
|
|
|
for(auto& p : expoly.contour.points) std::swap(p(X), p(Y));
|
|
|
|
for(auto& h : expoly.holes) for(auto& p : h.points) std::swap(p(X), p(Y));
|
|
|
|
}
|
2019-03-18 14:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string SLAPrint::validate() const
|
|
|
|
{
|
|
|
|
for(SLAPrintObject * po : m_objects) {
|
2019-03-26 16:16:50 +00:00
|
|
|
|
|
|
|
const ModelObject *mo = po->model_object();
|
|
|
|
|
|
|
|
if(po->config().supports_enable.getBool() &&
|
|
|
|
mo->sla_points_status == sla::PointsStatus::UserModified &&
|
|
|
|
mo->sla_support_points.empty())
|
|
|
|
return L("Cannot proceed without support points! "
|
|
|
|
"Add support points or disable support generation.");
|
|
|
|
|
2019-03-18 14:31:47 +00:00
|
|
|
sla::SupportConfig cfg = make_support_cfg(po->config());
|
|
|
|
|
|
|
|
double pinhead_width =
|
|
|
|
2 * cfg.head_front_radius_mm +
|
|
|
|
cfg.head_width_mm +
|
|
|
|
2 * cfg.head_back_radius_mm -
|
|
|
|
cfg.head_penetration_mm;
|
|
|
|
|
|
|
|
if(pinhead_width > cfg.object_elevation_mm)
|
2019-03-26 16:16:50 +00:00
|
|
|
return L("Elevation is too low for object.");
|
2019-03-18 14:31:47 +00:00
|
|
|
}
|
2018-12-13 11:42:45 +00:00
|
|
|
|
2019-03-18 14:31:47 +00:00
|
|
|
return "";
|
2018-11-23 12:03:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 15:58:55 +00:00
|
|
|
template<class...Args>
|
2019-03-21 14:16:33 +00:00
|
|
|
void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args)
|
|
|
|
{
|
2018-12-14 15:58:55 +00:00
|
|
|
BOOST_LOG_TRIVIAL(info) << st << "% " << msg;
|
|
|
|
p.set_status(st, msg, std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
2018-12-14 15:15:59 +00:00
|
|
|
|
2018-11-08 19:18:40 +00:00
|
|
|
void SLAPrint::process()
|
|
|
|
{
|
2018-11-09 17:32:35 +00:00
|
|
|
using namespace sla;
|
2018-12-14 08:57:48 +00:00
|
|
|
using ExPolygon = Slic3r::ExPolygon;
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2019-03-21 17:01:41 +00:00
|
|
|
if(m_objects.empty()) return;
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
// Assumption: at this point the print objects should be populated only with
|
|
|
|
// the model objects we have to process and the instances are also filtered
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
// shortcut to initial layer height
|
2018-11-20 15:12:04 +00:00
|
|
|
double ilhd = m_material_config.initial_layer_height.getFloat();
|
|
|
|
auto ilh = float(ilhd);
|
2019-03-21 17:01:41 +00:00
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
auto ilhs = coord_t(ilhd / SCALING_FACTOR);
|
2018-11-22 11:13:58 +00:00
|
|
|
const size_t objcount = m_objects.size();
|
|
|
|
|
2018-11-22 17:02:05 +00:00
|
|
|
const unsigned min_objstatus = 0; // where the per object operations start
|
2019-02-20 10:58:09 +00:00
|
|
|
const unsigned max_objstatus = PRINT_STEP_LEVELS[slapsRasterize]; // where the per object operations end
|
2018-11-22 17:02:05 +00:00
|
|
|
|
|
|
|
// the coefficient that multiplies the per object status values which
|
|
|
|
// are set up for <0, 100>. They need to be scaled into the whole process
|
2018-11-22 11:13:58 +00:00
|
|
|
const double ostepd = (max_objstatus - min_objstatus) / (objcount * 100.0);
|
2018-11-20 10:59:40 +00:00
|
|
|
|
2018-11-21 09:00:49 +00:00
|
|
|
// The slicing will be performed on an imaginary 1D grid which starts from
|
|
|
|
// the bottom of the bounding box created around the supported model. So
|
|
|
|
// the first layer which is usually thicker will be part of the supports
|
|
|
|
// not the model geometry. Exception is when the model is not in the air
|
|
|
|
// (elevation is zero) and no pad creation was requested. In this case the
|
|
|
|
// model geometry starts on the ground level and the initial layer is part
|
|
|
|
// of it. In any case, the model and the supports have to be sliced in the
|
|
|
|
// same imaginary grid (the height vector argument to TriangleMeshSlicer).
|
|
|
|
|
2018-11-13 16:46:02 +00:00
|
|
|
// Slicing the model object. This method is oversimplified and needs to
|
|
|
|
// be compared with the fff slicing algorithm for verification
|
2019-03-22 16:05:41 +00:00
|
|
|
auto slice_model = [this, ilhs, ilh](SLAPrintObject& po) {
|
2018-11-15 17:05:47 +00:00
|
|
|
TriangleMesh mesh = po.transformed_mesh();
|
2019-03-20 17:03:11 +00:00
|
|
|
|
|
|
|
// We need to prepare the slice index...
|
|
|
|
|
2019-03-22 16:05:41 +00:00
|
|
|
double lhd = m_objects.front()->m_config.layer_height.getFloat();
|
|
|
|
float lh = float(lhd);
|
2019-03-25 18:02:05 +00:00
|
|
|
auto lhs = coord_t(lhd / SCALING_FACTOR);
|
2019-03-22 16:05:41 +00:00
|
|
|
|
2019-03-20 17:03:11 +00:00
|
|
|
auto&& bb3d = mesh.bounding_box();
|
2019-03-21 17:01:41 +00:00
|
|
|
double minZ = bb3d.min(Z) - po.get_elevation();
|
|
|
|
double maxZ = bb3d.max(Z);
|
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
auto minZs = coord_t(minZ / SCALING_FACTOR);
|
|
|
|
auto maxZs = coord_t(maxZ / SCALING_FACTOR);
|
2019-03-20 17:03:11 +00:00
|
|
|
|
|
|
|
po.m_slice_index.clear();
|
2019-03-21 17:01:41 +00:00
|
|
|
po.m_slice_index.reserve(size_t(maxZs - (minZs + ilhs) / lhs) + 1);
|
2019-03-22 14:31:38 +00:00
|
|
|
po.m_slice_index.emplace_back(minZs + ilhs, float(minZ) + ilh / 2.f, ilh);
|
2019-03-20 17:03:11 +00:00
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
for(coord_t h = minZs + ilhs + lhs; h <= maxZs; h += lhs) {
|
2019-03-22 14:31:38 +00:00
|
|
|
po.m_slice_index.emplace_back(h, float(h*SCALING_FACTOR) - lh / 2.f, lh);
|
2019-03-20 17:03:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
// Just get the first record that is form the model:
|
2019-03-26 15:45:04 +00:00
|
|
|
auto slindex_it =
|
|
|
|
po.closest_slice_record(po.m_slice_index, float(bb3d.min(Z)));
|
2019-03-20 17:03:11 +00:00
|
|
|
|
|
|
|
if(slindex_it == po.m_slice_index.end())
|
|
|
|
throw std::runtime_error(L("Slicing had to be stopped "
|
|
|
|
"due to an internal error."));
|
|
|
|
|
2019-03-21 14:16:33 +00:00
|
|
|
po.m_model_height_levels.clear();
|
|
|
|
po.m_model_height_levels.reserve(po.m_slice_index.size());
|
2019-03-20 17:03:11 +00:00
|
|
|
for(auto it = slindex_it; it != po.m_slice_index.end(); ++it)
|
2019-03-21 14:16:33 +00:00
|
|
|
{
|
|
|
|
po.m_model_height_levels.emplace_back(it->slice_level());
|
|
|
|
}
|
2019-03-20 17:03:11 +00:00
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
TriangleMeshSlicer slicer(&mesh);
|
2018-11-20 10:59:40 +00:00
|
|
|
|
2019-03-20 17:03:11 +00:00
|
|
|
po.m_model_slices.clear();
|
2019-03-21 14:16:33 +00:00
|
|
|
slicer.slice(po.m_model_height_levels,
|
2019-03-20 17:03:11 +00:00
|
|
|
float(po.config().slice_closing_radius.value),
|
|
|
|
&po.m_model_slices,
|
|
|
|
[this](){ throw_if_canceled(); });
|
2018-11-15 14:14:14 +00:00
|
|
|
|
2019-03-20 17:03:11 +00:00
|
|
|
auto mit = slindex_it;
|
|
|
|
for(size_t id = 0;
|
|
|
|
id < po.m_model_slices.size() && mit != po.m_slice_index.end();
|
|
|
|
id++)
|
|
|
|
{
|
2019-03-26 09:57:45 +00:00
|
|
|
mit->set_model_slice_idx(po, id); ++mit;
|
2019-03-20 17:03:11 +00:00
|
|
|
}
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-12-14 15:15:59 +00:00
|
|
|
// In this step we check the slices, identify island and cover them with
|
|
|
|
// support points. Then we sprinkle the rest of the mesh.
|
2019-03-21 11:25:33 +00:00
|
|
|
auto support_points = [this](SLAPrintObject& po) {
|
2018-12-21 11:35:20 +00:00
|
|
|
const ModelObject& mo = *po.m_model_object;
|
2019-01-29 14:10:07 +00:00
|
|
|
po.m_supportdata.reset(
|
|
|
|
new SLAPrintObject::SupportData(po.transformed_mesh()) );
|
2018-12-21 11:35:20 +00:00
|
|
|
|
2019-01-28 15:17:43 +00:00
|
|
|
// If supports are disabled, we can skip the model scan.
|
|
|
|
if(!po.m_config.supports_enable.getBool()) return;
|
|
|
|
|
2019-01-03 13:20:01 +00:00
|
|
|
BOOST_LOG_TRIVIAL(debug) << "Support point count "
|
|
|
|
<< mo.sla_support_points.size();
|
2019-01-02 10:52:15 +00:00
|
|
|
|
2019-02-27 15:23:10 +00:00
|
|
|
// Unless the user modified the points or we already did the calculation, we will do
|
|
|
|
// the autoplacement. Otherwise we will just blindly copy the frontend data
|
2018-12-21 13:32:11 +00:00
|
|
|
// into the backend cache.
|
2019-02-27 15:23:10 +00:00
|
|
|
if (mo.sla_points_status != sla::PointsStatus::UserModified) {
|
|
|
|
|
2019-03-22 16:05:41 +00:00
|
|
|
// Hypotetical use of the slice index:
|
|
|
|
// auto bb = po.transformed_mesh().bounding_box();
|
|
|
|
// auto range = po.get_slice_records(bb.min(Z));
|
|
|
|
// std::vector<float> heights; heights.reserve(range.size());
|
|
|
|
// for(auto& record : range) heights.emplace_back(record.slice_level());
|
|
|
|
|
2018-12-21 11:35:20 +00:00
|
|
|
// calculate heights of slices (slices are calculated already)
|
2019-03-21 14:16:33 +00:00
|
|
|
const std::vector<float>& heights = po.m_model_height_levels;
|
2018-12-21 11:35:20 +00:00
|
|
|
|
2018-12-22 10:21:21 +00:00
|
|
|
this->throw_if_canceled();
|
2018-12-21 11:35:20 +00:00
|
|
|
SLAAutoSupports::Config config;
|
|
|
|
const SLAPrintObjectConfig& cfg = po.config();
|
2019-02-27 15:23:10 +00:00
|
|
|
|
|
|
|
// the density config value is in percents:
|
|
|
|
config.density_relative = float(cfg.support_points_density_relative / 100.f);
|
2019-02-20 11:21:22 +00:00
|
|
|
config.minimal_distance = float(cfg.support_points_minimal_distance);
|
2019-03-13 11:02:33 +00:00
|
|
|
config.head_diameter = float(cfg.support_head_front_diameter);
|
2018-12-21 11:35:20 +00:00
|
|
|
|
|
|
|
// Construction of this object does the calculation.
|
2018-12-22 10:21:21 +00:00
|
|
|
this->throw_if_canceled();
|
2018-12-21 13:32:11 +00:00
|
|
|
SLAAutoSupports auto_supports(po.transformed_mesh(),
|
|
|
|
po.m_supportdata->emesh,
|
|
|
|
po.get_model_slices(),
|
|
|
|
heights,
|
2018-12-22 10:21:21 +00:00
|
|
|
config,
|
|
|
|
[this]() { throw_if_canceled(); });
|
2018-12-21 13:32:11 +00:00
|
|
|
|
2018-12-21 11:35:20 +00:00
|
|
|
// Now let's extract the result.
|
2019-01-30 07:26:23 +00:00
|
|
|
const std::vector<sla::SupportPoint>& points = auto_supports.output();
|
2018-12-22 10:21:21 +00:00
|
|
|
this->throw_if_canceled();
|
2019-02-17 12:05:22 +00:00
|
|
|
po.m_supportdata->support_points = points;
|
2019-01-03 13:20:01 +00:00
|
|
|
|
|
|
|
BOOST_LOG_TRIVIAL(debug) << "Automatic support points: "
|
2019-02-17 12:05:22 +00:00
|
|
|
<< po.m_supportdata->support_points.size();
|
2019-02-06 13:18:04 +00:00
|
|
|
|
|
|
|
// Using RELOAD_SLA_SUPPORT_POINTS to tell the Plater to pass the update status to GLGizmoSlaSupports
|
|
|
|
report_status(*this, -1, L("Generating support points"), SlicingStatus::RELOAD_SLA_SUPPORT_POINTS);
|
2018-12-21 11:35:20 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-02-27 15:23:10 +00:00
|
|
|
// There are either some points on the front-end, or the user removed them on purpose. No calculation will be done.
|
2019-02-17 12:05:22 +00:00
|
|
|
po.m_supportdata->support_points = po.transformed_support_points();
|
2018-12-21 11:35:20 +00:00
|
|
|
}
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 16:46:02 +00:00
|
|
|
// In this step we create the supports
|
2018-11-22 11:13:58 +00:00
|
|
|
auto support_tree = [this, objcount, ostepd](SLAPrintObject& po) {
|
2018-11-15 14:14:14 +00:00
|
|
|
if(!po.m_supportdata) return;
|
|
|
|
|
2018-11-22 17:02:05 +00:00
|
|
|
if(!po.m_config.supports_enable.getBool()) {
|
|
|
|
// Generate empty support tree. It can still host a pad
|
|
|
|
po.m_supportdata->support_tree_ptr.reset(new SLASupportTree());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
sla::SupportConfig scfg = make_support_cfg(po.m_config);
|
|
|
|
sla::Controller ctl;
|
2018-11-22 11:13:58 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
// some magic to scale the status values coming from the support
|
|
|
|
// tree creation into the whole print process
|
|
|
|
auto stfirst = OBJ_STEP_LEVELS.begin();
|
|
|
|
auto stthis = stfirst + slaposSupportTree;
|
|
|
|
// we need to add up the status portions until this operation
|
|
|
|
int init = std::accumulate(stfirst, stthis, 0);
|
|
|
|
init = int(init * ostepd); // scale the init portion
|
2018-11-22 17:02:05 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
// scaling for the sub operations
|
|
|
|
double d = *stthis / (objcount * 100.0);
|
2018-11-22 11:13:58 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
ctl.statuscb = [this, init, d](unsigned st, const std::string& msg)
|
|
|
|
{
|
|
|
|
//FIXME this status line scaling does not seem to be correct.
|
|
|
|
// How does it account for an increasing object index?
|
|
|
|
report_status(*this, int(init + st*d), msg);
|
|
|
|
};
|
2018-11-22 17:02:05 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
ctl.stopcondition = [this](){ return canceled(); };
|
|
|
|
ctl.cancelfn = [this]() { throw_if_canceled(); };
|
2018-11-22 11:13:58 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
po.m_supportdata->support_tree_ptr.reset(
|
|
|
|
new SLASupportTree(po.m_supportdata->support_points,
|
|
|
|
po.m_supportdata->emesh, scfg, ctl));
|
2018-12-14 15:58:55 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
throw_if_canceled();
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
// Create the unified mesh
|
|
|
|
auto rc = SlicingStatus::RELOAD_SCENE;
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
// This is to prevent "Done." being displayed during merged_mesh()
|
|
|
|
report_status(*this, -1, L("Visualizing supports"));
|
|
|
|
po.m_supportdata->support_tree_ptr->merged_mesh();
|
2019-01-02 10:52:15 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
BOOST_LOG_TRIVIAL(debug) << "Processed support point count "
|
|
|
|
<< po.m_supportdata->support_points.size();
|
2019-01-02 10:52:15 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
// Check the mesh for later troubleshooting.
|
|
|
|
if(po.support_mesh().empty())
|
|
|
|
BOOST_LOG_TRIVIAL(warning) << "Support mesh is empty";
|
2019-01-02 10:52:15 +00:00
|
|
|
|
2019-02-26 16:13:33 +00:00
|
|
|
report_status(*this, -1, L("Visualizing supports"), rc);
|
2019-01-02 10:52:15 +00:00
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 16:46:02 +00:00
|
|
|
// This step generates the sla base pad
|
2018-11-29 09:57:06 +00:00
|
|
|
auto base_pool = [this](SLAPrintObject& po) {
|
2018-11-14 17:04:43 +00:00
|
|
|
// this step can only go after the support tree has been created
|
|
|
|
// and before the supports had been sliced. (or the slicing has to be
|
|
|
|
// repeated)
|
2018-11-15 14:14:14 +00:00
|
|
|
|
2018-12-20 14:22:58 +00:00
|
|
|
if(!po.m_supportdata || !po.m_supportdata->support_tree_ptr) {
|
2019-02-05 14:57:19 +00:00
|
|
|
BOOST_LOG_TRIVIAL(error) << "Uninitialized support data at "
|
|
|
|
<< "pad creation.";
|
2018-12-20 14:22:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(po.m_config.pad_enable.getBool())
|
2018-11-15 17:05:47 +00:00
|
|
|
{
|
|
|
|
double wt = po.m_config.pad_wall_thickness.getFloat();
|
|
|
|
double h = po.m_config.pad_wall_height.getFloat();
|
|
|
|
double md = po.m_config.pad_max_merge_distance.getFloat();
|
2019-02-25 11:06:38 +00:00
|
|
|
// Radius is disabled for now...
|
|
|
|
double er = 0; // po.m_config.pad_edge_radius.getFloat();
|
2019-02-25 15:04:46 +00:00
|
|
|
double tilt = po.m_config.pad_wall_slope.getFloat() * PI / 180.0;
|
2018-11-16 14:01:31 +00:00
|
|
|
double lh = po.m_config.layer_height.getFloat();
|
|
|
|
double elevation = po.m_config.support_object_elevation.getFloat();
|
2018-11-22 17:02:05 +00:00
|
|
|
if(!po.m_config.supports_enable.getBool()) elevation = 0;
|
2019-02-25 11:06:38 +00:00
|
|
|
sla::PoolConfig pcfg(wt, h, md, er, tilt);
|
2018-11-15 17:05:47 +00:00
|
|
|
|
2018-12-14 08:57:48 +00:00
|
|
|
ExPolygons bp;
|
2019-01-04 15:24:10 +00:00
|
|
|
double pad_h = sla::get_pad_fullheight(pcfg);
|
2018-11-22 17:02:05 +00:00
|
|
|
auto&& trmesh = po.transformed_mesh();
|
|
|
|
|
|
|
|
// This call can get pretty time consuming
|
2018-12-11 14:54:54 +00:00
|
|
|
auto thrfn = [this](){ throw_if_canceled(); };
|
2018-11-16 14:01:31 +00:00
|
|
|
|
2019-02-05 14:57:19 +00:00
|
|
|
if(elevation < pad_h) {
|
|
|
|
// we have to count with the model geometry for the base plate
|
2019-02-25 11:06:38 +00:00
|
|
|
sla::base_plate(trmesh, bp, float(pad_h), float(lh), thrfn);
|
2019-02-05 14:57:19 +00:00
|
|
|
}
|
2018-12-11 14:54:54 +00:00
|
|
|
|
|
|
|
pcfg.throw_on_cancel = thrfn;
|
|
|
|
po.m_supportdata->support_tree_ptr->add_pad(bp, pcfg);
|
2018-12-20 14:22:58 +00:00
|
|
|
} else {
|
|
|
|
po.m_supportdata->support_tree_ptr->remove_pad();
|
2018-11-15 17:05:47 +00:00
|
|
|
}
|
2018-11-29 09:57:06 +00:00
|
|
|
|
2018-12-11 14:54:54 +00:00
|
|
|
po.throw_if_canceled();
|
2018-11-29 09:57:06 +00:00
|
|
|
auto rc = SlicingStatus::RELOAD_SCENE;
|
2018-12-14 15:58:55 +00:00
|
|
|
report_status(*this, -1, L("Visualizing supports"), rc);
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-14 17:04:43 +00:00
|
|
|
// Slicing the support geometries similarly to the model slicing procedure.
|
|
|
|
// If the pad had been added previously (see step "base_pool" than it will
|
|
|
|
// be part of the slices)
|
2019-03-21 15:14:26 +00:00
|
|
|
auto slice_supports = [](SLAPrintObject& po) {
|
2018-11-14 17:04:43 +00:00
|
|
|
auto& sd = po.m_supportdata;
|
2019-03-22 14:31:38 +00:00
|
|
|
|
|
|
|
if(sd) sd->support_slices.clear();
|
|
|
|
|
2018-11-14 17:04:43 +00:00
|
|
|
if(sd && sd->support_tree_ptr) {
|
2019-03-21 15:14:26 +00:00
|
|
|
|
|
|
|
std::vector<float> heights; heights.reserve(po.m_slice_index.size());
|
|
|
|
|
|
|
|
for(auto& rec : po.m_slice_index) {
|
|
|
|
heights.emplace_back(rec.slice_level());
|
|
|
|
}
|
|
|
|
|
|
|
|
sd->support_slices = sd->support_tree_ptr->slice(
|
|
|
|
heights, float(po.config().slice_closing_radius.value));
|
2018-11-14 17:04:43 +00:00
|
|
|
}
|
2019-03-20 17:03:11 +00:00
|
|
|
|
|
|
|
for(size_t i = 0;
|
|
|
|
i < sd->support_slices.size() && i < po.m_slice_index.size();
|
|
|
|
++i)
|
|
|
|
{
|
2019-03-26 09:57:45 +00:00
|
|
|
po.m_slice_index[i].set_support_slice_idx(po, i);
|
2019-03-20 17:03:11 +00:00
|
|
|
}
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-26 14:03:57 +00:00
|
|
|
// We have the layer polygon collection but we need to unite them into
|
|
|
|
// an index where the key is the height level in discrete levels (clipper)
|
2019-03-21 11:25:33 +00:00
|
|
|
auto index_slices = [this/*, ilhd*/](SLAPrintObject& /*po*/) {
|
2019-03-14 14:11:27 +00:00
|
|
|
// Using RELOAD_SLA_PREVIEW to tell the Plater to pass the update status to the 3D preview to load the SLA slices.
|
|
|
|
report_status(*this, -2, "", SlicingStatus::RELOAD_SLA_PREVIEW);
|
2018-11-26 13:43:28 +00:00
|
|
|
};
|
2018-11-13 16:33:03 +00:00
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
auto fillstats = [this, ilhs]() {
|
2018-11-15 17:05:47 +00:00
|
|
|
|
2018-11-29 17:12:40 +00:00
|
|
|
// clear the rasterizer input
|
|
|
|
m_printer_input.clear();
|
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
size_t mx = 0;
|
2018-11-29 17:12:40 +00:00
|
|
|
for(SLAPrintObject * o : m_objects) {
|
2019-03-25 18:02:05 +00:00
|
|
|
if(auto m = o->get_slice_index().size() > mx) mx = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_printer_input.reserve(mx);
|
|
|
|
|
|
|
|
auto eps = coord_t(SCALED_EPSILON);
|
|
|
|
|
2018-11-29 17:12:40 +00:00
|
|
|
for(SLAPrintObject * o : m_objects) {
|
2019-03-25 18:02:05 +00:00
|
|
|
coord_t gndlvl = o->get_slice_index().front().print_level() - ilhs;
|
2019-03-22 16:05:41 +00:00
|
|
|
|
2019-03-26 09:57:45 +00:00
|
|
|
for(const SliceRecord& slicerecord : o->get_slice_index()) {
|
2019-03-25 18:02:05 +00:00
|
|
|
coord_t lvlid = slicerecord.print_level() - gndlvl;
|
2019-03-22 16:05:41 +00:00
|
|
|
|
|
|
|
// Neat trick to round the layer levels to the grid.
|
|
|
|
lvlid = eps * (lvlid / eps);
|
2019-03-21 11:25:33 +00:00
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
auto it = std::lower_bound(m_printer_input.begin(),
|
|
|
|
m_printer_input.end(),
|
2019-03-26 09:57:45 +00:00
|
|
|
PrintLayer(lvlid));
|
2019-03-21 11:25:33 +00:00
|
|
|
|
2019-03-26 13:06:40 +00:00
|
|
|
if(it == m_printer_input.end() || it->level() != lvlid)
|
2019-03-26 09:57:45 +00:00
|
|
|
it = m_printer_input.insert(it, PrintLayer(lvlid));
|
2019-03-21 11:25:33 +00:00
|
|
|
|
|
|
|
|
2019-03-26 13:06:40 +00:00
|
|
|
it->add(slicerecord);
|
2019-03-22 14:31:38 +00:00
|
|
|
}
|
2018-11-29 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
m_print_statistics.clear();
|
|
|
|
|
|
|
|
// Fill statistics
|
|
|
|
fill_statistics();
|
|
|
|
|
|
|
|
report_status(*this, -2, "", SlicingStatus::RELOAD_SLA_PREVIEW);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Rasterizing the model objects, and their supports
|
|
|
|
auto rasterize = [this, max_objstatus]() {
|
|
|
|
if(canceled()) return;
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
// collect all the keys
|
|
|
|
|
2018-12-13 11:42:45 +00:00
|
|
|
// If the raster has vertical orientation, we will flip the coordinates
|
|
|
|
bool flpXY = m_printer_config.display_orientation.getInt() ==
|
|
|
|
SLADisplayOrientation::sladoPortrait;
|
2018-12-12 17:45:45 +00:00
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
{ // create a raster printer for the current print parameters
|
|
|
|
// I don't know any better
|
|
|
|
auto& ocfg = m_objects.front()->m_config;
|
|
|
|
auto& matcfg = m_material_config;
|
|
|
|
auto& printcfg = m_printer_config;
|
|
|
|
|
|
|
|
double w = printcfg.display_width.getFloat();
|
|
|
|
double h = printcfg.display_height.getFloat();
|
2018-12-11 14:54:54 +00:00
|
|
|
auto pw = unsigned(printcfg.display_pixels_x.getInt());
|
|
|
|
auto ph = unsigned(printcfg.display_pixels_y.getInt());
|
2018-11-13 16:33:03 +00:00
|
|
|
double lh = ocfg.layer_height.getFloat();
|
|
|
|
double exp_t = matcfg.exposure_time.getFloat();
|
|
|
|
double iexp_t = matcfg.initial_exposure_time.getFloat();
|
|
|
|
|
2018-12-12 17:45:45 +00:00
|
|
|
if(flpXY) { std::swap(w, h); std::swap(pw, ph); }
|
|
|
|
|
2018-12-13 11:42:45 +00:00
|
|
|
m_printer.reset(new SLAPrinter(w, h, pw, ph, lh, exp_t, iexp_t,
|
|
|
|
flpXY? SLAPrinter::RO_PORTRAIT :
|
|
|
|
SLAPrinter::RO_LANDSCAPE));
|
2018-11-13 16:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate space for all the layers
|
|
|
|
SLAPrinter& printer = *m_printer;
|
2018-12-13 14:33:39 +00:00
|
|
|
auto lvlcnt = unsigned(m_printer_input.size());
|
2018-11-14 17:04:43 +00:00
|
|
|
printer.layers(lvlcnt);
|
2018-11-13 16:33:03 +00:00
|
|
|
|
2018-12-14 15:58:55 +00:00
|
|
|
// slot is the portion of 100% that is realted to rasterization
|
2018-11-22 12:42:52 +00:00
|
|
|
unsigned slot = PRINT_STEP_LEVELS[slapsRasterize];
|
2018-12-14 15:58:55 +00:00
|
|
|
// ist: initial state; pst: previous state
|
2018-11-22 12:42:52 +00:00
|
|
|
unsigned ist = max_objstatus, pst = ist;
|
2018-12-14 15:58:55 +00:00
|
|
|
// coefficient to map the rasterization state (0-99) to the allocated
|
|
|
|
// portion (slot) of the process state
|
2018-11-22 12:42:52 +00:00
|
|
|
double sd = (100 - ist) / 100.0;
|
|
|
|
SpinMutex slck;
|
2018-11-15 17:05:47 +00:00
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
// procedure to process one height level. This will run in parallel
|
2018-11-22 12:42:52 +00:00
|
|
|
auto lvlfn =
|
2019-03-25 18:02:05 +00:00
|
|
|
[this, &slck, &printer, slot, sd, ist, &pst, flpXY]
|
2018-11-22 12:42:52 +00:00
|
|
|
(unsigned level_id)
|
|
|
|
{
|
2018-11-15 17:05:47 +00:00
|
|
|
if(canceled()) return;
|
|
|
|
|
2019-03-26 13:06:40 +00:00
|
|
|
PrintLayer& printlayer = m_printer_input[level_id];
|
2018-11-13 16:33:03 +00:00
|
|
|
|
2018-11-15 14:14:14 +00:00
|
|
|
// Switch to the appropriate layer in the printer
|
|
|
|
printer.begin_layer(level_id);
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
for(const Polygon& poly : printlayer.transformed_slices())
|
2019-03-26 15:02:39 +00:00
|
|
|
printer.draw_polygon(poly, level_id);
|
|
|
|
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
// auto draw =
|
|
|
|
// [&printer, flpXY, level_id](Polygon& poly, const Instance& tr)
|
|
|
|
// {
|
|
|
|
// poly.rotate(double(tr.rotation));
|
|
|
|
// poly.translate(tr.shift(X), tr.shift(Y));
|
|
|
|
// if(flpXY) for(auto& p : poly.points) std::swap(p(X), p(Y));
|
|
|
|
// printer.draw_polygon(poly, level_id);
|
|
|
|
// };
|
2019-03-26 15:02:39 +00:00
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
// for(const SliceRecord& sr : printlayer.slices()) {
|
|
|
|
// if(! sr.print_obj()) continue;
|
|
|
|
|
|
|
|
// for(const Instance& inst : sr.print_obj()->instances()) {
|
|
|
|
// ExPolygons objsl = sr.get_slice(soModel);
|
|
|
|
// for(ExPolygon& poly : objsl) draw(poly, inst);
|
|
|
|
|
|
|
|
// ExPolygons supsl = sr.get_slice(soSupport);
|
|
|
|
// for(ExPolygon& poly : supsl) draw(poly, inst);
|
|
|
|
// }
|
|
|
|
// }
|
2018-11-15 14:14:14 +00:00
|
|
|
|
|
|
|
// Finish the layer for later saving it.
|
|
|
|
printer.finish_layer(level_id);
|
2018-11-22 12:42:52 +00:00
|
|
|
|
2018-12-14 15:58:55 +00:00
|
|
|
// Status indication guarded with the spinlock
|
2018-12-13 14:33:39 +00:00
|
|
|
auto st = ist + unsigned(sd*level_id*slot/m_printer_input.size());
|
2019-03-26 09:57:45 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<SpinMutex> lck(slck);
|
|
|
|
if( st > pst) {
|
|
|
|
report_status(*this, int(st),
|
|
|
|
PRINT_STEP_LABELS[slapsRasterize]);
|
|
|
|
pst = st;
|
|
|
|
}
|
2018-11-22 12:57:13 +00:00
|
|
|
}
|
2018-11-13 16:33:03 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 17:05:47 +00:00
|
|
|
// last minute escape
|
|
|
|
if(canceled()) return;
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
// Sequential version (for testing)
|
2018-11-14 17:04:43 +00:00
|
|
|
// for(unsigned l = 0; l < lvlcnt; ++l) process_level(l);
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
// Print all the layers in parallel
|
2018-11-14 17:04:43 +00:00
|
|
|
tbb::parallel_for<unsigned, decltype(lvlfn)>(0, lvlcnt, lvlfn);
|
2019-02-21 14:46:04 +00:00
|
|
|
|
|
|
|
// Set statistics values to the printer
|
|
|
|
m_printer->set_statistics({(m_print_statistics.objects_used_material + m_print_statistics.support_used_material)/1000,
|
2019-02-22 11:22:51 +00:00
|
|
|
double(m_default_object_config.faded_layers.getInt()),
|
2019-02-21 14:46:04 +00:00
|
|
|
double(m_print_statistics.slow_layers_count),
|
|
|
|
double(m_print_statistics.fast_layers_count)
|
|
|
|
});
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 16:33:03 +00:00
|
|
|
using slaposFn = std::function<void(SLAPrintObject&)>;
|
2018-11-13 10:53:54 +00:00
|
|
|
using slapsFn = std::function<void(void)>;
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2018-11-13 10:53:54 +00:00
|
|
|
std::array<slaposFn, slaposCount> pobj_program =
|
2018-11-09 17:32:35 +00:00
|
|
|
{
|
|
|
|
slice_model,
|
|
|
|
support_points,
|
|
|
|
support_tree,
|
|
|
|
base_pool,
|
2018-11-26 13:43:28 +00:00
|
|
|
slice_supports,
|
|
|
|
index_slices
|
2018-11-09 17:32:35 +00:00
|
|
|
};
|
|
|
|
|
2018-11-13 10:53:54 +00:00
|
|
|
std::array<slapsFn, slapsCount> print_program =
|
|
|
|
{
|
2019-03-26 17:04:04 +00:00
|
|
|
fillstats,
|
2018-11-13 10:53:54 +00:00
|
|
|
rasterize,
|
|
|
|
[](){} // validate
|
|
|
|
};
|
|
|
|
|
2018-11-22 11:13:58 +00:00
|
|
|
unsigned st = min_objstatus;
|
|
|
|
unsigned incr = 0;
|
|
|
|
|
2018-12-14 15:58:55 +00:00
|
|
|
BOOST_LOG_TRIVIAL(info) << "Start slicing process.";
|
|
|
|
|
2018-11-22 11:13:58 +00:00
|
|
|
// TODO: this loop could run in parallel but should not exhaust all the CPU
|
|
|
|
// power available
|
2019-02-20 10:58:09 +00:00
|
|
|
// Calculate the support structures first before slicing the supports, so that the preview will get displayed ASAP for all objects.
|
|
|
|
std::vector<SLAPrintObjectStep> step_ranges = { slaposObjectSlice, slaposSliceSupports, slaposCount };
|
|
|
|
for (size_t idx_range = 0; idx_range + 1 < step_ranges.size(); ++ idx_range) {
|
|
|
|
for(SLAPrintObject * po : m_objects) {
|
2018-12-14 15:58:55 +00:00
|
|
|
|
2019-02-20 10:58:09 +00:00
|
|
|
BOOST_LOG_TRIVIAL(info) << "Slicing object " << po->model_object()->name;
|
2018-12-14 15:58:55 +00:00
|
|
|
|
2019-02-20 11:21:22 +00:00
|
|
|
for (int s = (int)step_ranges[idx_range]; s < (int)step_ranges[idx_range + 1]; ++s) {
|
2019-02-20 10:58:09 +00:00
|
|
|
auto currentstep = (SLAPrintObjectStep)s;
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2019-02-20 10:58:09 +00:00
|
|
|
// Cancellation checking. Each step will check for cancellation
|
|
|
|
// on its own and return earlier gracefully. Just after it returns
|
|
|
|
// execution gets to this point and throws the canceled signal.
|
|
|
|
throw_if_canceled();
|
2018-11-09 17:32:35 +00:00
|
|
|
|
2019-02-20 10:58:09 +00:00
|
|
|
st += unsigned(incr * ostepd);
|
2018-11-21 11:10:10 +00:00
|
|
|
|
2019-02-20 10:58:09 +00:00
|
|
|
if(po->m_stepmask[currentstep] && po->set_started(currentstep)) {
|
|
|
|
report_status(*this, int(st), OBJ_STEP_LABELS[currentstep]);
|
|
|
|
pobj_program[currentstep](*po);
|
|
|
|
throw_if_canceled();
|
|
|
|
po->set_done(currentstep);
|
|
|
|
}
|
2018-11-22 11:13:58 +00:00
|
|
|
|
2019-02-20 10:58:09 +00:00
|
|
|
incr = OBJ_STEP_LEVELS[currentstep];
|
|
|
|
}
|
2018-11-09 17:32:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-13 10:53:54 +00:00
|
|
|
|
|
|
|
std::array<SLAPrintStep, slapsCount> printsteps = {
|
2019-03-26 17:04:04 +00:00
|
|
|
slapsStats, slapsRasterize, slapsValidate
|
2018-11-13 10:53:54 +00:00
|
|
|
};
|
|
|
|
|
2018-11-15 17:05:47 +00:00
|
|
|
// this would disable the rasterization step
|
2019-02-05 14:57:19 +00:00
|
|
|
// m_stepmask[slapsRasterize] = false;
|
2018-11-14 17:04:43 +00:00
|
|
|
|
2018-11-22 11:13:58 +00:00
|
|
|
double pstd = (100 - max_objstatus) / 100.0;
|
|
|
|
st = max_objstatus;
|
2018-11-13 10:53:54 +00:00
|
|
|
for(size_t s = 0; s < print_program.size(); ++s) {
|
|
|
|
auto currentstep = printsteps[s];
|
|
|
|
|
|
|
|
throw_if_canceled();
|
|
|
|
|
2018-11-22 13:16:55 +00:00
|
|
|
if(m_stepmask[currentstep] && set_started(currentstep))
|
2018-11-22 11:13:58 +00:00
|
|
|
{
|
2018-12-14 15:58:55 +00:00
|
|
|
report_status(*this, int(st), PRINT_STEP_LABELS[currentstep]);
|
2018-11-21 11:10:10 +00:00
|
|
|
print_program[currentstep]();
|
2018-12-20 15:25:32 +00:00
|
|
|
throw_if_canceled();
|
2018-11-13 10:53:54 +00:00
|
|
|
set_done(currentstep);
|
|
|
|
}
|
2018-11-22 11:13:58 +00:00
|
|
|
|
|
|
|
st += unsigned(PRINT_STEP_LEVELS[currentstep] * pstd);
|
2018-11-13 10:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If everything vent well
|
2018-12-14 15:58:55 +00:00
|
|
|
report_status(*this, 100, L("Slicing done"));
|
2018-11-08 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
bool SLAPrint::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)
|
|
|
|
{
|
|
|
|
if (opt_keys.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Cache the plenty of parameters, which influence the final rasterization only,
|
|
|
|
// or they are only notes not influencing the rasterization step.
|
|
|
|
static std::unordered_set<std::string> steps_rasterize = {
|
|
|
|
"exposure_time",
|
|
|
|
"initial_exposure_time",
|
|
|
|
"material_correction_printing",
|
|
|
|
"material_correction_curing",
|
|
|
|
"display_width",
|
|
|
|
"display_height",
|
|
|
|
"display_pixels_x",
|
|
|
|
"display_pixels_y",
|
2018-12-13 14:33:39 +00:00
|
|
|
"display_orientation",
|
2018-11-21 16:35:35 +00:00
|
|
|
"printer_correction"
|
|
|
|
};
|
|
|
|
|
|
|
|
static std::unordered_set<std::string> steps_ignore = {
|
|
|
|
"bed_shape",
|
|
|
|
"max_print_height",
|
|
|
|
"printer_technology",
|
2019-02-18 15:04:55 +00:00
|
|
|
"output_filename_format",
|
|
|
|
"fast_tilt_time",
|
|
|
|
"slow_tilt_time",
|
|
|
|
"area_fill"
|
2018-11-21 16:35:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<SLAPrintStep> steps;
|
|
|
|
std::vector<SLAPrintObjectStep> osteps;
|
|
|
|
bool invalidated = false;
|
|
|
|
|
|
|
|
for (const t_config_option_key &opt_key : opt_keys) {
|
|
|
|
if (steps_rasterize.find(opt_key) != steps_rasterize.end()) {
|
|
|
|
// These options only affect the final rasterization, or they are just notes without influence on the output,
|
|
|
|
// so there is nothing to invalidate.
|
|
|
|
steps.emplace_back(slapsRasterize);
|
|
|
|
} else if (steps_ignore.find(opt_key) != steps_ignore.end()) {
|
|
|
|
// These steps have no influence on the output. Just ignore them.
|
|
|
|
} else if (opt_key == "initial_layer_height") {
|
|
|
|
steps.emplace_back(slapsRasterize);
|
|
|
|
osteps.emplace_back(slaposObjectSlice);
|
|
|
|
} else {
|
|
|
|
// All values should be covered.
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort_remove_duplicates(steps);
|
|
|
|
for (SLAPrintStep step : steps)
|
|
|
|
invalidated |= this->invalidate_step(step);
|
|
|
|
sort_remove_duplicates(osteps);
|
|
|
|
for (SLAPrintObjectStep ostep : osteps)
|
|
|
|
for (SLAPrintObject *object : m_objects)
|
|
|
|
invalidated |= object->invalidate_step(ostep);
|
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:34:42 +00:00
|
|
|
void SLAPrint::fill_statistics()
|
|
|
|
{
|
2019-02-18 15:04:55 +00:00
|
|
|
const double area_fill = m_printer_config.area_fill.getFloat()*0.01;// 0.5 (50%);
|
|
|
|
const double fast_tilt = m_printer_config.fast_tilt_time.getFloat();// 5.0;
|
|
|
|
const double slow_tilt = m_printer_config.slow_tilt_time.getFloat();// 8.0;
|
2019-02-13 14:35:41 +00:00
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
const double init_exp_time = m_material_config.initial_exposure_time.getFloat();
|
|
|
|
const double exp_time = m_material_config.exposure_time.getFloat();
|
2019-02-13 14:35:41 +00:00
|
|
|
|
2019-02-21 14:46:04 +00:00
|
|
|
const int fade_layers_cnt = m_default_object_config.faded_layers.getInt();// 10 // [3;20]
|
2019-02-18 11:28:58 +00:00
|
|
|
|
2019-02-18 12:18:47 +00:00
|
|
|
const double width = m_printer_config.display_width.getFloat() / SCALING_FACTOR;
|
|
|
|
const double height = m_printer_config.display_height.getFloat() / SCALING_FACTOR;
|
2019-02-18 11:28:58 +00:00
|
|
|
const double display_area = width*height;
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
// If the raster has vertical orientation, we will flip the coordinates
|
|
|
|
bool flpXY = m_printer_config.display_orientation.getInt() ==
|
|
|
|
SLADisplayOrientation::sladoPortrait;
|
|
|
|
|
2019-02-20 14:13:03 +00:00
|
|
|
// get polygons for all instances in the object
|
2019-03-26 17:51:27 +00:00
|
|
|
auto get_all_polygons =
|
|
|
|
[flpXY](const ExPolygons& input_polygons,
|
|
|
|
const std::vector<SLAPrintObject::Instance>& instances)
|
|
|
|
{
|
2019-02-20 14:13:03 +00:00
|
|
|
const size_t inst_cnt = instances.size();
|
|
|
|
|
2019-02-21 14:46:04 +00:00
|
|
|
size_t polygon_cnt = 0;
|
|
|
|
for (const ExPolygon& polygon : input_polygons)
|
|
|
|
polygon_cnt += polygon.holes.size() + 1;
|
|
|
|
|
|
|
|
Polygons polygons;
|
|
|
|
polygons.reserve(polygon_cnt * inst_cnt);
|
2019-02-20 14:13:03 +00:00
|
|
|
for (const ExPolygon& polygon : input_polygons) {
|
|
|
|
for (size_t i = 0; i < inst_cnt; ++i)
|
|
|
|
{
|
|
|
|
ExPolygon tmp = polygon;
|
2019-03-26 15:02:39 +00:00
|
|
|
tmp.rotate(double(instances[i].rotation));
|
2019-02-20 14:13:03 +00:00
|
|
|
tmp.translate(instances[i].shift.x(), instances[i].shift.y());
|
2019-03-26 17:51:27 +00:00
|
|
|
if(flpXY) swapXY(tmp);
|
2019-02-21 14:46:04 +00:00
|
|
|
polygons_append(polygons, to_polygons(std::move(tmp)));
|
2019-02-20 14:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return polygons;
|
|
|
|
};
|
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
double supports_volume = 0.0;
|
|
|
|
double models_volume = 0.0;
|
|
|
|
|
|
|
|
double estim_time = 0.0;
|
2019-02-13 14:35:41 +00:00
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
size_t slow_layers = 0;
|
|
|
|
size_t fast_layers = 0;
|
2019-02-13 14:35:41 +00:00
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
const double delta_fade_time = (init_exp_time - exp_time) / (fade_layers_cnt + 1);
|
|
|
|
double fade_layer_time = init_exp_time;
|
|
|
|
|
|
|
|
int sliced_layer_cnt = 0;
|
2019-03-26 17:51:27 +00:00
|
|
|
for (PrintLayer& layer : m_printer_input)
|
2019-02-18 11:28:58 +00:00
|
|
|
{
|
2019-03-26 17:51:27 +00:00
|
|
|
if(layer.slices().empty()) continue;
|
|
|
|
|
|
|
|
// Layer height should match for all object slices for a given level.
|
|
|
|
const auto l_height = double(layer.slices().front().get().layer_height());
|
2019-02-18 11:28:58 +00:00
|
|
|
|
|
|
|
// Calculation of the consumed material
|
|
|
|
|
2019-02-20 14:13:03 +00:00
|
|
|
Polygons model_polygons;
|
|
|
|
Polygons supports_polygons;
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
for(const SliceRecord& record : layer.slices()) {
|
|
|
|
const SLAPrintObject *po = record.print_obj();
|
2019-02-19 11:14:13 +00:00
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
const ExPolygons &modelslices = record.get_slice(soModel);
|
2019-03-22 14:31:38 +00:00
|
|
|
if (!modelslices.empty())
|
|
|
|
append(model_polygons, get_all_polygons(modelslices, po->instances()));
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
const ExPolygons &supportslices = record.get_slice(soSupport);
|
2019-03-22 14:31:38 +00:00
|
|
|
if (!supportslices.empty())
|
|
|
|
append(supports_polygons, get_all_polygons(supportslices, po->instances()));
|
2019-02-13 14:35:41 +00:00
|
|
|
}
|
2019-02-20 14:13:03 +00:00
|
|
|
|
|
|
|
model_polygons = union_(model_polygons);
|
|
|
|
double layer_model_area = 0;
|
|
|
|
for (const Polygon& polygon : model_polygons)
|
|
|
|
layer_model_area += polygon.area();
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
if (layer_model_area < 0 || layer_model_area > 0)
|
2019-02-20 14:13:03 +00:00
|
|
|
models_volume += layer_model_area * l_height;
|
|
|
|
|
|
|
|
if (!supports_polygons.empty() && !model_polygons.empty())
|
2019-02-21 14:46:04 +00:00
|
|
|
supports_polygons = diff(supports_polygons, model_polygons);
|
2019-02-20 14:13:03 +00:00
|
|
|
double layer_support_area = 0;
|
|
|
|
for (const Polygon& polygon : supports_polygons)
|
|
|
|
layer_support_area += polygon.area();
|
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
if (layer_support_area < 0 || layer_model_area > 0)
|
2019-02-20 14:13:03 +00:00
|
|
|
supports_volume += layer_support_area * l_height;
|
2019-02-13 14:35:41 +00:00
|
|
|
|
2019-03-26 17:51:27 +00:00
|
|
|
// Here we can save the expensively calculated polygons for printing
|
|
|
|
append(model_polygons, supports_polygons);
|
|
|
|
layer.transformed_slices(union_(model_polygons));
|
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
// Calculation of the slow and fast layers to the future controlling those values on FW
|
|
|
|
|
2019-02-18 15:04:55 +00:00
|
|
|
const bool is_fast_layer = (layer_model_area + layer_support_area) <= display_area*area_fill;
|
2019-02-18 11:28:58 +00:00
|
|
|
const double tilt_time = is_fast_layer ? fast_tilt : slow_tilt;
|
|
|
|
if (is_fast_layer)
|
|
|
|
fast_layers++;
|
|
|
|
else
|
|
|
|
slow_layers++;
|
|
|
|
|
|
|
|
|
|
|
|
// Calculation of the printing time
|
|
|
|
|
|
|
|
if (sliced_layer_cnt < 3)
|
|
|
|
estim_time += init_exp_time;
|
|
|
|
else if (fade_layer_time > exp_time)
|
|
|
|
{
|
|
|
|
fade_layer_time -= delta_fade_time;
|
|
|
|
estim_time += fade_layer_time;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
estim_time += exp_time;
|
|
|
|
|
|
|
|
estim_time += tilt_time;
|
|
|
|
|
|
|
|
sliced_layer_cnt++;
|
2019-02-12 15:34:42 +00:00
|
|
|
}
|
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
m_print_statistics.support_used_material = supports_volume * SCALING_FACTOR * SCALING_FACTOR;
|
2019-02-13 14:35:41 +00:00
|
|
|
m_print_statistics.objects_used_material = models_volume * SCALING_FACTOR * SCALING_FACTOR;
|
|
|
|
|
|
|
|
// Estimated printing time
|
|
|
|
// A layers count o the highest object
|
2019-03-26 17:51:27 +00:00
|
|
|
if (m_printer_input.size() == 0)
|
2019-02-13 14:35:41 +00:00
|
|
|
m_print_statistics.estimated_print_time = "N/A";
|
2019-02-18 11:28:58 +00:00
|
|
|
else
|
|
|
|
m_print_statistics.estimated_print_time = get_time_dhms(float(estim_time));
|
2019-02-12 15:34:42 +00:00
|
|
|
|
2019-02-18 11:28:58 +00:00
|
|
|
m_print_statistics.fast_layers_count = fast_layers;
|
|
|
|
m_print_statistics.slow_layers_count = slow_layers;
|
2019-02-12 15:34:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-11 16:49:31 +00:00
|
|
|
// Returns true if an object step is done on all objects and there's at least one object.
|
|
|
|
bool SLAPrint::is_step_done(SLAPrintObjectStep step) const
|
|
|
|
{
|
|
|
|
if (m_objects.empty())
|
|
|
|
return false;
|
|
|
|
tbb::mutex::scoped_lock lock(this->state_mutex());
|
|
|
|
for (const SLAPrintObject *object : m_objects)
|
2019-02-21 07:44:07 +00:00
|
|
|
if (! object->is_step_done_unguarded(step))
|
2018-12-11 16:49:31 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object):
|
2018-11-16 17:28:50 +00:00
|
|
|
Inherited(print, model_object),
|
2018-11-21 14:21:57 +00:00
|
|
|
m_stepmask(slaposCount, true),
|
|
|
|
m_transformed_rmesh( [this](TriangleMesh& obj){
|
|
|
|
obj = m_model_object->raw_mesh(); obj.transform(m_trafo);
|
|
|
|
})
|
2018-11-09 17:32:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SLAPrintObject::~SLAPrintObject() {}
|
|
|
|
|
2018-11-21 16:35:35 +00:00
|
|
|
// Called by SLAPrint::apply_config().
|
|
|
|
// This method only accepts SLAPrintObjectConfig option keys.
|
|
|
|
bool SLAPrintObject::invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys)
|
|
|
|
{
|
|
|
|
if (opt_keys.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
std::vector<SLAPrintObjectStep> steps;
|
|
|
|
bool invalidated = false;
|
|
|
|
for (const t_config_option_key &opt_key : opt_keys) {
|
2019-02-22 11:22:51 +00:00
|
|
|
if ( opt_key == "layer_height"
|
2019-03-01 16:53:02 +00:00
|
|
|
|| opt_key == "faded_layers"
|
2019-03-22 14:48:20 +00:00
|
|
|
|| opt_key == "pad_enable"
|
|
|
|
|| opt_key == "pad_wall_thickness"
|
|
|
|
|| opt_key == "supports_enable"
|
|
|
|
|| opt_key == "support_object_elevation"
|
2019-03-01 16:53:02 +00:00
|
|
|
|| opt_key == "slice_closing_radius") {
|
2018-12-03 12:14:28 +00:00
|
|
|
steps.emplace_back(slaposObjectSlice);
|
2019-02-19 15:34:52 +00:00
|
|
|
} else if (
|
2019-03-22 14:48:20 +00:00
|
|
|
|
|
|
|
opt_key == "support_points_density_relative"
|
2019-02-19 15:34:52 +00:00
|
|
|
|| opt_key == "support_points_minimal_distance") {
|
2018-11-30 13:26:41 +00:00
|
|
|
steps.emplace_back(slaposSupportPoints);
|
2018-12-03 12:21:48 +00:00
|
|
|
} else if (
|
2018-11-30 13:26:41 +00:00
|
|
|
opt_key == "support_head_front_diameter"
|
2018-11-21 16:35:35 +00:00
|
|
|
|| opt_key == "support_head_penetration"
|
|
|
|
|| opt_key == "support_head_width"
|
2018-11-29 10:45:02 +00:00
|
|
|
|| opt_key == "support_pillar_diameter"
|
2019-01-09 11:21:43 +00:00
|
|
|
|| opt_key == "support_pillar_connection_mode"
|
2019-02-05 10:16:03 +00:00
|
|
|
|| opt_key == "support_buildplate_only"
|
2018-11-29 10:45:02 +00:00
|
|
|
|| opt_key == "support_base_diameter"
|
2018-11-21 16:35:35 +00:00
|
|
|
|| opt_key == "support_base_height"
|
|
|
|
|| opt_key == "support_critical_angle"
|
|
|
|
|| opt_key == "support_max_bridge_length"
|
2019-03-08 10:39:34 +00:00
|
|
|
|| opt_key == "support_max_pillar_link_distance"
|
2019-03-22 14:48:20 +00:00
|
|
|
) {
|
2018-11-21 16:35:35 +00:00
|
|
|
steps.emplace_back(slaposSupportTree);
|
|
|
|
} else if (
|
2019-03-22 14:48:20 +00:00
|
|
|
opt_key == "pad_wall_height"
|
2018-11-21 16:35:35 +00:00
|
|
|
|| opt_key == "pad_max_merge_distance"
|
2019-02-25 15:04:46 +00:00
|
|
|
|| opt_key == "pad_wall_slope"
|
2018-11-21 16:35:35 +00:00
|
|
|
|| opt_key == "pad_edge_radius") {
|
|
|
|
steps.emplace_back(slaposBasePool);
|
|
|
|
} else {
|
|
|
|
// All keys should be covered.
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort_remove_duplicates(steps);
|
|
|
|
for (SLAPrintObjectStep step : steps)
|
|
|
|
invalidated |= this->invalidate_step(step);
|
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SLAPrintObject::invalidate_step(SLAPrintObjectStep step)
|
|
|
|
{
|
|
|
|
bool invalidated = Inherited::invalidate_step(step);
|
|
|
|
// propagate to dependent steps
|
|
|
|
if (step == slaposObjectSlice) {
|
|
|
|
invalidated |= this->invalidate_all_steps();
|
|
|
|
} else if (step == slaposSupportPoints) {
|
2018-11-29 10:45:02 +00:00
|
|
|
invalidated |= this->invalidate_steps({ slaposSupportTree, slaposBasePool, slaposSliceSupports, slaposIndexSlices });
|
2018-11-21 16:35:35 +00:00
|
|
|
invalidated |= m_print->invalidate_step(slapsRasterize);
|
|
|
|
} else if (step == slaposSupportTree) {
|
2018-11-29 10:45:02 +00:00
|
|
|
invalidated |= this->invalidate_steps({ slaposBasePool, slaposSliceSupports, slaposIndexSlices });
|
2018-11-21 16:35:35 +00:00
|
|
|
invalidated |= m_print->invalidate_step(slapsRasterize);
|
|
|
|
} else if (step == slaposBasePool) {
|
2018-11-29 10:45:02 +00:00
|
|
|
invalidated |= this->invalidate_steps({slaposSliceSupports, slaposIndexSlices});
|
2018-11-21 16:35:35 +00:00
|
|
|
invalidated |= m_print->invalidate_step(slapsRasterize);
|
|
|
|
} else if (step == slaposSliceSupports) {
|
2018-11-29 10:45:02 +00:00
|
|
|
invalidated |= this->invalidate_step(slaposIndexSlices);
|
|
|
|
invalidated |= m_print->invalidate_step(slapsRasterize);
|
|
|
|
} else if(step == slaposIndexSlices) {
|
2018-11-21 16:35:35 +00:00
|
|
|
invalidated |= m_print->invalidate_step(slapsRasterize);
|
|
|
|
}
|
|
|
|
return invalidated;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SLAPrintObject::invalidate_all_steps()
|
|
|
|
{
|
|
|
|
return Inherited::invalidate_all_steps() | m_print->invalidate_all_steps();
|
|
|
|
}
|
|
|
|
|
2018-11-16 16:25:23 +00:00
|
|
|
double SLAPrintObject::get_elevation() const {
|
2018-11-22 17:02:05 +00:00
|
|
|
bool se = m_config.supports_enable.getBool();
|
|
|
|
double ret = se? m_config.support_object_elevation.getFloat() : 0;
|
2018-11-20 15:12:04 +00:00
|
|
|
|
|
|
|
// if the pad is enabled, then half of the pad height is its base plate
|
|
|
|
if(m_config.pad_enable.getBool()) {
|
|
|
|
// Normally the elevation for the pad itself would be the thickness of
|
|
|
|
// its walls but currently it is half of its thickness. Whatever it
|
|
|
|
// will be in the future, we provide the config to the get_pad_elevation
|
|
|
|
// method and we will have the correct value
|
2019-03-20 17:03:11 +00:00
|
|
|
sla::PoolConfig pcfg = make_pool_config(m_config);
|
2018-11-20 15:12:04 +00:00
|
|
|
ret += sla::get_pad_elevation(pcfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-11-16 16:25:23 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 12:57:13 +00:00
|
|
|
double SLAPrintObject::get_current_elevation() const
|
|
|
|
{
|
2018-11-22 17:02:05 +00:00
|
|
|
bool se = m_config.supports_enable.getBool();
|
2018-11-22 12:57:13 +00:00
|
|
|
bool has_supports = is_step_done(slaposSupportTree);
|
|
|
|
bool has_pad = is_step_done(slaposBasePool);
|
2018-12-21 13:32:11 +00:00
|
|
|
|
|
|
|
if(!has_supports && !has_pad)
|
|
|
|
return 0;
|
2018-11-22 12:57:13 +00:00
|
|
|
else if(has_supports && !has_pad)
|
2018-11-22 17:02:05 +00:00
|
|
|
return se ? m_config.support_object_elevation.getFloat() : 0;
|
2018-11-22 12:57:13 +00:00
|
|
|
|
2018-12-21 13:32:11 +00:00
|
|
|
return get_elevation();
|
2018-11-22 12:57:13 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
namespace { // dummy empty static containers for return values in some methods
|
|
|
|
const std::vector<ExPolygons> EMPTY_SLICES;
|
|
|
|
const TriangleMesh EMPTY_MESH;
|
2019-03-22 14:31:38 +00:00
|
|
|
const ExPolygons EMPTY_SLICE;
|
2018-11-21 14:21:57 +00:00
|
|
|
}
|
2018-11-16 16:25:23 +00:00
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
const SliceRecord SliceRecord::EMPTY(0, std::nanf(""), 0.f);
|
|
|
|
|
2019-02-17 12:05:22 +00:00
|
|
|
const std::vector<sla::SupportPoint>& SLAPrintObject::get_support_points() const
|
2018-12-21 11:35:20 +00:00
|
|
|
{
|
|
|
|
return m_supportdata->support_points;
|
|
|
|
}
|
|
|
|
|
2019-03-22 14:31:38 +00:00
|
|
|
const std::vector<ExPolygons> &SLAPrintObject::get_support_slices() const
|
2019-03-20 17:03:11 +00:00
|
|
|
{
|
2019-03-22 14:31:38 +00:00
|
|
|
// assert(is_step_done(slaposSliceSupports));
|
|
|
|
if (!m_supportdata) return EMPTY_SLICES;
|
|
|
|
return m_supportdata->support_slices;
|
|
|
|
}
|
2019-03-21 14:16:33 +00:00
|
|
|
|
2019-03-26 09:57:45 +00:00
|
|
|
const ExPolygons &SliceRecord::get_slice(SliceOrigin o) const
|
2019-03-22 14:31:38 +00:00
|
|
|
{
|
2019-03-26 09:57:45 +00:00
|
|
|
size_t idx = o == soModel ? m_model_slices_idx :
|
|
|
|
m_support_slices_idx;
|
|
|
|
|
|
|
|
if(m_po == nullptr) return EMPTY_SLICE;
|
2019-03-20 17:03:11 +00:00
|
|
|
|
2019-03-26 09:57:45 +00:00
|
|
|
const std::vector<ExPolygons>& v = o == soModel? m_po->get_model_slices() :
|
|
|
|
m_po->get_support_slices();
|
2019-03-21 14:16:33 +00:00
|
|
|
|
2019-03-22 14:31:38 +00:00
|
|
|
if(idx >= v.size()) return EMPTY_SLICE;
|
2019-03-21 14:16:33 +00:00
|
|
|
|
2019-03-22 14:31:38 +00:00
|
|
|
return idx >= v.size() ? EMPTY_SLICE : v[idx];
|
2019-03-20 17:03:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 18:02:05 +00:00
|
|
|
const std::vector<SliceRecord> & SLAPrintObject::get_slice_index() const
|
2018-11-26 13:43:28 +00:00
|
|
|
{
|
|
|
|
// assert(is_step_done(slaposIndexSlices));
|
|
|
|
return m_slice_index;
|
|
|
|
}
|
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
const std::vector<ExPolygons> &SLAPrintObject::get_model_slices() const
|
|
|
|
{
|
2018-11-26 13:43:28 +00:00
|
|
|
// assert(is_step_done(slaposObjectSlice));
|
2018-11-21 14:21:57 +00:00
|
|
|
return m_model_slices;
|
|
|
|
}
|
2018-11-16 16:25:23 +00:00
|
|
|
|
2018-11-17 16:23:56 +00:00
|
|
|
bool SLAPrintObject::has_mesh(SLAPrintObjectStep step) const
|
|
|
|
{
|
|
|
|
switch (step) {
|
|
|
|
case slaposSupportTree:
|
2018-11-27 12:52:42 +00:00
|
|
|
return ! this->support_mesh().empty();
|
2018-11-17 16:23:56 +00:00
|
|
|
case slaposBasePool:
|
2018-11-27 12:52:42 +00:00
|
|
|
return ! this->pad_mesh().empty();
|
|
|
|
default:
|
2018-11-17 16:23:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TriangleMesh SLAPrintObject::get_mesh(SLAPrintObjectStep step) const
|
|
|
|
{
|
2018-11-27 12:52:42 +00:00
|
|
|
switch (step) {
|
|
|
|
case slaposSupportTree:
|
|
|
|
return this->support_mesh();
|
|
|
|
case slaposBasePool:
|
|
|
|
return this->pad_mesh();
|
|
|
|
default:
|
|
|
|
return TriangleMesh();
|
|
|
|
}
|
2018-11-17 16:23:56 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
const TriangleMesh& SLAPrintObject::support_mesh() const
|
|
|
|
{
|
2018-11-30 13:26:41 +00:00
|
|
|
if(m_config.supports_enable.getBool() && m_supportdata &&
|
2018-12-11 14:54:54 +00:00
|
|
|
m_supportdata->support_tree_ptr) {
|
|
|
|
return m_supportdata->support_tree_ptr->merged_mesh();
|
|
|
|
}
|
2018-11-14 17:04:43 +00:00
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
return EMPTY_MESH;
|
2018-11-13 16:45:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
const TriangleMesh& SLAPrintObject::pad_mesh() const
|
2018-11-13 16:45:44 +00:00
|
|
|
{
|
2018-11-30 13:26:41 +00:00
|
|
|
if(m_config.pad_enable.getBool() && m_supportdata && m_supportdata->support_tree_ptr)
|
|
|
|
return m_supportdata->support_tree_ptr->get_pad();
|
2018-11-14 17:04:43 +00:00
|
|
|
|
2018-11-30 13:26:41 +00:00
|
|
|
return EMPTY_MESH;
|
2018-11-13 16:45:44 +00:00
|
|
|
}
|
|
|
|
|
2018-11-15 17:05:47 +00:00
|
|
|
const TriangleMesh &SLAPrintObject::transformed_mesh() const {
|
|
|
|
// we need to transform the raw mesh...
|
|
|
|
// currently all the instances share the same x and y rotation and scaling
|
|
|
|
// so we have to extract those from e.g. the first instance and apply to the
|
|
|
|
// raw mesh. This is also true for the support points.
|
|
|
|
// BUT: when the support structure is spawned for each instance than it has
|
|
|
|
// to omit the X, Y rotation and scaling as those have been already applied
|
|
|
|
// or apply an inverse transformation on the support structure after it
|
|
|
|
// has been created.
|
|
|
|
|
2018-11-21 14:21:57 +00:00
|
|
|
return m_transformed_rmesh.get();
|
2018-11-15 17:05:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-30 07:26:23 +00:00
|
|
|
std::vector<sla::SupportPoint> SLAPrintObject::transformed_support_points() const
|
2018-11-16 10:34:19 +00:00
|
|
|
{
|
|
|
|
assert(m_model_object != nullptr);
|
2019-01-30 07:26:23 +00:00
|
|
|
std::vector<sla::SupportPoint>& spts = m_model_object->sla_support_points;
|
2018-11-16 10:34:19 +00:00
|
|
|
|
|
|
|
// this could be cached as well
|
2019-01-30 07:26:23 +00:00
|
|
|
std::vector<sla::SupportPoint> ret;
|
|
|
|
ret.reserve(spts.size());
|
2018-11-16 10:34:19 +00:00
|
|
|
|
2019-01-30 07:26:23 +00:00
|
|
|
for(sla::SupportPoint& sp : spts) {
|
|
|
|
Vec3d transformed_pos = trafo() * Vec3d(sp.pos(0), sp.pos(1), sp.pos(2));
|
|
|
|
ret.emplace_back(transformed_pos(0), transformed_pos(1), transformed_pos(2), sp.head_front_radius, sp.is_new_island);
|
|
|
|
}
|
2018-11-16 10:34:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-02-12 15:34:42 +00:00
|
|
|
DynamicConfig SLAPrintStatistics::config() const
|
|
|
|
{
|
|
|
|
DynamicConfig config;
|
|
|
|
const std::string print_time = Slic3r::short_time(this->estimated_print_time);
|
|
|
|
config.set_key_value("print_time", new ConfigOptionString(print_time));
|
2019-02-13 14:35:41 +00:00
|
|
|
config.set_key_value("objects_used_material", new ConfigOptionFloat(this->objects_used_material));
|
|
|
|
config.set_key_value("support_used_material", new ConfigOptionFloat(this->support_used_material));
|
2019-02-12 15:34:42 +00:00
|
|
|
config.set_key_value("total_cost", new ConfigOptionFloat(this->total_cost));
|
|
|
|
config.set_key_value("total_weight", new ConfigOptionFloat(this->total_weight));
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
DynamicConfig SLAPrintStatistics::placeholders()
|
|
|
|
{
|
|
|
|
DynamicConfig config;
|
|
|
|
for (const std::string &key : {
|
2019-02-13 14:35:41 +00:00
|
|
|
"print_time", "total_cost", "total_weight",
|
|
|
|
"objects_used_material", "support_used_material" })
|
2019-02-12 15:34:42 +00:00
|
|
|
config.set_key_value(key, new ConfigOptionString(std::string("{") + key + "}"));
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SLAPrintStatistics::finalize_output_path(const std::string &path_in) const
|
|
|
|
{
|
|
|
|
std::string final_path;
|
|
|
|
try {
|
|
|
|
boost::filesystem::path path(path_in);
|
|
|
|
DynamicConfig cfg = this->config();
|
|
|
|
PlaceholderParser pp;
|
|
|
|
std::string new_stem = pp.process(path.stem().string(), 0, &cfg);
|
|
|
|
final_path = (path.parent_path() / (new_stem + path.extension().string())).string();
|
|
|
|
}
|
|
|
|
catch (const std::exception &ex) {
|
|
|
|
BOOST_LOG_TRIVIAL(error) << "Failed to apply the print statistics to the export file name: " << ex.what();
|
|
|
|
final_path = path_in;
|
|
|
|
}
|
|
|
|
return final_path;
|
|
|
|
}
|
|
|
|
|
2018-11-09 11:02:42 +00:00
|
|
|
} // namespace Slic3r
|