diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2018-07-18 15:26:42 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2018-07-18 15:26:42 +0300 |
commit | d805c8ac3bcaa3310b2c3542da061657a192c3b3 (patch) | |
tree | ed6658a2add05a7d5f02d9df32e6418150184805 /xs/src/libslic3r | |
parent | d672a69554097aa445c710e5bfe84f4dbfa4a246 (diff) |
Disable slicing when one object crosses the print volume boundary
Diffstat (limited to 'xs/src/libslic3r')
-rw-r--r-- | xs/src/libslic3r/BoundingBox.hpp | 4 | ||||
-rw-r--r-- | xs/src/libslic3r/Model.cpp | 11 | ||||
-rw-r--r-- | xs/src/libslic3r/Model.hpp | 26 | ||||
-rw-r--r-- | xs/src/libslic3r/Print.cpp | 2 | ||||
-rw-r--r-- | xs/src/libslic3r/PrintObject.cpp | 2 |
5 files changed, 33 insertions, 12 deletions
diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index 1f71536ee..82a3edc18 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -103,6 +103,10 @@ public: bool contains(const BoundingBox3Base<PointClass>& other) const { return contains(other.min) && contains(other.max); } + + bool intersects(const BoundingBox3Base<PointClass>& other) const { + return (min.x < other.max.x) && (max.x > other.min.x) && (min.y < other.max.y) && (max.y > other.min.y) && (min.z < other.max.z) && (max.z > other.min.z); + } }; class BoundingBox : public BoundingBoxBase<Point> diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index bd95d9959..509fe6190 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -1235,7 +1235,7 @@ void ModelObject::split(ModelObjectPtrs* new_objects) return; } -void ModelObject::check_instances_printability(const BoundingBoxf3& print_volume) +void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_volume) { for (ModelVolume* vol : this->volumes) { @@ -1274,10 +1274,15 @@ void ModelObject::check_instances_printability(const BoundingBoxf3& print_volume p.y += inst->offset.y; bb.merge(p); - - inst->is_printable = print_volume.contains(bb); } } + + if (print_volume.contains(bb)) + inst->print_volume_state = ModelInstance::PVS_Inside; + else if (print_volume.intersects(bb)) + inst->print_volume_state = ModelInstance::PVS_Partly_Outside; + else + inst->print_volume_state = ModelInstance::PVS_Fully_Outside; } } } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 08ba8487d..f5e97fb6a 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -131,7 +131,8 @@ public: bool needed_repair() const; void cut(coordf_t z, Model* model) const; void split(ModelObjectPtrs* new_objects); - void check_instances_printability(const BoundingBoxf3& print_volume); + + void check_instances_print_volume_state(const BoundingBoxf3& print_volume); // Print object statistics to console. void print_info() const; @@ -198,14 +199,23 @@ private: // Knows the affine transformation of an object. class ModelInstance { - friend class ModelObject; public: + enum EPrintVolumeState : unsigned char + { + PVS_Inside, + PVS_Partly_Outside, + PVS_Fully_Outside, + Num_BedStates + }; + + friend class ModelObject; + double rotation; // Rotation around the Z axis, in radians around mesh center point double scaling_factor; Pointf offset; // in unscaled coordinates - // whether or not this instance is contained in the print volume (set by Print::validate() using ModelObject::check_instances_printability()) - bool is_printable; + // flag showing the position of this instance with respect to the print volume (set by Print::validate() using ModelObject::check_instances_print_volume_state()) + EPrintVolumeState print_volume_state; ModelObject* get_object() const { return this->object; } @@ -217,14 +227,16 @@ public: BoundingBoxf3 transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate = false) const; // To be called on an external polygon. It does not translate the polygon, only rotates and scales. void transform_polygon(Polygon* polygon) const; - + + bool is_printable() const { return print_volume_state == PVS_Inside; } + private: // Parent object, owning this instance. ModelObject* object; - ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), object(object), is_printable(false) {} + ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), object(object), print_volume_state(PVS_Inside) {} ModelInstance(ModelObject *object, const ModelInstance &other) : - rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), is_printable(false) {} + rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), print_volume_state(PVS_Inside) {} }; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 9c9f7f5bb..838cdfc9f 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -543,7 +543,7 @@ std::string Print::validate() const print_volume.min.z = -1e10; unsigned int printable_count = 0; for (PrintObject *po : this->objects) { - po->model_object()->check_instances_printability(print_volume); + po->model_object()->check_instances_print_volume_state(print_volume); po->reload_model_instances(); if (po->is_printable()) ++printable_count; diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 1d0a81cd2..8888da76d 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -103,7 +103,7 @@ bool PrintObject::reload_model_instances() copies.reserve(this->_model_object->instances.size()); for (const ModelInstance *mi : this->_model_object->instances) { - if (mi->is_printable) + if (mi->is_printable()) copies.emplace_back(Point::new_scale(mi->offset.x, mi->offset.y)); } return this->set_copies(copies); |