From dcf83706a16cd9373038667325e5acd0d7a6df9f Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Sun, 26 May 2019 15:04:45 +0200 Subject: [PATCH] comments and floating type adaptation --- xs/src/libslic3r/TransformationMatrix.cpp | 28 ++++++---- xs/src/libslic3r/TransformationMatrix.hpp | 65 ++++++++++++----------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/xs/src/libslic3r/TransformationMatrix.cpp b/xs/src/libslic3r/TransformationMatrix.cpp index 50d5273fb..d1539ad93 100644 --- a/xs/src/libslic3r/TransformationMatrix.cpp +++ b/xs/src/libslic3r/TransformationMatrix.cpp @@ -117,9 +117,15 @@ void TransformationMatrix::translate(double x, double y, double z) this->applyLeft(mat); } -void TransformationMatrix::translateXY(Slic3r::Pointf position) +void TransformationMatrix::translate(Vectorf3 vector) { - TransformationMatrix mat = mat_translation(position.x, position.y, 0.0); + TransformationMatrix mat = mat_translation(x, y, z); + this->applyLeft(mat); +} + +void TransformationMatrix::translateXY(Vectorf vector) +{ + TransformationMatrix mat = mat_translation(vector.x, vector.y, 0.0); this->applyLeft(mat); } @@ -140,7 +146,7 @@ void TransformationMatrix::mirror(const Axis &axis) this->applyLeft(mat); } -void TransformationMatrix::mirror(const Pointf3 & normal) +void TransformationMatrix::mirror(const Vectorf3 & normal) { TransformationMatrix mat = mat_mirror(normal); this->applyLeft(mat); @@ -152,7 +158,7 @@ void TransformationMatrix::rotate(double angle_rad, const Axis & axis) this->applyLeft(mat); } -void TransformationMatrix::rotate(double angle_rad, const Pointf3 & axis) +void TransformationMatrix::rotate(double angle_rad, const Vectorf3 & axis) { TransformationMatrix mat = mat_rotation(angle_rad, axis); this->applyLeft(mat); @@ -285,7 +291,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(double q1, double q2, do 2.0 * (q1*q3 - q2*q4), 2.0 * (q2*q3 + q1*q4), 1.0 - 2.0 * (q1*q1 + q2*q2), 0.0); } -TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Pointf3 &axis) +TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Vectorf3 &axis) { double s, factor, q1, q2, q3, q4; s = sin(angle_rad/2); @@ -298,7 +304,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const return mat_rotation(q1, q2, q3, q4); } -TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 target) +TransformationMatrix TransformationMatrix::mat_rotation(Vectorf3 origin, Vectorf3 target) { // TODO: there is a lot of float <-> double conversion going on here @@ -322,7 +328,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 rec_length = 1.0 / sqrt(length_sq); target.scale(rec_length); - Pointf3 cross; + Vectorf3 cross; cross.x = origin.y*target.z - origin.z*target.y; cross.y = origin.z*target.x - origin.x*target.z; cross.z = origin.x*target.y - origin.y*target.x; @@ -336,20 +342,20 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 } else { - Pointf3 help; + Vectorf3 help; // make help garanteed not colinear if (abs(abs(origin.x) - 1) < 0.02) help.z = 1.0; // origin mainly in x direction else help.x = 1.0; - Pointf3 proj = Pointf3(origin); + Vectorf3 proj = origin; // projection of axis onto unit vector origin dot = origin.x*help.x + origin.y*help.y + origin.z*help.z; proj.scale(dot); // help - proj is normal to origin -> rotation axis - Pointf3 axis = (Pointf3)proj.vector_to(help); + Vectorf3 axis = ((Pointf3)proj).vector_to((Pointf3)help); // axis is not unit length -> gets normalized in called function return mat_rotation(PI, axis); @@ -387,7 +393,7 @@ TransformationMatrix TransformationMatrix::mat_mirror(const Axis &axis) return mat; } -TransformationMatrix TransformationMatrix::mat_mirror(const Pointf3 &normal) +TransformationMatrix TransformationMatrix::mat_mirror(const Vectorf3 &normal) { // Kov�cs, E. Rotation about arbitrary axis and reflection through an arbitrary plane, Annales Mathematicae // et Informaticae, Vol 40 (2012) pp 175-186 diff --git a/xs/src/libslic3r/TransformationMatrix.hpp b/xs/src/libslic3r/TransformationMatrix.hpp index 8c80ef58e..1ef910ad2 100644 --- a/xs/src/libslic3r/TransformationMatrix.hpp +++ b/xs/src/libslic3r/TransformationMatrix.hpp @@ -25,85 +25,86 @@ public: /// matrix entries double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34; - /// Return the row-major form of the represented transformation matrix + /// return the row-major form of the represented transformation matrix /// for admesh transform std::vector matrix3x4f() const; - /// Return the determinante of the matrix + /// return the determinante of the matrix double determinante() const; - /// Returns the inverse of the matrix + /// returns the inverse of the matrix bool inverse(TransformationMatrix &inverse) const; - /// Perform Translation + /// performs translation void translate(double x, double y, double z); - void translateXY(Slic3r::Pointf position); + void translate(Vectorf3 vector); + void translateXY(Vectorf vector); - /// Perform uniform scale + /// performs uniform scale void scale(double factor); - /// Perform per-axis scale + /// performs per-axis scale void scale(double x, double y, double z); - /// Perform mirroring along given axis + /// performs mirroring along given axis void mirror(const Axis &axis); - /// Perform mirroring along given axis - void mirror(const Pointf3 &normal); + /// performs mirroring along given axis + void mirror(const Vectorf3 &normal); - /// Perform rotation around given axis + /// performs rotation around given axis void rotate(double angle_rad, const Axis &axis); - /// Perform rotation around arbitrary axis - void rotate(double angle_rad, const Pointf3 &axis); + /// performs rotation around arbitrary axis + void rotate(double angle_rad, const Vectorf3 &axis); - /// Perform rotation defined by unit quaternion + /// performs rotation defined by unit quaternion void rotate(double q1, double q2, double q3, double q4); - /// Multiplies the Parameter-Matrix from the left (this=left*this) + /// multiplies the parameter-matrix from the left (this=left*this) void applyLeft(const TransformationMatrix &left); - /// Multiplies the Parameter-Matrix from the left (out=left*this) + /// multiplies the parameter-matrix from the left (out=left*this) TransformationMatrix multiplyLeft(const TransformationMatrix &left); - /// Multiplies the Parameter-Matrix from the right (this=this*right) + /// multiplies the parameter-matrix from the right (this=this*right) void applyRight(const TransformationMatrix &right); - /// Multiplies the Parameter-Matrix from the right (out=this*right) + /// multiplies the parameter-matrix from the right (out=this*right) TransformationMatrix multiplyRight(const TransformationMatrix &right); - /// Generate an eye matrix. + /// generates an eye matrix. static TransformationMatrix mat_eye(); - /// Generate a per axis scaling matrix + /// generates a per axis scaling matrix static TransformationMatrix mat_scale(double x, double y, double z); - /// Generate a uniform scaling matrix + /// generates an uniform scaling matrix static TransformationMatrix mat_scale(double scale); - /// Generate a reflection matrix by coordinate axis + /// generates a reflection matrix by coordinate axis static TransformationMatrix mat_mirror(const Axis &axis); - /// Generate a reflection matrix by arbitrary vector - static TransformationMatrix mat_mirror(const Pointf3 &normal); + /// generates a reflection matrix by arbitrary vector + static TransformationMatrix mat_mirror(const Vectorf3 &normal); - /// Generate a translation matrix + /// generates a translation matrix static TransformationMatrix mat_translation(double x, double y, double z); - /// Generate a rotation matrix around coodinate axis + /// generates a rotation matrix around coodinate axis static TransformationMatrix mat_rotation(double angle_rad, const Axis &axis); - /// Generate a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4 + /// generates a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4 static TransformationMatrix mat_rotation(double q1, double q2, double q3, double q4); - /// Generate a rotation matrix around arbitrary axis - static TransformationMatrix mat_rotation(double angle_rad, const Pointf3 &axis); + /// generates a rotation matrix around arbitrary axis + static TransformationMatrix mat_rotation(double angle_rad, const Vectorf3 &axis); - /// Generate a rotation matrix by specifying a vector (origin) that is to be rotated + /// generates a rotation matrix by specifying a vector (origin) that is to be rotated /// to be colinear with another vector (target) - static TransformationMatrix mat_rotation(Pointf3 origin, Pointf3 target); + static TransformationMatrix mat_rotation(Vectorf3 origin, Vectorf3 target); - /// Performs a matrix multiplication + /// performs a matrix multiplication static TransformationMatrix multiply(const TransformationMatrix &left, const TransformationMatrix &right); };