Merge remote-tracking branch 'remotes/origin/dev_native' into vb_3dscene_partial_update

This commit is contained in:
bubnikv 2018-11-16 18:31:39 +01:00
commit dafa4621aa
23 changed files with 804 additions and 273 deletions

View file

@ -935,6 +935,10 @@ public:
// The max length of a bridge in mm
ConfigOptionFloat support_max_bridge_length /*= 15.0*/;
// The elevation in Z direction upwards. This is the space between the pad
// and the model object's bounding box bottom.
ConfigOptionFloat support_object_elevation;
// Now for the base pool (plate) ///////////////////////////////////////////
ConfigOptionFloat pad_wall_thickness /*= 2*/;

View file

@ -418,17 +418,32 @@ ExPolygons concave_hull(const ExPolygons& polys, double max_dist_mm = 50)
return punion;
}
void base_plate(const TriangleMesh &mesh, ExPolygons &output, float h)
void base_plate(const TriangleMesh &mesh, ExPolygons &output, float h,
float layerh)
{
TriangleMesh m = mesh;
TriangleMeshSlicer slicer(&m);
TriangleMesh upper, lower;
slicer.cut(h, &upper, &lower);
// TriangleMesh upper, lower;
// slicer.cut(h, &upper, &lower);
// TODO: this might be slow
output = lower.horizontal_projection();
// TODO: this might be slow (in fact it was)
// output = lower.horizontal_projection();
auto bb = mesh.bounding_box();
float gnd = float(bb.min(Z));
std::vector<float> heights = {float(bb.min(Z))};
for(float hi = gnd + layerh; hi <= gnd + h; hi += layerh)
heights.emplace_back(hi);
std::vector<ExPolygons> out; out.reserve(size_t(std::ceil(h/layerh)));
slicer.slice(heights, &out, [](){});
size_t count = 0; for(auto& o : out) count += o.size();
ExPolygons tmp; tmp.reserve(count);
for(auto& o : out) for(auto& e : o) tmp.emplace_back(std::move(e));
output = unify(tmp);
for(auto& o : output) o = o.simplify(0.1/SCALING_FACTOR).front();
}

View file

