Manual unification of print polygons.

With clipper not with the agg rasterizer, because they can be reused for the statistics.
This commit is contained in:
tamasmeszaros 2019-03-26 14:06:40 +01:00
parent 9946a1c914
commit 221a4836fd
2 changed files with 115 additions and 36 deletions

View File

@ -934,11 +934,11 @@ void SLAPrint::process()
m_printer_input.end(), m_printer_input.end(),
PrintLayer(lvlid)); PrintLayer(lvlid));
if(it == m_printer_input.end() || it->level != lvlid) if(it == m_printer_input.end() || it->level() != lvlid)
it = m_printer_input.insert(it, PrintLayer(lvlid)); it = m_printer_input.insert(it, PrintLayer(lvlid));
it->slices.emplace_back(std::cref(slicerecord)); it->add(slicerecord);
} }
} }
@ -990,43 +990,53 @@ void SLAPrint::process()
{ {
if(canceled()) return; if(canceled()) return;
PrintLayer& lrange = m_printer_input[level_id]; PrintLayer& printlayer = m_printer_input[level_id];
// Switch to the appropriate layer in the printer // Switch to the appropriate layer in the printer
printer.begin_layer(level_id); printer.begin_layer(level_id);
for(const SliceRecord& slrecord : lrange.slices) auto orientation = flpXY? SLADisplayOrientation::sladoPortrait :
{ // for all layers in the current level SLADisplayOrientation::sladoLandscape;
if(canceled()) break; // Get the transformed and properly oriented slice
const ExPolygons& slice = printlayer.transformed_slice(orientation);
// get the layer reference // Now draw all the polygons with the printer...
const ExPolygons& objslice = slrecord.get_slice(soModel); for(const ExPolygon& p : slice) printer.draw_polygon(p, level_id);
const ExPolygons& supslice = slrecord.get_slice(soSupport);
const SLAPrintObject *po = slrecord.print_obj();
assert(po != nullptr);
// Draw all the polygons in the slice to the actual layer.
for(const SLAPrintObject::Instance& tr : po->instances()) {
for(ExPolygon poly : objslice) {
// The order is important here:
// apply rotation before translation...
poly.rotate(double(tr.rotation));
poly.translate(tr.shift(X), tr.shift(Y));
if(flpXY) swapXY(poly);
printer.draw_polygon(poly, level_id);
}
for(ExPolygon poly : supslice) { // for(const SliceRecord& slrecord : printlayer.m_slices)
// The order is important here: // { // for all layers in the current level
// apply rotation before translation...
poly.rotate(double(tr.rotation)); // if(canceled()) break;
poly.translate(tr.shift(X), tr.shift(Y));
if(flpXY) swapXY(poly); // // get the layer reference
printer.draw_polygon(poly, level_id); // const ExPolygons& objslice = slrecord.get_slice(soModel);
} // const ExPolygons& supslice = slrecord.get_slice(soSupport);
} // const SLAPrintObject *po = slrecord.print_obj();
} // assert(po != nullptr);
// // Draw all the polygons in the slice to the actual layer.
// for(const SLAPrintObject::Instance& tr : po->instances()) {
// for(ExPolygon poly : objslice) {
// // The order is important here:
// // apply rotation before translation...
// poly.rotate(double(tr.rotation));
// poly.translate(tr.shift(X), tr.shift(Y));
// if(flpXY) swapXY(poly);
// printer.draw_polygon(poly, level_id);
// }
// for(ExPolygon poly : supslice) {
// // The order is important here:
// // apply rotation before translation...
// poly.rotate(double(tr.rotation));
// poly.translate(tr.shift(X), tr.shift(Y));
// if(flpXY) swapXY(poly);
// printer.draw_polygon(poly, level_id);
// }
// }
// }
// Finish the layer for later saving it. // Finish the layer for later saving it.
printer.finish_layer(level_id); printer.finish_layer(level_id);
@ -1662,4 +1672,60 @@ std::string SLAPrintStatistics::finalize_output_path(const std::string &path_in)
return final_path; return final_path;
} }
const ExPolygons &SLAPrint::PrintLayer::transformed_slice(SLADisplayOrientation o) const
{
if (! m_trcache.empty()) return m_trcache;
size_t cap = 0;
for (const SliceRecord& sr : m_slices) {
if(sr.print_obj()) {
size_t insts = sr.print_obj()->instances().size();
cap += insts * (sr.get_slice(soModel).size() +
sr.get_slice(soSupport).size());
}
}
Polygons allpolys;
allpolys.reserve(cap);
for (const SliceRecord& sr : m_slices) {
const ExPolygons& objsl = sr.get_slice(soModel);
const ExPolygons& supsl = sr.get_slice(soSupport);
if (! sr.print_obj()) continue;
for(const SLAPrintObject::Instance& tr : sr.print_obj()->instances())
{
Polygons polys;
size_t polyscap = 0;
for(const ExPolygon &p : objsl) polyscap += p.holes.size() + 1;
for(const ExPolygon &p : supsl) polyscap += p.holes.size() + 1;
polys.reserve(polyscap);
for(const ExPolygon &p : objsl) {
polys.emplace_back(p.contour);
for(auto& h : p.holes) polys.emplace_back(h);
}
for(const ExPolygon &p : supsl) {
polys.emplace_back(p.contour);
for(auto& h : p.holes) polys.emplace_back(h);
}
for(Polygon& poly : polys) {
poly.rotate(double(tr.rotation));
poly.translate(tr.shift(X), tr.shift(Y));
if(o == SLADisplayOrientation::sladoPortrait)
for(auto& p : poly.points) std::swap(p(X), p(Y));
allpolys.emplace_back(std::move(poly));
}
}
}
m_trcache = union_ex(allpolys);
return m_trcache;
}
} // namespace Slic3r } // namespace Slic3r

View File

@ -329,18 +329,31 @@ public:
// An aggregation of SliceRecord-s from all the print objects for each // An aggregation of SliceRecord-s from all the print objects for each
// occupied layer. Slice record levels dont have to match exactly. // occupied layer. Slice record levels dont have to match exactly.
// They are unified if the level difference is within +/- SCALED_EPSILON // They are unified if the level difference is within +/- SCALED_EPSILON
struct PrintLayer { class PrintLayer {
coord_t level; coord_t m_level;
// The collection of slice records for the current level. // The collection of slice records for the current level.
std::vector<std::reference_wrapper<const SliceRecord>> slices; std::vector<std::reference_wrapper<const SliceRecord>> m_slices;
explicit PrintLayer(coord_t lvl) : level(lvl) {} // No need for concurrency handling with CachedObject (hopefully)
mutable ExPolygons m_trcache;
public:
explicit PrintLayer(coord_t lvl) : m_level(lvl) {}
// for being sorted in their container (see m_printer_input) // for being sorted in their container (see m_printer_input)
bool operator<(const PrintLayer& other) const { bool operator<(const PrintLayer& other) const {
return level < other.level; return m_level < other.m_level;
} }
void add(const SliceRecord& sr) {
m_trcache.clear(); m_slices.emplace_back(sr);
}
coord_t level() const { return m_level; }
const ExPolygons& transformed_slice(SLADisplayOrientation o) const;
}; };
SLAPrint(): m_stepmask(slapsCount, true) {} SLAPrint(): m_stepmask(slapsCount, true) {}