From 5aa8d8e748cb8fb25466d18c96f6185a112dd9f1 Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Thu, 18 Jul 2019 18:59:17 +0200 Subject: [PATCH] shift indices, set from 0 --- xs/src/libslic3r/IO/TMF.cpp | 38 +++---- xs/src/libslic3r/TransformationMatrix.cpp | 122 +++++++++++----------- xs/src/libslic3r/TransformationMatrix.hpp | 12 +-- xs/src/libslic3r/TriangleMesh.cpp | 6 +- xs/t/25_transformationmatrix.t | 6 +- xs/xsp/TransformationMatrix.xsp | 58 +++++----- 6 files changed, 121 insertions(+), 121 deletions(-) diff --git a/xs/src/libslic3r/IO/TMF.cpp b/xs/src/libslic3r/IO/TMF.cpp index 6aa8a680e..4f3319a3c 100644 --- a/xs/src/libslic3r/IO/TMF.cpp +++ b/xs/src/libslic3r/IO/TMF.cpp @@ -250,18 +250,18 @@ TMFEditor::write_build(boost::nowide::ofstream& fout) // Add the transform fout << " transform=\"" + << trafo.m00 << " " + << trafo.m10 << " " + << trafo.m20 << " " + << trafo.m01 << " " << trafo.m11 << " " << trafo.m21 << " " - << trafo.m31 << " " + << trafo.m02 << " " << trafo.m12 << " " << trafo.m22 << " " - << trafo.m32 << " " + << trafo.m03 << " " << trafo.m13 << " " - << trafo.m23 << " " - << trafo.m33 << " " - << trafo.m14 << " " - << trafo.m24 << " " - << trafo.m34 + << trafo.m23 << "\"/>\n"; } @@ -728,18 +728,18 @@ TMFParserContext::get_transformations(std::string matrix, TransformationMatrix & // matrices in 3mf is row-major for row-vectors multiplied from the left, // so we have to transpose the matrix - trafo.m11 = m[0]; - trafo.m21 = m[1]; - trafo.m31 = m[2]; - trafo.m12 = m[3]; - trafo.m22 = m[4]; - trafo.m32 = m[5]; - trafo.m13 = m[6]; - trafo.m23 = m[7]; - trafo.m33 = m[8]; - trafo.m14 = m[9]; - trafo.m24 = m[10]; - trafo.m34 = m[11]; + trafo.m00 = m[0]; + trafo.m10 = m[1]; + trafo.m20 = m[2]; + trafo.m01 = m[3]; + trafo.m11 = m[4]; + trafo.m21 = m[5]; + trafo.m02 = m[6]; + trafo.m12 = m[7]; + trafo.m22 = m[8]; + trafo.m03 = m[9]; + trafo.m13 = m[10]; + trafo.m23 = m[11]; if (transformations) { diff --git a/xs/src/libslic3r/TransformationMatrix.cpp b/xs/src/libslic3r/TransformationMatrix.cpp index 155b77759..cca9b3fec 100644 --- a/xs/src/libslic3r/TransformationMatrix.cpp +++ b/xs/src/libslic3r/TransformationMatrix.cpp @@ -5,19 +5,19 @@ namespace Slic3r { TransformationMatrix::TransformationMatrix() - : m11(1.0), m12(0.0), m13(0.0), m14(0.0), - m21(0.0), m22(1.0), m23(0.0), m24(0.0), - m31(0.0), m32(0.0), m33(1.0), m34(0.0) + : m00(1.0), m01(0.0), m02(0.0), m03(0.0), + m10(0.0), m11(1.0), m12(0.0), m13(0.0), + m20(0.0), m21(0.0), m22(1.0), m23(0.0) { } TransformationMatrix::TransformationMatrix( - double _m11, double _m12, double _m13, double _m14, - double _m21, double _m22, double _m23, double _m24, - double _m31, double _m32, double _m33, double _m34) - : m11(_m11), m12(_m12), m13(_m13), m14(_m14), - m21(_m21), m22(_m22), m23(_m23), m24(_m24), - m31(_m31), m32(_m32), m33(_m33), m34(_m34) + double _m00, double _m01, double _m02, double _m03, + double _m10, double _m11, double _m12, double _m13, + double _m20, double _m21, double _m22, double _m23) + : m00(_m00), m01(_m01), m02(_m02), m03(_m03), + m10(_m10), m11(_m11), m12(_m12), m13(_m13), + m20(_m20), m21(_m21), m22(_m22), m23(_m23) { } @@ -29,16 +29,16 @@ TransformationMatrix::TransformationMatrix(const std::vector &entries_ro CONFESS("Invalid number of entries when initalizing TransformationMatrix. Vector length must be 12."); return; } - m11 = entries_row_maj[0]; m12 = entries_row_maj[1]; m13 = entries_row_maj[2]; m14 = entries_row_maj[3]; - m21 = entries_row_maj[4]; m22 = entries_row_maj[5]; m23 = entries_row_maj[6]; m24 = entries_row_maj[7]; - m31 = entries_row_maj[8]; m32 = entries_row_maj[9]; m33 = entries_row_maj[10]; m34 = entries_row_maj[11]; + m00 = entries_row_maj[0]; m01 = entries_row_maj[1]; m02 = entries_row_maj[2]; m03 = entries_row_maj[3]; + m10 = entries_row_maj[4]; m11 = entries_row_maj[5]; m12 = entries_row_maj[6]; m13 = entries_row_maj[7]; + m20 = entries_row_maj[8]; m21 = entries_row_maj[9]; m22 = entries_row_maj[10]; m23 = entries_row_maj[11]; } TransformationMatrix::TransformationMatrix(const TransformationMatrix &other) { - this->m11 = other.m11; this->m12 = other.m12; this->m13 = other.m13; this->m14 = other.m14; - this->m21 = other.m21; this->m22 = other.m22; this->m23 = other.m23; this->m24 = other.m24; - this->m31 = other.m31; this->m32 = other.m32; this->m33 = other.m33; this->m34 = other.m34; + this->m00 = other.m00; this->m01 = other.m01; this->m02 = other.m02; this->m03 = other.m03; + this->m10 = other.m10; this->m11 = other.m11; this->m12 = other.m12; this->m13 = other.m13; + this->m20 = other.m20; this->m21 = other.m21; this->m22 = other.m22; this->m23 = other.m23; } TransformationMatrix& TransformationMatrix::operator= (TransformationMatrix other) @@ -49,30 +49,30 @@ TransformationMatrix& TransformationMatrix::operator= (TransformationMatrix othe void TransformationMatrix::swap(TransformationMatrix &other) { - std::swap(this->m11, other.m11); std::swap(this->m12, other.m12); - std::swap(this->m13, other.m13); std::swap(this->m14, other.m14); - std::swap(this->m21, other.m21); std::swap(this->m22, other.m22); - std::swap(this->m23, other.m23); std::swap(this->m24, other.m24); - std::swap(this->m31, other.m31); std::swap(this->m32, other.m32); - std::swap(this->m33, other.m33); std::swap(this->m34, other.m34); + std::swap(this->m00, other.m00); std::swap(this->m01, other.m01); + std::swap(this->m02, other.m02); std::swap(this->m03, other.m03); + std::swap(this->m10, other.m10); std::swap(this->m11, other.m11); + std::swap(this->m12, other.m12); std::swap(this->m13, other.m13); + std::swap(this->m20, other.m20); std::swap(this->m21, other.m21); + std::swap(this->m22, other.m22); std::swap(this->m23, other.m23); } bool TransformationMatrix::operator==(const TransformationMatrix &other) const { double const eps = EPSILON; bool is_equal = true; + is_equal &= (abs(this->m00 - other.m00) < eps); + is_equal &= (abs(this->m01 - other.m01) < eps); + is_equal &= (abs(this->m02 - other.m02) < eps); + is_equal &= (abs(this->m03 - other.m03) < eps); + is_equal &= (abs(this->m10 - other.m10) < eps); is_equal &= (abs(this->m11 - other.m11) < eps); is_equal &= (abs(this->m12 - other.m12) < eps); is_equal &= (abs(this->m13 - other.m13) < eps); - is_equal &= (abs(this->m14 - other.m14) < eps); + is_equal &= (abs(this->m20 - other.m20) < eps); is_equal &= (abs(this->m21 - other.m21) < eps); is_equal &= (abs(this->m22 - other.m22) < eps); is_equal &= (abs(this->m23 - other.m23) < eps); - is_equal &= (abs(this->m24 - other.m24) < eps); - is_equal &= (abs(this->m31 - other.m31) < eps); - is_equal &= (abs(this->m32 - other.m32) < eps); - is_equal &= (abs(this->m33 - other.m33) < eps); - is_equal &= (abs(this->m34 - other.m34) < eps); return is_equal; } @@ -80,18 +80,18 @@ std::vector TransformationMatrix::matrix3x4f() const { std::vector out_arr(0); out_arr.reserve(12); + out_arr.push_back(this->m00); + out_arr.push_back(this->m01); + out_arr.push_back(this->m02); + out_arr.push_back(this->m03); + out_arr.push_back(this->m10); out_arr.push_back(this->m11); out_arr.push_back(this->m12); out_arr.push_back(this->m13); - out_arr.push_back(this->m14); + out_arr.push_back(this->m20); out_arr.push_back(this->m21); out_arr.push_back(this->m22); out_arr.push_back(this->m23); - out_arr.push_back(this->m24); - out_arr.push_back(this->m31); - out_arr.push_back(this->m32); - out_arr.push_back(this->m33); - out_arr.push_back(this->m34); return out_arr; } @@ -99,7 +99,7 @@ double TransformationMatrix::determinante() const { // translation elements don't influence the determinante // because of the 0s on the other side of main diagonal - return m11*(m22*m33 - m23*m32) - m12*(m21*m33 - m23*m31) + m13*(m21*m32 - m31*m22); + return m00*(m11*m22 - m12*m21) - m01*(m10*m22 - m12*m20) + m02*(m10*m21 - m20*m11); } TransformationMatrix TransformationMatrix::inverse() const @@ -116,19 +116,19 @@ TransformationMatrix TransformationMatrix::inverse() const TransformationMatrix inverse; - inverse.m11 = fac * (this->m22 * this->m33 - this->m23 * this->m32); - inverse.m12 = fac * (this->m13 * this->m32 - this->m12 * this->m33); - inverse.m13 = fac * (this->m12 * this->m23 - this->m13 * this->m22); - inverse.m21 = fac * (this->m23 * this->m31 - this->m21 * this->m33); - inverse.m22 = fac * (this->m11 * this->m33 - this->m13 * this->m31); - inverse.m23 = fac * (this->m13 * this->m21 - this->m11 * this->m23); - inverse.m31 = fac * (this->m21 * this->m32 - this->m22 * this->m31); - inverse.m32 = fac * (this->m12 * this->m31 - this->m11 * this->m32); - inverse.m33 = fac * (this->m11 * this->m22 - this->m12 * this->m21); + inverse.m00 = fac * (this->m11 * this->m22 - this->m12 * this->m21); + inverse.m01 = fac * (this->m02 * this->m21 - this->m01 * this->m22); + inverse.m02 = fac * (this->m01 * this->m12 - this->m02 * this->m11); + inverse.m10 = fac * (this->m12 * this->m20 - this->m10 * this->m22); + inverse.m11 = fac * (this->m00 * this->m22 - this->m02 * this->m20); + inverse.m12 = fac * (this->m02 * this->m10 - this->m00 * this->m12); + inverse.m20 = fac * (this->m10 * this->m21 - this->m11 * this->m20); + inverse.m21 = fac * (this->m01 * this->m20 - this->m00 * this->m21); + inverse.m22 = fac * (this->m00 * this->m11 - this->m01 * this->m10); - inverse.m14 = -(inverse.m11 * this->m14 + inverse.m12 * this->m24 + inverse.m13 * this->m34); - inverse.m24 = -(inverse.m21 * this->m14 + inverse.m22 * this->m24 + inverse.m23 * this->m34); - inverse.m34 = -(inverse.m31 * this->m14 + inverse.m32 * this->m24 + inverse.m33 * this->m34); + inverse.m03 = -(inverse.m00 * this->m03 + inverse.m01 * this->m13 + inverse.m02 * this->m23); + inverse.m13 = -(inverse.m10 * this->m03 + inverse.m11 * this->m13 + inverse.m12 * this->m23); + inverse.m23 = -(inverse.m20 * this->m03 + inverse.m21 * this->m13 + inverse.m22 * this->m23); return inverse; } @@ -159,20 +159,20 @@ TransformationMatrix TransformationMatrix::multiply(const TransformationMatrix & { TransformationMatrix trafo; - trafo.m11 = left.m11*right.m11 + left.m12*right.m21 + left.m13*right.m31; - trafo.m12 = left.m11*right.m12 + left.m12*right.m22 + left.m13*right.m32; - trafo.m13 = left.m11*right.m13 + left.m12*right.m23 + left.m13*right.m33; - trafo.m14 = left.m11*right.m14 + left.m12*right.m24 + left.m13*right.m34 + left.m14; + trafo.m00 = left.m00*right.m00 + left.m01*right.m10 + left.m02*right.m20; + trafo.m01 = left.m00*right.m01 + left.m01*right.m11 + left.m02*right.m21; + trafo.m02 = left.m00*right.m02 + left.m01*right.m12 + left.m02*right.m22; + trafo.m03 = left.m00*right.m03 + left.m01*right.m13 + left.m02*right.m23 + left.m03; - trafo.m21 = left.m21*right.m11 + left.m22*right.m21 + left.m23*right.m31; - trafo.m22 = left.m21*right.m12 + left.m22*right.m22 + left.m23*right.m32; - trafo.m23 = left.m21*right.m13 + left.m22*right.m23 + left.m23*right.m33; - trafo.m24 = left.m21*right.m14 + left.m22*right.m24 + left.m23*right.m34 + left.m24; + trafo.m10 = left.m10*right.m00 + left.m11*right.m10 + left.m12*right.m20; + trafo.m11 = left.m10*right.m01 + left.m11*right.m11 + left.m12*right.m21; + trafo.m12 = left.m10*right.m02 + left.m11*right.m12 + left.m12*right.m22; + trafo.m13 = left.m10*right.m03 + left.m11*right.m13 + left.m12*right.m23 + left.m13; - trafo.m31 = left.m31*right.m11 + left.m32*right.m21 + left.m33*right.m31; - trafo.m32 = left.m31*right.m12 + left.m32*right.m22 + left.m33*right.m32; - trafo.m33 = left.m31*right.m13 + left.m32*right.m23 + left.m33*right.m33; - trafo.m34 = left.m31*right.m14 + left.m32*right.m24 + left.m33*right.m34 + left.m34; + trafo.m20 = left.m20*right.m00 + left.m21*right.m10 + left.m22*right.m20; + trafo.m21 = left.m20*right.m01 + left.m21*right.m11 + left.m22*right.m21; + trafo.m22 = left.m20*right.m02 + left.m21*right.m12 + left.m22*right.m22; + trafo.m23 = left.m20*right.m03 + left.m21*right.m13 + left.m22*right.m23 + left.m23; return trafo; } @@ -347,13 +347,13 @@ TransformationMatrix TransformationMatrix::mat_mirror(const Axis &axis) switch (axis) { case X: - mat.m11 = -1.0; + mat.m00 = -1.0; break; case Y: - mat.m22 = -1.0; + mat.m11 = -1.0; break; case Z: - mat.m33 = -1.0; + mat.m22 = -1.0; break; default: CONFESS("Invalid Axis supplied to TransformationMatrix::mat_mirror"); diff --git a/xs/src/libslic3r/TransformationMatrix.hpp b/xs/src/libslic3r/TransformationMatrix.hpp index 28401041f..a6b6bfa76 100644 --- a/xs/src/libslic3r/TransformationMatrix.hpp +++ b/xs/src/libslic3r/TransformationMatrix.hpp @@ -23,9 +23,9 @@ namespace Slic3r { and direction vectors lying in hyperplane w=0 Using this, affine transformations (scaling, rotating, shearing, translating and their combinations) - can be represented as 4x4 Matri. + can be represented as 4x4 Matrix. The 4th row equals [0 0 0 1] in order to not alter the w component. - The other entries are represented by the class properties mij (i-th row [1,2,3], j-th column [1,2,3,4]). + The other entries are represented by the class properties mij (i-th row [0,1,2], j-th column [0,1,2,3]). The 4th row is not explicitly stored, it is hard coded in the multiply function. Column vectors have to be multiplied from the right side. @@ -41,9 +41,9 @@ public: TransformationMatrix(const std::vector &entries_row_maj); TransformationMatrix( - double m11, double m12, double m13, double m14, - double m21, double m22, double m23, double m24, - double m31, double m32, double m33, double m34); + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23); TransformationMatrix(const TransformationMatrix &other); TransformationMatrix& operator= (TransformationMatrix other); @@ -53,7 +53,7 @@ public: bool operator!= (const TransformationMatrix &other) const { return !(*this == other); }; /// matrix entries - double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34; + double m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23; /// return the row-major form of the represented transformation matrix /// for admesh transform diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 45f9cdbab..ff3b17758 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -704,9 +704,9 @@ TriangleMesh::get_transformed_bounding_box(TransformationMatrix const & trafo) c double v_y = facet.vertex[j].y; double v_z = facet.vertex[j].z; Pointf3 poi; - poi.x = float(trafo.m11*v_x + trafo.m12*v_y + trafo.m13*v_z + trafo.m14); - poi.y = float(trafo.m21*v_x + trafo.m22*v_y + trafo.m23*v_z + trafo.m24); - poi.z = float(trafo.m31*v_x + trafo.m32*v_y + trafo.m33*v_z + trafo.m34); + poi.x = float(trafo.m00*v_x + trafo.m01*v_y + trafo.m02*v_z + trafo.m03); + poi.y = float(trafo.m10*v_x + trafo.m11*v_y + trafo.m12*v_z + trafo.m13); + poi.z = float(trafo.m20*v_x + trafo.m21*v_y + trafo.m22*v_z + trafo.m23); bbox.merge(poi); } } diff --git a/xs/t/25_transformationmatrix.t b/xs/t/25_transformationmatrix.t index fcc45390b..f81203e16 100644 --- a/xs/t/25_transformationmatrix.t +++ b/xs/t/25_transformationmatrix.t @@ -134,9 +134,9 @@ sub multiply_point { } my $ret = Slic3r::Pointf3->new; - $ret->set_x($trafo->m11()*$x + $trafo->m12()*$y + $trafo->m13()*$z + $trafo->m14()); - $ret->set_y($trafo->m21()*$x + $trafo->m22()*$y + $trafo->m23()*$z + $trafo->m24()); - $ret->set_z($trafo->m31()*$x + $trafo->m32()*$y + $trafo->m33()*$z + $trafo->m34()); + $ret->set_x($trafo->m00()*$x + $trafo->m01()*$y + $trafo->m02()*$z + $trafo->m03()); + $ret->set_y($trafo->m10()*$x + $trafo->m11()*$y + $trafo->m12()*$z + $trafo->m13()); + $ret->set_z($trafo->m20()*$x + $trafo->m21()*$y + $trafo->m22()*$z + $trafo->m23()); return $ret } diff --git a/xs/xsp/TransformationMatrix.xsp b/xs/xsp/TransformationMatrix.xsp index 0a5be7134..bfd7ac1d4 100644 --- a/xs/xsp/TransformationMatrix.xsp +++ b/xs/xsp/TransformationMatrix.xsp @@ -32,6 +32,27 @@ double determinante(); + double m00() + %code%{ RETVAL = THIS->m00; %}; + void set_m00(double value) + %code%{ THIS->m00 = value; %}; + double m01() + %code%{ RETVAL = THIS->m01; %}; + void set_m01(double value) + %code%{ THIS->m01 = value; %}; + double m02() + %code%{ RETVAL = THIS->m02; %}; + void set_m02(double value) + %code%{ THIS->m02 = value; %}; + double m03() + %code%{ RETVAL = THIS->m03; %}; + void set_m03(double value) + %code%{ THIS->m03 = value; %}; + + double m10() + %code%{ RETVAL = THIS->m10; %}; + void set_m10(double value) + %code%{ THIS->m10 = value; %}; double m11() %code%{ RETVAL = THIS->m11; %}; void set_m11(double value) @@ -44,11 +65,11 @@ %code%{ RETVAL = THIS->m13; %}; void set_m13(double value) %code%{ THIS->m13 = value; %}; - double m14() - %code%{ RETVAL = THIS->m14; %}; - void set_m14(double value) - %code%{ THIS->m14 = value; %}; + double m20() + %code%{ RETVAL = THIS->m20; %}; + void set_m20(double value) + %code%{ THIS->m20 = value; %}; double m21() %code%{ RETVAL = THIS->m21; %}; void set_m21(double value) @@ -61,33 +82,12 @@ %code%{ RETVAL = THIS->m23; %}; void set_m23(double value) %code%{ THIS->m23 = value; %}; - double m24() - %code%{ RETVAL = THIS->m24; %}; - void set_m24(double value) - %code%{ THIS->m24 = value; %}; - - double m31() - %code%{ RETVAL = THIS->m31; %}; - void set_m31(double value) - %code%{ THIS->m31 = value; %}; - double m32() - %code%{ RETVAL = THIS->m32; %}; - void set_m32(double value) - %code%{ THIS->m32 = value; %}; - double m33() - %code%{ RETVAL = THIS->m33; %}; - void set_m33(double value) - %code%{ THIS->m33 = value; %}; - double m34() - %code%{ RETVAL = THIS->m34; %}; - void set_m34(double value) - %code%{ THIS->m34 = value; %}; void set_elements( - double m11, double m12, double m13, double m14, - double m21, double m22, double m23, double m24, - double m31, double m32, double m33, double m34) - %code{% *THIS = TransformationMatrix(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34); %}; + double m00, double m01, double m02, double m03, + double m10, double m11, double m12, double m13, + double m20, double m21, double m22, double m23) + %code{% *THIS = TransformationMatrix(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23); %}; void set_eye() %code{% *THIS = TransformationMatrix::mat_eye(); %};