diff options
-rw-r--r-- | xs/src/libslic3r/ExtrusionEntity.hpp | 1 | ||||
-rw-r--r-- | xs/src/libslic3r/ExtrusionEntityCollection.cpp | 30 | ||||
-rw-r--r-- | xs/src/libslic3r/ExtrusionEntityCollection.hpp | 13 | ||||
-rw-r--r-- | xs/src/libslic3r/GCode.cpp | 10 | ||||
-rw-r--r-- | xs/src/libslic3r/PerimeterGenerator.cpp | 10 |
5 files changed, 54 insertions, 10 deletions
diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index 15363e8ed..1e874083f 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -68,6 +68,7 @@ enum ExtrusionLoopRole { class ExtrusionEntity { public: + std::string label; virtual ExtrusionRole role() const = 0; virtual bool is_collection() const { return false; } virtual bool is_loop() const { return false; } diff --git a/xs/src/libslic3r/ExtrusionEntityCollection.cpp b/xs/src/libslic3r/ExtrusionEntityCollection.cpp index c54541a7d..a9682c280 100644 --- a/xs/src/libslic3r/ExtrusionEntityCollection.cpp +++ b/xs/src/libslic3r/ExtrusionEntityCollection.cpp @@ -13,6 +13,7 @@ ExtrusionEntityCollection::ExtrusionEntityCollection(const ExtrusionPaths &paths ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const ExtrusionEntityCollection &other) { + label = other.label; this->entities = other.entities; for (size_t i = 0; i < this->entities.size(); ++i) this->entities[i] = this->entities[i]->clone(); @@ -24,6 +25,7 @@ ExtrusionEntityCollection& ExtrusionEntityCollection::operator= (const Extrusion void ExtrusionEntityCollection::swap(ExtrusionEntityCollection &c) { + std::swap(label, c.label); std::swap(this->entities, c.entities); std::swap(this->orig_indices, c.orig_indices); std::swap(this->no_sort, c.no_sort); @@ -104,13 +106,16 @@ ExtrusionEntityCollection ExtrusionEntityCollection::chained_path_from(Point sta void ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse, ExtrusionRole role, std::vector<size_t>* orig_indices) const { + std::cout << "BEGIN chained_path_from" << retval->label<< "\n"; if (this->no_sort) { *retval = *this; return; } + std::cout << "1 chained_path_from" << "\n"; retval->entities.reserve(this->entities.size()); retval->orig_indices.reserve(this->entities.size()); - + + std::cout << "2 chained_path_from" << "\n"; // if we're asked to return the original indices, build a map std::map<ExtrusionEntity*,size_t> indices_map; @@ -130,6 +135,7 @@ void ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEnt my_paths.push_back(entity); if (orig_indices != NULL) indices_map[entity] = it - this->entities.begin(); } + std::cout << "3 chained_path_from" << "\n"; Points endpoints; for (ExtrusionEntitiesPtr::iterator it = my_paths.begin(); it != my_paths.end(); ++it) { @@ -140,22 +146,38 @@ void ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEnt endpoints.push_back((*it)->last_point()); } } + std::cout << "4 chained_path_from" << "\n"; while (!my_paths.empty()) { // find nearest point int start_index = start_near.nearest_point_index(endpoints); - int path_index = start_index/2; + std::cout << "start_index=" << start_index << " / " << endpoints .size()<< "\n"; + int path_index = start_index / 2; + std::cout << "path_index=" << path_index << " / " << my_paths.size()<< "\n"; ExtrusionEntity* entity = my_paths.at(path_index); + std::cout << "entity=" << (int)entity << "\n"; + std::cout << "entity.coll?=" << entity->is_collection() << "\n"; + std::cout << "entity.lable=" << entity->label << "\n"; // never reverse loops, since it's pointless for chained path and callers might depend on orientation if (start_index % 2 && !no_reverse && entity->can_reverse()) { + std::cout << "reverse\n"; entity->reverse(); } - retval->entities.push_back(my_paths.at(path_index)); + retval->entities.push_back(entity); + std::cout << "1retval->entities.size()=" << retval->entities.size() << "\n"; if (orig_indices != NULL) orig_indices->push_back(indices_map[entity]); + std::cout << "2retval->entities.size()=" << retval->entities.size() << "\n"; my_paths.erase(my_paths.begin() + path_index); - endpoints.erase(endpoints.begin() + 2*path_index, endpoints.begin() + 2*path_index + 2); + std::cout << "3retval->entities.size()=" << retval->entities.size() << "\n"; + endpoints.erase(endpoints.begin() + 2 * path_index, endpoints.begin() + 2 * path_index + 2); + std::cout << "4retval->entities.size()=" << retval->entities.size() << "\n"; + std::cout << "4retval->entities.back()=" << (int)(retval->entities.back()) << "\n"; + std::cout << "4retval->entities.back()->coll?=" << retval->entities.back()->is_collection() << "\n"; + std::cout << "4retval->entities.back()->label=" << retval->entities.back()->label << "\n"; start_near = retval->entities.back()->last_point(); + std::cout << "new start next loop\n"; } + std::cout << "END chained_path_from" << "\n"; } void ExtrusionEntityCollection::polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const diff --git a/xs/src/libslic3r/ExtrusionEntityCollection.hpp b/xs/src/libslic3r/ExtrusionEntityCollection.hpp index a2cdc31ad..425145872 100644 --- a/xs/src/libslic3r/ExtrusionEntityCollection.hpp +++ b/xs/src/libslic3r/ExtrusionEntityCollection.hpp @@ -14,12 +14,14 @@ public: std::vector<size_t> orig_indices; // handy for XS bool no_sort; ExtrusionEntityCollection(): no_sort(false) {}; - ExtrusionEntityCollection(const ExtrusionEntityCollection &other) : orig_indices(other.orig_indices), no_sort(other.no_sort) { this->append(other.entities); } - ExtrusionEntityCollection(ExtrusionEntityCollection &&other) : entities(std::move(other.entities)), orig_indices(std::move(other.orig_indices)), no_sort(other.no_sort) {} + ExtrusionEntityCollection(const ExtrusionEntityCollection &other) : orig_indices(other.orig_indices), no_sort(other.no_sort) { label = other.label; this->append(other.entities); } + ExtrusionEntityCollection(ExtrusionEntityCollection &&other) : entities(std::move(other.entities)), orig_indices(std::move(other.orig_indices)), no_sort(other.no_sort) { label = other.label; } explicit ExtrusionEntityCollection(const ExtrusionPaths &paths); ExtrusionEntityCollection& operator=(const ExtrusionEntityCollection &other); ExtrusionEntityCollection& operator=(ExtrusionEntityCollection &&other) - { this->entities = std::move(other.entities); this->orig_indices = std::move(other.orig_indices); this->no_sort = other.no_sort; return *this; } + { + label = other.label; this->entities = std::move(other.entities); this->orig_indices = std::move(other.orig_indices); this->no_sort = other.no_sort; return *this; + } ~ExtrusionEntityCollection() { clear(); } explicit operator ExtrusionPaths() const; @@ -63,7 +65,10 @@ public: void chained_path_from(Point start_near, ExtrusionEntityCollection* retval, bool no_reverse = false, ExtrusionRole role = erMixed, std::vector<size_t>* orig_indices = nullptr) const; void reverse(); Point first_point() const { return this->entities.front()->first_point(); } - Point last_point() const { return this->entities.back()->last_point(); } + Point last_point() const { + std::cout << "last_point: nbEnities=" << this->entities.size() << "\n"; + std::cout << "last_point: entities.back().label=" << this->entities.back()->label << "\n"; + return this->entities.back()->last_point(); } // Produce a list of 2D polygons covered by the extruded paths, offsetted by the extrusion width. // Increase the offset by scaled_epsilon to achieve an overlap, so a union will produce no gaps. virtual void polygons_covered_by_width(Polygons &out, const float scaled_epsilon) const; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 62563ef25..ecc5ad42b 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -1219,6 +1219,7 @@ void GCode::process_layer( coordf_t print_z = layer.print_z; bool first_layer = layer.id() == 0; unsigned int first_extruder_id = layer_tools.extruders.front(); + std::cout << "Process layer" << layer.id() << ", z=" << print_z<< "\n"; // Initialize config with the 1st object to be printed at this layer. m_config.apply(layer.object()->config, true); @@ -1546,6 +1547,7 @@ void GCode::process_layer( unsigned int copy_id = 0; for (const Point © : copies) { + std::cout << "Process layer_infill " << layer_id<<":"<<copy_id << " @layer" << layer.id() << ", z=" << print_z << "\n"; if (this->config().gcode_comments){ gcode += ((std::ostringstream&)(std::ostringstream() << "; printing object " << print_object->model_object()->name << " id:" << layer_id << " copy " << copy_id << "\n")).str(); } @@ -1569,6 +1571,7 @@ void GCode::process_layer( gcode += this->extrude_perimeters(print, by_region_specific, lower_layer_edge_grids[layer_id]); gcode += this->extrude_infill(print, by_region_specific, false); } + std::cout << "End Process layer_infill " << layer_id << ":" << copy_id << " @layer" << layer.id() << ", z=" << print_z << "\n"; if (this->config().gcode_comments) { gcode += ((std::ostringstream&)(std::ostringstream() << "; stop printing object " << print_object->model_object()->name << " id:" << layer_id << " copy " << copy_id << "\n")).str(); } @@ -1595,6 +1598,7 @@ void GCode::process_layer( if (m_pressure_equalizer) gcode = m_pressure_equalizer->process(gcode.c_str(), false); // printf("G-code after filter:\n%s\n", out.c_str()); + std::cout << "END Process layer" << layer.id() << ", z=" << print_z << "\n"; _write(file, gcode); } @@ -2219,14 +2223,18 @@ std::string GCode::extrude_perimeters(const Print &print, const std::vector<Obje // Chain the paths hierarchically by a greedy algorithm to minimize a travel distance. std::string GCode::extrude_infill(const Print &print, const std::vector<ObjectByExtruder::Island::Region> &by_region, bool is_infill_first) { + std::cout << "BEGIN extrude INFILL\n"; std::string gcode; for (const ObjectByExtruder::Island::Region ®ion : by_region) { if (print.regions[®ion - &by_region.front()]->config.infill_first == is_infill_first) { m_config.apply(print.regions[®ion - &by_region.front()]->config); + std::cout << "chained_path_from" << "\n"; ExtrusionEntityCollection chained = region.infills.chained_path_from(m_last_pos, false); + std::cout << "extrude_entity" << "\n"; gcode += extrude_entity(chained, "infill"); } } + std::cout << "END extrude INFILL\n"; return gcode; } @@ -2476,7 +2484,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, gcode += ";_EXTRUDE_END\n"; - this->set_last_pos(path.last_point()); + this->set_last_pos(path.last_point()); return gcode; } diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 0c2b0655a..eb70876d4 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -401,6 +401,7 @@ void PerimeterGenerator::process() } } // at this point, all loops should be in contours[0] + std::cout << "perimetergenerator:process\n"; ExtrusionEntityCollection entities = this->_traverse_loops(contours.front(), thin_walls); // if brim will be printed, reverse the order of perimeters so that // we continue inwards after having finished the brim @@ -489,6 +490,7 @@ void PerimeterGenerator::process() ExtrusionEntityCollection PerimeterGenerator::_traverse_loops( const PerimeterGeneratorLoops &loops, ThickPolylines &thin_walls) const { + std::cout << "_traverse_loops\n"; // loops is an arrayref of ::Loop objects // turn each one into an ExtrusionLoop object ExtrusionEntityCollection coll; @@ -531,7 +533,8 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops( this->_mm3_per_mm_overhang, this->overhang_flow.width, this->overhang_flow.height); - + + std::cout << "chained_path()\n"; // reapply the nearest point search for starting point // We allow polyline reversal because Clipper may have randomly // reversed polylines during clipping. @@ -560,10 +563,13 @@ ExtrusionEntityCollection PerimeterGenerator::_traverse_loops( // sort entities into a new collection using a nearest-neighbor search, // preserving the original indices which are useful for detecting thin walls ExtrusionEntityCollection sorted_coll; + sorted_coll.label = "sorted coll"; + std::cout << "chained_path(&sorted_coll, false, erMixed, &sorted_coll.orig_indices)\n"; coll.chained_path(&sorted_coll, false, erMixed, &sorted_coll.orig_indices); // traverse children and build the final collection ExtrusionEntityCollection entities; + entities.label = "peri entities"; for (std::vector<size_t>::const_iterator idx = sorted_coll.orig_indices.begin(); idx != sorted_coll.orig_indices.end(); ++idx) { @@ -603,6 +609,7 @@ ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylin const double tolerance = scale_(0.05); ExtrusionEntityCollection coll; + coll.label = "_variable_width"; for (const ThickPolyline &p : polylines) { ExtrusionPaths paths; ExtrusionPath path(role); @@ -686,6 +693,7 @@ ExtrusionEntityCollection PerimeterGenerator::_variable_width(const ThickPolylin } else { //not a loop : avoid to "sort" it. ExtrusionEntityCollection unsortable_coll(paths); + unsortable_coll.label = "unsortable coll of thin wall"; unsortable_coll.no_sort = true; coll.append(unsortable_coll); } |