mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-14 17:15:53 +08:00
Remove dependency on main app in job
This commit is contained in:
parent
934da5592c
commit
88af7762fc
@ -2,11 +2,6 @@
|
|||||||
|
|
||||||
// rasterization of ExPoly
|
// rasterization of ExPoly
|
||||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||||
|
|
||||||
// for get DPI
|
|
||||||
#include "slic3r/GUI/GUI_App.hpp"
|
|
||||||
#include "slic3r/GUI/MainFrame.hpp"
|
|
||||||
|
|
||||||
#include "slic3r/GUI/3DScene.hpp" // ::glsafe
|
#include "slic3r/GUI/3DScene.hpp" // ::glsafe
|
||||||
|
|
||||||
// ability to request new frame after finish rendering
|
// ability to request new frame after finish rendering
|
||||||
@ -20,15 +15,15 @@ using namespace Slic3r::GUI;
|
|||||||
using namespace Slic3r::GUI::Emboss;
|
using namespace Slic3r::GUI::Emboss;
|
||||||
|
|
||||||
|
|
||||||
CreateFontStyleImagesJob::CreateFontStyleImagesJob(
|
CreateFontStyleImagesJob::CreateFontStyleImagesJob(StyleManager::StyleImagesData &&input)
|
||||||
StyleManager::StyleImagesData &&input)
|
: m_input(std::move(input)), m_width(0), m_height(0)
|
||||||
: m_input(std::move(input))
|
|
||||||
{
|
{
|
||||||
assert(m_input.result != nullptr);
|
assert(m_input.result != nullptr);
|
||||||
assert(!m_input.styles.empty());
|
assert(!m_input.styles.empty());
|
||||||
assert(!m_input.text.empty());
|
assert(!m_input.text.empty());
|
||||||
assert(m_input.max_size.x() > 1);
|
assert(m_input.max_size.x() > 1);
|
||||||
assert(m_input.max_size.y() > 1);
|
assert(m_input.max_size.y() > 1);
|
||||||
|
assert(m_input.ppm > 1e-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
void CreateFontStyleImagesJob::process(Ctl &ctl)
|
||||||
@ -36,7 +31,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
// create shapes and calc size (bounding boxes)
|
// create shapes and calc size (bounding boxes)
|
||||||
std::vector<ExPolygons> name_shapes(m_input.styles.size());
|
std::vector<ExPolygons> name_shapes(m_input.styles.size());
|
||||||
std::vector<double> scales(m_input.styles.size());
|
std::vector<double> scales(m_input.styles.size());
|
||||||
images = std::vector<StyleManager::StyleImage>(m_input.styles.size());
|
m_images = std::vector<StyleManager::StyleImage>(m_input.styles.size());
|
||||||
|
|
||||||
for (auto &item : m_input.styles) {
|
for (auto &item : m_input.styles) {
|
||||||
size_t index = &item - &m_input.styles.front();
|
size_t index = &item - &m_input.styles.front();
|
||||||
@ -44,21 +39,17 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
shapes = text2shapes(item.font, m_input.text.c_str(), item.prop);
|
shapes = text2shapes(item.font, m_input.text.c_str(), item.prop);
|
||||||
|
|
||||||
// create image description
|
// create image description
|
||||||
StyleManager::StyleImage &image = images[index];
|
StyleManager::StyleImage &image = m_images[index];
|
||||||
BoundingBox &bounding_box = image.bounding_box;
|
BoundingBox &bounding_box = image.bounding_box;
|
||||||
for (ExPolygon &shape : shapes)
|
for (ExPolygon &shape : shapes)
|
||||||
bounding_box.merge(BoundingBox(shape.contour.points));
|
bounding_box.merge(BoundingBox(shape.contour.points));
|
||||||
for (ExPolygon &shape : shapes) shape.translate(-bounding_box.min);
|
for (ExPolygon &shape : shapes) shape.translate(-bounding_box.min);
|
||||||
|
|
||||||
// calculate conversion from FontPoint to screen pixels by size of font
|
// calculate conversion from FontPoint to screen pixels by size of font
|
||||||
auto mf = wxGetApp().mainframe;
|
|
||||||
// dot per inch for monitor
|
|
||||||
int dpi = get_dpi_for_window(mf);
|
|
||||||
double ppm = dpi / 25.4; // pixel per milimeter
|
|
||||||
const auto &cn = item.prop.collection_number;
|
const auto &cn = item.prop.collection_number;
|
||||||
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
unsigned int font_index = (cn.has_value()) ? *cn : 0;
|
||||||
double unit_per_em = item.font.font_file->infos[font_index].unit_per_em;
|
double unit_per_em = item.font.font_file->infos[font_index].unit_per_em;
|
||||||
double scale = item.prop.size_in_mm / unit_per_em * SHAPE_SCALE * ppm;
|
double scale = item.prop.size_in_mm / unit_per_em * SHAPE_SCALE * m_input.ppm;
|
||||||
scales[index] = scale;
|
scales[index] = scale;
|
||||||
|
|
||||||
//double scale = font_prop.size_in_mm * SCALING_FACTOR;
|
//double scale = font_prop.size_in_mm * SCALING_FACTOR;
|
||||||
@ -78,30 +69,30 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
|
|
||||||
// arrange bounding boxes
|
// arrange bounding boxes
|
||||||
int offset_y = 0;
|
int offset_y = 0;
|
||||||
width = 0;
|
m_width = 0;
|
||||||
for (StyleManager::StyleImage &image : images) {
|
for (StyleManager::StyleImage &image : m_images) {
|
||||||
image.offset.y() = offset_y;
|
image.offset.y() = offset_y;
|
||||||
offset_y += image.tex_size.y+1;
|
offset_y += image.tex_size.y+1;
|
||||||
if (width < image.tex_size.x)
|
if (m_width < image.tex_size.x)
|
||||||
width = image.tex_size.x;
|
m_width = image.tex_size.x;
|
||||||
}
|
}
|
||||||
height = offset_y;
|
m_height = offset_y;
|
||||||
for (StyleManager::StyleImage &image : images) {
|
for (StyleManager::StyleImage &image : m_images) {
|
||||||
const Point &o = image.offset;
|
const Point &o = image.offset;
|
||||||
const ImVec2 &s = image.tex_size;
|
const ImVec2 &s = image.tex_size;
|
||||||
image.uv0 = ImVec2(o.x() / (double) width,
|
image.uv0 = ImVec2(o.x() / (double) m_width,
|
||||||
o.y() / (double) height);
|
o.y() / (double) m_height);
|
||||||
image.uv1 = ImVec2((o.x() + s.x) / (double) width,
|
image.uv1 = ImVec2((o.x() + s.x) / (double) m_width,
|
||||||
(o.y() + s.y) / (double) height);
|
(o.y() + s.y) / (double) m_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up result
|
// Set up result
|
||||||
pixels = std::vector<unsigned char>(4*width * height, {255});
|
m_pixels = std::vector<unsigned char>(4 * m_width * m_height, {255});
|
||||||
|
|
||||||
// upload sub textures
|
// upload sub textures
|
||||||
for (StyleManager::StyleImage &image : images) {
|
for (StyleManager::StyleImage &image : m_images) {
|
||||||
sla::Resolution resolution(image.tex_size.x, image.tex_size.y);
|
sla::Resolution resolution(image.tex_size.x, image.tex_size.y);
|
||||||
size_t index = &image - &images.front();
|
size_t index = &image - &m_images.front();
|
||||||
double pixel_dim = SCALING_FACTOR / scales[index];
|
double pixel_dim = SCALING_FACTOR / scales[index];
|
||||||
sla::PixelDim dim(pixel_dim, pixel_dim);
|
sla::PixelDim dim(pixel_dim, pixel_dim);
|
||||||
double gamma = 1.;
|
double gamma = 1.;
|
||||||
@ -110,7 +101,7 @@ void CreateFontStyleImagesJob::process(Ctl &ctl)
|
|||||||
for (const ExPolygon &shape : name_shapes[index]) r->draw(shape);
|
for (const ExPolygon &shape : name_shapes[index]) r->draw(shape);
|
||||||
|
|
||||||
// copy rastered data to pixels
|
// copy rastered data to pixels
|
||||||
sla::RasterEncoder encoder = [&offset = image.offset, &pix = pixels, w=width,h=height]
|
sla::RasterEncoder encoder = [&offset = image.offset, &pix = m_pixels, w=m_width,h=m_height]
|
||||||
(const void *ptr, size_t width, size_t height, size_t num_components) {
|
(const void *ptr, size_t width, size_t height, size_t num_components) {
|
||||||
// bigger value create darker image
|
// bigger value create darker image
|
||||||
unsigned char gray_level = 5;
|
unsigned char gray_level = 5;
|
||||||
@ -142,18 +133,18 @@ void CreateFontStyleImagesJob::finalize(bool canceled, std::exception_ptr &)
|
|||||||
glsafe(::glBindTexture(target, tex_id));
|
glsafe(::glBindTexture(target, tex_id));
|
||||||
glsafe(::glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
glsafe(::glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
|
||||||
glsafe(::glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
glsafe(::glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
|
||||||
GLint w = width, h=height;
|
GLint w = m_width, h = m_height;
|
||||||
glsafe(::glTexImage2D(target, level, GL_RGBA, w, h, border, format, type,
|
glsafe(::glTexImage2D(target, level, GL_RGBA, w, h, border, format, type,
|
||||||
(const void *) pixels.data()));
|
(const void *) m_pixels.data()));
|
||||||
|
|
||||||
// set up texture id
|
// set up texture id
|
||||||
void *texture_id = (void *) (intptr_t) tex_id;
|
void *texture_id = (void *) (intptr_t) tex_id;
|
||||||
for (StyleManager::StyleImage &image : images)
|
for (StyleManager::StyleImage &image : m_images)
|
||||||
image.texture_id = texture_id;
|
image.texture_id = texture_id;
|
||||||
|
|
||||||
// move to result
|
// move to result
|
||||||
m_input.result->styles = std::move(m_input.styles);
|
m_input.result->styles = std::move(m_input.styles);
|
||||||
m_input.result->images = std::move(images);
|
m_input.result->images = std::move(m_images);
|
||||||
|
|
||||||
// bind default texture
|
// bind default texture
|
||||||
GLuint no_texture_id = 0;
|
GLuint no_texture_id = 0;
|
||||||
|
@ -19,11 +19,11 @@ class CreateFontStyleImagesJob : public Job
|
|||||||
|
|
||||||
// Output data
|
// Output data
|
||||||
// texture size
|
// texture size
|
||||||
int width, height;
|
int m_width, m_height;
|
||||||
// texture data
|
// texture data
|
||||||
std::vector<unsigned char> pixels;
|
std::vector<unsigned char> m_pixels;
|
||||||
// descriptors of sub textures
|
// descriptors of sub textures
|
||||||
std::vector<StyleManager::StyleImage> images;
|
std::vector<StyleManager::StyleImage> m_images;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CreateFontStyleImagesJob(StyleManager::StyleImagesData &&input);
|
CreateFontStyleImagesJob(StyleManager::StyleImagesData &&input);
|
||||||
|
@ -304,12 +304,15 @@ void StyleManager::init_trunc_names(float max_width) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "slic3r/GUI/Jobs/CreateFontStyleImagesJob.hpp"
|
|
||||||
|
|
||||||
// for access to worker
|
// for access to worker
|
||||||
#include "slic3r/GUI/GUI_App.hpp"
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
#include "slic3r/GUI/Plater.hpp"
|
#include "slic3r/GUI/Plater.hpp"
|
||||||
|
|
||||||
|
// for get DPI
|
||||||
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
|
#include "slic3r/GUI/MainFrame.hpp"
|
||||||
|
#include "slic3r/GUI/GUI_ObjectManipulation.hpp"
|
||||||
|
|
||||||
void StyleManager::init_style_images(const Vec2i &max_size,
|
void StyleManager::init_style_images(const Vec2i &max_size,
|
||||||
const std::string &text)
|
const std::string &text)
|
||||||
{
|
{
|
||||||
@ -361,8 +364,15 @@ void StyleManager::init_style_images(const Vec2i &max_size,
|
|||||||
style.prop
|
style.prop
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto mf = wxGetApp().mainframe;
|
||||||
|
// dot per inch for monitor
|
||||||
|
int dpi = get_dpi_for_window(mf);
|
||||||
|
// pixel per milimeter
|
||||||
|
double ppm = dpi / ObjectManipulation::in_to_mm;
|
||||||
|
|
||||||
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
auto &worker = wxGetApp().plater()->get_ui_job_worker();
|
||||||
StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images};
|
StyleImagesData data{std::move(styles), max_size, text, m_temp_style_images, ppm};
|
||||||
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
queue_job(worker, std::make_unique<CreateFontStyleImagesJob>(std::move(data)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,6 +277,9 @@ private:
|
|||||||
|
|
||||||
// place to store result in main thread in Finalize
|
// place to store result in main thread in Finalize
|
||||||
std::shared_ptr<StyleImages> result;
|
std::shared_ptr<StyleImages> result;
|
||||||
|
|
||||||
|
// pixel per milimeter (scaled DPI)
|
||||||
|
double ppm;
|
||||||
};
|
};
|
||||||
std::shared_ptr<StyleImagesData::StyleImages> m_temp_style_images;
|
std::shared_ptr<StyleImagesData::StyleImages> m_temp_style_images;
|
||||||
bool m_exist_style_images;
|
bool m_exist_style_images;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user