From d984864ce09e32660f8cd79f6fd12c83182e11d0 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 1 Mar 2017 17:20:43 +0100 Subject: [PATCH] New "rear" seam position --- xs/src/libslic3r/BoundingBox.cpp | 20 ++++++++++++++++++++ xs/src/libslic3r/BoundingBox.hpp | 2 ++ xs/src/libslic3r/GCode.cpp | 12 +++++++++--- xs/src/libslic3r/PrintConfig.cpp | 2 ++ xs/src/libslic3r/PrintConfig.hpp | 3 ++- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 809f8925c5..8f884264d3 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -183,6 +183,26 @@ BoundingBox3Base::size() const } template Pointf3 BoundingBox3Base::size() const; +template double +BoundingBoxBase::radius() const +{ + double x = this->max.x - this->min.x; + double y = this->max.y - this->min.y; + return 0.5 * sqrt(x*x+y*y); +} +template double BoundingBoxBase::radius() const; +template double BoundingBoxBase::radius() const; + +template double +BoundingBox3Base::radius() const +{ + double x = this->max.x - this->min.x; + double y = this->max.y - this->min.y; + double z = this->max.z - this->min.z; + return 0.5 * sqrt(x*x+y*y+z*z); +} +template double BoundingBox3Base::radius() const; + template void BoundingBoxBase::translate(coordf_t x, coordf_t y) { diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index 2b51201101..7169a6af70 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -29,6 +29,7 @@ class BoundingBoxBase void merge(const BoundingBoxBase &bb); void scale(double factor); PointClass size() const; + double radius() const; void translate(coordf_t x, coordf_t y); void offset(coordf_t delta); PointClass center() const; @@ -48,6 +49,7 @@ class BoundingBox3Base : public BoundingBoxBase void merge(const std::vector &points); void merge(const BoundingBox3Base &bb); PointClass size() const; + double radius() const; void translate(coordf_t x, coordf_t y, coordf_t z); void offset(coordf_t delta); PointClass center() const; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index d7f0400e32..2f17e91c39 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -324,7 +324,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) Point last_pos = this->last_pos(); if (this->config.spiral_vase) { loop.split_at(last_pos); - } else if (seam_position == spNearest || seam_position == spAligned) { + } else if (seam_position == spNearest || seam_position == spAligned || seam_position == spRear) { const Polygon polygon = loop.polygon(); // simplify polygon in order to skip false positives in concave/convex detection @@ -354,8 +354,13 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) } // retrieve the last start position for this object - if (this->layer != NULL && this->_seam_position.count(this->layer->object()) > 0) { - last_pos = this->_seam_position[this->layer->object()]; + if (this->layer != NULL) { + if (seam_position == spRear) { + last_pos = this->layer->object()->bounding_box().center(); + last_pos.y += coord_t(3. * this->layer->object()->bounding_box().radius()); + } else if (this->_seam_position.count(this->layer->object()) > 0) { + last_pos = this->_seam_position[this->layer->object()]; + } } Point point; @@ -392,6 +397,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) last_pos = Point(polygon.bounding_box().max.x, centroid.y); last_pos.rotate(fmod((float)rand()/16.0, 2.0*PI), centroid); } + // Find the closest point, avoid overhangs. loop.split_at(last_pos, true); } diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 1005321998..0dfbed9ea8 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -943,9 +943,11 @@ PrintConfigDef::PrintConfigDef() def->enum_values.push_back("random"); def->enum_values.push_back("nearest"); def->enum_values.push_back("aligned"); + def->enum_values.push_back("rear"); def->enum_labels.push_back("Random"); def->enum_labels.push_back("Nearest"); def->enum_labels.push_back("Aligned"); + def->enum_labels.push_back("Rear"); def->default_value = new ConfigOptionEnum(spAligned); def = this->add("serial_port", coString); diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 8388a06159..1ef353f8b7 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -41,7 +41,7 @@ enum SupportMaterialPattern { }; enum SeamPosition { - spRandom, spNearest, spAligned + spRandom, spNearest, spAligned, spRear }; template<> inline t_config_enum_values ConfigOptionEnum::get_enum_values() { @@ -89,6 +89,7 @@ template<> inline t_config_enum_values ConfigOptionEnum::get_enum_ keys_map["random"] = spRandom; keys_map["nearest"] = spNearest; keys_map["aligned"] = spAligned; + keys_map["rear"] = spRear; return keys_map; }