From 256d44cc43aaf30e18f7fc3f3472d516cd3bd0c8 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 13 Jul 2018 11:26:59 +0200 Subject: [PATCH] Disabling reverse order checks in DJD selection. It causes unacceptable running times for large number of objects. --- xs/src/libslic3r/Model.cpp | 96 +++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 6664020a3..c1d58f963 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -21,6 +21,7 @@ #include // #include +#include "SVG.hpp" namespace Slic3r { @@ -308,6 +309,86 @@ namespace arr { using namespace libnest2d; +std::string toString(const Model& model) { + std::stringstream ss; + + ss << "{\n"; + + for(auto objptr : model.objects) { + if(!objptr) continue; + + auto rmesh = objptr->raw_mesh(); + + for(auto objinst : objptr->instances) { + if(!objinst) continue; + + Slic3r::TriangleMesh tmpmesh = rmesh; + tmpmesh.scale(objinst->scaling_factor); + objinst->transform_mesh(&tmpmesh); + ExPolygons expolys = tmpmesh.horizontal_projection(); + for(auto& expoly_complex : expolys) { + + auto tmp = expoly_complex.simplify(1.0/SCALING_FACTOR); + if(tmp.empty()) continue; + auto expoly = tmp.front(); + expoly.contour.make_clockwise(); + for(auto& h : expoly.holes) h.make_counter_clockwise(); + + ss << "\t{\n"; + ss << "\t\t{\n"; + + for(auto v : expoly.contour.points) ss << "\t\t\t{" + << v.x << ", " + << v.y << "},\n"; + { + auto v = expoly.contour.points.front(); + ss << "\t\t\t{" << v.x << ", " << v.y << "},\n"; + } + ss << "\t\t},\n"; + + // Holes: + ss << "\t\t{\n"; +// for(auto h : expoly.holes) { +// ss << "\t\t\t{\n"; +// for(auto v : h.points) ss << "\t\t\t\t{" +// << v.x << ", " +// << v.y << "},\n"; +// { +// auto v = h.points.front(); +// ss << "\t\t\t\t{" << v.x << ", " << v.y << "},\n"; +// } +// ss << "\t\t\t},\n"; +// } + ss << "\t\t},\n"; + + ss << "\t},\n"; + } + } + } + + ss << "}\n"; + + return ss.str(); +} + +void toSVG(SVG& svg, const Model& model) { + for(auto objptr : model.objects) { + if(!objptr) continue; + + auto rmesh = objptr->raw_mesh(); + + for(auto objinst : objptr->instances) { + if(!objinst) continue; + + Slic3r::TriangleMesh tmpmesh = rmesh; + tmpmesh.scale(objinst->scaling_factor); + objinst->transform_mesh(&tmpmesh); + ExPolygons expolys = tmpmesh.horizontal_projection(); + svg.draw(expolys); + } + } +} + // A container which stores a pointer to the 3D object and its projected // 2D shape from top view. using ShapeData2D = @@ -480,15 +561,17 @@ bool arrange(Model &model, coordf_t dist, const Slic3r::BoundingBoxf* bb, SConf scfg; // Selection configuration // Try inserting groups of 2, and 3 items in all possible order. - scfg.try_reverse_order = true; + scfg.try_reverse_order = false; // If there are more items that could possibly fit into one bin, // use multiple threads. (Potencially decreased pack efficiency) - scfg.allow_parallel = false; + scfg.allow_parallel = true; // Use multiple threads whenever possible scfg.force_parallel = false; + scfg.waste_increment = 0.01; + // Align the arranged pile into the center of the bin pcfg.alignment = PConf::Alignment::CENTER; @@ -605,6 +688,15 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb, bool ret = false; if(bb != nullptr && bb->defined) { ret = arr::arrange(*this, dist, bb, false, progressind); +// std::fstream out("out.cpp", std::fstream::out); +// if(out.good()) { +// out << "const TestData OBJECTS = \n"; +// out << arr::toString(*this); +// } +// out.close(); +// SVG svg("out.svg"); +// arr::toSVG(svg, *this); +// svg.Close(); } else { // get the (transformed) size of each instance so that we take // into account their different transformations when packing