2018-11-08 19:18:40 +00:00
|
|
|
#include "SLAPrint.hpp"
|
2018-11-09 17:32:35 +00:00
|
|
|
#include "SLA/SLASupportTree.hpp"
|
|
|
|
|
|
|
|
#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-09 17:32:35 +00:00
|
|
|
class SLAPrintObject::SupportData {
|
|
|
|
public:
|
|
|
|
sla::EigenMesh3D emesh; // index-triangle representation
|
|
|
|
sla::PointSet support_points; // all the support points (manual/auto)
|
|
|
|
std::unique_ptr<sla::SLASupportTree> support_tree_ptr; // the supports
|
|
|
|
SlicedSupports slice_cache; // sliced supports
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const std::array<unsigned, slaposCount> OBJ_STEP_LEVELS =
|
|
|
|
{
|
|
|
|
20,
|
|
|
|
30,
|
|
|
|
50,
|
|
|
|
70,
|
|
|
|
80,
|
|
|
|
100
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::array<std::string, slaposCount> OBJ_STEP_LABELS =
|
|
|
|
{
|
|
|
|
L("Slicing model"), // slaposObjectSlice,
|
|
|
|
L("Generating islands"), // slaposSupportIslands,
|
|
|
|
L("Scanning model structure"), // slaposSupportPoints,
|
|
|
|
L("Generating support tree"), // slaposSupportTree,
|
|
|
|
L("Generating base pool"), // slaposBasePool,
|
|
|
|
L("Slicing supports") // slaposSliceSupports,
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::array<unsigned, slapsCount> PRINT_STEP_LEVELS =
|
|
|
|
{
|
|
|
|
50, // slapsRasterize
|
|
|
|
100, // slapsValidate
|
|
|
|
};
|
|
|
|
|
|
|
|
const std::array<std::string, slapsCount> PRINT_STEP_LABELS =
|
|
|
|
{
|
|
|
|
L("Rasterizing layers"), // slapsRasterize
|
|
|
|
L("Validating"), // slapsValidate
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-08 19:18:40 +00:00
|
|
|
void SLAPrint::clear()
|
|
|
|
{
|
2018-11-09 11:02:42 +00:00
|
|
|
tbb::mutex::scoped_lock lock(this->cancel_mutex());
|
|
|
|
// The following call should stop background processing if it is running.
|
|
|
|
this->invalidate_all_steps();
|
2018-11-09 17:32:35 +00:00
|
|
|
|
|
|
|
for (SLAPrintObject *object : m_objects) delete object;
|
2018-11-09 11:02:42 +00:00
|
|
|
m_objects.clear();
|
2018-11-08 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
SLAPrint::ApplyStatus SLAPrint::apply(const Model &model,
|
|
|
|
const DynamicPrintConfig &config)
|
2018-11-08 19:18:40 +00:00
|
|
|
{
|
2018-11-12 10:46:38 +00:00
|
|
|
// if (m_objects.empty())
|
|
|
|
// return APPLY_STATUS_UNCHANGED;
|
2018-11-09 11:02:42 +00:00
|
|
|
|
|
|
|
// Grab the lock for the Print / PrintObject milestones.
|
|
|
|
tbb::mutex::scoped_lock lock(this->cancel_mutex());
|
2018-11-12 10:46:38 +00:00
|
|
|
if(m_objects.empty() && model.objects.empty())
|
|
|
|
return APPLY_STATUS_UNCHANGED;
|
2018-11-09 11:02:42 +00:00
|
|
|
|
|
|
|
// Temporary quick fix, just invalidate everything.
|
|
|
|
{
|
2018-11-12 10:46:38 +00:00
|
|
|
std::cout << "deleting object cache " << std::endl;
|
2018-11-09 17:32:35 +00:00
|
|
|
for (SLAPrintObject *print_object : m_objects) {
|
2018-11-09 11:02:42 +00:00
|
|
|
print_object->invalidate_all_steps();
|
2018-11-09 17:32:35 +00:00
|
|
|
delete print_object;
|
2018-11-09 11:02:42 +00:00
|
|
|
}
|
|
|
|
m_objects.clear();
|
|
|
|
this->invalidate_all_steps();
|
2018-11-09 17:32:35 +00:00
|
|
|
|
|
|
|
// Copy the model by value (deep copy),
|
|
|
|
// keep the Model / ModelObject / ModelInstance / ModelVolume IDs.
|
2018-11-09 11:02:42 +00:00
|
|
|
m_model.assign_copy(model);
|
|
|
|
// Generate new SLAPrintObjects.
|
2018-11-09 17:32:35 +00:00
|
|
|
for (ModelObject *model_object : m_model.objects) {
|
2018-11-09 11:02:42 +00:00
|
|
|
//TODO
|
2018-11-09 17:32:35 +00:00
|
|
|
m_objects.emplace_back(new SLAPrintObject(this, model_object));
|
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-08 19:18:40 +00:00
|
|
|
return APPLY_STATUS_INVALIDATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SLAPrint::process()
|
|
|
|
{
|
2018-11-09 17:32:35 +00:00
|
|
|
using namespace sla;
|
|
|
|
|
|
|
|
std::cout << "SLA Processing triggered" << std::endl;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
auto slice_model = [](const SLAPrintObject&) {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
auto support_points = [](const SLAPrintObject&) {
|
|
|
|
// for(SLAPrintObject *po : pobjects) {
|
|
|
|
// TODO: calculate automatic support points
|
|
|
|
// po->m_supportdata->slice_cache contains the slices at this point
|
|
|
|
//}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto support_tree = [this](const SLAPrintObject& po) {
|
|
|
|
auto& emesh = po.m_supportdata->emesh;
|
|
|
|
auto& pts = po.m_supportdata->support_points; // nowhere filled yet
|
|
|
|
auto& supportd = *po.m_supportdata;
|
|
|
|
try {
|
|
|
|
SupportConfig scfg; // TODO fill or replace with po.m_config
|
|
|
|
|
|
|
|
sla::Controller ctl;
|
|
|
|
ctl.statuscb = [this](unsigned st, const std::string& msg) {
|
|
|
|
unsigned stinit = OBJ_STEP_LEVELS[slaposSupportTree];
|
|
|
|
double d = (OBJ_STEP_LEVELS[slaposBasePool] - stinit) / 100.0;
|
|
|
|
set_status(unsigned(stinit + st*d), msg);
|
|
|
|
};
|
|
|
|
ctl.stopcondition = [this](){ return canceled(); };
|
|
|
|
|
|
|
|
supportd.support_tree_ptr.reset(
|
|
|
|
new SLASupportTree(pts, emesh, scfg, ctl));
|
|
|
|
|
|
|
|
} catch(sla::SLASupportsStoppedException&) {
|
|
|
|
// no need to rethrow
|
|
|
|
// throw_if_canceled();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
auto base_pool = [](const SLAPrintObject&) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
auto slice_supports = [](const SLAPrintObject&) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
auto rasterize = []() {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
using slaposFn = std::function<void(const SLAPrintObject&)>;
|
|
|
|
|
|
|
|
std::array<SLAPrintObjectStep, slaposCount> objectsteps = {
|
|
|
|
slaposObjectSlice,
|
|
|
|
slaposSupportIslands,
|
|
|
|
slaposSupportPoints,
|
|
|
|
slaposSupportTree,
|
|
|
|
slaposBasePool,
|
|
|
|
slaposSliceSupports
|
|
|
|
};
|
|
|
|
|
|
|
|
std::array<slaposFn, slaposCount> fullprogram =
|
|
|
|
{
|
|
|
|
slice_model,
|
|
|
|
[](const SLAPrintObject&){}, // slaposSupportIslands now empty
|
|
|
|
support_points,
|
|
|
|
support_tree,
|
|
|
|
base_pool,
|
|
|
|
slice_supports
|
|
|
|
};
|
|
|
|
|
|
|
|
for(SLAPrintObject * po : m_objects) {
|
|
|
|
for(size_t s = 0; s < fullprogram.size(); ++s) {
|
|
|
|
auto currentstep = objectsteps[s];
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
if(po->m_stepmask[s]) {
|
|
|
|
set_status(OBJ_STEP_LEVELS[currentstep],
|
|
|
|
OBJ_STEP_LABELS[currentstep]);
|
|
|
|
|
|
|
|
po->set_started(currentstep);
|
|
|
|
fullprogram[s](*po);
|
|
|
|
po->set_done(currentstep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-08 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 16:35:57 +00:00
|
|
|
void SLAPrint::render_supports(SLASupportRenderer &renderer)
|
|
|
|
{
|
|
|
|
std::cout << "Would show the SLA supports" << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-11-09 17:32:35 +00:00
|
|
|
SLAPrintObject::SLAPrintObject(SLAPrint *print, ModelObject *model_object):
|
|
|
|
Inherited(print),
|
|
|
|
m_model_object(model_object),
|
|
|
|
m_supportdata(new SupportData()),
|
|
|
|
m_stepmask(slaposCount, true)
|
|
|
|
{
|
|
|
|
m_supportdata->emesh = sla::to_eigenmesh(*m_model_object);
|
2018-11-12 10:46:38 +00:00
|
|
|
m_supportdata->support_points = sla::support_points(*m_model_object);
|
|
|
|
std::cout << "support points copied " << m_supportdata->support_points.rows() << std::endl;
|
2018-11-09 17:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SLAPrintObject::~SLAPrintObject() {}
|
|
|
|
|
2018-11-09 11:02:42 +00:00
|
|
|
} // namespace Slic3r
|