Added tech ENABLE_THUMBNAIL_GENERATOR -> 1st installment of generation of thumbnail from plater (WIP)

This commit is contained in:
Enrico Turri 2019-10-22 16:02:31 +02:00
parent 2d610f9b84
commit 32a42f2808
10 changed files with 231 additions and 0 deletions

View file

@ -446,6 +446,13 @@ 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; }
// GLVolumeCollection& get_volumes() { return m_volumes; }
#endif // ENABLE_THUMBNAIL_GENERATOR
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bool init();
void post_event(wxEvent &&event);

View file

@ -62,6 +62,11 @@
#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"
@ -1373,6 +1378,11 @@ 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 };
@ -3060,6 +3070,11 @@ void Plater::priv::export_gcode(fs::path output_path, PrintHostJob upload_job)
return;
if (! output_path.empty()) {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_THUMBNAIL_GENERATOR
thumbnail_generator.render_to_png_file(*view3D->get_canvas3d(), "C:/prusa/test/test.png", 256, 256, false);
#endif // ENABLE_THUMBNAIL_GENERATOR
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
background_process.schedule_export(output_path.string());
} else {
background_process.schedule_upload(std::move(upload_job));

View file

@ -0,0 +1,97 @@
#include "libslic3r/libslic3r.h"
#include "ThumbnailGenerator.hpp"
#if ENABLE_THUMBNAIL_GENERATOR
#include "GLCanvas3D.hpp"
#include "3DScene.hpp"
#include <GL/glew.h>
namespace Slic3r {
namespace GUI {
void ThumbnailGenerator::reset()
{
m_data.reset();
}
bool ThumbnailGenerator::render_to_png_file(const GLCanvas3D& canvas, const std::string& filename, unsigned int w, unsigned int h, bool printable_only)
{
m_data.set(w, h);
render(canvas, printable_only);
wxImage image(m_data.width, m_data.height);
image.InitAlpha();
for (unsigned int r = 0; r < m_data.height; ++r)
{
unsigned int rr = (m_data.height - 1 - r) * m_data.width;
for (unsigned int c = 0; c < m_data.width; ++c)
{
unsigned char* px = m_data.pixels.data() + 4 * (rr + c);
// unsigned char* px = m_data.pixels.data() + 4 * (r * m_data.width + c);
image.SetRGB((int)c, (int)r, px[0], px[1], px[2]);
image.SetAlpha((int)c, (int)r, px[3]);
}
}
image.SaveFile(filename, wxBITMAP_TYPE_PNG);
return true;
}
void ThumbnailGenerator::render(const GLCanvas3D& canvas, bool printable_only)
{
const GLVolumeCollection& volumes = canvas.get_volumes();
std::vector<const GLVolume*> visible_volumes;
for (const GLVolume* vol : volumes.volumes)
{
if (!printable_only || vol->printable)
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, m_data.width, m_data.height);
camera.apply_viewport(0, 0, m_data.width, m_data.height);
camera.apply_view_matrix();
camera.apply_projection(box);
glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
render_objects(visible_volumes);
glsafe(::glReadPixels(0, 0, m_data.width, m_data.height, GL_RGBA, GL_UNSIGNED_BYTE, (void*)m_data.pixels.data()));
}
void ThumbnailGenerator::render_objects(const std::vector<const GLVolume*>& volumes) const
{
static const float orange[] = { 0.99f, 0.49f, 0.26f };
static const float gray[] = { 0.64f, 0.64f, 0.64f };
glsafe(::glEnable(GL_LIGHTING));
glsafe(::glEnable(GL_DEPTH_TEST));
for (const GLVolume* vol : volumes)
{
glsafe(::glColor3fv(vol->printable ? orange : gray));
vol->render();
}
glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_LIGHTING));
}
} // namespace GUI
} // namespace Slic3r
#endif // ENABLE_THUMBNAIL_GENERATOR

View file

@ -0,0 +1,37 @@
#ifndef slic3r_GUI_ThumbnailGenerator_hpp_
#define slic3r_GUI_ThumbnailGenerator_hpp_
#if ENABLE_THUMBNAIL_GENERATOR
#include "../libslic3r/GCode/ThumbnailData.hpp"
#include <array>
namespace Slic3r {
class GLVolume;
namespace GUI {
class GLCanvas3D;
class ThumbnailGenerator
{
ThumbnailData m_data;
public:
ThumbnailGenerator() { reset(); }
void reset();
bool render_to_png_file(const GLCanvas3D& canvas, const std::string& filename, unsigned int w, unsigned int h, bool printable_only);
private:
void render(const GLCanvas3D& canvas, bool printable_only);
void render_objects(const std::vector<const GLVolume*>& volumes) const;
};
} // namespace GUI
} // namespace Slic3r
#endif // ENABLE_THUMBNAIL_GENERATOR
#endif // slic3r_GUI_ThumbnailGenerator_hpp_