From 70e8db8a0a24c236acb1506afc558be4fb28e135 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 19 Dec 2015 20:27:04 +0100 Subject: [PATCH] Minor code cleanup here and there --- lib/Slic3r/GUI/Plater/ObjectCutDialog.pm | 2 +- xs/src/libslic3r/MotionPlanner.cpp | 22 ++++++---------------- xs/src/libslic3r/TriangleMesh.cpp | 13 ++++++------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index 1f98c6241..ad4ab9221 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -22,7 +22,7 @@ sub new { keep_upper => 1, keep_lower => 1, rotate_lower => 1, - preview => 0, + preview => 1, }; my $optgroup; diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index 7211100c3..ee8378588 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -90,12 +90,8 @@ MotionPlanner::shortest_path(const Point &from, const Point &to) if (!this->initialized) this->initialize(); // if we have an empty configuration space, return a straight move - if (this->islands.empty()) { - Polyline p; - p.points.push_back(from); - p.points.push_back(to); - return p; - } + if (this->islands.empty()) + return Line(from, to); // Are both points in the same island? int island_idx = -1; @@ -103,12 +99,9 @@ MotionPlanner::shortest_path(const Point &from, const Point &to) if (island->contains(from) && island->contains(to)) { // since both points are in the same island, is a direct move possible? // if so, we avoid generating the visibility environment - if (island->contains(Line(from, to))) { - Polyline p; - p.points.push_back(from); - p.points.push_back(to); - return p; - } + if (island->contains(Line(from, to))) + return Line(from, to); + island_idx = island - this->islands.begin(); break; } @@ -119,10 +112,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to) if (env.expolygons.empty()) { // if this environment is empty (probably because it's too small), perform straight move // and avoid running the algorithms on empty dataset - Polyline p; - p.points.push_back(from); - p.points.push_back(to); - return p; // bye bye + return Line(from, to); } // Now check whether points are inside the environment. diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 8bc5f9d00..484fee9fc 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -472,11 +472,10 @@ TriangleMeshSlicer::slice(const std::vector &z, std::vector* la // build loops layers->resize(z.size()); for (std::vector::iterator it = lines.begin(); it != lines.end(); ++it) { - int layer_idx = it - lines.begin(); + size_t layer_idx = it - lines.begin(); #ifdef SLIC3R_DEBUG - printf("Layer %d:\n", layer_idx); + printf("Layer %zu:\n", layer_idx); #endif - this->make_loops(*it, &(*layers)[layer_idx]); } } @@ -708,7 +707,7 @@ TriangleMeshSlicer::make_loops(std::vector &lines, Polygons* l // loop is complete Polygon p; p.points.reserve(loop.size()); - for (IntersectionLinePtrs::iterator lineptr = loop.begin(); lineptr != loop.end(); ++lineptr) { + for (IntersectionLinePtrs::const_iterator lineptr = loop.begin(); lineptr != loop.end(); ++lineptr) { p.points.push_back((*lineptr)->a); } loops->push_back(p); @@ -858,7 +857,7 @@ TriangleMeshSlicer::make_expolygons(std::vector &lines, ExPoly void TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) { - std::vector upper_lines, lower_lines; + IntersectionLines upper_lines, lower_lines; float scaled_z = scale_(z); for (int facet_idx = 0; facet_idx < this->mesh->stl.stats.number_of_facets; facet_idx++) { @@ -869,11 +868,11 @@ TriangleMeshSlicer::cut(float z, TriangleMesh* upper, TriangleMesh* lower) float max_z = fmaxf(facet->vertex[0].z, fmaxf(facet->vertex[1].z, facet->vertex[2].z)); // intersect facet with cutting plane - std::vector lines; + IntersectionLines lines; this->slice_facet(scaled_z, *facet, facet_idx, min_z, max_z, &lines); // save intersection lines for generating correct triangulations - for (std::vector::iterator it = lines.begin(); it != lines.end(); ++it) { + for (IntersectionLines::const_iterator it = lines.begin(); it != lines.end(); ++it) { if (it->edge_type == feTop) { lower_lines.push_back(*it); } else if (it->edge_type == feBottom) {