From f6911e4660c8315eb01db84cc9f1767c2aec1e1d Mon Sep 17 00:00:00 2001 From: Sebastian Hoogen Date: Tue, 12 Jun 2012 16:54:07 +0200 Subject: [PATCH] Matrix4D::analyse function it returns a textual description of the transformation --- src/Base/Matrix.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ src/Base/Matrix.h | 2 + 2 files changed, 97 insertions(+) diff --git a/src/Base/Matrix.cpp b/src/Base/Matrix.cpp index 4ea9864155..ba936e13f9 100644 --- a/src/Base/Matrix.cpp +++ b/src/Base/Matrix.cpp @@ -691,3 +691,98 @@ void Matrix4D::fromString(const std::string &str) input >> dMtrx4D[i][j]; } } + +// Analyse the a transformation Matrix and describe the transformation +std::string Matrix4D::analyse(void) const +{ + const double eps=1.0e-06; + bool hastranslation = (dMtrx4D[0][3] != 0.0 || + dMtrx4D[1][3] != 0.0 || dMtrx4D[2][3] != 0.0); + const Base::Matrix4D unityMatrix = Base::Matrix4D(); + std::string text; + if (*this == unityMatrix) + { + text = "Unity Matrix"; + } + else + { + if (dMtrx4D[3][0] != 0.0 || dMtrx4D[3][1] != 0.0 || + dMtrx4D[3][2] != 0.0 || dMtrx4D[3][3] != 1.0) + { + text = "Projection"; + } + else //translation and affine + { + if (dMtrx4D[0][1] == 0.0 && dMtrx4D[0][2] == 0.0 && + dMtrx4D[1][0] == 0.0 && dMtrx4D[1][2] == 0.0 && + dMtrx4D[2][0] == 0.0 && dMtrx4D[2][1] == 0.0) //scaling + { + std::ostringstream stringStream; + stringStream << "Scale [" << dMtrx4D[0][0] << ", " << + dMtrx4D[1][1] << ", " << dMtrx4D[2][2] << "]"; + text = stringStream.str(); + } + else + { + Base::Matrix4D sub; + sub[0][0] = dMtrx4D[0][0]; sub[0][1] = dMtrx4D[0][1]; + sub[0][2] = dMtrx4D[0][2]; sub[1][0] = dMtrx4D[1][0]; + sub[1][1] = dMtrx4D[1][1]; sub[1][2] = dMtrx4D[1][2]; + sub[2][0] = dMtrx4D[2][0]; sub[2][1] = dMtrx4D[2][1]; + sub[2][2] = dMtrx4D[2][2]; + + Base::Matrix4D trp = sub; + trp.transpose(); + trp = trp * sub; + bool ortho = true; + for (int i=0; i<4 && ortho; i++) { + for (int j=0; j<4 && ortho; j++) { + if (i != j) { + if (fabs(trp[i][j]) > eps) { + ortho = false; + break; + } + } + } + } + + double determinant = sub.determinant(); + if (ortho) + { + if (fabs(determinant-1.0)