From 3f1868791695969b575b6aa39415416ee223a26f Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Tue, 1 May 2018 22:32:09 -0500 Subject: [PATCH] Implemented make_thumbnail and transform_thumbnail; neither is tested yet. --- src/GUI/Plater/PlaterObject.cpp | 29 +++++++++++++++-------------- src/GUI/Plater/PlaterObject.hpp | 5 +++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/GUI/Plater/PlaterObject.cpp b/src/GUI/Plater/PlaterObject.cpp index 39b6bca3b..b27ba821b 100644 --- a/src/GUI/Plater/PlaterObject.cpp +++ b/src/GUI/Plater/PlaterObject.cpp @@ -2,49 +2,50 @@ #include "Geometry.hpp" #include "ExPolygon.hpp" +#include "libslic3r.h" namespace Slic3r { namespace GUI { -Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_index) { +Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_idx) { // make method idempotent - this->thumbnail.clear(); + this->thumbnail.expolygons.clear(); - auto mesh {model.objects[obj_index]->raw_mesh()}; + auto mesh {model.objects[obj_idx]->raw_mesh()}; auto model_instance {model.objects[obj_idx]->instances[0]}; // Apply any x/y rotations and scaling vector if this came from a 3MF object. - mesh.rotate_x(model_instance.x_rotation); - mesh.rotate_y(model_instance.y_rotation); - mesh.scale_xyz(model_instance.scaling_vector); + mesh.rotate_x(model_instance->x_rotation); + mesh.rotate_y(model_instance->y_rotation); + mesh.scale(model_instance->scaling_vector); - if (mesh.facets_count <= 5000) { - auto area_threshold {Slic3r::Geometry::scale(1)}; + if (mesh.facets_count() <= 5000) { + auto area_threshold {scale_(1.0)}; ExPolygons tmp {}; std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area this->thumbnail.append(tmp); this->thumbnail.simplify(0.5); } else { - auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull)}; + auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull())}; this->thumbnail.append(convex_hull); } return this->thumbnail; } -Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(Slic3r::Model model, int obj_idx) { +Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(const Slic3r::Model& model, int obj_idx) { if (this->thumbnail.expolygons.size() == 0) return this->thumbnail; const auto& model_object {model.objects[obj_idx] }; - const auto& model_instance {model_object.instances[0]}; + const auto& model_instance {model_object->instances[0]}; // the order of these transformations MUST be the same everywhere, including // in Slic3r::Print->add_model_object() auto t {this->thumbnail}; - t.rotate(model_instance.rotation(), Slic3r::Point(0,0)); - t.scale(model_instance.scaling_factor()); + t.rotate(model_instance->rotation, Slic3r::Point(0,0)); + t.scale(model_instance->scaling_factor); this->transformed_thumbnail = t; - + return this->transformed_thumbnail; } } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PlaterObject.hpp b/src/GUI/Plater/PlaterObject.hpp index 32709a30c..72b71d88e 100644 --- a/src/GUI/Plater/PlaterObject.hpp +++ b/src/GUI/Plater/PlaterObject.hpp @@ -6,6 +6,7 @@ #endif #include "ExPolygonCollection.hpp" +#include "Model.hpp" namespace Slic3r { namespace GUI { @@ -26,8 +27,8 @@ public: bool selected {false}; int selected_instance {-1}; - Slic3r::ExPolygonCollection& make_thumbnail(Slic3r::Model model, int obj_index); - Slic3r::ExPolygonCollection& transform_thumbnail(Slic3r::Model model, int obj_index); + Slic3r::ExPolygonCollection& make_thumbnail(const Slic3r::Model& model, int obj_idx); + Slic3r::ExPolygonCollection& transform_thumbnail(const Slic3r::Model& model, int obj_idx); }; }} // Namespace Slic3r::GUI