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

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

Inheritance diagram for Slic3r::GUI::RotoptimizeJob:
Collaboration diagram for Slic3r::GUI::RotoptimizeJob:

Classes

struct  FindMethod
struct  ObjRot

Public Types

enum  JobPrepareState { PREPARE_STATE_DEFAULT = 0 , PREPARE_STATE_MENU = 1 }

Public Member Functions

void prepare ()
void process (Ctl &ctl) override
 RotoptimizeJob ()
void finalize (bool canceled, std::exception_ptr &) override

Static Public Member Functions

static constexpr size_t get_methods_count ()
static std::string get_method_name (size_t i)
static std::string get_method_description (size_t i)

Private Types

using FindFn

Private Attributes

size_t m_method_id = 0
float m_accuracy = 0.75
DynamicPrintConfig m_default_print_cfg
std::vector< ObjRot > m_selected_object_ids
Plater * m_plater

Static Private Attributes

static const FindMethod Methods []

Detailed Description


Class Documentation

◆ Slic3r::GUI::RotoptimizeJob::FindMethod

struct Slic3r::GUI::RotoptimizeJob::FindMethod
Collaboration diagram for Slic3r::GUI::RotoptimizeJob::FindMethod:
Class Members
string descr
FindFn findfn
string name

Member Typedef Documentation

◆ FindFn

Initial value:
std::function<Vec2d(const ModelObject & mo,
const sla::RotOptimizeParams &params)>
Definition Model.hpp:382
Definition Rotfinder.hpp:21
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

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

◆ RotoptimizeJob()

Slic3r::GUI::RotoptimizeJob::RotoptimizeJob ( )
90: m_plater{wxGetApp().plater()} { prepare(); }
void prepare()
Definition RotoptimizeJob.cpp:27
Plater * m_plater
Definition RotoptimizeJob.hpp:58

References m_plater, Slic3r::GUI::plater(), and prepare().

Here is the call graph for this function:

Member Function Documentation

◆ finalize()

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

Reimplemented from Slic3r::GUI::Job.

93{
94 if (canceled || eptr)
95 return;
96
97 for (const ObjRot &objrot : m_selected_object_ids) {
98 ModelObject *o = m_plater->model().objects[size_t(objrot.idx)];
99 if (!o) continue;
100
101 for(ModelInstance * oi : o->instances) {
102 if (objrot.rot)
103 oi->set_rotation({objrot.rot->x(), objrot.rot->y(), 0.});
104
105 auto trmatrix = oi->get_transformation().get_matrix();
106 Polygon trchull = o->convex_hull_2d(trmatrix);
107
108 MinAreaBoundigBox rotbb(trchull, MinAreaBoundigBox::pcConvex);
109 double phi = rotbb.angle_to_X();
110
111 // The box should be landscape
112 if(rotbb.width() < rotbb.height()) phi += PI / 2;
113
114 Vec3d rt = oi->get_rotation(); rt(Z) += phi;
115
116 oi->set_rotation(rt);
117 }
118
119 // Correct the z offset of the object which was corrupted be
120 // the rotation
121 o->ensure_on_bed();
122
123// m_plater->find_new_position(o->instances);
124 }
125
126 if (!canceled)
127 m_plater->update();
128}
std::vector< ObjRot > m_selected_object_ids
Definition RotoptimizeJob.hpp:57
@ pcConvex
Definition MinAreaBoundingBox.hpp:25
static constexpr double PI
Definition libslic3r.h:81
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
@ Z
Definition libslic3r.h:143
Slic3r::Polygon Polygon
Definition Emboss.cpp:101
Definition RotoptimizeJob.hpp:51

References Slic3r::MinAreaBoundigBox::angle_to_X(), Slic3r::ModelObject::convex_hull_2d(), Slic3r::ModelObject::ensure_on_bed(), Slic3r::Geometry::Transformation::get_matrix(), Slic3r::ModelInstance::get_rotation(), Slic3r::ModelInstance::get_transformation(), Slic3r::MinAreaBoundigBox::height(), Slic3r::ModelObject::instances, m_plater, m_selected_object_ids, Slic3r::MinAreaBoundigBox::pcConvex, PI, Slic3r::ModelInstance::set_rotation(), Slic3r::MinAreaBoundigBox::width(), and Slic3r::Z.

Here is the call graph for this function:

◆ get_method_description()

std::string Slic3r::GUI::RotoptimizeJob::get_method_description ( size_t i)
inlinestatic
77 {
78 return _utf8(Methods[i].descr);
79 }
static const FindMethod Methods[]
Definition RotoptimizeJob.hpp:32
#define _utf8(s)
Definition I18N.hpp:10

References _utf8, and Methods.

Referenced by Slic3r::GUI::GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow().

Here is the caller graph for this function:

◆ get_method_name()

std::string Slic3r::GUI::RotoptimizeJob::get_method_name ( size_t i)
inlinestatic
72 {
73 return _utf8(Methods[i].name);
74 }

References _utf8, and Methods.

Referenced by Slic3r::GUI::GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow().

Here is the caller graph for this function:

◆ get_methods_count()

constexpr size_t Slic3r::GUI::RotoptimizeJob::get_methods_count ( )
inlinestaticconstexpr
69{ return std::size(Methods); }

References Methods.

Referenced by Slic3r::GUI::GLGizmoRotate3D::RotoptimzeWindow::RotoptimzeWindow(), Slic3r::GUI::GLGizmoRotate3D::load_rotoptimize_state(), and prepare().

