mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Merge remote-tracking branch 'remotes/origin/dev_native' into vb_3dscene_partial_update
This commit is contained in:
commit
dafa4621aa
23 changed files with 804 additions and 273 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "SLAPrint.hpp"
|
||||
#include "SLA/SLASupportTree.hpp"
|
||||
#include "SLA/SLABasePool.hpp"
|
||||
|
||||
#include <tbb/parallel_for.h>
|
||||
//#include <tbb/spin_mutex.h>//#include "tbb/mutex.h"
|
||||
|
@ -27,12 +28,12 @@ namespace {
|
|||
|
||||
const std::array<unsigned, slaposCount> OBJ_STEP_LEVELS =
|
||||
{
|
||||
0,
|
||||
20,
|
||||
30,
|
||||
50,
|
||||
70,
|
||||
80,
|
||||
100
|
||||
90
|
||||
};
|
||||
|
||||
const std::array<std::string, slaposCount> OBJ_STEP_LABELS =
|
||||
|
@ -47,8 +48,9 @@ const std::array<std::string, slaposCount> OBJ_STEP_LABELS =
|
|||
|
||||
const std::array<unsigned, slapsCount> PRINT_STEP_LEVELS =
|
||||
{
|
||||
// This is after processing all the Print objects, so we start from 50%
|
||||
50, // slapsRasterize
|
||||
100, // slapsValidate
|
||||
90, // slapsValidate
|
||||
};
|
||||
|
||||
const std::array<std::string, slapsCount> PRINT_STEP_LABELS =
|
||||
|
@ -118,8 +120,6 @@ void SLAPrint::process()
|
|||
{
|
||||
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
|
||||
|
||||
|
@ -128,31 +128,32 @@ void SLAPrint::process()
|
|||
|
||||
// Slicing the model object. This method is oversimplified and needs to
|
||||
// be compared with the fff slicing algorithm for verification
|
||||
auto slice_model = [ilh](SLAPrintObject& po) {
|
||||
auto slice_model = [this, ilh](SLAPrintObject& po) {
|
||||
auto lh = float(po.m_config.layer_height.getFloat());
|
||||
|
||||
ModelObject *o = po.m_model_object;
|
||||
|
||||
TriangleMesh&& mesh = o->raw_mesh();
|
||||
TriangleMesh mesh = po.transformed_mesh();
|
||||
TriangleMeshSlicer slicer(&mesh);
|
||||
auto bb3d = mesh.bounding_box();
|
||||
|
||||
auto H = bb3d.max(Z) - bb3d.min(Z);
|
||||
std::vector<float> heights = {ilh};
|
||||
for(float h = ilh; h < H; h += lh) heights.emplace_back(h);
|
||||
auto gnd = float(bb3d.min(Z));
|
||||
std::vector<float> heights = {gnd};
|
||||
for(float h = gnd + ilh; h < gnd + H; h += lh) heights.emplace_back(h);
|
||||
|
||||
auto& layers = po.m_model_slices;
|
||||
slicer.slice(heights, &layers, [](){});
|
||||
slicer.slice(heights, &layers, [this](){
|
||||
throw_if_canceled();
|
||||
});
|
||||
};
|
||||
|
||||
auto support_points = [](SLAPrintObject& po) {
|
||||
ModelObject& mo = *po.m_model_object;
|
||||
if(!mo.sla_support_points.empty()) {
|
||||
po.m_supportdata.reset(new SLAPrintObject::SupportData());
|
||||
po.m_supportdata->emesh = sla::to_eigenmesh(mo);
|
||||
po.m_supportdata->support_points = sla::support_points(mo);
|
||||
po.m_supportdata->emesh = sla::to_eigenmesh(po.transformed_mesh());
|
||||
|
||||
std::cout << "support points copied "
|
||||
<< po.m_supportdata->support_points.rows() << std::endl;
|
||||
po.m_supportdata->support_points =
|
||||
sla::to_point_set(po.transformed_support_points());
|
||||
}
|
||||
|
||||
// for(SLAPrintObject *po : pobjects) {
|
||||
|
@ -163,6 +164,8 @@ void SLAPrint::process()
|
|||
|
||||
// In this step we create the supports
|
||||
auto support_tree = [this](SLAPrintObject& po) {
|
||||
if(!po.m_supportdata) return;
|
||||
|
||||
auto& emesh = po.m_supportdata->emesh;
|
||||
auto& pts = po.m_supportdata->support_points; // nowhere filled yet
|
||||
try {
|
||||
|
@ -175,6 +178,7 @@ void SLAPrint::process()
|
|||
set_status(unsigned(stinit + st*d), msg);
|
||||
};
|
||||
ctl.stopcondition = [this](){ return canceled(); };
|
||||
ctl.cancelfn = [this]() { throw_if_canceled(); };
|
||||
|
||||
po.m_supportdata->support_tree_ptr.reset(
|
||||
new SLASupportTree(pts, emesh, scfg, ctl));
|
||||
|
@ -190,6 +194,7 @@ void SLAPrint::process()
|
|||
// 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)
|
||||
|
||||
if(po.is_step_done(slaposSupportTree) &&
|
||||
po.m_supportdata &&
|
||||
po.m_supportdata->support_tree_ptr)
|
||||
|
@ -198,8 +203,15 @@ void SLAPrint::process()
|
|||
double h = po.m_config.pad_wall_height.getFloat();
|
||||
double md = po.m_config.pad_max_merge_distance.getFloat();
|
||||
double er = po.m_config.pad_edge_radius.getFloat();
|
||||
double lh = po.m_config.layer_height.getFloat();
|
||||
double elevation = po.m_config.support_object_elevation.getFloat();
|
||||
|
||||
po.m_supportdata->support_tree_ptr->add_pad(wt, h, md, er);
|
||||
sla::ExPolygons bp;
|
||||
if(elevation < h/2)
|
||||
sla::base_plate(po.transformed_mesh(), bp,
|
||||
float(h/2), float(lh));
|
||||
|
||||
po.m_supportdata->support_tree_ptr->add_pad(bp, wt, h, md, er);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -216,7 +228,7 @@ void SLAPrint::process()
|
|||
|
||||
// Rasterizing the model objects, and their supports
|
||||
auto rasterize = [this, ilh]() {
|
||||
using Layer = ExPolygons;
|
||||
using Layer = sla::ExPolygons;
|
||||
using LayerCopies = std::vector<SLAPrintObject::Instance>;
|
||||
struct LayerRef {
|
||||
std::reference_wrapper<const Layer> lref;
|
||||
|
@ -232,12 +244,17 @@ void SLAPrint::process()
|
|||
|
||||
// For all print objects, go through its initial layers and place them
|
||||
// into the layers hash
|
||||
// long long initlyridx = static_cast<long long>(scale_(ilh));
|
||||
for(SLAPrintObject *o : m_objects) {
|
||||
|
||||
double gndlvl = o->transformed_mesh().bounding_box().min(Z);
|
||||
|
||||
double lh = o->m_config.layer_height.getFloat();
|
||||
std::vector<ExPolygons> & oslices = o->m_model_slices;
|
||||
SlicedModel & oslices = o->m_model_slices;
|
||||
for(int i = 0; i < oslices.size(); ++i) {
|
||||
double h = ilh + i * lh;
|
||||
int a = i == 0 ? 0 : 1;
|
||||
int b = i == 0 ? 0 : i - 1;
|
||||
|
||||
double h = gndlvl + ilh * a + b * lh;
|
||||
long long lyridx = static_cast<long long>(scale_(h));
|
||||
auto& lyrs = levels[lyridx]; // this initializes a new record
|
||||
lyrs.emplace_back(oslices[i], o->m_instances);
|
||||
|
@ -245,36 +262,25 @@ void SLAPrint::process()
|
|||
|
||||
if(o->m_supportdata) { // deal with the support slices if present
|
||||
auto& sslices = o->m_supportdata->support_slices;
|
||||
double el = o->m_config.support_object_elevation.getFloat();
|
||||
//TODO: remove next line:
|
||||
el = SupportConfig().object_elevation_mm;
|
||||
|
||||
for(int i = 0; i < sslices.size(); ++i) {
|
||||
double h = ilh + i * lh;
|
||||
int a = i == 0 ? 0 : 1;
|
||||
int b = i == 0 ? 0 : i - 1;
|
||||
|
||||
double h = gndlvl - el + ilh * a + b * lh;
|
||||
|
||||
long long lyridx = static_cast<long long>(scale_(h));
|
||||
auto& lyrs = levels[lyridx];
|
||||
lyrs.emplace_back(sslices[i], o->m_instances);
|
||||
}
|
||||
}
|
||||
|
||||
// auto& oslices = o->m_model_slices;
|
||||
// auto& firstlyr = oslices.front();
|
||||
// auto& initlevel = levels[initlyridx];
|
||||
// initlevel.emplace_back(firstlyr, o->m_instances);
|
||||
|
||||
// // now push the support slices as well
|
||||
// // TODO
|
||||
|
||||
// double lh = o->m_config.layer_height.getFloat();
|
||||
// size_t li = 1;
|
||||
// for(auto lit = std::next(oslices.begin());
|
||||
// lit != oslices.end();
|
||||
// ++lit)
|
||||
// {
|
||||
// double h = ilh + li++ * lh;
|
||||
// long long lyridx = static_cast<long long>(scale_(h));
|
||||
// auto& lyrs = levels[lyridx];
|
||||
// lyrs.emplace_back(*lit, o->m_instances);
|
||||
// }
|
||||
}
|
||||
|
||||
if(canceled()) return;
|
||||
|
||||
// collect all the keys
|
||||
std::vector<long long> keys; keys.reserve(levels.size());
|
||||
for(auto& e : levels) keys.emplace_back(e.first);
|
||||
|
@ -301,32 +307,41 @@ void SLAPrint::process()
|
|||
auto lvlcnt = unsigned(levels.size());
|
||||
printer.layers(lvlcnt);
|
||||
|
||||
// TODO exclusive progress indication for this step would be good
|
||||
// as it is the longest of all. It would require synchronization
|
||||
// in the parallel processing.
|
||||
|
||||
// procedure to process one height level. This will run in parallel
|
||||
auto lvlfn = [&keys, &levels, &printer](unsigned level_id) {
|
||||
auto lvlfn = [this, &keys, &levels, &printer](unsigned level_id) {
|
||||
if(canceled()) return;
|
||||
|
||||
LayerRefs& lrange = levels[keys[level_id]];
|
||||
|
||||
for(auto& lyrref : lrange) { // for all layers in the current level
|
||||
const Layer& l = lyrref.lref; // get the layer reference
|
||||
const LayerCopies& copies = lyrref.copies;
|
||||
ExPolygonCollection sl = l;
|
||||
// Switch to the appropriate layer in the printer
|
||||
printer.begin_layer(level_id);
|
||||
|
||||
// Switch to the appropriate layer in the printer
|
||||
printer.begin_layer(level_id);
|
||||
for(auto& lyrref : lrange) { // for all layers in the current level
|
||||
if(canceled()) break;
|
||||
const Layer& sl = lyrref.lref; // get the layer reference
|
||||
const LayerCopies& copies = lyrref.copies;
|
||||
|
||||
// Draw all the polygons in the slice to the actual layer.
|
||||
for(auto& cp : copies) {
|
||||
for(ExPolygon slice : sl.expolygons) {
|
||||
for(ExPolygon slice : sl) {
|
||||
slice.translate(cp.shift(X), cp.shift(Y));
|
||||
slice.rotate(cp.rotation);
|
||||
printer.draw_polygon(slice, level_id);
|
||||
}
|
||||
}
|
||||
|
||||
// Finish the layer for later saving it.
|
||||
printer.finish_layer(level_id);
|
||||
}
|
||||
|
||||
// Finish the layer for later saving it.
|
||||
printer.finish_layer(level_id);
|
||||
};
|
||||
|
||||
// last minute escape
|
||||
if(canceled()) return;
|
||||
|
||||
// Sequential version (for testing)
|
||||
// for(unsigned l = 0; l < lvlcnt; ++l) process_level(l);
|
||||
|
||||
|
@ -362,6 +377,11 @@ void SLAPrint::process()
|
|||
[](){} // validate
|
||||
};
|
||||
|
||||
const unsigned min_objstatus = 0;
|
||||
const unsigned max_objstatus = PRINT_STEP_LEVELS[slapsRasterize];
|
||||
const size_t objcount = m_objects.size();
|
||||
const double ostepd = (max_objstatus - min_objstatus) / (objcount * 100.0);
|
||||
|
||||
for(SLAPrintObject * po : m_objects) {
|
||||
for(size_t s = 0; s < pobj_program.size(); ++s) {
|
||||
auto currentstep = objectsteps[s];
|
||||
|
@ -372,8 +392,9 @@ void SLAPrint::process()
|
|||
throw_if_canceled();
|
||||
|
||||
if(po->m_stepmask[s] && !po->is_step_done(currentstep)) {
|
||||
set_status(OBJ_STEP_LEVELS[currentstep],
|
||||
OBJ_STEP_LABELS[currentstep]);
|
||||
unsigned st = OBJ_STEP_LEVELS[currentstep];
|
||||
st = unsigned(min_objstatus + st * ostepd);
|
||||
set_status(st, OBJ_STEP_LABELS[currentstep]);
|
||||
|
||||
po->set_started(currentstep);
|
||||
pobj_program[s](*po);
|
||||
|
@ -386,8 +407,8 @@ void SLAPrint::process()
|
|||
slapsRasterize, slapsValidate
|
||||
};
|
||||
|
||||
// TODO: enable rasterizing
|
||||
m_stepmask[slapsRasterize] = false;
|
||||
// this would disable the rasterization step
|
||||
// m_stepmask[slapsRasterize] = false;
|
||||
|
||||
for(size_t s = 0; s < print_program.size(); ++s) {
|
||||
auto currentstep = printsteps[s];
|
||||
|
@ -423,22 +444,47 @@ TriangleMesh SLAPrintObject::support_mesh() const
|
|||
if(m_supportdata && m_supportdata->support_tree_ptr)
|
||||
m_supportdata->support_tree_ptr->merged_mesh(trm);
|
||||
|
||||
// TODO: is this necessary?
|
||||
trm.repair();
|
||||
|
||||
std::cout << "support mesh united and returned" << std::endl;
|
||||
return trm;
|
||||
// return make_cube(10., 10., 10.);
|
||||
}
|
||||
|
||||
TriangleMesh SLAPrintObject::pad_mesh() const
|
||||
{
|
||||
if(!m_supportdata || !m_supportdata->support_tree_ptr) {
|
||||
std::cout << "Empty pad mesh returned.." << std::endl;
|
||||
return TriangleMesh();
|
||||
}
|
||||
if(!m_supportdata || !m_supportdata->support_tree_ptr) return {};
|
||||
|
||||
// FIXME: pad mesh is empty here for some reason.
|
||||
return m_supportdata->support_tree_ptr->get_pad();
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
if(m_trmesh_valid) return m_transformed_rmesh;
|
||||
m_transformed_rmesh = m_model_object->raw_mesh();
|
||||
m_transformed_rmesh.transform(m_trafo);
|
||||
m_trmesh_valid = true;
|
||||
return m_transformed_rmesh;
|
||||
}
|
||||
|
||||
std::vector<Vec3d> SLAPrintObject::transformed_support_points() const
|
||||
{
|
||||
assert(m_model_object != nullptr);
|
||||
auto& spts = m_model_object->sla_support_points;
|
||||
|
||||
// this could be cached as well
|
||||
std::vector<Vec3d> ret; ret.reserve(spts.size());
|
||||
|
||||
for(auto& sp : spts) ret.emplace_back( trafo() * Vec3d(sp.cast<double>()));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue