//---------------------------------------------------------------------------
#ifndef TransformationMatrix_H
#define TransformationMatrix_H
//---------------------------------------------------------------------------


#include "..\TNT\cmat.h"
using namespace TNT;

/****************************************************************************
* TransformationMatrix - 4x4 matrix used to transform from one to the other
*     cooridnating system. For instance, can pe used in conjunction with 
*     3D poitns:
*
*     TransformationMatrix R = readMatrixFromFile();
*     Points3D p0, p = readPointsFromFile();
*     Points3D q = R * p;    				// transform to another coord.sys.
*/

typedef Matrix<double> Matrix_d;


class TransformationMatrix: public Matrix_d			// inherits from Matrix
{
	public:
		TransformationMatrix() : Matrix_d(4,4) {	// its size is 4x4 (homogeneous coordinates)
		}											// uninitialized

		virtual ~TransformationMatrix() {}			// virtual destructor

		// Returns a unit TransformationMatrix (diagonal elements are 1.0)
		static TransformationMatrix unit() {
			TransformationMatrix* I = new TransformationMatrix();
			I->setUnit();
			return *I;
		}


		static TransformationMatrix* matrixToPoints3D(Matrix_d* mptr){
			return (TransformationMatrix*)(mptr);		// converts Matrix pointer to Points3D pointer
		}                                   // used to inherit all matrix operators

		TransformationMatrix& operator = (Matrix_d& m){
			assert( m.num_rows()==4  && m.num_cols()==4 );
			Matrix_d::operator = (m);
			return *this;
		}
	private:
		void setUnit(){								// sets matrix to unit value
			for(Subscript i=0; i<4; ++i)            
				for(Subscript j=0; j<4; ++j)
					(*this)[i][j] =                 // all elements are zero, except
						( i!=j ? 0.0 : 1.0 );       // .. diagonal elements = 1
		}
};


#endif



