Commit 8aa2018e authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] moved duplicate functions to math and and wmath namespace

parent d203dbfb
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include "WGridRegular3D.h"
#include "../math/WLinearAlgebraFunctions.h"
using wmath::WVector3D;
using wmath::WPosition;
......@@ -61,7 +62,7 @@ WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsign
m_matrix( 3, 3 ) = 1.;
m_matrixInverse = invertMatrix3x3( m_matrix );
m_matrixInverse = wmath::invertMatrix3x3( m_matrix );
}
WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsigned int nbPosZ,
......@@ -89,7 +90,7 @@ WGridRegular3D::WGridRegular3D( unsigned int nbPosX, unsigned int nbPosY, unsign
m_matrix = mat;
m_matrixInverse = invertMatrix3x3( m_matrix );
m_matrixInverse = wmath::invertMatrix3x3( m_matrix );
}
......@@ -157,44 +158,11 @@ wmath::WMatrix<double> WGridRegular3D::getTransformationMatrix() const
return m_matrix;
}
wmath::WVector3D WGridRegular3D::multMatrixWithVector3D( wmath::WMatrix<double> mat, wmath::WVector3D vec )
{
wmath::WVector3D result;
result[0] = mat( 0, 0 ) * vec[0] + mat( 0, 1 ) * vec[1] + mat( 0, 2 ) * vec[2];
result[1] = mat( 1, 0 ) * vec[0] + mat( 1, 1 ) * vec[1] + mat( 1, 2 ) * vec[2];
result[2] = mat( 2, 0 ) * vec[0] + mat( 2, 1 ) * vec[1] + mat( 2, 2 ) * vec[2];
return result;
}
wmath::WMatrix<double> WGridRegular3D::invertMatrix3x3( wmath::WMatrix<double> mat )
{
double det = mat( 0, 0 ) * mat( 1, 1 ) * mat( 2, 2 ) +
mat( 0, 1 ) * mat( 1, 2 ) * mat( 2, 0 ) +
mat( 0, 2 ) * mat( 1, 0 ) * mat( 2, 1 ) -
mat( 0, 2 ) * mat( 1, 1 ) * mat( 2, 0 ) -
mat( 0, 1 ) * mat( 1, 0 ) * mat( 2, 2 ) -
mat( 0, 0 ) * mat( 1, 2 ) * mat( 2, 1 );
wmath::WMatrix<double> r( 3, 3 );
r( 0, 0 ) = ( mat( 1, 1 ) * mat( 2, 2 ) - mat( 1, 2 ) * mat( 2, 1 ) ) / det;
r( 1, 0 ) = ( mat( 1, 2 ) * mat( 2, 0 ) - mat( 1, 0 ) * mat( 2, 2 ) ) / det;
r( 2, 0 ) = ( mat( 1, 0 ) * mat( 2, 1 ) - mat( 1, 1 ) * mat( 2, 0 ) ) / det;
r( 0, 1 ) = ( mat( 0, 2 ) * mat( 2, 1 ) - mat( 0, 1 ) * mat( 2, 2 ) ) / det;
r( 1, 1 ) = ( mat( 0, 0 ) * mat( 2, 2 ) - mat( 0, 2 ) * mat( 2, 0 ) ) / det;
r( 2, 1 ) = ( mat( 0, 1 ) * mat( 2, 0 ) - mat( 0, 0 ) * mat( 2, 1 ) ) / det;
r( 0, 2 ) = ( mat( 0, 1 ) * mat( 1, 2 ) - mat( 0, 2 ) * mat( 1, 1 ) ) / det;
r( 1, 2 ) = ( mat( 0, 2 ) * mat( 1, 0 ) - mat( 0, 0 ) * mat( 1, 2 ) ) / det;
r( 2, 2 ) = ( mat( 0, 0 ) * mat( 1, 1 ) - mat( 0, 1 ) * mat( 1, 0 ) ) / det;
return r;
}
osg::Vec3 WGridRegular3D::transformTexCoord( osg::Vec3 point )
{
wmath::WVector3D p( point.x() - 0.5 , point.y() - 0.5, point.z() - 0.5 );
wmath::WVector3D r( multMatrixWithVector3D( m_matrixInverse , p ) );
wmath::WVector3D r( wmath::multMatrixWithVector3D( m_matrixInverse , p ) );
r[0] = r[0] * m_offsetX + 0.5;
r[1] = r[1] * m_offsetY + 0.5;
......
......@@ -195,16 +195,6 @@ public:
*/
wmath::WMatrix<double> getTransformationMatrix() const;
/**
*
*/
wmath::WVector3D multMatrixWithVector3D( wmath::WMatrix<double> mat, wmath::WVector3D vec );
/**
*
*/
wmath::WMatrix<double> invertMatrix3x3( wmath::WMatrix<double> mat );
/**
*
*/
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WLinearAlgebraFunctions.h"
#include "WMatrix.h"
#include "WVector3D.h"
namespace wmath
{
WVector3D multMatrixWithVector3D( WMatrix<double> mat, WVector3D vec )
{
WVector3D result;
result[0] = mat( 0, 0 ) * vec[0] + mat( 0, 1 ) * vec[1] + mat( 0, 2 ) * vec[2];
result[1] = mat( 1, 0 ) * vec[0] + mat( 1, 1 ) * vec[1] + mat( 1, 2 ) * vec[2];
result[2] = mat( 2, 0 ) * vec[0] + mat( 2, 1 ) * vec[1] + mat( 2, 2 ) * vec[2];
return result;
}
WMatrix<double> invertMatrix3x3( WMatrix<double> mat )
{
double det = mat( 0, 0 ) * mat( 1, 1 ) * mat( 2, 2 ) +
mat( 0, 1 ) * mat( 1, 2 ) * mat( 2, 0 ) +
mat( 0, 2 ) * mat( 1, 0 ) * mat( 2, 1 ) -
mat( 0, 2 ) * mat( 1, 1 ) * mat( 2, 0 ) -
mat( 0, 1 ) * mat( 1, 0 ) * mat( 2, 2 ) -
mat( 0, 0 ) * mat( 1, 2 ) * mat( 2, 1 );
WMatrix<double> r( 3, 3 );
r( 0, 0 ) = ( mat( 1, 1 ) * mat( 2, 2 ) - mat( 1, 2 ) * mat( 2, 1 ) ) / det;
r( 1, 0 ) = ( mat( 1, 2 ) * mat( 2, 0 ) - mat( 1, 0 ) * mat( 2, 2 ) ) / det;
r( 2, 0 ) = ( mat( 1, 0 ) * mat( 2, 1 ) - mat( 1, 1 ) * mat( 2, 0 ) ) / det;
r( 0, 1 ) = ( mat( 0, 2 ) * mat( 2, 1 ) - mat( 0, 1 ) * mat( 2, 2 ) ) / det;
r( 1, 1 ) = ( mat( 0, 0 ) * mat( 2, 2 ) - mat( 0, 2 ) * mat( 2, 0 ) ) / det;
r( 2, 1 ) = ( mat( 0, 1 ) * mat( 2, 0 ) - mat( 0, 0 ) * mat( 2, 1 ) ) / det;
r( 0, 2 ) = ( mat( 0, 1 ) * mat( 1, 2 ) - mat( 0, 2 ) * mat( 1, 1 ) ) / det;
r( 1, 2 ) = ( mat( 0, 2 ) * mat( 1, 0 ) - mat( 0, 0 ) * mat( 1, 2 ) ) / det;
r( 2, 2 ) = ( mat( 0, 0 ) * mat( 1, 1 ) - mat( 0, 1 ) * mat( 1, 0 ) ) / det;
return r;
}
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WLINEARALGEBRAFUNCTIONS_H
#define WLINEARALGEBRAFUNCTIONS_H
namespace wmath
{
class WVector3D;
template< typename > class WMatrix;
/**
* helper routine to multiply a 3x3 matrix with a vector
*
* \param mat 3x3 matrix
* \param vec vector
*/
WVector3D multMatrixWithVector3D( WMatrix<double> mat, WVector3D vec );
/**
* helper routine to invert a 3x3 matrix
*
* \param mat 3x3 matrix
*
* \return inverted 3x3 matrix
*/
WMatrix<double> invertMatrix3x3( WMatrix<double> mat );
}
#endif // WLINEARALGEBRAFUNCTIONS_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WLINEARALGEBRAFUNCTIONS_TEST_H
#define WLINEARALGEBRAFUNCTIONS_TEST_H
#include <cxxtest/TestSuite.h>
#include "../WLinearAlgebraFunctions.h"
using wmath::WMatrix;
/**
* Tests for WMatrix.
*/
class WLinearAlgebraFunctionsTest : public CxxTest::TestSuite
{
public:
// TODO(schurade): document and implement multMatrixWithVector3D and invertMatrix3x3 here.
/**
* This is a dummy
*/
void testOneOftheFunctions( void )
{
}
};
#endif // WLINEARALGEBRAFUNCTIONS_TEST_H
......@@ -25,6 +25,7 @@
#include <cassert>
#include "WTalairachConverter.h"
#include "../../math/WLinearAlgebraFunctions.h"
WTalairachConverter::WTalairachConverter( wmath::WVector3D ac, wmath::WVector3D pc, wmath::WVector3D ihp ) :
m_rotMat( 3, 3 ),
......@@ -56,12 +57,12 @@ WTalairachConverter::~WTalairachConverter()
wmath::WVector3D WTalairachConverter::Canonical2ACPC( const wmath::WVector3D point )
{
wmath::WVector3D rpoint = point - m_ac;
return multMatrixWithVector3D( m_rotMat, rpoint );
return wmath::multMatrixWithVector3D( m_rotMat, rpoint );
}
wmath::WVector3D WTalairachConverter::ACPC2Canonical( const wmath::WVector3D point )
{
wmath::WVector3D rpoint = multMatrixWithVector3D( m_rotMatInvert, point );
wmath::WVector3D rpoint = wmath::multMatrixWithVector3D( m_rotMatInvert, point );
return rpoint + m_ac;
}
......@@ -233,7 +234,7 @@ void WTalairachConverter::defineRotationMatrix()
m_rotMat( 2, 1 ) = ez[1];
m_rotMat( 2, 2 ) = ez[2];
m_rotMatInvert = invertMatrix3x3( m_rotMat );
m_rotMatInvert = wmath::invertMatrix3x3( m_rotMat );
}
wmath::WVector3D WTalairachConverter::getAc() const
......@@ -338,37 +339,3 @@ wmath::WMatrix<double> WTalairachConverter::getInvRotMat()
{
return m_rotMatInvert;
}
wmath::WVector3D WTalairachConverter::multMatrixWithVector3D( wmath::WMatrix<double> mat, wmath::WVector3D vec )
{
wmath::WVector3D result;
result[0] = mat( 0, 0 ) * vec[0] + mat( 0, 1 ) * vec[1] + mat( 0, 2 ) * vec[2];
result[1] = mat( 1, 0 ) * vec[0] + mat( 1, 1 ) * vec[1] + mat( 1, 2 ) * vec[2];
result[2] = mat( 2, 0 ) * vec[0] + mat( 2, 1 ) * vec[1] + mat( 2, 2 ) * vec[2];
return result;
}
wmath::WMatrix<double> WTalairachConverter::invertMatrix3x3( wmath::WMatrix<double> mat )
{
double det = mat( 0, 0 ) * mat( 1, 1 ) * mat( 2, 2 ) +
mat( 0, 1 ) * mat( 1, 2 ) * mat( 2, 0 ) +
mat( 0, 2 ) * mat( 1, 0 ) * mat( 2, 1 ) -
mat( 0, 2 ) * mat( 1, 1 ) * mat( 2, 0 ) -
mat( 0, 1 ) * mat( 1, 0 ) * mat( 2, 2 ) -
mat( 0, 0 ) * mat( 1, 2 ) * mat( 2, 1 );
wmath::WMatrix<double> r( 3, 3 );
r( 0, 0 ) = ( mat( 1, 1 ) * mat( 2, 2 ) - mat( 1, 2 ) * mat( 2, 1 ) ) / det;
r( 1, 0 ) = ( mat( 1, 2 ) * mat( 2, 0 ) - mat( 1, 0 ) * mat( 2, 2 ) ) / det;
r( 2, 0 ) = ( mat( 1, 0 ) * mat( 2, 1 ) - mat( 1, 1 ) * mat( 2, 0 ) ) / det;
r( 0, 1 ) = ( mat( 0, 2 ) * mat( 2, 1 ) - mat( 0, 1 ) * mat( 2, 2 ) ) / det;
r( 1, 1 ) = ( mat( 0, 0 ) * mat( 2, 2 ) - mat( 0, 2 ) * mat( 2, 0 ) ) / det;
r( 2, 1 ) = ( mat( 0, 1 ) * mat( 2, 0 ) - mat( 0, 0 ) * mat( 2, 1 ) ) / det;
r( 0, 2 ) = ( mat( 0, 1 ) * mat( 1, 2 ) - mat( 0, 2 ) * mat( 1, 1 ) ) / det;
r( 1, 2 ) = ( mat( 0, 2 ) * mat( 1, 0 ) - mat( 0, 0 ) * mat( 1, 2 ) ) / det;
r( 2, 2 ) = ( mat( 0, 0 ) * mat( 1, 1 ) - mat( 0, 1 ) * mat( 1, 0 ) ) / det;
return r;
}
......@@ -253,23 +253,6 @@ private:
*/
void defineRotationMatrix();
/**
* helper routine to multiply a 3x3 matrix with a vector
*
* \param mat 3x3 matrix
* \param vec vector
*/
wmath::WVector3D multMatrixWithVector3D( wmath::WMatrix<double> mat, wmath::WVector3D vec );
/**
* helper routine to invert a 3x3 matrix
*
* \param mat 3x3 matrix
*
* \return inverted 3x3 matrix
*/
wmath::WMatrix<double> invertMatrix3x3( wmath::WMatrix<double> mat );
/**
* the rotation matrix
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment