Added tech ENABLE_THUMBNAIL_GENERATOR -> 1st installment of generation of thumbnail from plater (WIP)
This commit is contained in:
parent
2d610f9b84
commit
32a42f2808
10 changed files with 231 additions and 0 deletions
|
@ -71,6 +71,8 @@ add_library(libslic3r STATIC
|
||||||
Format/STL.hpp
|
Format/STL.hpp
|
||||||
GCode/Analyzer.cpp
|
GCode/Analyzer.cpp
|
||||||
GCode/Analyzer.hpp
|
GCode/Analyzer.hpp
|
||||||
|
GCode/ThumbnailData.cpp
|
||||||
|
GCode/ThumbnailData.hpp
|
||||||
GCode/CoolingBuffer.cpp
|
GCode/CoolingBuffer.cpp
|
||||||
GCode/CoolingBuffer.hpp
|
GCode/CoolingBuffer.hpp
|
||||||
GCode/PostProcessor.cpp
|
GCode/PostProcessor.cpp
|
||||||
|
|
|
@ -945,6 +945,11 @@ void GCode::_do_export(Print &print, FILE *file)
|
||||||
}
|
}
|
||||||
print.throw_if_canceled();
|
print.throw_if_canceled();
|
||||||
|
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
#if ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
#endif // ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
|
||||||
// Write some terse information on the slicing parameters.
|
// Write some terse information on the slicing parameters.
|
||||||
const PrintObject *first_object = print.objects().front();
|
const PrintObject *first_object = print.objects().front();
|
||||||
const double layer_height = first_object->config().layer_height.value;
|
const double layer_height = first_object->config().layer_height.value;
|
||||||
|
|
31
src/libslic3r/GCode/ThumbnailData.cpp
Normal file
31
src/libslic3r/GCode/ThumbnailData.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "libslic3r/libslic3r.h"
|
||||||
|
#include "ThumbnailData.hpp"
|
||||||
|
|
||||||
|
#if ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
void ThumbnailData::set(unsigned int w, unsigned int h)
|
||||||
|
{
|
||||||
|
if (!pixels.empty())
|
||||||
|
reset();
|
||||||
|
|
||||||
|
if ((w == 0) || (h == 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
width = w;
|
||||||
|
height = h;
|
||||||
|
// defaults to white texture
|
||||||
|
pixels = std::vector<unsigned char>(width * height * 4, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ThumbnailData::reset()
|
||||||
|
{
|
||||||
|
width = 0;
|
||||||
|
height = 0;
|
||||||
|
pixels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
#endif // ENABLE_THUMBNAIL_GENERATOR
|
25
src/libslic3r/GCode/ThumbnailData.hpp
Normal file
25
src/libslic3r/GCode/ThumbnailData.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef slic3r_ThumbnailData_hpp_
|
||||||
|
#define slic3r_ThumbnailData_hpp_
|
||||||
|
|
||||||
|
#if ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
struct ThumbnailData
|
||||||
|
{
|
||||||
|
unsigned int width;
|
||||||
|
unsigned int height;
|
||||||
|
std::vector<unsigned char> pixels;
|
||||||
|
|
||||||
|
ThumbnailData() { reset(); }
|
||||||
|
void set(unsigned int w, unsigned int h);
|
||||||
|
void reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
#endif // ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
|
||||||
|
#endif // slic3r_ThumbnailData_hpp_
|
|
@ -32,4 +32,14 @@
|
||||||
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1)
|
#define ENABLE_NONCUSTOM_DATA_VIEW_RENDERING (0 && ENABLE_1_42_0_ALPHA1)
|
||||||
|
|
||||||
|
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
//====================
|
||||||
|
// 2.2.0.alpha1 techs
|
||||||
|
//====================
|
||||||
|
#define ENABLE_2_2_0_ALPHA1 1
|
||||||
|
|
||||||
|
// Enable thumbnail generator
|
||||||
|
#define ENABLE_THUMBNAIL_GENERATOR (1 && ENABLE_2_2_0_ALPHA1)
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
|
||||||
#endif // _technologies_h_
|
#endif // _technologies_h_
|
||||||
|
|
|
@ -136,6 +136,8 @@ set(SLIC3R_GUI_SOURCES
|
||||||
GUI/ProgressStatusBar.cpp
|
GUI/ProgressStatusBar.cpp
|
||||||
GUI/PrintHostDialogs.cpp
|
GUI/PrintHostDialogs.cpp
|
||||||
GUI/PrintHostDialogs.hpp
|
GUI/PrintHostDialogs.hpp
|
||||||
|
GUI/ThumbnailGenerator.cpp
|
||||||
|
GUI/ThumbnailGenerator.hpp
|
||||||
Utils/Http.cpp
|
Utils/Http.cpp
|
||||||
Utils/Http.hpp
|
Utils/Http.hpp
|
||||||
Utils/FixModelByWin10.cpp
|
Utils/FixModelByWin10.cpp
|
||||||
|
|
|
@ -446,6 +446,13 @@ public:
|
||||||
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
|
wxGLCanvas* get_wxglcanvas() { return m_canvas; }
|
||||||
const wxGLCanvas* get_wxglcanvas() const { 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();
|
bool init();
|
||||||
void post_event(wxEvent &&event);
|
void post_event(wxEvent &&event);
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,11 @@
|
||||||
#include "GUI_Preview.hpp"
|
#include "GUI_Preview.hpp"
|
||||||
#include "3DBed.hpp"
|
#include "3DBed.hpp"
|
||||||
#include "Camera.hpp"
|
#include "Camera.hpp"
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
#if ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
#include "ThumbnailGenerator.hpp"
|
||||||
|
#endif // ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
#include "Tab.hpp"
|
#include "Tab.hpp"
|
||||||
#include "PresetBundle.hpp"
|
#include "PresetBundle.hpp"
|
||||||
#include "BackgroundSlicingProcess.hpp"
|
#include "BackgroundSlicingProcess.hpp"
|
||||||
|
@ -1373,6 +1378,11 @@ struct Plater::priv
|
||||||
View3D* view3D;
|
View3D* view3D;
|
||||||
GLToolbar view_toolbar;
|
GLToolbar view_toolbar;
|
||||||
Preview *preview;
|
Preview *preview;
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
#if ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
ThumbnailGenerator thumbnail_generator;
|
||||||
|
#endif // ENABLE_THUMBNAIL_GENERATOR
|
||||||
|
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
|
||||||
BackgroundSlicingProcess background_process;
|
BackgroundSlicingProcess background_process;
|
||||||
bool suppressed_backround_processing_update { false };
|
bool suppressed_backround_processing_update { false };
|
||||||
|
@ -3060,6 +3070,11 @@ void Plater::priv::export_gcode(fs::path output_path, PrintHostJob upload_job)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (! output_path.empty()) {
|
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());
|
background_process.schedule_export(output_path.string());
|
||||||
} else {
|
} else {
|
||||||
background_process.schedule_upload(std::move(upload_job));
|
background_process.schedule_upload(std::move(upload_job));
|
||||||
|
|
97
src/slic3r/GUI/ThumbnailGenerator.cpp
Normal file
97
src/slic3r/GUI/ThumbnailGenerator.cpp
Normal 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
|
37
src/slic3r/GUI/ThumbnailGenerator.hpp
Normal file
37
src/slic3r/GUI/ThumbnailGenerator.hpp
Normal 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_
|
||||||
|
|
Loading…
Add table
Reference in a new issue