OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Geometry::TransformationSVD Struct Reference

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

Public Member Functions

 TransformationSVD (const Transformation &trafo)
 TransformationSVD (const Transform3d &trafo)
Eigen::DiagonalMatrix< double, 3, 3 > mirror_matrix () const

Public Attributes

Matrix3d u { Matrix3d::Identity() }
Matrix3d s { Matrix3d::Identity() }
Matrix3d v { Matrix3d::Identity() }
bool mirror { false }
bool scale { false }
bool anisotropic_scale { false }
bool rotation { false }
bool rotation_90_degrees { false }
bool skew { false }

Detailed Description

Constructor & Destructor Documentation

◆ TransformationSVD() [1/2]

Slic3r::Geometry::TransformationSVD::TransformationSVD ( const Transformation & trafo)
inlineexplicit
528: TransformationSVD(trafo.get_matrix()) {}
TransformationSVD(const Transformation &trafo)
Definition Geometry.hpp:528

References TransformationSVD().

Referenced by TransformationSVD().

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

◆ TransformationSVD() [2/2]

Slic3r::Geometry::TransformationSVD::TransformationSVD ( const Transform3d & trafo)
explicit
780{
781 const Matrix3d m0 = trafo.matrix().block<3, 3>(0, 0);
782 mirror = m0.determinant() < 0.0;
783
784 Matrix3d m;
785 if (mirror)
786 m = m0 * Eigen::DiagonalMatrix<double, 3, 3>(-1.0, 1.0, 1.0);
787 else
788 m = m0;
789 const Eigen::JacobiSVD<Matrix3d> svd(m, Eigen::ComputeFullU | Eigen::ComputeFullV);
790 u = svd.matrixU();
791 v = svd.matrixV();
792 s = svd.singularValues().asDiagonal();
793
794 scale = !s.isApprox(Matrix3d::Identity());
795 anisotropic_scale = ! is_approx(s(0, 0), s(1, 1)) || ! is_approx(s(1, 1), s(2, 2));
796 rotation = !v.isApprox(u);
797
798 if (anisotropic_scale) {
799 rotation_90_degrees = true;
800 for (int i = 0; i < 3; ++i) {
801 const Vec3d row = v.row(i).cwiseAbs();
802 const size_t num_zeros = is_approx(row[0], 0.) + is_approx(row[1], 0.) + is_approx(row[2], 0.);
803 const size_t num_ones = is_approx(row[0], 1.) + is_approx(row[1], 1.) + is_approx(row[2], 1.);
804 if (num_zeros != 2 || num_ones != 1) {
805 rotation_90_degrees = false;
806 break;
807 }
808 }
809 // Detect skew by brute force: check if the axes are still orthogonal after transformation
810 const Matrix3d trafo_linear = trafo.linear();
811 const std::array<Vec3d, 3> axes = { Vec3d::UnitX(), Vec3d::UnitY(), Vec3d::UnitZ() };
812 std::array<Vec3d, 3> transformed_axes;
813 for (int i = 0; i < 3; ++i) {
814 transformed_axes[i] = trafo_linear * axes[i];
815 }
816 skew = std::abs(transformed_axes[0].dot(transformed_axes[1])) > EPSILON ||
817 std::abs(transformed_axes[1].dot(transformed_axes[2])) > EPSILON ||
818 std::abs(transformed_axes[2].dot(transformed_axes[0])) > EPSILON;
819
820 // This following old code does not work under all conditions. The v matrix can become non diagonal (see SPE-1492)
821// skew = ! rotation_90_degrees;
822 } else
823 skew = false;
824}
#define EPSILON
Definition ColorUtils.cpp:64
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vec3d
Definition Point.hpp:68
constexpr bool is_approx(Number value, Number test_value, Number precision=EPSILON)
Definition libslic3r.h:320
T dot(const boost::geometry::model::d2::point_xy< T > &v1, const boost::geometry::model::d2::point_xy< T > &v2)
Definition ExtrusionSimulator.cpp:154
Eigen::Matrix< double, 3, 3, Eigen::DontAlign > Matrix3d
Definition Point.hpp:86
bool mirror
Definition Geometry.hpp:521
bool rotation
Definition Geometry.hpp:524
Matrix3d v
Definition Geometry.hpp:519
bool anisotropic_scale
Definition Geometry.hpp:523
bool skew
Definition Geometry.hpp:526
bool scale
Definition Geometry.hpp:522
bool rotation_90_degrees
Definition Geometry.hpp:525
Matrix3d u
Definition Geometry.hpp:517
Matrix3d s
Definition Geometry.hpp:518

References anisotropic_scale, Slic3r::dot(), EPSILON, Slic3r::is_approx(), mirror, rotation, rotation_90_degrees, s, scale, skew, u, and v.

Here is the call graph for this function:

Member Function Documentation

◆ mirror_matrix()

Eigen::DiagonalMatrix< double, 3, 3 > Slic3r::Geometry::TransformationSVD::mirror_matrix ( ) const
inline
531{ return Eigen::DiagonalMatrix<double, 3, 3>(this->mirror ? -1. : 1., 1., 1.); }

Referenced by Slic3r::Geometry::Transformation::reset_rotation(), Slic3r::Geometry::Transformation::reset_scaling_factor(), and Slic3r::Geometry::Transformation::reset_skew().

Here is the caller graph for this function:

Member Data Documentation

◆ anisotropic_scale

bool Slic3r::Geometry::TransformationSVD::anisotropic_scale { false }
523{ false };

Referenced by TransformationSVD().

◆ mirror

bool Slic3r::Geometry::TransformationSVD::mirror { false }
521{ false };

Referenced by TransformationSVD().

◆ rotation

bool Slic3r::Geometry::TransformationSVD::rotation { false }
524{ false };

Referenced by TransformationSVD().

◆ rotation_90_degrees

bool Slic3r::Geometry::TransformationSVD::rotation_90_degrees { false }
525{ false };

Referenced by TransformationSVD().

◆ s

Matrix3d Slic3r::Geometry::TransformationSVD::s { Matrix3d::Identity() }

◆ scale

bool Slic3r::Geometry::TransformationSVD::scale { false }
522{ false };

Referenced by TransformationSVD().

◆ skew

bool Slic3r::Geometry::TransformationSVD::skew { false }
526{ false };

Referenced by TransformationSVD().

◆ u

Matrix3d Slic3r::Geometry::TransformationSVD::u { Matrix3d::Identity() }

◆ v


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