#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Math/Geometry/Euclidean/FAffine.hh" // This file is part of RAVL, Recognition And Vision Library // Copyright (C) 2001, University of Surrey // This code may be redistributed under the terms of the GNU Lesser // General Public License (LGPL). See the lgpl.licence file for details or // see http://www.gnu.org/copyleft/lesser.html // file-header-ends-here #ifndef RAVL_FAFFINE_HEADER #define RAVL_FAFFINE_HEADER 1 ////////////////////////////////////////////////////// //! author="Charles Galambos" //! date="17/3/1997" //! docentry="Ravl.Math.Geometry" //! rcsid="$Id: FAffine.hh,v 1.7 2002/08/08 16:03:18 craftit Exp $" //! example=exFAffine.cc //! lib=RavlMath //! file="Ravl/Math/Geometry/Euclidean/FAffine.hh" #include "Ravl/FMatrix.hh" #include "Ravl/FVector.hh" namespace RavlN { //! userlevel=Normal //: General affine transformation. template class FAffineC { public: inline FAffineC(); //: Construct no-change transform. inline FAffineC(const FAffineC &Oth); //: Copy constructor. inline FAffineC(const FMatrixC &SR, const FVectorC &T); //: Construct from Scale/Rotate matrix and a translation vector. inline FVectorC &Translation() { return T; } //: Access the translation component of the transformation. inline FVectorC Translation() const { return T; } //: Constant access to the translation component of the transformation. inline void Scale(FVectorC xy); //: In place Scaling along the X & Y axis by value given in the vector. // If all values 1, then no effect. inline void Translate(const FVectorC &T); //: Add a translation in direction T. inline FVectorC operator*(const FVectorC &In) const; //: Transform Vector, Scale, Rotate, Translate. // Take a vector and put it though the transformation. inline FAffineC operator*(const FAffineC &In) const; //: Compose this transform with 'In' inline FAffineC operator/(const FAffineC &In) const; //: 'In' / 'Out' = this; FAffineC I() const; //: Generate an inverse transformation. FMatrixC &SRMatrix() { return SR; } //: Get Scale/Rotate matrix. const FMatrixC &SRMatrix() const { return SR; } //: Get Scale/Rotate matrix. inline const FAffineC &operator=(const FAffineC &Oth); //: Assigmment. protected: FMatrixC SR; // Scale/rotate. FVectorC T; // Translate. private: #if RAVL_NEW_ANSI_CXX_DRAFT friend istream & operator>> (istream & inS, FAffineC & vector); friend ostream & operator<< (ostream & outS, const FAffineC & vector); #else friend istream & operator>> (istream & inS, FAffineC & vector); friend ostream & operator<< (ostream & outS, const FAffineC & vector); #endif }; template ostream & operator<< (ostream & outS, const FAffineC & vector); template istream & operator>> (istream & inS, FAffineC & vector); ///////////////////////////////////////////////// template inline FAffineC::FAffineC() : SR() { T.Fill(0); SR.Fill(0.0); for(unsigned int i = 0;i < N;i++) SR[i][i] = 1.0; } template inline FAffineC::FAffineC(const FAffineC &Oth) : SR(Oth.SR), T(Oth.T) {} template inline FAffineC::FAffineC(const FMatrixC &nSR, const FVectorC &nT) : SR(nSR), T(nT) {} template inline void FAffineC::Scale(FVectorC xy) { for(UIntT i = 0;i < N;i++) for(UIntT j = 0;j < N;i++) SR[i][j] *= xy[j]; } template inline void FAffineC::Translate(const FVectorC &DT) { T += DT; } template inline FAffineC FAffineC::I(void) const { FAffineC ret; ret.SR = SR.I(); Mul(ret.SR,T,ret.T); ret.T *= -1; return ret; } template inline FVectorC FAffineC::operator*(const FVectorC &In) const { return (SR * In) + T; } template inline FAffineC FAffineC::operator*(const FAffineC &In) const{ return FAffineC(In.SRMatrix()*SR, In.SRMatrix()*T + In.Translation()); } template inline FAffineC FAffineC::operator/(const FAffineC &In) const{ return FAffineC(SR*In.SRMatrix().I(), In.SRMatrix().I()*(T-In.Translation())); } template inline const FAffineC &FAffineC::operator=(const FAffineC &Oth) { SR = Oth.SR; T = Oth.T; return *this; } template ostream & operator<<(ostream & outS, const FAffineC & vector) { outS << vector.SRMatrix() << "\t" << vector.Translation(); return outS; } template istream & operator>>(istream & inS, FAffineC & vector) { inS >> vector.SRMatrix() >> "\t" >> vector.Translation(); return inS; } } #endif