ENABLE_THUMBNAIL_GENERATOR -> Refactoring to simplify code

This commit is contained in:
Enrico Turri 2019-10-24 12:09:09 +02:00
parent a417da8fea
commit 29fd0ef7c6
5 changed files with 76 additions and 26 deletions

View file

@ -136,8 +136,6 @@ set(SLIC3R_GUI_SOURCES
GUI/ProgressStatusBar.cpp
GUI/PrintHostDialogs.cpp
GUI/PrintHostDialogs.hpp
GUI/ThumbnailGenerator.cpp
GUI/ThumbnailGenerator.hpp
Utils/Http.cpp
Utils/Http.hpp
Utils/FixModelByWin10.cpp

View file

@ -7,6 +7,9 @@
#include "libslic3r/ClipperUtils.hpp"
#include "libslic3r/PrintConfig.hpp"
#include "libslic3r/GCode/PreviewData.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "libslic3r/GCode/ThumbnailData.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include "libslic3r/Geometry.hpp"
#include "libslic3r/ExtrusionEntity.hpp"
#include "libslic3r/Utils.hpp"
@ -1643,6 +1646,64 @@ void GLCanvas3D::render()
#endif // ENABLE_RENDER_STATISTICS
}
#if ENABLE_THUMBNAIL_GENERATOR
void GLCanvas3D::render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only)
{
auto is_visible = [](const GLVolume& v) -> bool {
bool ret = v.printable;
ret &= (!v.shader_outside_printer_detection_enabled || !v.is_outside);
return ret;
};
static const float orange[] = { 0.99f, 0.49f, 0.26f };
static const float gray[] = { 0.64f, 0.64f, 0.64f };
thumbnail_data.set(w, h);
GLVolumePtrs visible_volumes;
for (GLVolume* vol : m_volumes.volumes)
{
if (!printable_only || is_visible(*vol))
visible_volumes.push_back(vol);
}
if (visible_volumes.empty())
return;
BoundingBoxf3 box;
for (const GLVolume* vol : visible_volumes)
{
box.merge(vol->transformed_bounding_box());
}
Camera camera;
camera.zoom_to_box(box, thumbnail_data.width, thumbnail_data.height);
camera.apply_viewport(0, 0, thumbnail_data.width, thumbnail_data.height);
camera.apply_view_matrix();
camera.apply_projection(box);
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
glsafe(::glEnable(GL_LIGHTING));
glsafe(::glEnable(GL_DEPTH_TEST));
for (const GLVolume* vol : visible_volumes)
{
glsafe(::glColor3fv((vol->printable && !vol->is_outside) ? orange : gray));
vol->render();
}
glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_LIGHTING));
glsafe(::glReadPixels(0, 0, thumbnail_data.width, thumbnail_data.height, GL_RGBA, GL_UNSIGNED_BYTE, (void*)thumbnail_data.pixels.data()));
std::cout << "Generated thumbnail " << thumbnail_data.width << "x" << thumbnail_data.height << std::endl;
// force a frame render to restore the default framebuffer
render();
}
#endif // ENABLE_THUMBNAIL_GENERATOR
void GLCanvas3D::select_all()
{
m_selection.add_all();

View file

@ -36,6 +36,9 @@ class GLShader;
class ExPolygon;
class BackgroundSlicingProcess;
class GCodePreviewData;
#if ENABLE_THUMBNAIL_GENERATOR
struct ThumbnailData;
#endif // ENABLE_THUMBNAIL_GENERATOR
struct SlicingParameters;
enum LayerHeightEditActionType : unsigned int;
@ -446,10 +449,6 @@ public:
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
const wxGLCanvas* get_wxglcanvas() const { return m_canvas; }
#if ENABLE_THUMBNAIL_GENERATOR
const GLVolumeCollection& get_volumes() const { return m_volumes; }
#endif // ENABLE_THUMBNAIL_GENERATOR
bool init();
void post_event(wxEvent &&event);
@ -523,6 +522,9 @@ public:
bool is_dragging() const { return m_gizmos.is_dragging() || m_moving; }
void render();
#if ENABLE_THUMBNAIL_GENERATOR
void render_thumbnail(ThumbnailData& thumbnail_data, unsigned int w, unsigned int h, bool printable_only);
#endif // ENABLE_THUMBNAIL_GENERATOR
void select_all();
void deselect_all();

View file

@ -32,6 +32,9 @@
#include "libslic3r/Format/AMF.hpp"
#include "libslic3r/Format/3mf.hpp"
#include "libslic3r/GCode/PreviewData.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "libslic3r/GCode/ThumbnailData.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include "libslic3r/Model.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/Print.hpp"
@ -62,9 +65,6 @@
#include "GUI_Preview.hpp"
#include "3DBed.hpp"
#include "Camera.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "ThumbnailGenerator.hpp"
#endif // ENABLE_THUMBNAIL_GENERATOR
#include "Tab.hpp"
#include "PresetBundle.hpp"
#include "BackgroundSlicingProcess.hpp"
@ -1370,6 +1370,9 @@ struct Plater::priv
Slic3r::Model model;
PrinterTechnology printer_technology = ptFFF;
Slic3r::GCodePreviewData gcode_preview_data;
#if ENABLE_THUMBNAIL_GENERATOR
Slic3r::ThumbnailData thumbnail_data;
#endif // ENABLE_THUMBNAIL_GENERATOR
// GUI elements
wxSizer* panel_sizer{ nullptr };
@ -1381,9 +1384,6 @@ struct Plater::priv
View3D* view3D;
GLToolbar view_toolbar;
Preview *preview;
#if ENABLE_THUMBNAIL_GENERATOR
ThumbnailGenerator thumbnail_generator;
#endif // ENABLE_THUMBNAIL_GENERATOR
BackgroundSlicingProcess background_process;
bool suppressed_backround_processing_update { false };
@ -1999,7 +1999,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
background_process.set_sla_print(&sla_print);
background_process.set_gcode_preview_data(&gcode_preview_data);
#if ENABLE_THUMBNAIL_GENERATOR
background_process.set_thumbnail_data(&thumbnail_generator.get_data());
background_process.set_thumbnail_data(&thumbnail_data);
#endif // ENABLE_THUMBNAIL_GENERATOR
background_process.set_slicing_completed_event(EVT_SLICING_COMPLETED);
background_process.set_finished_event(EVT_PROCESS_COMPLETED);
@ -3627,7 +3627,7 @@ bool Plater::priv::init_object_menu()
#if ENABLE_THUMBNAIL_GENERATOR
void Plater::priv::generate_thumbnail(unsigned int w, unsigned int h, bool printable_only)
{
thumbnail_generator.generate(view3D->get_canvas3d()->get_volumes().volumes, w, h, printable_only);
view3D->get_canvas3d()->render_thumbnail(thumbnail_data, w, h, printable_only);
}
#endif // ENABLE_THUMBNAIL_GENERATOR
@ -4671,7 +4671,7 @@ void Plater::export_3mf(const boost::filesystem::path& output_path)
wxBusyCursor wait;
#if ENABLE_THUMBNAIL_GENERATOR
p->generate_thumbnail(THUMBNAIL_SIZE_3MF.first, THUMBNAIL_SIZE_3MF.second, false);
if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr, &p->thumbnail_generator.get_data())) {
if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr, &p->thumbnail_data)) {
#else
if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr)) {
#endif // ENABLE_THUMBNAIL_GENERATOR
@ -5171,13 +5171,6 @@ void Plater::paste_from_clipboard()
p->view3D->get_canvas3d()->get_selection().paste_from_clipboard();
}
#if ENABLE_THUMBNAIL_GENERATOR
void Plater::generate_thumbnail(unsigned int w, unsigned int h, bool printable_only)
{
p->generate_thumbnail(w, h, printable_only);
}
#endif // ENABLE_THUMBNAIL_GENERATOR
void Plater::msw_rescale()
{
p->preview->msw_rescale();

View file

@ -240,10 +240,6 @@ public:
void copy_selection_to_clipboard();
void paste_from_clipboard();
#if ENABLE_THUMBNAIL_GENERATOR
void generate_thumbnail(unsigned int w, unsigned int h, bool printable_only);
#endif // ENABLE_THUMBNAIL_GENERATOR
bool can_delete() const;
bool can_delete_all() const;
bool can_increase_instances() const;