Implemented make_thumbnail and transform_thumbnail; neither is tested yet.

This commit is contained in:
Joseph Lenox 2018-05-01 22:32:09 -05:00
parent 1074b04326
commit 76b86c807b
2 changed files with 18 additions and 16 deletions

View File

@ -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

View File

@ -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