@ -15,7 +15,8 @@ using ExPolygons = std::vector<ExPolygon>;
/// Calculate the polygon representing the silhouette from the specified height
void base_plate(const TriangleMesh& mesh,
ExPolygons& output,
float height = 0.1f);
float zlevel = 0.1f,
float layerheight = 0.05f);
struct PoolConfig {
double min_wall_thickness_mm = 2;

View file

@ -9,6 +9,7 @@
#include "SLASpatIndex.hpp"
#include "SLABasePool.hpp"
#include <libnest2d/tools/benchmark.h>
#include "ClipperUtils.hpp"
#include "Model.hpp"
@ -70,12 +71,6 @@ template<class Vec> double distance(const Vec& pp1, const Vec& pp2) {
return distance(p);
}
/// The horizontally projected 2D boundary of the model as individual line
/// segments. This can be used later to create a spatial index of line segments
/// and query for possible pillar positions for non-ground facing support points
std::vector<std::pair<Vec2d, Vec2d>> model_boundary(const EigenMesh3D& emesh,
double offs = 0.01);
Contour3D sphere(double rho, Portion portion = make_portion(0.0, 2.0*PI),
double fa=(2*PI/360)) {
@ -416,9 +411,9 @@ struct Pillar {
base.points.emplace_back(ep);
auto& indices = base.indices;
auto hcenter = base.points.size() - 1;
auto lcenter = base.points.size() - 2;
auto offs = steps;
auto hcenter = int(base.points.size() - 1);
auto lcenter = int(base.points.size() - 2);
auto offs = int(steps);
for(int i = 0; i < steps - 1; ++i) {
indices.emplace_back(i, i + offs, offs + i + 1);
indices.emplace_back(i, offs + i + 1, i + 1);
@ -426,7 +421,7 @@ struct Pillar {
indices.emplace_back(lcenter, offs + i + 1, offs + i);
}
auto last = steps - 1;
auto last = int(steps - 1);
indices.emplace_back(0, last, offs);
indices.emplace_back(last, offs + last, offs);
indices.emplace_back(hcenter, last, 0);
@ -510,15 +505,20 @@ struct Pad {
Pad() {}
Pad(const TriangleMesh& object_support_mesh,
const ExPolygons& baseplate,
double ground_level,
const PoolConfig& cfg) : zlevel(ground_level)
const PoolConfig& cfg) : zlevel(ground_level + cfg.min_wall_height_mm/2)
{
ExPolygons basep;
base_plate(object_support_mesh, basep);
base_plate(object_support_mesh, basep,
float(cfg.min_wall_height_mm)/*,layer_height*/);
for(auto& bp : baseplate) basep.emplace_back(bp);
create_base_pool(basep, tmesh, cfg);
tmesh.translate(0, 0, float(zlevel));
std::cout << "pad ground level " << zlevel << std::endl;
}
bool empty() const { return tmesh.facets_count() == 0; }
};
EigenMesh3D to_eigenmesh(const Contour3D& cntr) {
@ -563,6 +563,10 @@ EigenMesh3D to_eigenmesh(const TriangleMesh& tmesh) {
const stl_file& stl = tmesh.stl;
EigenMesh3D outmesh;
auto&& bb = tmesh.bounding_box();
outmesh.ground_level += bb.min(Z);
auto& V = outmesh.V;
auto& F = outmesh.F;
@ -586,11 +590,7 @@ EigenMesh3D to_eigenmesh(const TriangleMesh& tmesh) {
}
EigenMesh3D to_eigenmesh(const ModelObject& modelobj) {
auto&& rmesh = modelobj.raw_mesh();
auto&& ret = to_eigenmesh(rmesh);
auto&& bb = rmesh.bounding_box();
ret.ground_level = bb.min(Z);
return ret;
return to_eigenmesh(modelobj.raw_mesh());
}
EigenMesh3D to_eigenmesh(const Model& model) {
@ -608,7 +608,12 @@ EigenMesh3D to_eigenmesh(const Model& model) {
return to_eigenmesh(combined_mesh);
}
PointSet to_point_set(const std::vector<Vec3d> &v)
{
PointSet ret(v.size(), 3);
{ long i = 0; for(const Vec3d& p : v) ret.row(i++) = p; }
return ret;
}
Vec3d model_coord(const ModelInstance& object, const Vec3f& mesh_coord) {
return object.transform_vector(mesh_coord.cast<double>());
@ -635,9 +640,18 @@ PointSet support_points(const Model& model) {
PointSet support_points(const ModelObject& modelobject)
{
PointSet ret(modelobject.sla_support_points.size(), 3);
auto rot = modelobject.instances.front()->get_rotation();
// auto scaling = modelobject.instances.front()->get_scaling_factor();
// Transform3d tr;
// tr.rotate(Eigen::AngleAxisd(rot(X), Vec3d::UnitX()) *
// Eigen::AngleAxisd(rot(Y), Vec3d::UnitY()));
long i = 0;
for(const Vec3f& msource : modelobject.sla_support_points) {
ret.row(i++) = msource.cast<double>();
Vec3d&& p = msource.cast<double>();
// p = tr * p;
ret.row(i++) = p;
}
return ret;
}
@ -694,20 +708,18 @@ public:
return m_pillars.back();
}
const Head& pillar_head(long pillar_id) {
assert(pillar_id > 0 && pillar_id < m_pillars.size());
Pillar& p = m_pillars[pillar_id];
assert(p.starts_from_head && p.start_junction_id > 0 &&
const Head& pillar_head(long pillar_id) const {
assert(pillar_id >= 0 && pillar_id < m_pillars.size());
const Pillar& p = m_pillars[pillar_id];
assert(p.starts_from_head && p.start_junction_id >= 0 &&
p.start_junction_id < m_heads.size() );
meshcache_valid = false;
return m_heads[p.start_junction_id];
}
const Pillar& head_pillar(long headid) {
const Pillar& head_pillar(long headid) const {
assert(headid >= 0 && headid < m_heads.size());
Head& h = m_heads[headid];
assert(h.pillar_id > 0 && h.pillar_id < m_pillars.size());
meshcache_valid = false;
const Head& h = m_heads[headid];
assert(h.pillar_id >= 0 && h.pillar_id < m_pillars.size());
return m_pillars[h.pillar_id];
}
@ -743,8 +755,9 @@ public:
}
const Pad& create_pad(const TriangleMesh& object_supports,
const ExPolygons& baseplate,
const PoolConfig& cfg) {
m_pad = Pad(object_supports, ground_level, cfg);
m_pad = Pad(object_supports, baseplate, ground_level, cfg);
return m_pad;
}
@ -778,16 +791,25 @@ public:
}
BoundingBoxf3&& bb = meshcache.bounding_box();
model_height = bb.max(Z);
model_height = bb.max(Z) - bb.min(Z);
meshcache_valid = true;
return meshcache;
}
// WITH THE PAD
double full_height() const {
double h = mesh_height();
if(!pad().empty()) h += pad().cfg.min_wall_height_mm / 2;
return h;
}
// WITHOUT THE PAD!!!
double mesh_height() const {
if(!meshcache_valid) merged_mesh();
return model_height;
}
};
template<class DistFn>
@ -990,7 +1012,6 @@ bool SLASupportTree::generate(const PointSet &points,
using Result = SLASupportTree::Impl;
Result& result = *m_impl;
result.ground_level = mesh.ground_level;
enum Steps {
BEGIN,
@ -1259,13 +1280,11 @@ bool SLASupportTree::generate(const PointSet &points,
const double hbr = cfg.head_back_radius_mm;
const double pradius = cfg.pillar_radius_mm;
const double maxbridgelen = cfg.max_bridge_length_mm;
const double gndlvl = emesh.ground_level - cfg.object_elevation_mm;
const double gndlvl = result.ground_level;
ClusterEl cl_centroids;
cl_centroids.reserve(gnd_clusters.size());
std::cout << "gnd_clusters size: " << gnd_clusters.size() << std::endl;
SpatIndex pheadindex; // spatial index for the junctions
for(auto cl : gnd_clusters) {
// place all the centroid head positions into the index. We will
@ -1665,52 +1684,34 @@ void SLASupportTree::merged_mesh_with_pad(TriangleMesh &outmesh) const {
outmesh.merge(get_pad());
}
template<class T> void slice_part(const T& inp,
std::vector<SlicedSupports>& mergev,
const std::vector<float>& heights)
{
for(auto& part : inp) {
TriangleMesh&& m = mesh(part.mesh);
TriangleMeshSlicer slicer(&m);
SlicedSupports slout;
slicer.slice(heights, &slout, [](){});
for(size_t i = 0; i < slout.size(); i++) {
// move the layers obtained from this mesh to the merge area
mergev[i].emplace_back(std::move(slout[i]));
}
}
}
SlicedSupports SLASupportTree::slice(float layerh, float init_layerh) const
{
if(init_layerh < 0) init_layerh = layerh;
auto& stree = get();
const float modelh = stree.full_height();
std::vector<float> heights; heights.reserve(size_t(modelh/layerh) + 1);
for(float h = init_layerh; h <= modelh; h += layerh) {
const auto modelh = float(stree.full_height());
auto gndlvl = float(this->m_impl->ground_level);
const Pad& pad = m_impl->pad();
if(!pad.empty()) gndlvl -= float(pad.cfg.min_wall_height_mm/2);
std::vector<float> heights = {gndlvl};
heights.reserve(size_t(modelh/layerh) + 1);
for(float h = gndlvl + init_layerh; h < gndlvl + modelh; h += layerh) {
heights.emplace_back(h);
}
std::vector<SlicedSupports> mergev(heights.size());
TriangleMesh fullmesh = m_impl->merged_mesh();
fullmesh.merge(get_pad());
TriangleMeshSlicer slicer(&fullmesh);
SlicedSupports ret;
slicer.slice(heights, &ret, m_ctl.cancelfn);
slice_part(stree.heads(), mergev, heights);
slice_part(stree.pillars(), mergev, heights);
slice_part(stree.junctions(), mergev, heights);
slice_part(stree.bridges(), mergev, heights);
slice_part(stree.compact_bridges(), mergev, heights);
// TODO: do this for all
for(SlicedSupports& level : mergev) {
// TODO merge all expolygon in the current level
}
return {};
return ret;
}
const TriangleMesh &SLASupportTree::add_pad(double min_wall_thickness_mm,
const TriangleMesh &SLASupportTree::add_pad(const SliceLayer& baseplate,
double min_wall_thickness_mm,
double min_wall_height_mm,
double max_merge_distance_mm,
double edge_radius_mm) const
@ -1722,7 +1723,7 @@ const TriangleMesh &SLASupportTree::add_pad(double min_wall_thickness_mm,
// pcfg.min_wall_height_mm = min_wall_height_mm;
// pcfg.max_merge_distance_mm = max_merge_distance_mm;
// pcfg.edge_radius_mm = edge_radius_mm;
return m_impl->create_pad(mm, pcfg).tmesh;
return m_impl->create_pad(mm, baseplate, pcfg).tmesh;
}
const TriangleMesh &SLASupportTree::get_pad() const
@ -1730,9 +1731,17 @@ const TriangleMesh &SLASupportTree::get_pad() const
return m_impl->pad().tmesh;
}
double SLASupportTree::get_elevation() const
{
double ph = m_impl->pad().empty()? 0 :
m_impl->pad().cfg.min_wall_height_mm/2.0;
return -m_impl->ground_level + ph;
}
SLASupportTree::SLASupportTree(const Model& model,
const SupportConfig& cfg,
const Controller& ctl): m_impl(new Impl())
const Controller& ctl):
m_impl(new Impl()), m_ctl(ctl)
{
generate(support_points(model), to_eigenmesh(model), cfg, ctl);
}
@ -1740,13 +1749,15 @@ SLASupportTree::SLASupportTree(const Model& model,
SLASupportTree::SLASupportTree(const PointSet &points,
const EigenMesh3D& emesh,
const SupportConfig &cfg,
const Controller &ctl): m_impl(new Impl())
const Controller &ctl):
m_impl(new Impl()), m_ctl(ctl)
{
m_impl->ground_level = emesh.ground_level - cfg.object_elevation_mm;
generate(points, emesh, cfg, ctl);
}
SLASupportTree::SLASupportTree(const SLASupportTree &c):
m_impl( new Impl(*c.m_impl)) {}
m_impl(new Impl(*c.m_impl)), m_ctl(c.m_ctl) {}
SLASupportTree &SLASupportTree::operator=(const SLASupportTree &c)
{

View file

@ -63,16 +63,25 @@ struct SupportConfig {
// The elevation in Z direction upwards. This is the space between the pad
// and the model object's bounding box bottom.
double object_elevation_mm = 0;
double object_elevation_mm = 10;
};
/// A Control structure for the support calculation. Consists of the status
/// indicator callback and the stop condition predicate.
struct Controller {
// This will signal the status of the calculation to the front-end
std::function<void(unsigned, const std::string&)> statuscb =
[](unsigned, const std::string&){};
// Returns true if the calculation should be aborted.
std::function<bool(void)> stopcondition = [](){ return false; };
// Similar to cancel callback. This should check the stop condition and
// if true, throw an appropriate exception. (TriangleMeshSlicer needs this)
// consider it a hard abort. stopcondition is permits the algorithm to
// terminate itself
std::function<void(void)> cancelfn = [](){};
};
/// An index-triangle structure for libIGL functions. Also serves as an
@ -101,11 +110,15 @@ void add_sla_supports(Model& model, const SupportConfig& cfg = {},
const Controller& ctl = {});
EigenMesh3D to_eigenmesh(const TriangleMesh& m);
PointSet to_point_set(const std::vector<Vec3d>&);
// obsolete, not used anymore
EigenMesh3D to_eigenmesh(const Model& model);
EigenMesh3D to_eigenmesh(const ModelObject& model);
PointSet support_points(const Model& model);
PointSet support_points(const ModelObject& modelobject);
PointSet support_points(const Model& model);
/* ************************************************************************** */
@ -120,6 +133,7 @@ public:
class SLASupportTree {
class Impl;
std::unique_ptr<Impl> m_impl;
Controller m_ctl;
Impl& get() { return *m_impl; }
const Impl& get() const { return *m_impl; }
@ -160,7 +174,8 @@ public:
SlicedSupports slice(float layerh, float init_layerh = -1.0) const;
/// Adding the "pad" (base pool) under the supports
const TriangleMesh& add_pad(double min_wall_thickness_mm,
const TriangleMesh& add_pad(const SliceLayer& baseplate,
double min_wall_thickness_mm,
double min_wall_height_mm,
double max_merge_distance_mm,
double edge_radius_mm) const;
@ -168,6 +183,11 @@ public:
/// Get the pad geometry
const TriangleMesh& get_pad() const;
/// The Z offset to raise the model and the supports to the ground level.
/// This is the elevation given in the support config and the height of the
/// pad (if requested).
double get_elevation() const;
};
}

View file

@ -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

View file

@ -55,6 +55,11 @@ public:
// Support mesh is only valid if this->is_step_done(slaposPad) is true.
TriangleMesh pad_mesh() const;
// This will return the transformed mesh which is cached
const TriangleMesh& transformed_mesh() const;
std::vector<Vec3d> transformed_support_points() const;
// I refuse to grantee copying (Tamas)
SLAPrintObject(const SLAPrintObject&) = delete;
SLAPrintObject& operator=(const SLAPrintObject&) = delete;
@ -69,7 +74,7 @@ protected:
void config_apply(const ConfigBase &other, bool ignore_nonexistent = false) { this->m_config.apply(other, ignore_nonexistent); }
void config_apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent = false)
{ this->m_config.apply_only(other, keys, ignore_nonexistent); }
void set_trafo(const Transform3d& trafo) { m_trafo = trafo; }
void set_trafo(const Transform3d& trafo) { m_trafo = trafo; m_trmesh_valid = false; }
bool set_instances(const std::vector<Instance> &instances);
// Invalidates the step, and its depending steps in SLAPrintObject and SLAPrint.
@ -86,6 +91,10 @@ private:
std::vector<bool> m_stepmask;
std::vector<ExPolygons> m_model_slices;
// Caching the transformed (m_trafo) raw mesh of the object
mutable TriangleMesh m_transformed_rmesh;
mutable bool m_trmesh_valid = false;
class SupportData;
std::unique_ptr<SupportData> m_supportdata;
};

View file

@ -6,7 +6,7 @@
//============
// Shows camera target in the 3D scene
#define ENABLE_SHOW_CAMERA_TARGET 1
#define ENABLE_SHOW_CAMERA_TARGET 0
//=============
// 1.42.0 techs
@ -23,8 +23,12 @@
#define ENABLE_MODIFIED_CAMERA_TARGET (1 && ENABLE_1_42_0)
// Add Geometry::Transformation class and use it into ModelInstance, ModelVolume and GLVolume
#define ENABLE_MODELVOLUME_TRANSFORM (1 && ENABLE_1_42_0)
// Keeps objects on bed while scaling them using the scale gizmo
#define ENABLE_ENSURE_ON_BED_WHILE_SCALING (1 && ENABLE_MODELVOLUME_TRANSFORM)
// Gizmos always rendered on top of objects
#define ENABLE_GIZMOS_ON_TOP (1 && ENABLE_1_42_0)
// New menu layout (open/save/save as project + import/export)
#define ENABLE_NEW_MENU_LAYOUT (1 && ENABLE_1_42_0)
#endif // _technologies_h_