Here is the caller graph for this function:

◆ prepare()

void Slic3r::GUI::RotoptimizeJob::prepare ( )
28{
29 std::string accuracy_str =
30 wxGetApp().app_config->get("sla_auto_rotate", "accuracy");
31
32 std::string method_str =
33 wxGetApp().app_config->get("sla_auto_rotate", "method_id");
34
35 if (!accuracy_str.empty())
36 m_accuracy = std::stof(accuracy_str);
37
38 if (!method_str.empty())
39 m_method_id = std::stoi(method_str);
40
41 m_accuracy = std::max(0.f, std::min(m_accuracy, 1.f));
42 m_method_id = std::max(size_t(0), std::min(get_methods_count() - 1, m_method_id));
43
44 m_default_print_cfg = wxGetApp().preset_bundle->full_config();
45
46 const auto &sel = m_plater->get_selection().get_content();
47
49 m_selected_object_ids.reserve(sel.size());
50
51 for (const auto &s : sel) {
52 int obj_id;
53 std::tie(obj_id, std::ignore) = s;
54 m_selected_object_ids.emplace_back(obj_id);
55 }
56}
size_t m_method_id
Definition RotoptimizeJob.hpp:45
float m_accuracy
Definition RotoptimizeJob.hpp:46
DynamicPrintConfig m_default_print_cfg
Definition RotoptimizeJob.hpp:48
static constexpr size_t get_methods_count()
Definition RotoptimizeJob.hpp:69

References get_methods_count(), m_accuracy, m_default_print_cfg, m_method_id, m_plater, and m_selected_object_ids.

Referenced by RotoptimizeJob().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

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

Implements Slic3r::GUI::Job.

59{
60 int prev_status = 0;
61 auto statustxt = _u8L("Searching for optimal orientation");
62 ctl.update_status(0, statustxt);
63
64 auto params =
65 sla::RotOptimizeParams{}
66 .accuracy(m_accuracy)
67 .print_config(&m_default_print_cfg)
68 .statucb([&ctl/*, &statustxt*/](int s)
69 {
70 return !ctl.was_canceled();
71 });
72
73
74 for (ObjRot &objrot : m_selected_object_ids) {
75 ModelObject *o = m_plater->model().objects[size_t(objrot.idx)];
76 if (!o) continue;
77
78 if (Methods[m_method_id].findfn)
79 objrot.rot = Methods[m_method_id].findfn(*o, params);
80
81 prev_status += 100 / m_selected_object_ids.size();
82
83 if (ctl.was_canceled()) break;
84 }
85
86 ctl.update_status(100, ctl.was_canceled() ? _u8L("Orientation search canceled.") :
87 _u8L("Orientation found."));
88}
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::sla::RotOptimizeParams::accuracy(), m_accuracy, m_default_print_cfg, m_method_id, m_plater, m_selected_object_ids, Methods, Slic3r::sla::RotOptimizeParams::print_config(), Slic3r::sla::RotOptimizeParams::statucb(), Slic3r::GUI::Job::Ctl::update_status(), and Slic3r::GUI::Job::Ctl::was_canceled().

Here is the call graph for this function:

Member Data Documentation

◆ m_accuracy

float Slic3r::GUI::RotoptimizeJob::m_accuracy = 0.75
private

Referenced by prepare(), and process().

◆ m_default_print_cfg

DynamicPrintConfig Slic3r::GUI::RotoptimizeJob::m_default_print_cfg
private

Referenced by prepare(), and process().

◆ m_method_id

size_t Slic3r::GUI::RotoptimizeJob::m_method_id = 0
private

Referenced by prepare(), and process().

◆ m_plater

Plater* Slic3r::GUI::RotoptimizeJob::m_plater
private

◆ m_selected_object_ids

std::vector<ObjRot> Slic3r::GUI::RotoptimizeJob::m_selected_object_ids
private

Referenced by finalize(), prepare(), and process().

◆ Methods

const FindMethod Slic3r::GUI::RotoptimizeJob::Methods[]
inlinestaticprivate
Initial value:
= {{L("Best surface quality"),
L("Optimize object rotation for best surface quality.")},
{L("Reduced overhang slopes"),
L("Optimize object rotation to have minimum amount of overhangs needing support "
"structures.\nNote that this method will try to find the best surface of the object "
"for touching the print bed if no elevation is set.")},
{L("Lowest Z height"),
L("Rotate the model to have the lowest z height for faster print time.")}}
#define L(s)
Definition ExtrusionEntity.cpp:25
Vec2d find_least_supports_rotation(const ModelObject &mo, const RotOptimizeParams &params)
Definition Rotfinder.cpp:369
Vec2d find_min_z_height_rotation(const ModelObject &mo, const RotOptimizeParams &params)
Definition Rotfinder.cpp:446
Vec2d find_best_misalignment_rotation(const ModelObject &mo, const RotOptimizeParams &params)
Definition Rotfinder.cpp:341
32 {{L("Best surface quality"),
34 L("Optimize object rotation for best surface quality.")},
35 {L("Reduced overhang slopes"),
37 L("Optimize object rotation to have minimum amount of overhangs needing support "
38 "structures.\nNote that this method will try to find the best surface of the object "
39 "for touching the print bed if no elevation is set.")},
40 // Just a min area bounding box that is done for all methods anyway.
41 {L("Lowest Z height"),
43 L("Rotate the model to have the lowest z height for faster print time.")}};

Referenced by get_method_description(), get_method_name(), get_methods_count(), and process().


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