OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::TextureDisplacementDebugJob Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Jobs/TextureDisplacementDebugJob.hpp>

Inheritance diagram for Slic3r::GUI::TextureDisplacementDebugJob:
Collaboration diagram for Slic3r::GUI::TextureDisplacementDebugJob:

Public Types

enum  JobPrepareState { PREPARE_STATE_DEFAULT = 0 , PREPARE_STATE_MENU = 1 }

Public Member Functions

 TextureDisplacementDebugJob (TextureDisplacementDebugInput &&input, std::function< void(std::vector< BakeStageSnapshot >)> on_finished)
void process (Ctl &ctl) override
void finalize (bool canceled, std::exception_ptr &eptr) override

Private Attributes

TextureDisplacementDebugInput m_input
std::vector< BakeStageSnapshot > m_stages
std::function< void(std::vector< BakeStageSnapshot >)> m_on_finished

Detailed Description

Member Enumeration Documentation

◆ JobPrepareState

Enumerator
PREPARE_STATE_DEFAULT 
PREPARE_STATE_MENU 
22 {
25 };
@ PREPARE_STATE_MENU
Definition Job.hpp:24
@ PREPARE_STATE_DEFAULT
Definition Job.hpp:23

Constructor & Destructor Documentation

◆ TextureDisplacementDebugJob()

Slic3r::GUI::TextureDisplacementDebugJob::TextureDisplacementDebugJob ( TextureDisplacementDebugInput && input,
std::function< void(std::vector< BakeStageSnapshot >)> on_finished )
27 : m_input(std::move(input)), m_on_finished(std::move(on_finished))
28{
29}
TextureDisplacementDebugInput m_input
Definition TextureDisplacementDebugJob.hpp:77
std::function< void(std::vector< BakeStageSnapshot >)> m_on_finished
Definition TextureDisplacementDebugJob.hpp:79

References m_input, and m_on_finished.

Member Function Documentation

◆ finalize()

void Slic3r::GUI::TextureDisplacementDebugJob::finalize ( bool canceled,
std::exception_ptr & eptr )
overridevirtual

Reimplemented from Slic3r::GUI::Job.

97{
98 if (!m_on_finished)
99 return;
100 // The handler must run on every outcome - the caller uses it to clear its in-progress latch, and
101 // an empty vector is its signal that nothing usable came back.
102 if (canceled || eptr)
103 m_on_finished({});
104 else
105 m_on_finished(std::move(m_stages));
106}
std::vector< BakeStageSnapshot > m_stages
Definition TextureDisplacementDebugJob.hpp:78

References m_on_finished, and m_stages.

◆ process()

void Slic3r::GUI::TextureDisplacementDebugJob::process ( Ctl & ctl)
overridevirtual

Implements Slic3r::GUI::Job.

32{
33 const std::string status = _u8L("Capturing bake stages");
34 ctl.update_status(1, status);
35
36 // Only ever touches m_input (captured by value before this job was queued) and local state - and,
37 // unlike the bake job, never writes anything back either.
38 int last_reported = 1;
39 const auto report = [&ctl, &status, &last_reported](int percent) {
40 if (ctl.was_canceled())
41 return false;
42 if (percent > last_reported) {
43 last_reported = percent;
44 ctl.update_status(percent, status);
45 }
46 return true;
47 };
48
49 BakeStageRecorder recorder;
50 recorder.enable(true);
51 recorder.set_check_topology(m_input.check_topology);
52 recorder.set_mesh_cap(m_input.mesh_cap);
53
54 indexed_triangle_set mesh = m_input.base_mesh;
55 TextureDisplacementFacetsData masks = m_input.facets_data;
56 std::vector<Vec2f> uv = m_input.model_uv;
57
58 // The default pipeline can only move vertices the mesh already has, so its recipe starts with the
59 // preparation - which is where "first it remeshes, then it refines" actually happens. The
60 // experimental pipeline refines as part of the bake and has nothing to prepare.
61 if (m_input.run_prepare && !m_input.options.pipeline_v2) {
62 const TextureDisplacementPrepareResult prepared =
63 GLGizmoTextureDisplacement::prepare_mesh(mesh, masks, m_input.layers, uv, m_input.prepare_texture_frame,
64 m_input.prepare_params, m_input.color,
65 // Preparation is roughly half the run; the bake
66 // takes the progress bar from there.
67 [&report](int pct) { return report(1 + pct / 2); },
68 &recorder);
69 if (ctl.was_canceled())
70 return;
71 // An empty result means nothing needed doing, which is not a failure - the bake below simply
72 // runs on the mesh as it stands. paint_lost means the remesh dropped every layer's paint, so
73 // there is nothing left to displace and the stages recorded so far are the whole story.
74 if (prepared.paint_lost) {
75 m_stages = recorder.take();
76 ctl.update_status(100, status);
77 return;
78 }
79 if (!prepared.mesh.indices.empty()) {
80 mesh = prepared.mesh;
81 masks = prepared.masks;
82 uv = prepared.uv; // resampled onto the prepared mesh, as the prepare commit stores it
83 }
84 }
85
86 build_texture_displacement(mesh, m_input.layers, masks, m_input.options,
87 [&report](int pct) { return report(50 + pct / 2); },
88 /* color */ nullptr, m_input.volume_to_world, &recorder, /* stats */ nullptr,
89 uv.empty() ? nullptr : &uv, /* texture_anchor: the volume's own origin */ nullptr,
90 m_input.resting_drop);
91
92 m_stages = recorder.take();
93 ctl.update_status(100, status); // always finish at 100: this is what closes the notification
94}
static TextureDisplacementPrepareResult prepare_mesh(const indexed_triangle_set &base, const TextureDisplacementFacetsData &masks, const std::vector< TextureDisplacementLayer > &layers, const std::vector< Vec2f > &model_uv, const Transform3d &texture_frame, const TextureDisplacementPrepareParams &params, const TextureColorSettings &color_settings, const DisplacementProgressFn &progress, BakeStageRecorder *debug=nullptr)
Definition GLGizmoTextureDisplacement.cpp:6071
std::array< TriangleSelector::TriangleSplittingData, TEXTURE_DISPLACEMENT_MAX_LAYERS > TextureDisplacementFacetsData
Definition TextureDisplacement.hpp:913
indexed_triangle_set build_texture_displacement(const indexed_triangle_set &base_mesh, const std::vector< TextureDisplacementLayer > &layers, const TextureDisplacementFacetsData &facets_data, const TextureDisplacementOptions &options, const DisplacementProgressFn &progress, const TextureColorRequest *color, const Transform3d &volume_to_world, BakeStageRecorder *debug, TextureBakeStats *stats, const std::vector< Vec2f > *model_uv, const Vec3d *texture_anchor, float resting_drop)
Definition TextureDisplacement.cpp:3495
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::build_texture_displacement(), Slic3r::BakeStageRecorder::enable(), m_input, m_stages, Slic3r::TextureDisplacementPrepareResult::masks, Slic3r::TextureDisplacementPrepareResult::mesh, Slic3r::TextureDisplacementPrepareResult::paint_lost, Slic3r::GUI::GLGizmoTextureDisplacement::prepare_mesh(), Slic3r::BakeStageRecorder::set_check_topology(), Slic3r::BakeStageRecorder::set_mesh_cap(), Slic3r::BakeStageRecorder::take(), Slic3r::GUI::Job::Ctl::update_status(), Slic3r::TextureDisplacementPrepareResult::uv, and Slic3r::GUI::Job::Ctl::was_canceled().

Here is the call graph for this function:

Member Data Documentation

◆ m_input

TextureDisplacementDebugInput Slic3r::GUI::TextureDisplacementDebugJob::m_input
private

◆ m_on_finished

std::function<void(std::vector<BakeStageSnapshot>)> Slic3r::GUI::TextureDisplacementDebugJob::m_on_finished
private

◆ m_stages

std::vector<BakeStageSnapshot> Slic3r::GUI::TextureDisplacementDebugJob::m_stages
private

Referenced by finalize(), and process().


The documentation for this class was generated from the following files: