OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Geometry::Transformation Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Geometry.hpp>

Public Member Functions

 Transformation ()=default
 Transformation (const Transform3d &transform)
Vec3d get_offset () const
double get_offset (Axis axis) const
Transform3d get_offset_matrix () const
void set_offset (const Vec3d &offset)
void set_offset (Axis axis, double offset)
Vec3d get_rotation () const
Vec3d get_rotation_by_quaternion () const
double get_rotation (Axis axis) const
Transform3d get_rotation_matrix () const
void set_rotation (const Vec3d &rotation)
void set_rotation (Axis axis, double rotation)
Vec3d get_scaling_factor () const
double get_scaling_factor (Axis axis) const
Transform3d get_scaling_factor_matrix () const
bool is_scaling_uniform () const
void set_scaling_factor (const Vec3d &scaling_factor)
void set_scaling_factor (Axis axis, double scaling_factor)
Vec3d get_mirror () const
double get_mirror (Axis axis) const
Transform3d get_mirror_matrix () const
bool is_left_handed () const
void set_mirror (const Vec3d &mirror)
void set_mirror (Axis axis, double mirror)
bool has_skew () const
void reset ()
void reset_offset ()
void reset_rotation ()
void reset_scaling_factor ()
void reset_mirror ()
void reset_skew ()
const Transform3d & get_matrix () const
Transform3d get_matrix_no_offset () const
Transform3d get_matrix_no_scaling_factor () const
Transform3d get_matrix_with_applied_shrinkage_compensation (const Vec3d &shrinkage_compensation) const
void set_matrix (const Transform3d &transform)
Transformation operator* (const Transformation &other) const

Static Public Member Functions

static Transformation volume_to_bed_transformation (const Transformation &instance_transformation, const BoundingBoxf3 &bbox)

Private Member Functions

template<class Archive>
void serialize (Archive &ar)
 Transformation (int)

Static Private Member Functions

template<class Archive>
static void load_and_construct (Archive &ar, cereal::construct< Transformation > &construct)

Private Attributes

Transform3d m_matrix { Transform3d::Identity() }

Friends

class cereal::access
bool operator== (Transformation const &l, Transformation const &r)
bool operator!= (Transformation const &l, Transformation const &r)

Detailed Description

Constructor & Destructor Documentation

◆ Transformation() [1/3]

Slic3r::Geometry::Transformation::Transformation ( )
default

Referenced by get_matrix_no_offset(), get_matrix_no_scaling_factor(), get_matrix_with_applied_shrinkage_compensation(), operator!=, operator*(), operator==, and volume_to_bed_transformation().

Here is the caller graph for this function:

◆ Transformation() [2/3]

Slic3r::Geometry::Transformation::Transformation ( const Transform3d & transform)
inlineexplicit
Transform3d m_matrix
Definition Geometry.hpp:420
Linef3 transform(const Linef3 &line, const Transform3d &t)
Definition Line.cpp:15

References m_matrix, and Slic3r::transform().

Here is the call graph for this function:

◆ Transformation() [3/3]

Slic3r::Geometry::Transformation::Transformation ( int )
inlineexplicitprivate
506{}

Member Function Documentation

◆ get_matrix()

const Transform3d & Slic3r::Geometry::Transformation::get_matrix ( ) const
inline
477{ return m_matrix; }

References m_matrix.

