Matrix33: make const the binary operators

This commit is contained in:
Paolo Cignoni 2008-10-24 12:20:44 +00:00
parent 4783ac9a62
commit 24ea4251a9
1 changed files with 39 additions and 39 deletions

View File

@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* This program 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. *
@ -103,10 +103,10 @@ namespace vcg {
template <class S>
class Matrix33Diag:public Point3<S>{
public:
/** @name Matrix33
Class Matrix33Diag.
This is the class for definition of a diagonal matrix 3x3.
This is the class for definition of a diagonal matrix 3x3.
@param S (Templete Parameter) Specifies the ScalarType field.
*/
Matrix33Diag(const S & p0,const S & p1,const S & p2):Point3<S>(p0,p1,p2){};
@ -116,14 +116,14 @@ public:
template<class S>
/** @name Matrix33
Class Matrix33.
This is the class for definition of a matrix 3x3.
This is the class for definition of a matrix 3x3.
@param S (Templete Parameter) Specifies the ScalarType field.
*/
class Matrix33
{
public:
typedef S ScalarType;
/// Default constructor
inline Matrix33() {}
@ -172,7 +172,7 @@ public:
}
/// Operatore di indicizzazione
inline S * operator [] ( const int i )
{
@ -183,7 +183,7 @@ public:
{
return a+i*3;
}
/// Modificatore somma per matrici 3x3
Matrix33 & operator += ( const Matrix33 &m )
@ -209,7 +209,7 @@ public:
a[i] -= m.a[i];
return *this;
}
/// Modificatore somma per matrici 3x3
Matrix33 & operator -= ( const Matrix33Diag<S> &p )
{
@ -236,18 +236,18 @@ public:
int i,j;
for(i=0;i<3;++i)
for(j=0;j<3;++j)
r[i][j] = (*this)[i][0]*t[0][j] + (*this)[i][1]*t[1][j] + (*this)[i][2]*t[2][j];
r[i][j] = (*this)[i][0]*t[0][j] + (*this)[i][1]*t[1][j] + (*this)[i][2]*t[2][j];
return r;
}
/// Modificatore prodotto per matrice
void operator *=( const Matrix33< S> & t )
void operator *=( const Matrix33< S> & t )
{
int i,j;
for(i=0;i<3;++i)
for(j=0;j<3;++j)
(*this)[i][j] = (*this)[i][0]*t[0][j] + (*this)[i][1]*t[1][j] + (*this)[i][2]*t[2][j];
(*this)[i][j] = (*this)[i][0]*t[0][j] + (*this)[i][1]*t[1][j] + (*this)[i][2]*t[2][j];
}
@ -259,18 +259,18 @@ public:
int i,j;
for(i=0;i<3;++i)
for(j=0;j<3;++j)
r[i][j] = (*this)[i][j]*t[j];
r[i][j] = (*this)[i][j]*t[j];
return r;
}
/// Dot product modifier with a diagonal matrix
void operator *=( const Matrix33Diag< S> & t )
void operator *=( const Matrix33Diag< S> & t )
{
int i,j;
for(i=0;i<3;++i)
for(j=0;j<3;++j)
(*this)[i][j] = (*this)[i][j]*t[j];
(*this)[i][j] = (*this)[i][j]*t[j];
}
/// Modificatore prodotto per costante
@ -282,7 +282,7 @@ public:
}
/// Operatore prodotto per costante
Matrix33 operator * ( const S t )
Matrix33 operator * ( const S t ) const
{
Matrix33<S> r;
for(int i=0;i<9;++i)
@ -292,7 +292,7 @@ public:
}
/// Operatore sottrazione per matrici 3x3
Matrix33 operator - ( const Matrix33 &m )
Matrix33 operator - ( const Matrix33 &m ) const
{
Matrix33<S> r;
for(int i=0;i<9;++i)
@ -300,9 +300,9 @@ public:
return r;
}
/// Operatore sottrazione di matrici 3x3 con matrici diagonali
Matrix33 operator - ( const Matrix33Diag<S> &p )
Matrix33 operator - ( const Matrix33Diag<S> &p ) const
{
Matrix33<S> r=a;
r[0][0] -= p[0];
@ -312,7 +312,7 @@ public:
}
/// Operatore sottrazione per matrici 3x3
Matrix33 operator + ( const Matrix33 &m )
Matrix33 operator + ( const Matrix33 &m ) const
{
Matrix33<S> r;
for(int i=0;i<9;++i)
@ -320,9 +320,9 @@ public:
return r;
}
/// Operatore addizione di matrici 3x3 con matrici diagonali
Matrix33 operator + ( const Matrix33Diag<S> &p )
Matrix33 operator + ( const Matrix33Diag<S> &p ) const
{
Matrix33<S> r=(*this);
r[0][0] += p[0];
@ -502,10 +502,10 @@ S Trace() const
return a[0]+a[4]+a[8];
}
/*
/*
compute the matrix generated by the product of a * b^T
*/
void ExternalProduct(const Point3<S> &a, const Point3<S> &b)
void ExternalProduct(const Point3<S> &a, const Point3<S> &b)
{
for(int i=0;i<3;++i)
for(int j=0;j<3;++j)
@ -524,8 +524,8 @@ ScalarType Norm()
}
/*
It compute the covariance matrix of a set of 3d points. Returns the barycenter
/*
It compute the covariance matrix of a set of 3d points. Returns the barycenter
*/
template <class STLPOINTCONTAINER >
void Covariance(const STLPOINTCONTAINER &points, Point3<S> &bp) {
@ -547,19 +547,19 @@ void Covariance(const STLPOINTCONTAINER &points, Point3<S> &bp) {
/*
/*
It compute the cross covariance matrix of two set of 3d points P and X;
it returns also the barycenters of P and X.
fonte:
Besl, McKay
A method for registration o f 3d Shapes
A method for registration o f 3d Shapes
IEEE TPAMI Vol 14, No 2 1992
*/
*/
template <class STLPOINTCONTAINER >
void CrossCovariance(const STLPOINTCONTAINER &P, const STLPOINTCONTAINER &X,
Point3<S> &bp, Point3<S> &bx)
void CrossCovariance(const STLPOINTCONTAINER &P, const STLPOINTCONTAINER &X,
Point3<S> &bp, Point3<S> &bx)
{
SetZero();
assert(P.size()==X.size());
@ -582,10 +582,10 @@ void CrossCovariance(const STLPOINTCONTAINER &P, const STLPOINTCONTAINER &X,
template <class STLPOINTCONTAINER, class STLREALCONTAINER>
void WeightedCrossCovariance(const STLREALCONTAINER & weights,
const STLPOINTCONTAINER &P,
const STLPOINTCONTAINER &X,
Point3<S> &bp,
Point3<S> &bx)
const STLPOINTCONTAINER &P,
const STLPOINTCONTAINER &X,
Point3<S> &bp,
Point3<S> &bx)
{
SetZero();
assert(P.size()==X.size());
@ -603,7 +603,7 @@ void WeightedCrossCovariance(const STLREALCONTAINER & weights,
bx/=X.size();
for(pi=P.begin(),xi=X.begin(),pw = weights.begin();pi!=P.end();++pi,++xi,++pw){
tmp.ExternalProduct(((*pi)-(bp)),((*xi)-(bp)));
(*this)+=tmp*(*pw);
@ -656,11 +656,11 @@ Matrix33<S> RotationMatrix(vcg::Point3<S> v0,vcg::Point3<S> v1,bool normalized=t
return rotM;
}
///find the axis of rotation
///find the axis of rotation
CoordType axis;
axis=v0^v1;
axis.Normalize();
///construct rotation matrix
S u=axis.X();
S v=axis.Y();
@ -668,7 +668,7 @@ Matrix33<S> RotationMatrix(vcg::Point3<S> v0,vcg::Point3<S> v1,bool normalized=t
S phi=acos(dot);
S rcos = cos(phi);
S rsin = sin(phi);
rotM[0][0] = rcos + u*u*(1-rcos);
rotM[1][0] = w * rsin + v*u*(1-rcos);
rotM[2][0] = -v * rsin + w*u*(1-rcos);
@ -725,7 +725,7 @@ template <class S>
return M;
}
///
///
typedef Matrix33<short> Matrix33s;
typedef Matrix33<int> Matrix33i;
typedef Matrix33<float> Matrix33f;