Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

hugin-cvs

 [Hugin-cvs] SF.net SVN: hugin: [2159] hugin/branches/ippei/src/hugin_base/hugin_math From: - 2007-06-25 17:00:56 ```Revision: 2159 http://hugin.svn.sourceforge.net/hugin/?rev=2159&view=rev Author: ippei Date: 2007-06-25 10:00:51 -0700 (Mon, 25 Jun 2007) Log Message: ----------- tomorrow from hugin_math Modified Paths: -------------- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h hugin/branches/ippei/src/hugin_base/hugin_math/math.h Modified: hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h 2007-06-25 16:38:25 UTC (rev 2158) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h 2007-06-25 17:00:51 UTC (rev 2159) @@ -24,14 +24,15 @@ #ifndef _HUGIN_MATH_MATRIX3_H_ #define _HUGIN_MATH_MATRIX3_H_ -#include "common/Vector3.h" +#include "hugin_math/Vector3.h" +// [TODO] methods to a cpp file. + /** general : Matrix3 is a class for handling 3x3 Matrix manipulation. * * We do not use 4x4 matrix for view point changement as the calculus could be inefficent * (some of the coefficients are null, m14 = m24 = m34 = 0 et m44 = 1.0 always). */ - class Matrix3 { public: @@ -112,9 +113,10 @@ } #endif - // Ippei note: Why the hell is this a method of general Matrix3 class? + + // [Ippei note]: Why the hell is this a method of general Matrix3 class? // Should be subclassed or externally provided - // eg. static Matrix3 RotationMatrixPT::makeRotationPT(double yaw, double pitch, double roll) + // eg. static Matrix3 RotationMatrixPT::makeRotationMatrixPT(double yaw, double pitch, double roll) /** set rotation in panotools style, * code adapted from Panotools-Script by Bruno Postle Modified: hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h 2007-06-25 16:38:25 UTC (rev 2158) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h 2007-06-25 17:00:51 UTC (rev 2159) @@ -21,6 +21,8 @@ * */ +// [TODO] methods to a cpp file + #ifndef _HUGIN_MATH_VECTOR3_H_ #define _HUGIN_MATH_VECTOR3_H_ Modified: hugin/branches/ippei/src/hugin_base/hugin_math/math.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/math.h 2007-06-25 16:38:25 UTC (rev 2158) +++ hugin/branches/ippei/src/hugin_base/hugin_math/math.h 2007-06-25 17:00:51 UTC (rev 2159) @@ -50,14 +50,14 @@ namespace hugin_utils { - inline double round(double x); + inline double round(double x); // do we need this? inline double round(double x) { return floor(x+0.5); } - inline float roundf(float x); + inline float roundf(float x); // do we need this? inline float roundf(float x) { @@ -74,6 +74,8 @@ return (int) floor(x); } + + template inline int roundi(T x) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Hugin-cvs] SF.net SVN: hugin: [2162] hugin/branches/ippei/src/hugin_base/hugin_math From: - 2007-06-26 12:15:42 ```Revision: 2162 http://hugin.svn.sourceforge.net/hugin/?rev=2162&view=rev Author: ippei Date: 2007-06-26 05:15:32 -0700 (Tue, 26 Jun 2007) Log Message: ----------- hugin_math clean up complete and compiles okay Modified Paths: -------------- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h Added Paths: ----------- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.cpp hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.cpp hugin/branches/ippei/src/hugin_base/hugin_math/hugin_math.h Removed Paths: ------------- hugin/branches/ippei/src/hugin_base/hugin_math/math.h Added: hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.cpp =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.cpp (rev 0) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.cpp 2007-06-26 12:15:32 UTC (rev 2162) @@ -0,0 +1,311 @@ +// -*- c-basic-offset: 4 -*- +/** @file Matrix3.h + * + * @author Alexandre Jenny + * + * \$Id: Matrix3.h 1769 2006-12-20 00:42:16Z dangelo \$ + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "Matrix3.h" + +/** default constructor : initialise to zero */ +Matrix3::Matrix3() { + for (int i=0; i<3; i++) + for (int j=0; j<3; j++) + m[i][j] = 0.0; +} + +/** copy constructor */ +Matrix3::Matrix3(const Matrix3& ot) +{ + (*this) = ot; // call copy operator +} + +/** Set the identity matrix */ +void Matrix3::SetIdentity() +{ + m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; + m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; + m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; +} + +/** Set the matrice to rotation using yaw, pitch, roll angle */ +void Matrix3::SetRotation( double Yaw, double Pitch, double Roll ) +{ + double SR = sin(Roll), + SP = sin(Pitch), + SY = sin(Yaw), + CR = cos(Roll), + CP = cos(Pitch), + CY = cos(Yaw); + + m[0][0] = CP * CY; + m[0][1] = CP * SY; + m[0][2] = SP; + + m[1][0] = SR * SP * CY - CR * SY; + m[1][1] = SR * SP * SY + CR * CY; + m[1][2] = - SR * CP; + + m[2][0] = -( CR * SP * CY + SR * SY ); + m[2][1] = CY * SR - CR * SP * SY; + m[2][2] = CR * CP; +} + +#if 0 +/** Set the matrice to rotation using yaw, pitch, roll angle, panotools style, + * copied from Panotools-Script by Bruno Postle + */ +Matrix3::void SetRotationPT( double Yaw, double Pitch, double Roll ) +{ + double SR = sin(Roll), + SP = sin(Pitch), + SY = sin(Yaw), + CR = cos(Roll), + CP = cos(Pitch), + CY = cos(Yaw); + + m[0][0] = CP * CY; + m[0][1] = CP * SY; + m[0][2] = -SP; + + m[1][0] = SR * SP * CY - CR * SY; + m[1][1] = SR * SP * SY + CR * CY; + m[1][2] = SR * CP; + + m[2][0] = CR * SP * CY + SR * SY; + m[2][1] = CR * SP * SY - CY * SR; + m[2][2] = CR * CP; +} +#endif + + +/** set rotation in panotools style, + * code adapted from Panotools-Script by Bruno Postle + */ +void Matrix3::SetRotationPT( double yaw, double pitch, double roll ) +{ + double cosr = cos (roll); + double sinr = sin (roll); + double cosp = cos (pitch); + double sinp = sin (0 - pitch); + double cosy = cos (yaw); + double siny = sin (0 - yaw); + + Matrix3 rollm; + + /* + rollm[0][0] = new Math::Matrix ([ 1, 0, 0 ], + [ 0, cosr,-1*sinr ], + [ 0, sinr, cosr ]); + */ + + rollm.m[0][0] = 1.0; rollm.m[0][1] = 0.0; rollm.m[0][2] = 0.0; + rollm.m[1][0] = 0.0; rollm.m[1][1] = cosr; rollm.m[1][2] = -sinr; + rollm.m[2][0] = 0.0; rollm.m[2][1] = sinr; rollm.m[2][2] = cosr; + + /* +my pitchm = new Math::Matrix ([ cosp, 0, sinp ], + [ 0, 1, 0 ], + [ -1*sinp, 0, cosp ]); + */ + + Matrix3 pitchm; + pitchm.m[0][0] = cosp; pitchm.m[0][1] = 0.0; pitchm.m[0][2] = sinp; + pitchm.m[1][0] = 0.0; pitchm.m[1][1] = 1; pitchm.m[1][2] = 0.0; + pitchm.m[2][0] = -sinp; pitchm.m[2][1] = 0.0; pitchm.m[2][2] = cosp; + + /* +my yawm = new Math::Matrix ([ cosy,-1*siny, 0 ], + [ siny, cosy, 0 ], + [ 0, 0, 1 ]); + */ + Matrix3 yawm; + yawm.m[0][0] = cosy; yawm.m[0][1] = -siny; yawm.m[0][2] = 0.0; + yawm.m[1][0] = siny; yawm.m[1][1] = cosy; yawm.m[1][2] = 0.0; + yawm.m[2][0] = 0.0; yawm.m[2][1] = 0.0; yawm.m[2][2] = 1.0; + + + *this = yawm * pitchm * rollm; +} + +/** GetRotation in panotools style. */ +void Matrix3::GetRotationPT( double & Yaw, double & Pitch, double & Roll ) +{ + /* + my \$matrix = shift; + my \$roll = atan2 (\$matrix->[2]->[1], \$matrix->[2]->[2]); + my \$pitch = -1 * asin (-1 * \$matrix->[2]->[0]); + my \$yaw = atan2 (-1 * \$matrix->[1]->[0], \$matrix->[0]->[0]); + return (\$roll, \$pitch, \$yaw); + + */ + Roll = atan2 (m[2][1], m[2][2]); + Pitch = - asin (- m[2][0]); + Yaw = atan2 (- m[1][0], m[0][0]); +} + +/** set the matrice to rotation around X */ +void Matrix3::SetRotationX( double a ) +{ + m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; + m[1][0] = 0.0; m[1][1] = cos(a); m[1][2] = sin(a); + m[2][0] = 0.0; m[2][1] =-m[1][2]; m[2][2] = m[1][1]; +} + +void Matrix3::SetRotationY( double a ) +{ + m[0][0] = cos(a); m[0][1] = 0.0; m[0][2] =-sin(a); + m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; + m[2][0] =-m[0][2]; m[2][1] = 0.0; m[2][2] = m[0][0]; +} + +void Matrix3::SetRotationZ( double a ) +{ + m[0][0] = cos(a); m[0][1] = sin(a); m[0][2] = 0.0; + m[1][0] =-m[0][1]; m[1][1] = m[0][0]; m[1][2] = 0.0; + m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; +} + +/** copy operator */ +Matrix3& Matrix3::operator= (const Matrix3& ot) +{ + for (int i=0; i<3; i++) + for (int j=0; j<3; j++) + m[i][j] = ot.m[i][j]; + return *this; +} + +/** multiplication with another matrix */ +Matrix3 Matrix3::operator*(const Matrix3& ot) const +{ + Matrix3 Result; + Result.m[0][0] = m[0][0] * ot.m[0][0] + m[0][1] * ot.m[1][0] + m[0][2] * ot.m[2][0]; + Result.m[0][1] = m[0][0] * ot.m[0][1] + m[0][1] * ot.m[1][1] + m[0][2] * ot.m[2][1]; + Result.m[0][2] = m[0][0] * ot.m[0][2] + m[0][1] * ot.m[1][2] + m[0][2] * ot.m[2][2]; + + Result.m[1][0] = m[1][0] * ot.m[0][0] + m[1][1] * ot.m[1][0] + m[1][2] * ot.m[2][0]; + Result.m[1][1] = m[1][0] * ot.m[0][1] + m[1][1] * ot.m[1][1] + m[1][2] * ot.m[2][1]; + Result.m[1][2] = m[1][0] * ot.m[0][2] + m[1][1] * ot.m[1][2] + m[1][2] * ot.m[2][2]; + + Result.m[2][0] = m[2][0] * ot.m[0][0] + m[2][1] * ot.m[1][0] + m[2][2] * ot.m[2][0]; + Result.m[2][1] = m[2][0] * ot.m[0][1] + m[2][1] * ot.m[1][1] + m[2][2] * ot.m[2][1]; + Result.m[2][2] = m[2][0] * ot.m[0][2] + m[2][1] * ot.m[1][2] + m[2][2] * ot.m[2][2]; + return Result; +} + +/** operator *= */ +void Matrix3::operator/=(double s) +{ + for (int i=0; i<3; i++) + for (int j=0; j<3; j++) + m[i][j] /= s; +} + +/** operator *= */ +void Matrix3::operator*=(double s) +{ + for (int i=0; i<3; i++) + for (int j=0; j<3; j++) + m[i][j] *= s; +} + +/** operator *= */ +void Matrix3::operator*=(Matrix3 ot) +{ + Matrix3 Result; + Result.m[0][0] = m[0][0] * ot.m[0][0] + m[0][1] * ot.m[1][0] + m[0][2] * ot.m[2][0]; + Result.m[0][1] = m[0][0] * ot.m[0][1] + m[0][1] * ot.m[1][1] + m[0][2] * ot.m[2][1]; + Result.m[0][2] = m[0][0] * ot.m[0][2] + m[0][1] * ot.m[1][2] + m[0][2] * ot.m[2][2]; + + Result.m[1][0] = m[1][0] * ot.m[0][0] + m[1][1] * ot.m[1][0] + m[1][2] * ot.m[2][0]; + Result.m[1][1] = m[1][0] * ot.m[0][1] + m[1][1] * ot.m[1][1] + m[1][2] * ot.m[2][1]; + Result.m[1][2] = m[1][0] * ot.m[0][2] + m[1][1] * ot.m[1][2] + m[1][2] * ot.m[2][2]; + + Result.m[2][0] = m[2][0] * ot.m[0][0] + m[2][1] * ot.m[1][0] + m[2][2] * ot.m[2][0]; + Result.m[2][1] = m[2][0] * ot.m[0][1] + m[2][1] * ot.m[1][1] + m[2][2] * ot.m[2][1]; + Result.m[2][2] = m[2][0] * ot.m[0][2] + m[2][1] * ot.m[1][2] + m[2][2] * ot.m[2][2]; + *this = Result; +} + +/** return inverse if it exists, otherwise identity */ +Matrix3 Matrix3::Inverse() const +{ + Matrix3 Result; + double Det = Determinant(); + + if (Det == 0.0f) + return Matrix3::Identity; + + double invDet = 1.0f / Det; + + Result.m[0][0] = invDet * ( m[1][1] * m[2][2] - m[2][1] * m[1][2] ); + Result.m[0][1] = -invDet * ( m[0][1] * m[2][2] - m[2][1] * m[0][2] ); + Result.m[0][2] = invDet * ( m[0][1] * m[1][2] - m[1][1] * m[0][2] ); + + Result.m[1][0] = -invDet * ( m[1][0] * m[2][2] - m[2][0] * m[1][2] ); + Result.m[1][1] = invDet * ( m[0][0] * m[2][2] - m[2][0] * m[0][2] ); + Result.m[1][2] = -invDet * ( m[0][0] * m[1][2] - m[1][0] * m[0][2] ); + + Result.m[2][0] = invDet * ( m[1][0] * m[2][1] - m[2][0] * m[1][1] ); + Result.m[2][1] = -invDet * ( m[0][0] * m[2][1] - m[2][0] * m[0][1] ); + Result.m[2][2] = invDet * ( m[0][0] * m[1][1] - m[1][0] * m[0][1] ); + return Result; +} + +void Matrix3::Print(std::ostream & o) const +{ + o << "[ " << m[0][0] << "\t" << m[0][1] << "\t" << m[0][2] << std::endl + << " " << m[1][0] << "\t" << m[1][1] << "\t" << m[1][2] << std::endl + << " " << m[2][0] << "\t" << m[2][1] << "\t" << m[2][2] << std::endl; +} + + +/*// return the rotation matrix around X +Matrix3 GetRotationX(double Ang) +{ + double a = cos(Ang); + double b = sin(Ang); + return Matrix3( + 1.0, 0.0, 0.0, + 0.0, a, b, + 0.0, -b, a ); +} + +//return the rotation matrix around Y +Matrix3 GetRotationY(double Ang) +{ + double a = cos(Ang); + double b = -sin(Ang); + return Matrix3( + a, 0.0, b, + 0.0, 1.0, 0.0, + -b, 0.0, a ); +} + +//return the rotation matrix around Z +Matrix3 GetRotationZ(double Ang) +{ + double a = cos(Ang); + double b = sin(Ang); + return Matrix3( + a, b, 0.0, + -b, a, 0.0, + 0.0, 0.0, 1.0); +} +*/ \ No newline at end of file Modified: hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h 2007-06-26 10:50:13 UTC (rev 2161) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Matrix3.h 2007-06-26 12:15:32 UTC (rev 2162) @@ -24,9 +24,9 @@ #ifndef _HUGIN_MATH_MATRIX3_H_ #define _HUGIN_MATH_MATRIX3_H_ -#include "hugin_math/Vector3.h" +#include +#include -// [TODO] methods to a cpp file. /** general : Matrix3 is a class for handling 3x3 Matrix manipulation. * @@ -43,74 +43,22 @@ public: /** default constructor : initialise to zero */ - Matrix3() { - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - m[i][j] = 0.0; - } + Matrix3(); /** copy constructor */ - Matrix3(const Matrix3& ot) - { - (*this) = ot; // call copy operator - } + Matrix3(const Matrix3& ot); /** Set the identity matrix */ - void SetIdentity() - { - m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; - m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; - m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; - } + void SetIdentity(); /** Set the matrice to rotation using yaw, pitch, roll angle */ - void SetRotation( double Yaw, double Pitch, double Roll ) - { - double SR = sin(Roll), - SP = sin(Pitch), - SY = sin(Yaw), - CR = cos(Roll), - CP = cos(Pitch), - CY = cos(Yaw); + void SetRotation( double Yaw, double Pitch, double Roll ); - m[0][0] = CP * CY; - m[0][1] = CP * SY; - m[0][2] = SP; - - m[1][0] = SR * SP * CY - CR * SY; - m[1][1] = SR * SP * SY + CR * CY; - m[1][2] = - SR * CP; - - m[2][0] = -( CR * SP * CY + SR * SY ); - m[2][1] = CY * SR - CR * SP * SY; - m[2][2] = CR * CP; - } - #if 0 /** Set the matrice to rotation using yaw, pitch, roll angle, panotools style, * copied from Panotools-Script by Bruno Postle */ - void SetRotationPT( double Yaw, double Pitch, double Roll ) - { - double SR = sin(Roll), - SP = sin(Pitch), - SY = sin(Yaw), - CR = cos(Roll), - CP = cos(Pitch), - CY = cos(Yaw); - - m[0][0] = CP * CY; - m[0][1] = CP * SY; - m[0][2] = -SP; - - m[1][0] = SR * SP * CY - CR * SY; - m[1][1] = SR * SP * SY + CR * CY; - m[1][2] = SR * CP; - - m[2][0] = CR * SP * CY + SR * SY; - m[2][1] = CR * SP * SY - CY * SR; - m[2][2] = CR * CP; - } + void SetRotationPT( double Yaw, double Pitch, double Roll ); #endif @@ -121,150 +69,33 @@ /** set rotation in panotools style, * code adapted from Panotools-Script by Bruno Postle */ - void SetRotationPT( double yaw, double pitch, double roll ) - { - double cosr = cos (roll); - double sinr = sin (roll); - double cosp = cos (pitch); - double sinp = sin (0 - pitch); - double cosy = cos (yaw); - double siny = sin (0 - yaw); + void SetRotationPT( double yaw, double pitch, double roll ); - Matrix3 rollm; - - /* - rollm[0][0] = new Math::Matrix ([ 1, 0, 0 ], - [ 0, cosr,-1*sinr ], - [ 0, sinr, cosr ]); - */ - - rollm.m[0][0] = 1.0; rollm.m[0][1] = 0.0; rollm.m[0][2] = 0.0; - rollm.m[1][0] = 0.0; rollm.m[1][1] = cosr; rollm.m[1][2] = -sinr; - rollm.m[2][0] = 0.0; rollm.m[2][1] = sinr; rollm.m[2][2] = cosr; - - /* - my pitchm = new Math::Matrix ([ cosp, 0, sinp ], - [ 0, 1, 0 ], - [ -1*sinp, 0, cosp ]); - */ - - Matrix3 pitchm; - pitchm.m[0][0] = cosp; pitchm.m[0][1] = 0.0; pitchm.m[0][2] = sinp; - pitchm.m[1][0] = 0.0; pitchm.m[1][1] = 1; pitchm.m[1][2] = 0.0; - pitchm.m[2][0] = -sinp; pitchm.m[2][1] = 0.0; pitchm.m[2][2] = cosp; - - /* - my yawm = new Math::Matrix ([ cosy,-1*siny, 0 ], - [ siny, cosy, 0 ], - [ 0, 0, 1 ]); - */ - Matrix3 yawm; - yawm.m[0][0] = cosy; yawm.m[0][1] = -siny; yawm.m[0][2] = 0.0; - yawm.m[1][0] = siny; yawm.m[1][1] = cosy; yawm.m[1][2] = 0.0; - yawm.m[2][0] = 0.0; yawm.m[2][1] = 0.0; yawm.m[2][2] = 1.0; - - - *this = yawm * pitchm * rollm; - } - /** GetRotation in panotools style. */ - void GetRotationPT( double & Yaw, double & Pitch, double & Roll ) - { - /* - my \$matrix = shift; - my \$roll = atan2 (\$matrix->[2]->[1], \$matrix->[2]->[2]); - my \$pitch = -1 * asin (-1 * \$matrix->[2]->[0]); - my \$yaw = atan2 (-1 * \$matrix->[1]->[0], \$matrix->[0]->[0]); - return (\$roll, \$pitch, \$yaw); + void GetRotationPT( double & Yaw, double & Pitch, double & Roll ); - */ - Roll = atan2 (m[2][1], m[2][2]); - Pitch = - asin (- m[2][0]); - Yaw = atan2 (- m[1][0], m[0][0]); - } - + /** set the matrice to rotation around X */ - void SetRotationX( double a ) - { - m[0][0] = 1.0; m[0][1] = 0.0; m[0][2] = 0.0; - m[1][0] = 0.0; m[1][1] = cos(a); m[1][2] = sin(a); - m[2][0] = 0.0; m[2][1] =-m[1][2]; m[2][2] = m[1][1]; - } + void SetRotationX( double a ); - void SetRotationY( double a ) - { - m[0][0] = cos(a); m[0][1] = 0.0; m[0][2] =-sin(a); - m[1][0] = 0.0; m[1][1] = 1.0; m[1][2] = 0.0; - m[2][0] =-m[0][2]; m[2][1] = 0.0; m[2][2] = m[0][0]; - } + void SetRotationY( double a ); - void SetRotationZ( double a ) - { - m[0][0] = cos(a); m[0][1] = sin(a); m[0][2] = 0.0; - m[1][0] =-m[0][1]; m[1][1] = m[0][0]; m[1][2] = 0.0; - m[2][0] = 0.0; m[2][1] = 0.0; m[2][2] = 1.0; - } + void SetRotationZ( double a ); /** copy operator */ - Matrix3& operator= (const Matrix3& ot) - { - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - m[i][j] = ot.m[i][j]; - return *this; - } + Matrix3& operator= (const Matrix3& ot); /** multiplication with another matrix */ - Matrix3 operator*(const Matrix3& ot) const - { - Matrix3 Result; - Result.m[0][0] = m[0][0] * ot.m[0][0] + m[0][1] * ot.m[1][0] + m[0][2] * ot.m[2][0]; - Result.m[0][1] = m[0][0] * ot.m[0][1] + m[0][1] * ot.m[1][1] + m[0][2] * ot.m[2][1]; - Result.m[0][2] = m[0][0] * ot.m[0][2] + m[0][1] * ot.m[1][2] + m[0][2] * ot.m[2][2]; - - Result.m[1][0] = m[1][0] * ot.m[0][0] + m[1][1] * ot.m[1][0] + m[1][2] * ot.m[2][0]; - Result.m[1][1] = m[1][0] * ot.m[0][1] + m[1][1] * ot.m[1][1] + m[1][2] * ot.m[2][1]; - Result.m[1][2] = m[1][0] * ot.m[0][2] + m[1][1] * ot.m[1][2] + m[1][2] * ot.m[2][2]; - - Result.m[2][0] = m[2][0] * ot.m[0][0] + m[2][1] * ot.m[1][0] + m[2][2] * ot.m[2][0]; - Result.m[2][1] = m[2][0] * ot.m[0][1] + m[2][1] * ot.m[1][1] + m[2][2] * ot.m[2][1]; - Result.m[2][2] = m[2][0] * ot.m[0][2] + m[2][1] * ot.m[1][2] + m[2][2] * ot.m[2][2]; - return Result; - } + Matrix3 operator*(const Matrix3& ot) const; /** operator *= */ - void operator/=(double s) - { - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - m[i][j] /= s; - } + void operator/=(double s); /** operator *= */ - void operator*=(double s) - { - for (int i=0; i<3; i++) - for (int j=0; j<3; j++) - m[i][j] *= s; - } + void operator*=(double s); /** operator *= */ - void operator*=(Matrix3 ot) - { - Matrix3 Result; - Result.m[0][0] = m[0][0] * ot.m[0][0] + m[0][1] * ot.m[1][0] + m[0][2] * ot.m[2][0]; - Result.m[0][1] = m[0][0] * ot.m[0][1] + m[0][1] * ot.m[1][1] + m[0][2] * ot.m[2][1]; - Result.m[0][2] = m[0][0] * ot.m[0][2] + m[0][1] * ot.m[1][2] + m[0][2] * ot.m[2][2]; - - Result.m[1][0] = m[1][0] * ot.m[0][0] + m[1][1] * ot.m[1][0] + m[1][2] * ot.m[2][0]; - Result.m[1][1] = m[1][0] * ot.m[0][1] + m[1][1] * ot.m[1][1] + m[1][2] * ot.m[2][1]; - Result.m[1][2] = m[1][0] * ot.m[0][2] + m[1][1] * ot.m[1][2] + m[1][2] * ot.m[2][2]; - - Result.m[2][0] = m[2][0] * ot.m[0][0] + m[2][1] * ot.m[1][0] + m[2][2] * ot.m[2][0]; - Result.m[2][1] = m[2][0] * ot.m[0][1] + m[2][1] * ot.m[1][1] + m[2][2] * ot.m[2][1]; - Result.m[2][2] = m[2][0] * ot.m[0][2] + m[2][1] * ot.m[1][2] + m[2][2] * ot.m[2][2]; - *this = Result; - } + void operator*=(Matrix3 ot); /** comparison */ inline bool operator==(Matrix3& ot) const @@ -319,37 +150,11 @@ } /** return inverse if it exists, otherwise identity */ - Matrix3 Inverse() const - { - Matrix3 Result; - double Det = Determinant(); + Matrix3 Inverse() const; + + /// + void Print(std::ostream & o) const; - if (Det == 0.0f) - return Matrix3::Identity; - - double invDet = 1.0f / Det; - - Result.m[0][0] = invDet * ( m[1][1] * m[2][2] - m[2][1] * m[1][2] ); - Result.m[0][1] = -invDet * ( m[0][1] * m[2][2] - m[2][1] * m[0][2] ); - Result.m[0][2] = invDet * ( m[0][1] * m[1][2] - m[1][1] * m[0][2] ); - - Result.m[1][0] = -invDet * ( m[1][0] * m[2][2] - m[2][0] * m[1][2] ); - Result.m[1][1] = invDet * ( m[0][0] * m[2][2] - m[2][0] * m[0][2] ); - Result.m[1][2] = -invDet * ( m[0][0] * m[1][2] - m[1][0] * m[0][2] ); - - Result.m[2][0] = invDet * ( m[1][0] * m[2][1] - m[2][0] * m[1][1] ); - Result.m[2][1] = -invDet * ( m[0][0] * m[2][1] - m[2][0] * m[0][1] ); - Result.m[2][2] = invDet * ( m[0][0] * m[1][1] - m[1][0] * m[0][1] ); - return Result; - } - - void Print(std::ostream & o) const - { - o << "[ " << m[0][0] << "\t" << m[0][1] << "\t" << m[0][2] << std::endl - << " " << m[1][0] << "\t" << m[1][1] << "\t" << m[1][2] << std::endl - << " " << m[2][0] << "\t" << m[2][1] << "\t" << m[2][2] << std::endl; - } - }; /** return the rotation matrix around vector U : checked */ Added: hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.cpp =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.cpp (rev 0) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.cpp 2007-06-26 12:15:32 UTC (rev 2162) @@ -0,0 +1,108 @@ +// -*- c-basic-offset: 4 -*- +/** @file Vector3.h + * + * @author Alexandre Jenny + * + * \$Id: Vector3.h 1769 2006-12-20 00:42:16Z dangelo \$ + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include + +#include "Vector3.h" + + +/** set */ +void Vector3::Set(double a, double b, double c) { x=a; y=b; z=c; } + +/** comparison : zero */ +bool Vector3::IsZero() const +{ + return ((x==0.f) && (y==0.f) && (z==0.f)); +} + +/** comparison : nearly zero */ +bool Vector3::IsNearlyZero() const +{ + return ( (fabs(x)= EPSILON ) + { + double invNorm = 1.f/sqrt(SquareSum); + x *= invNorm; + y *= invNorm; + z *= invNorm; + return true; + } + return false; +} + +/** return a normalized vector */ +Vector3 Vector3::GetNormalized() const +{ + Vector3 result(*this); + double SquareSum = x*x + y*y + z*z; + if( SquareSum >= EPSILON ) + { + double invNorm = 1.f/sqrt(SquareSum); + result.x *= invNorm; + result.y *= invNorm; + result.z *= invNorm; + } + return result; +} + Modified: hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h 2007-06-26 10:50:13 UTC (rev 2161) +++ hugin/branches/ippei/src/hugin_base/hugin_math/Vector3.h 2007-06-26 12:15:32 UTC (rev 2162) @@ -21,14 +21,17 @@ * */ -// [TODO] methods to a cpp file - #ifndef _HUGIN_MATH_VECTOR3_H_ #define _HUGIN_MATH_VECTOR3_H_ + +#include + + // small number below which we consider that it's zero #define EPSILON 0.0000001 + /** general : Vector3 is a class for handling 3D Vectors manipulation. * * We made a choose to store only a 3 dimensions vectors to speed @@ -55,16 +58,10 @@ Vector3(const Vector3& v) { x = v.x; y = v.y; z = v.z; } /** copy operator */ - inline Vector3& operator= (const Vector3& v) - { - x = v.x; - y = v.y; - z = v.z; - return *this; - } + inline Vector3& operator= (const Vector3& v); /** set */ - void Set(double a, double b, double c) { x=a; y=b; z=c; } + void Set(double a, double b, double c); /** comparison : equality */ inline bool operator== (const Vector3& v) const @@ -79,28 +76,19 @@ } /** comparison : zero */ - bool IsZero() const - { - return ((x==0.f) && (y==0.f) && (z==0.f)); - } + bool IsZero() const; /** comparison : nearly zero */ - bool IsNearlyZero() const - { - return ( (fabs(x)= EPSILON ) - { - double invNorm = 1.f/sqrt(SquareSum); - x *= invNorm; - y *= invNorm; - z *= invNorm; - return true; - } - return false; - } + bool Normalize(); /** return a normalized vector */ - Vector3 GetNormalized() const - { - Vector3 result(*this); - double SquareSum = x*x + y*y + z*z; - if( SquareSum >= EPSILON ) - { - double invNorm = 1.f/sqrt(SquareSum); - result.x *= invNorm; - result.y *= invNorm; - result.z *= invNorm; - } - return result; - } + Vector3 GetNormalized() const; }; + +/// inline std::ostream & operator<<(std::ostream & s, const Vector3 & v) { s << "[ " << v.x << ", " << v.y << ", " << v.z << " ]"; Copied: hugin/branches/ippei/src/hugin_base/hugin_math/hugin_math.h (from rev 2159, hugin/branches/ippei/src/hugin_base/hugin_math/math.h) =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/hugin_math.h (rev 0) +++ hugin/branches/ippei/src/hugin_base/hugin_math/hugin_math.h 2007-06-26 12:15:32 UTC (rev 2162) @@ -0,0 +1,252 @@ +// -*- c-basic-offset: 4 -*- +/** @file math.h + * + * @brief misc math function & classes used by other parts + * of the program + * + * @author Pablo d'Angelo + * + * \$Id: math.h 1952 2007-04-15 20:57:55Z dangelo \$ + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef _HUGIN_MATH_MATH_H +#define _HUGIN_MATH_MATH_H + +#include +#include + +#ifndef PI + #define PI 3.14159265358979323846 +#endif + +#define DEG_TO_RAD( x ) ( (x) * 2.0 * PI / 360.0 ) +#define RAD_TO_DEG( x ) ( (x) * 360.0 / ( 2.0 * PI ) ) + + +#ifdef _MSC_VER +inline double log2(double x) +{ + return log(x)/log(2.0); +} +#endif + + +/** namespace for various utils */ +namespace hugin_utils +{ + + inline double round(double x); // do we need this? + + inline double round(double x) + { + return floor(x+0.5); + } + + inline float roundf(float x); // do we need this? + + inline float roundf(float x) + { + return (float) floor(x+0.5f); + } + + inline int ceili(double x) + { + return (int) ceil(x); + } + + inline int floori(double x) + { + return (int) floor(x); + } + + + + template + inline int roundi(T x) + { + return ((x < 0.0) ? + ((x < (float)INT_MIN) ? INT_MIN : static_cast(x - 0.5)) : + ((x > (float)INT_MAX) ? INT_MAX : static_cast(x + 0.5))); + } + + // a simple point class + template + struct TDiff2D + { + TDiff2D() + : x(0), y(0) + { } + TDiff2D(T x, T y) + : x(x), y(y) + { } + TDiff2D(const vigra::Diff2D &d) + : x(d.x), y(d.y) + { } + + bool operator==(TDiff2D rhs) const + { + return x == rhs.x && y == rhs.y; + } + + TDiff2D operator+(TDiff2D rhs) const + { + return TDiff2D (x+rhs.x, y+rhs.y); + } + + TDiff2D operator-(TDiff2D rhs) const + { + return TDiff2D (x-rhs.x, y-rhs.y); + } + + TDiff2D & operator*=(double val) + { + x = x*val; + y = y*val; + return *this; + } + + vigra::Diff2D toDiff2D() const + { + return vigra::Diff2D(roundi(x), roundi(y)); + } + + double x,y; + }; + + /** clip a point to fit int [min, max] + * does not do a mathematical clipping, just sets p.x and p.y + * to the borders if they are outside. + */ + template + T simpleClipPoint(const T & point, const T & min, const T & max) + { + T p(point); + if (p.x < min.x) p.x = min.x; + if (p.x > max.x) p.x = max.x; + if (p.y < min.y) p.y = min.y; + if (p.y > max.y) p.y = max.y; + return p; + } + + template + T sqr(T t) + { + return t*t; + } + + template + double norm(T t) + { + return sqrt(t.x*t.x + t.y*t.y); + } + + /** calculate squared Euclidean distance between two vectors. + */ + template + double euclid_dist(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2) + { + typename InputIterator1::value_type res = 0; + InputIterator1 i(first1); + while (i != last1) { + double a = *i; + double b = *(first2 + (i - first1)); + res = res + a*a + b*b; + ++i; + } + return sqrt(res); + } + + /** calculate squared Euclidean distance between two vectors. + */ + template + T sqr_dist(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, T res) + { + InputIterator1 i(first1); + while (i != last1) { + T a = (T)(*i) - (T) (*(first2 + (i - first1))); + res = res + a*a; + ++i; + } + return res; + } + + /** calculate the bounding box of a circle that goes through + * both points. the center of the circle is halfway between + * the two points + */ + template + vigra::Rect2D calcCircleROIFromPoints(const POINT& p1, const POINT & p2) + { + double dx = p2.x - p1.x; + double dy = p2.y - p1.y; + double r = sqrt(dx*dx + dy*dy) / 2.0; + double mx = p1.x + dx/2; + double my = p1.y + dy/2; + + vigra::Rect2D rect; + rect.setUpperLeft(vigra::Point2D(roundi(mx-r), roundi(my -r))); + rect.setLowerRight(vigra::Point2D(roundi(mx+r), roundi(my+r))); + return rect; + } + +} // namespace + + + +typedef hugin_utils::TDiff2D FDiff2D; + +template +inline std::ostream & operator<<(std::ostream & o, const hugin_utils::TDiff2D & d) +{ + return o << "( " << d.x << " " << d.y << " )"; +} + +inline FDiff2D operator/(const FDiff2D & lhs, double val) +{ + return FDiff2D (lhs.x/val, lhs.y/val); +} + +// uses ceil for rounding. +inline vigra::Diff2D operator*(const vigra::Diff2D & d, double scale) +{ + return vigra::Diff2D((int)(ceil(d.x * scale)), + (int)(ceil(d.y * scale))); +} + +#if 0 +/// FIXME - DGSW duplicates function in diff2d.hxx +/// uses ceil for rounding. -> might extend the image size. +inline vigra::Size2D operator*(const vigra::Size2D & d, double scale) +{ + return vigra::Size2D((int)(ceil(d.x * scale)), + (int)(ceil(d.y * scale))); +} +#endif + +/// uses floor for left and top and ceil for right and bottom -> extend image when rounding.. +inline vigra::Rect2D operator*(const vigra::Rect2D & r, double scale) +{ + return vigra::Rect2D( (int)floor(r.left()*scale), + (int)floor(r.top()*scale), + (int)ceil(r.right()*scale), + (int)ceil(r.bottom()*scale)); +} + +#endif // _H Deleted: hugin/branches/ippei/src/hugin_base/hugin_math/math.h =================================================================== --- hugin/branches/ippei/src/hugin_base/hugin_math/math.h 2007-06-26 10:50:13 UTC (rev 2161) +++ hugin/branches/ippei/src/hugin_base/hugin_math/math.h 2007-06-26 12:15:32 UTC (rev 2162) @@ -1,252 +0,0 @@ -// -*- c-basic-offset: 4 -*- -/** @file math.h - * - * @brief misc math function & classes used by other parts - * of the program - * - * @author Pablo d'Angelo - * - * \$Id: math.h 1952 2007-04-15 20:57:55Z dangelo \$ - * - * This is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef _HUGIN_MATH_MATH_H -#define _HUGIN_MATH_MATH_H - -#include -#include - -#ifndef PI - #define PI 3.14159265358979323846 -#endif - -#define DEG_TO_RAD( x ) ( (x) * 2.0 * PI / 360.0 ) -#define RAD_TO_DEG( x ) ( (x) * 360.0 / ( 2.0 * PI ) ) - - -#ifdef _MSC_VER -inline double log2(double x) -{ - return log(x)/log(2.0); -} -#endif - - -/** namespace for various utils */ -namespace hugin_utils -{ - - inline double round(double x); // do we need this? - - inline double round(double x) - { - return floor(x+0.5); - } - - inline float roundf(float x); // do we need this? - - inline float roundf(float x) - { - return (float) floor(x+0.5f); - } - - inline int ceili(double x) - { - return (int) ceil(x); - } - - inline int floori(double x) - { - return (int) floor(x); - } - - - - template - inline int roundi(T x) - { - return ((x < 0.0) ? - ((x < (float)INT_MIN) ? INT_MIN : static_cast(x - 0.5)) : - ((x > (float)INT_MAX) ? INT_MAX : static_cast(x + 0.5))); - } - - // a simple point class - template - struct TDiff2D - { - TDiff2D() - : x(0), y(0) - { } - TDiff2D(T x, T y) - : x(x), y(y) - { } - TDiff2D(const vigra::Diff2D &d) - : x(d.x), y(d.y) - { } - - bool operator==(TDiff2D rhs) const - { - return x == rhs.x && y == rhs.y; - } - - TDiff2D operator+(TDiff2D rhs) const - { - return TDiff2D (x+rhs.x, y+rhs.y); - } - - TDiff2D operator-(TDiff2D rhs) const - { - return TDiff2D (x-rhs.x, y-rhs.y); - } - - TDiff2D & operator*=(double val) - { - x = x*val; - y = y*val; - return *this; - } - - vigra::Diff2D toDiff2D() const - { - return vigra::Diff2D(roundi(x), roundi(y)); - } - - double x,y; - }; - - /** clip a point to fit int [min, max] - * does not do a mathematical clipping, just sets p.x and p.y - * to the borders if they are outside. - */ - template - T simpleClipPoint(const T & point, const T & min, const T & max) - { - T p(point); - if (p.x < min.x) p.x = min.x; - if (p.x > max.x) p.x = max.x; - if (p.y < min.y) p.y = min.y; - if (p.y > max.y) p.y = max.y; - return p; - } - - template - T sqr(T t) - { - return t*t; - } - - template - double norm(T t) - { - return sqrt(t.x*t.x + t.y*t.y); - } - - /** calculate squared Euclidean distance between two vectors. - */ - template - double euclid_dist(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2) - { - typename InputIterator1::value_type res = 0; - InputIterator1 i(first1); - while (i != last1) { - double a = *i; - double b = *(first2 + (i - first1)); - res = res + a*a + b*b; - ++i; - } - return sqrt(res); - } - - /** calculate squared Euclidean distance between two vectors. - */ - template - T sqr_dist(InputIterator1 first1, InputIterator1 last1, - InputIterator2 first2, T res) - { - InputIterator1 i(first1); - while (i != last1) { - T a = (T)(*i) - (T) (*(first2 + (i - first1))); - res = res + a*a; - ++i; - } - return res; - } - - /** calculate the bounding box of a circle that goes through - * both points. the center of the circle is halfway between - * the two points - */ - template - vigra::Rect2D calcCircleROIFromPoints(const POINT& p1, const POINT & p2) - { - double dx = p2.x - p1.x; - double dy = p2.y - p1.y; - double r = sqrt(dx*dx + dy*dy) / 2.0; - double mx = p1.x + dx/2; - double my = p1.y + dy/2; - - vigra::Rect2D rect; - rect.setUpperLeft(vigra::Point2D(roundi(mx-r), roundi(my -r))); - rect.setLowerRight(vigra::Point2D(roundi(mx+r), roundi(my+r))); - return rect; - } - -} // namespace - - - -typedef utils::TDiff2D FDiff2D; - -template -inline std::ostream & operator<<(std::ostream & o, const utils::TDiff2D & d) -{ - return o << "( " << d.x << " " << d.y << " )"; -} - -inline FDiff2D operator/(const FDiff2D & lhs, double val) -{ - return FDiff2D (lhs.x/val, lhs.y/val); -} - -// uses ceil for rounding. -inline vigra::Diff2D operator*(const vigra::Diff2D & d, double scale) -{ - return vigra::Diff2D((int)(ceil(d.x * scale)), - (int)(ceil(d.y * scale))); -} - -#if 0 -/// FIXME - DGSW duplicates function in diff2d.hxx -/// uses ceil for rounding. -> might extend the image size. -inline vigra::Size2D operator*(const vigra::Size2D & d, double scale) -{ - return vigra::Size2D((int)(ceil(d.x * scale)), - (int)(ceil(d.y * scale))); -} -#endif - -/// uses floor for left and top and ceil for right and bottom -> extend image when rounding.. -inline vigra::Rect2D operator*(const vigra::Rect2D & r, double scale) -{ - return vigra::Rect2D( (int)floor(r.left()*scale), - (int)floor(r.top()*scale), - (int)ceil(r.right()*scale), - (int)ceil(r.bottom()*scale)); -} - -#endif // _H This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```