Referenced by Slic3r::_3MF_Exporter::_add_model_config_file_to_archive(), Slic3r::_BBS_3MF_Exporter::_add_model_config_file_to_archive(), Slic3r::GUI::GLCanvas3D::_render_imex_ghosts(), Slic3r::GUI::ObjectList::apply_object_instance_transfrom_to_all_volumes(), Slic3r::GUI::GLGizmoBrimEars::auto_generate(), Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::PrintObject::contour_z(), Slic3r::GUI::CameraUtils::create_hull2d(), Slic3r::ModelObject::delete_volume(), Slic3r::GUI::GLCanvas3D::do_rotate(), Slic3r::GUI::dragging_rotate_gizmo(), Slic3r::GUI::Plater::export_stl(), Slic3r::GUI::RotoptimizeJob::finalize(), Slic3r::GUI::GLGizmoBrimEars::first_layer_slicer(), Slic3r::ModelInstance::get_arrange_polygon(), Slic3r::GUI::Selection::get_bounding_box_in_reference_system(), Slic3r::GUI::GLCanvas3D::get_empty_cells(), Slic3r::GUI::Selection::get_full_scaled_instance_bounding_box(), Slic3r::GUI::Selection::get_full_unscaled_instance_bounding_box(), Slic3r::GUI::Selection::get_full_unscaled_instance_local_bounding_box(), get_matrix_no_offset(), get_matrix_no_scaling_factor(), get_matrix_with_applied_shrinkage_compensation(), Slic3r::GUI::GLGizmoPainterBase::get_projected_height_range(), Slic3r::GUI::Selection::get_scaled_instance_bounding_box(), Slic3r::GUI::MeshRaycaster::get_unobscured_idxs(), Slic3r::GUI::Selection::get_unscaled_instance_bounding_box(), Slic3r::GUI::GLGizmoBrimEars::gizmo_event(), Slic3r::GUI::GLGizmoMeshBoolean::gizmo_event(), Slic3r::GUI::GLGizmoPainterBase::gizmo_event(), anonymous_namespace{GLGizmoEmboss.cpp}::init_text_lines(), Slic3r::ModelObject::instance_bounding_box(), Slic3r::GUI::anonymous_namespace{GLGizmoAlignment.cpp}::instance_box_in_frame(), Slic3r::ModelObject::instance_convex_hull_bounding_box(), Slic3r::GUI::GLGizmoBrimEars::is_mesh_point_clipped(), Slic3r::make_brim_ears(), Slic3r::GUI::GLGizmoBrimEars::make_polygon(), Slic3r::Geometry::mat_around_a_point_rotate(), Slic3r::GUI::ObjectList::merge(), Slic3r::GUI::GLGizmoPainterBase::mesh_trafo_matrices(), Slic3r::GUI::GLGizmoFlatten::on_register_raycasters_for_picking(), Slic3r::GUI::GLGizmoFlatten::on_render(), Slic3r::GUI::GLGizmoMeasure::on_render(), Slic3r::GUI::GLGizmoMove3D::on_render(), operator*(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_height_range(), Slic3r::GUI::GLGizmoBrimEars::render_points(), Slic3r::GUI::Selection::render_synchronized_volumes(), Slic3r::GUI::GLGizmoCut3D::rotate_vec3d_around_plane_center(), Slic3r::CLI::run(), Slic3r::GUI::Selection::scale_and_translate(), Slic3r::GUI::selection_transform(), Slic3r::GUI::GLGizmoMeasure::set_to_around_center_of_faces(), Slic3r::GUI::GLGizmoMeasure::set_to_reverse_rotation(), Slic3r::GUI::MeshClipper::set_transformation(), Slic3r::ModelObject::split(), anonymous_namespace{SurfaceDrag.cpp}::start_dragging(), Slic3r::GUI::Selection::synchronize_unselected_instances(), Slic3r::GUI::Selection::transform_instance_relative(), Slic3r::GUI::Selection::transform_volume_relative(), Slic3r::GUI::GLGizmoCut3D::transformed_bounding_box(), Slic3r::GUI::GLGizmoBrimEars::unproject_on_mesh(), Slic3r::GUI::GLCanvas3D::update_compacted_wipe_tower_clearance(), and Slic3r::GUI::GLCanvas3D::update_sequential_clearance().

◆ get_matrix_no_offset()

Transform3d Slic3r::Geometry::Transformation::get_matrix_no_offset ( ) const
641{
642 Transformation copy(*this);
643 copy.reset_offset();
644 return copy.get_matrix();
645}

References Transformation(), get_matrix(), and reset_offset().

Referenced by Slic3r::ModelVolume::calculate_convex_hull_2d(), Slic3r::GUI::Selection::flattening_rotate(), Slic3r::GUI::Selection::get_bounding_box_in_reference_system(), Slic3r::GUI::GLGizmoPainterBase::get_projected_height_range(), Slic3r::GUI::GLGizmoBrimEars::gizmo_event(), Slic3r::GUI::GLGizmoPainterBase::gizmo_event(), Slic3r::ModelObject::instance_bounding_box(), Slic3r::ModelObject::instance_convex_hull_bounding_box(), Slic3r::lay_on_face(), Slic3r::GUI::ObjectList::load_generic_subobject(), Slic3r::GUI::ObjectList::load_modifier(), Slic3r::GUI::GCodeViewer::load_shells(), Slic3r::make_brim_ears(), Slic3r::GUI::GLGizmoRotate::mouse_position_in_local_plane(), Slic3r::GUI::Selection::paste_volumes_from_clipboard(), Slic3r::GUI::Plater::priv::reload_from_disk(), Slic3r::GUI::Plater::priv::replace_volume_with_stl(), Slic3r::GUI::Selection::rotate(), Slic3r::GUI::Selection::scale_and_translate(), Slic3r::GUI::GLGizmoMeasure::set_distance(), Slic3r::GUI::GizmoObjectManipulation::set_init_rotation(), Slic3r::ModelObject::split(), Slic3r::GUI::Selection::transform_volume_relative(), Slic3r::GUI::GLGizmoCut3D::transformed_bounding_box(), Slic3r::GUI::Selection::translate(), and volume_to_bed_transformation().

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

◆ get_matrix_no_scaling_factor()

Transform3d Slic3r::Geometry::Transformation::get_matrix_no_scaling_factor ( ) const
648{
649 Transformation copy(*this);
650 copy.reset_scaling_factor();
651 return copy.get_matrix();
652}

References Transformation(), get_matrix(), and reset_scaling_factor().

Referenced by Slic3r::GUI::Selection::get_bounding_box_in_reference_system(), Slic3r::GUI::Selection::get_full_unscaled_instance_bounding_box(), and Slic3r::GUI::Selection::get_unscaled_instance_bounding_box().

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

◆ get_matrix_with_applied_shrinkage_compensation()

Transform3d Slic3r::Geometry::Transformation::get_matrix_with_applied_shrinkage_compensation ( const Vec3d & shrinkage_compensation) const
655 {
656 const Transform3d shrinkage_trafo = Geometry::scale_transform(shrinkage_compensation);
657 const Vec3d trafo_offset = this->get_offset();
658 const Vec3d trafo_offset_xy = Vec3d(trafo_offset.x(), trafo_offset.y(), 0.);
659
660 Transformation copy(*this);
661 copy.set_offset(Axis::X, 0.);
662 copy.set_offset(Axis::Y, 0.);
663
664 Transform3d trafo_after_shrinkage = (shrinkage_trafo * copy.get_matrix());
665 trafo_after_shrinkage.translation() += trafo_offset_xy;
666
667 return trafo_after_shrinkage;
668 }
Vec3d get_offset() const
Definition Geometry.hpp:426
void scale_transform(Transform3d &transform, double scale)
Definition Geometry.cpp:372
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
Eigen::Transform< double, 3, Eigen::Affine, Eigen::DontAlign > Transform3d
Definition Point.hpp:96
@ Y
Definition libslic3r.h:142
@ X
Definition libslic3r.h:141

References Transformation(), get_matrix(), get_offset(), Slic3r::Geometry::scale_transform(), set_offset(), Slic3r::X, and Slic3r::Y.

Referenced by Slic3r::print_objects_from_model_object().

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

◆ get_mirror() [1/2]

Vec3d Slic3r::Geometry::Transformation::get_mirror ( ) const
551{
553 return { scale(0, 0) / std::abs(scale(0, 0)), scale(1, 1) / std::abs(scale(1, 1)), scale(2, 2) / std::abs(scale(2, 2)) };
554}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
static Transform3d extract_scale(const Transform3d &trafo)
Definition Geometry.cpp:461

References Slic3r::Geometry::extract_scale(), m_matrix, and scale().

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::ModelVolume::get_convex_hull_2d(), and volume_to_bed_transformation().

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

◆ get_mirror() [2/2]

double Slic3r::Geometry::Transformation::get_mirror ( Axis axis) const
inline
457{ return get_mirror()[axis]; }
Vec3d get_mirror() const
Definition Geometry.cpp:550

References get_mirror().

Referenced by get_mirror().

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

◆ get_mirror_matrix()

Transform3d Slic3r::Geometry::Transformation::get_mirror_matrix ( ) const
557{
559 scale(0, 0) = scale(0, 0) / std::abs(scale(0, 0));
560 scale(1, 1) = scale(1, 1) / std::abs(scale(1, 1));
561 scale(2, 2) = scale(2, 2) / std::abs(scale(2, 2));
562 return scale;
563}

References Slic3r::Geometry::extract_scale(), m_matrix, and scale().

Here is the call graph for this function:

◆ get_offset() [1/2]

Vec3d Slic3r::Geometry::Transformation::get_offset ( ) const
inline
426{ return m_matrix.translation(); }

References m_matrix.

Referenced by Slic3r::GUI::PartPlate::add_instance(), Slic3r::GUI::ObjectList::apply_object_instance_transfrom_to_all_volumes(), Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::ModelVolume::calculate_convex_hull_2d(), Slic3r::Model::convert_multipart_object(), Slic3r::GUI::GLGizmoMeshBoolean::generate_new_volume(), get_matrix_with_applied_shrinkage_compensation(), get_offset_matrix(), Slic3r::GUI::GLGizmoPainterBase::gizmo_event(), Slic3r::Geometry::mat_around_a_point_rotate(), Slic3r::GUI::GLGizmoPainterBase::mesh_trafo_matrices(), Slic3r::GUI::Selection::paste_volumes_from_clipboard(), Slic3r::Cut::perform_with_plane(), Slic3r::GUI::GLGizmoCut3D::process_selection_rectangle(), Slic3r::process_volume_cut(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_height_range(), Slic3r::GUI::CommonGizmosDataObjects::InstancesHider::render_cut(), Slic3r::GUI::CommonGizmosDataObjects::ObjectClipper::render_cut(), Slic3r::GUI::GLGizmoPainterBase::render_triangles(), Slic3r::GUI::GizmoObjectManipulation::reset_rotation_value(), Slic3r::GUI::Selection::rotate(), Slic3r::GUI::Selection::scale_and_translate(), set_mirror(), set_mirror(), Slic3r::GUI::PartPlate::set_pos_and_size(), set_rotation(), set_rotation(), set_scaling_factor(), set_scaling_factor(), Slic3r::GUI::Selection::transform_instance_relative(), Slic3r::GUI::Selection::transform_volume_relative(), Slic3r::GUI::Selection::translate(), Slic3r::GUI::GLCanvas3D::update_compacted_wipe_tower_clearance(), and Slic3r::GUI::GizmoObjectManipulation::update_settings_value().

Here is the caller graph for this function:

◆ get_offset() [2/2]

double Slic3r::Geometry::Transformation::get_offset ( Axis axis) const
inline
427{ return get_offset()[axis]; }

References get_offset().

Referenced by get_offset().

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

◆ get_offset_matrix()

Transform3d Slic3r::Geometry::Transformation::get_offset_matrix ( ) const
427{
429}
void translation_transform(Transform3d &transform, const Vec3d &translation)
Definition Geometry.cpp:346

References get_offset(), and Slic3r::Geometry::translation_transform().

Referenced by Slic3r::GUI::Selection::flattening_rotate(), Slic3r::lay_on_face(), reset_rotation(), reset_scaling_factor(), and reset_skew().

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

◆ get_rotation() [1/2]

Vec3d Slic3r::Geometry::Transformation::get_rotation ( ) const
472{
474}
static Transform3d extract_rotation_matrix(const Transform3d &trafo)
Definition Geometry.cpp:456
Vec3d extract_euler_angles(const Eigen::Matrix< double, 3, 3, Eigen::DontAlign > &rotation_matrix)
Definition Geometry.cpp:395

References Slic3r::Geometry::extract_euler_angles(), Slic3r::Geometry::extract_rotation_matrix(), and m_matrix.

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::sla::anonymous_namespace{Rotfinder.cpp}::from_transform3f(), Slic3r::ModelVolume::get_convex_hull_2d(), Slic3r::reset_instance_transformation(), Slic3r::GUI::GizmoObjectManipulation::set_init_rotation(), and volume_to_bed_transformation().

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

◆ get_rotation() [2/2]

double Slic3r::Geometry::Transformation::get_rotation ( Axis axis) const
inline
436{ return get_rotation()[axis]; }
Vec3d get_rotation() const
Definition Geometry.cpp:471

References get_rotation().

Referenced by get_rotation().

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

◆ get_rotation_by_quaternion()

Vec3d Slic3r::Geometry::Transformation::get_rotation_by_quaternion ( ) const
482{
483 Matrix3d rotation_matrix = m_matrix.matrix().block(0, 0, 3, 3);
484 Eigen::Quaterniond quaternion(rotation_matrix);
485 quaternion.normalize();
486 Vec3d temp_rotation = quaternion.matrix().eulerAngles(2, 1, 0);
487 std::swap(temp_rotation(0), temp_rotation(2));
488 return temp_rotation;
489}
Eigen::Matrix< double, 3, 3, Eigen::DontAlign > Matrix3d
Definition Point.hpp:86

References m_matrix.

Referenced by Slic3r::GUI::GizmoObjectManipulation::update_settings_value().

Here is the caller graph for this function:

◆ get_rotation_matrix()

Transform3d Slic3r::Geometry::Transformation::get_rotation_matrix ( ) const
477{
479}

References Slic3r::Geometry::extract_rotation_matrix(), and m_matrix.

Referenced by Slic3r::GUI::MeshRaycaster::get_unobscured_idxs(), Slic3r::Cut::perform_with_plane(), Slic3r::process_volume_cut(), Slic3r::reset_instance_transformation(), Slic3r::GUI::Selection::rotate(), Slic3r::GUI::GLGizmoMeasure::set_to_parallel(), and Slic3r::GUI::Selection::translate().

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

◆ get_scaling_factor() [1/2]

Vec3d Slic3r::Geometry::Transformation::get_scaling_factor ( ) const
514{
516 return { std::abs(scale(0, 0)), std::abs(scale(1, 1)), std::abs(scale(2, 2)) };
517}

References Slic3r::Geometry::extract_scale(), m_matrix, and scale().

Referenced by Slic3r::TriangleSelector::Cursor::Cursor(), Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::ModelVolume::get_convex_hull_2d(), Slic3r::GUI::MeshRaycaster::get_unobscured_idxs(), is_scaling_uniform(), and volume_to_bed_transformation().

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

◆ get_scaling_factor() [2/2]

double Slic3r::Geometry::Transformation::get_scaling_factor ( Axis axis) const
inline
444{ return get_scaling_factor()[axis]; }
Vec3d get_scaling_factor() const
Definition Geometry.cpp:513

References get_scaling_factor().

Referenced by get_scaling_factor().

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

◆ get_scaling_factor_matrix()

Transform3d Slic3r::Geometry::Transformation::get_scaling_factor_matrix ( ) const
520{
522 scale(0, 0) = std::abs(scale(0, 0));
523 scale(1, 1) = std::abs(scale(1, 1));
524 scale(2, 2) = std::abs(scale(2, 2));
525 return scale;
526}

References Slic3r::Geometry::extract_scale(), m_matrix, and scale().

Referenced by Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), Slic3r::GUI::GLGizmoBrimEars::render_points(), Slic3r::GUI::Selection::rotate(), and Slic3r::GUI::Selection::translate().

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

◆ has_skew()

bool Slic3r::Geometry::Transformation::has_skew ( ) const
609{
610 return contains_skew(m_matrix);
611}
static bool contains_skew(const Transform3d &trafo)
Definition Geometry.cpp:466

References Slic3r::Geometry::contains_skew(), and m_matrix.

Here is the call graph for this function:

◆ is_left_handed()

bool Slic3r::Geometry::Transformation::is_left_handed ( ) const
inline
461 {
462 return m_matrix.linear().determinant() < 0;
463 }

References m_matrix.

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::GUI::GLGizmoPainterBase::render_cursor_sphere(), and Slic3r::GUI::Selection::rotate().

Here is the caller graph for this function:

◆ is_scaling_uniform()

bool Slic3r::Geometry::Transformation::is_scaling_uniform ( ) const
inline
448 {
450 return std::abs(scale.x() - scale.y()) < 1e-8 && std::abs(scale.x() - scale.z()) < 1e-8;
451 }

References get_scaling_factor(), and scale().

Referenced by volume_to_bed_transformation().

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

◆ load_and_construct()

template<class Archive>
void Slic3r::Geometry::Transformation::load_and_construct ( Archive & ar,
cereal::construct< Transformation > & construct )
inlinestaticprivate
508 {
509 // Calling a private constructor with special "int" parameter to indicate that no construction is necessary.
510 construct(1);
511 ar(construct.ptr()->m_matrix);
512 }

◆ operator*()

Transformation Slic3r::Geometry::Transformation::operator* ( const Transformation & other) const
671{
672 return Transformation(get_matrix() * other.get_matrix());
673}
const Transform3d & get_matrix() const
Definition Geometry.hpp:477

References Transformation(), and get_matrix().

Here is the call graph for this function:

◆ reset()

void Slic3r::Geometry::Transformation::reset ( )
614{
615 m_matrix = Transform3d::Identity();
616}

References m_matrix.

◆ reset_mirror()

void Slic3r::Geometry::Transformation::reset_mirror ( )
inline
474{ set_mirror(Vec3d::Ones()); }
void set_mirror(const Vec3d &mirror)
Definition Geometry.cpp:565

References set_mirror().

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes().

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

◆ reset_offset()

void Slic3r::Geometry::Transformation::reset_offset ( )
inline
471{ set_offset(Vec3d::Zero()); }
void set_offset(const Vec3d &offset)
Definition Geometry.hpp:431

References set_offset().

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes(), and get_matrix_no_offset().

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

◆ reset_rotation()

void Slic3r::Geometry::Transformation::reset_rotation ( )
619{
620 const Geometry::TransformationSVD svd(*this);
621 m_matrix = get_offset_matrix() * Transform3d(svd.v * svd.s * svd.v.transpose()) * svd.mirror_matrix();
622}
Transform3d get_offset_matrix() const
Definition Geometry.cpp:426

References get_offset_matrix(), m_matrix, Slic3r::Geometry::TransformationSVD::mirror_matrix(), Slic3r::Geometry::TransformationSVD::s, and Slic3r::Geometry::TransformationSVD::v.

Referenced by Slic3r::GUI::GizmoObjectManipulation::reset_rotation_value(), and Slic3r::GUI::Selection::synchronize_unselected_instances().

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

◆ reset_scaling_factor()

void Slic3r::Geometry::Transformation::reset_scaling_factor ( )
625{
626 const Geometry::TransformationSVD svd(*this);
627 m_matrix = get_offset_matrix() * Transform3d(svd.u) * Transform3d(svd.v.transpose()) * svd.mirror_matrix();
628}

References get_offset_matrix(), m_matrix, Slic3r::Geometry::TransformationSVD::mirror_matrix(), Slic3r::Geometry::TransformationSVD::u, and Slic3r::Geometry::TransformationSVD::v.

Referenced by Slic3r::ModelObject::bake_xy_rotation_into_meshes(), Slic3r::GUI::Selection::get_bounding_box_in_reference_system(), get_matrix_no_scaling_factor(), and Slic3r::GUI::GLGizmoAlignment::reference_basis().

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

◆ reset_skew()

void Slic3r::Geometry::Transformation::reset_skew ( )
631{
632 auto new_scale_factor = [](const Matrix3d& s) {
633 return pow(s(0, 0) * s(1, 1) * s(2, 2), 1. / 3.); // scale average
634 };
635
636 const Geometry::TransformationSVD svd(*this);
637 m_matrix = get_offset_matrix() * Transform3d(svd.u) * scale_transform(new_scale_factor(svd.s)) * Transform3d(svd.v.transpose()) * svd.mirror_matrix();
638}

References get_offset_matrix(), m_matrix, Slic3r::Geometry::TransformationSVD::mirror_matrix(), Slic3r::Geometry::TransformationSVD::s, Slic3r::Geometry::scale_transform(), Slic3r::Geometry::TransformationSVD::u, and Slic3r::Geometry::TransformationSVD::v.

Here is the call graph for this function:

◆ serialize()

template<class Archive>
void Slic3r::Geometry::Transformation::serialize ( Archive & ar)
inlineprivate
505{ ar(m_matrix); }

References m_matrix.

◆ set_matrix()

void Slic3r::Geometry::Transformation::set_matrix ( const Transform3d & transform)
inline
484{ m_matrix = transform; }

References m_matrix, and Slic3r::transform().

Referenced by Slic3r::Geometry::mat_around_a_point_rotate(), Slic3r::GUI::GizmoObjectManipulation::reset_rotation_value(), and volume_to_bed_transformation().

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

◆ set_mirror() [1/2]

void Slic3r::Geometry::Transformation::set_mirror ( Axis axis,
double mirror )
590{
591 double abs_mirror = std::abs(mirror);
592 if (abs_mirror == 0.0)
593 mirror = 1.0;
594 else if (abs_mirror != 1.0)
595 mirror /= abs_mirror;
596
597 auto [rotation, scale] = extract_rotation_scale(m_matrix);
598 const double curr_scale = scale(axis, axis);
599 const double sign = curr_scale * mirror;
600
601 if (sign < 0.0) scale(axis, axis) = -scale(axis, axis);
602
603 const Vec3d offset = get_offset();
604 m_matrix = rotation * scale;
605 m_matrix.translation() = offset;
606}
static std::pair< Transform3d, Transform3d > extract_rotation_scale(const Transform3d &trafo)
Definition Geometry.cpp:432
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582

References Slic3r::Geometry::extract_rotation_scale(), get_offset(), m_matrix, Slic3r::offset(), and scale().

Here is the call graph for this function:

◆ set_mirror() [2/2]

void Slic3r::Geometry::Transformation::set_mirror ( const Vec3d & mirror)
566{
567 Vec3d copy(mirror);
568 const Vec3d abs_mirror = copy.cwiseAbs();
569 for (int i = 0; i < 3; ++i) {
570 if (abs_mirror(i) == 0.0)
571 copy(i) = 1.0;
572 else if (abs_mirror(i) != 1.0)
573 copy(i) /= abs_mirror(i);
574 }
575
576 auto [rotation, scale] = extract_rotation_scale(m_matrix);
577 const Vec3d curr_scales = { scale(0, 0), scale(1, 1), scale(2, 2) };
578 const Vec3d signs = curr_scales.cwiseProduct(copy);
579
580 if (signs[0] < 0.0) scale(0, 0) = -scale(0, 0);
581 if (signs[1] < 0.0) scale(1, 1) = -scale(1, 1);
582 if (signs[2] < 0.0) scale(2, 2) = -scale(2, 2);
583
584 const Vec3d offset = get_offset();
585 m_matrix = rotation * scale;
586 m_matrix.translation() = offset;
587}

References Slic3r::Geometry::extract_rotation_scale(), get_offset(), m_matrix, Slic3r::offset(), and scale().

Referenced by reset_mirror(), and volume_to_bed_transformation().

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

◆ set_offset() [1/2]

void Slic3r::Geometry::Transformation::set_offset ( Axis axis,
double offset )
inline
432{ m_matrix.translation()[axis] = offset; }

References m_matrix, and Slic3r::offset().

Here is the call graph for this function:

◆ set_offset() [2/2]

◆ set_rotation() [1/2]

void Slic3r::Geometry::Transformation::set_rotation ( Axis axis,
double rotation )
499{
500 rotation = angle_to_0_2PI(rotation);
501 if (is_approx(std::abs(rotation), 2.0 * double(PI)))
502 rotation = 0.0;
503
504 auto [curr_rotation, scale] = extract_rotation_scale(m_matrix);
505 Vec3d angles = extract_euler_angles(curr_rotation);
506 angles[axis] = rotation;
507
508 const Vec3d offset = get_offset();
510 m_matrix.translation() = offset;
511}
static constexpr double PI
Definition libslic3r.h:81
T angle_to_0_2PI(T angle)
Definition Geometry.hpp:317
void rotation_transform(Transform3d &transform, const Vec3d &rotation)
Definition Geometry.cpp:359
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320

References Slic3r::Geometry::angle_to_0_2PI(), Slic3r::Geometry::extract_euler_angles(), Slic3r::Geometry::extract_rotation_scale(), get_offset(), Slic3r::is_approx(), m_matrix, Slic3r::offset(), PI, Slic3r::Geometry::rotation_transform(), and scale().

Here is the call graph for this function:

◆ set_rotation() [2/2]

void Slic3r::Geometry::Transformation::set_rotation ( const Vec3d & rotation)
492{
493 const Vec3d offset = get_offset();
495 m_matrix.translation() = offset;
496}

References Slic3r::Geometry::extract_scale(), get_offset(), m_matrix, Slic3r::offset(), and Slic3r::Geometry::rotation_transform().

Referenced by Slic3r::ModelInstance::get_arrange_polygon(), Slic3r::GUI::GLCanvas3D::get_empty_cells(), Slic3r::GUI::GLCanvas3D::update_sequential_clearance(), and volume_to_bed_transformation().

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

◆ set_scaling_factor() [1/2]

void Slic3r::Geometry::Transformation::set_scaling_factor ( Axis axis,
double scaling_factor )
538{
539 assert(scaling_factor > 0.0);
540
541 auto [rotation, scale] = extract_rotation_scale(m_matrix);
542 // Keep a mirror that sits on this axis.
543 scale(axis, axis) = std::copysign(scaling_factor, scale(axis, axis));
544
545 const Vec3d offset = get_offset();
546 m_matrix = rotation * scale;
547 m_matrix.translation() = offset;
548}

References Slic3r::Geometry::extract_rotation_scale(), get_offset(), m_matrix, Slic3r::offset(), and scale().

Here is the call graph for this function:

◆ set_scaling_factor() [2/2]

void Slic3r::Geometry::Transformation::set_scaling_factor ( const Vec3d & scaling_factor)
529{
530 assert(scaling_factor.x() > 0.0 && scaling_factor.y() > 0.0 && scaling_factor.z() > 0.0);
531
532 const Vec3d offset = get_offset();
534 m_matrix.translation() = offset;
535}

References Slic3r::Geometry::extract_rotation_matrix(), get_offset(), m_matrix, Slic3r::offset(), and Slic3r::Geometry::scale_transform().

Referenced by volume_to_bed_transformation().

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

◆ volume_to_bed_transformation()

Transformation Slic3r::Geometry::Transformation::volume_to_bed_transformation ( const Transformation & instance_transformation,
const BoundingBoxf3 & bbox )
static
676{
677 Transformation out;
678
679 if (instance_transformation.is_scaling_uniform()) {
680 // No need to run the non-linear least squares fitting for uniform scaling.
681 // Just set the inverse.
682 out.set_matrix(instance_transformation.get_matrix_no_offset().inverse());
683 }
684 else if (is_rotation_ninety_degrees(instance_transformation.get_rotation())) {
685 // Anisotropic scaling, rotation by multiples of ninety degrees.
686 Eigen::Matrix3d instance_rotation_trafo =
687 (Eigen::AngleAxisd(instance_transformation.get_rotation().z(), Vec3d::UnitZ()) *
688 Eigen::AngleAxisd(instance_transformation.get_rotation().y(), Vec3d::UnitY()) *
689 Eigen::AngleAxisd(instance_transformation.get_rotation().x(), Vec3d::UnitX())).toRotationMatrix();
690 Eigen::Matrix3d volume_rotation_trafo =
691 (Eigen::AngleAxisd(-instance_transformation.get_rotation().x(), Vec3d::UnitX()) *
692 Eigen::AngleAxisd(-instance_transformation.get_rotation().y(), Vec3d::UnitY()) *
693 Eigen::AngleAxisd(-instance_transformation.get_rotation().z(), Vec3d::UnitZ())).toRotationMatrix();
694
695 // 8 corners of the bounding box.
696 auto pts = Eigen::MatrixXd(8, 3);
697 pts(0, 0) = bbox.min.x(); pts(0, 1) = bbox.min.y(); pts(0, 2) = bbox.min.z();
698 pts(1, 0) = bbox.min.x(); pts(1, 1) = bbox.min.y(); pts(1, 2) = bbox.max.z();
699 pts(2, 0) = bbox.min.x(); pts(2, 1) = bbox.max.y(); pts(2, 2) = bbox.min.z();
700 pts(3, 0) = bbox.min.x(); pts(3, 1) = bbox.max.y(); pts(3, 2) = bbox.max.z();
701 pts(4, 0) = bbox.max.x(); pts(4, 1) = bbox.min.y(); pts(4, 2) = bbox.min.z();
702 pts(5, 0) = bbox.max.x(); pts(5, 1) = bbox.min.y(); pts(5, 2) = bbox.max.z();
703 pts(6, 0) = bbox.max.x(); pts(6, 1) = bbox.max.y(); pts(6, 2) = bbox.min.z();
704 pts(7, 0) = bbox.max.x(); pts(7, 1) = bbox.max.y(); pts(7, 2) = bbox.max.z();
705
706 // Corners of the bounding box transformed into the modifier mesh coordinate space, with inverse rotation applied to the modifier.
707 auto qs = (pts *
708 (instance_rotation_trafo *
709 Eigen::Scaling(instance_transformation.get_scaling_factor().cwiseProduct(instance_transformation.get_mirror())) *
710 volume_rotation_trafo).inverse().transpose()).eval();
711 // Fill in scaling based on least squares fitting of the bounding box corners.
712 Vec3d scale;
713 for (int i = 0; i < 3; ++i)
714 scale(i) = pts.col(i).dot(qs.col(i)) / pts.col(i).dot(pts.col(i));
715
716 out.set_rotation(Geometry::extract_euler_angles(volume_rotation_trafo));
717 out.set_scaling_factor(Vec3d(std::abs(scale.x()), std::abs(scale.y()), std::abs(scale.z())));
718 out.set_mirror(Vec3d(scale.x() > 0 ? 1. : -1, scale.y() > 0 ? 1. : -1, scale.z() > 0 ? 1. : -1));
719 }
720 else
721 {
722 // General anisotropic scaling, general rotation.
723 // Keep the modifier mesh in the instance coordinate system, so the modifier mesh will not be aligned with the world.
724 // Scale it to get the required size.
725 out.set_scaling_factor(instance_transformation.get_scaling_factor().cwiseInverse());
726 }
727
728 return out;
729}
bool is_rotation_ninety_degrees(double a)
Definition Geometry.hpp:545

References Transformation(), Slic3r::Geometry::extract_euler_angles(), get_matrix_no_offset(), get_mirror(), get_rotation(), get_scaling_factor(), Slic3r::Geometry::is_rotation_ninety_degrees(), is_scaling_uniform(), Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::max, Slic3r::BoundingBoxBase< PointType, std::vector< PointType > >::min, scale(), set_matrix(), set_mirror(), set_rotation(), and set_scaling_factor().

Referenced by Slic3r::GUI::ObjectList::load_modifier().

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

◆ cereal::access

friend class cereal::access
friend

References cereal::access.

Referenced by cereal::access.

◆ operator!=

bool operator!= ( Transformation const & l,
Transformation const & r )
friend
499 {
500 return !(l == r);
501 }

References Transformation().

◆ operator==

bool operator== ( Transformation const & l,
Transformation const & r )
friend
494 {
495 return l.m_matrix.isApprox(r.m_matrix);
496 }

References Transformation(), and m_matrix.

Member Data Documentation

◆ m_matrix


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Geometry.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Geometry.cpp