/vol/vipdata/irtk/contrib++/include/irtkVector3.h

00001 /*=========================================================================
00002 
00003   Library   : Image Registration Toolkit (IRTK)
00004   Module    : $Id: irtkVector3.h 2 2008-12-23 12:40:14Z dr $
00005   Copyright : Imperial College, Department of Computing
00006               Visual Information Processing (VIP), 2008 onwards
00007   Date      : $Date: 2008-12-23 12:40:14 +0000 (Tue, 23 Dec 2008) $
00008   Version   : $Revision: 2 $
00009   Changes   : $Author: dr $
00010 
00011 =========================================================================*/
00012 
00013 #ifndef IRTKVECTOR3_H
00014 
00015 #define IRTKVECTOR3_H
00016 
00017 #include <irtkArith.h>
00018 
00019 class irtkVector3
00020 {
00021 public:
00022   // construction
00023   irtkVector3 ();
00024   irtkVector3 (double fX, double fY, double fZ);
00025   irtkVector3 (double afCoordinate[3]);
00026   irtkVector3 (const irtkVector3& rkVector);
00027 
00028   // member access (allows V.x or V[0], V.y or V[1], V.z or V[2])
00029   double x, y, z;
00030   double& operator[] (int i) const;
00031   operator double* ();
00032 
00033   // assignment and comparison
00034   irtkVector3& operator= (const irtkVector3& rkVector);
00035   bool operator== (const irtkVector3& rkVector) const;
00036   bool operator!= (const irtkVector3& rkVector) const;
00037 
00038   // arithmetic operations
00039   irtkVector3 operator+ (const irtkVector3& rkVector) const;
00040   irtkVector3 operator- (const irtkVector3& rkVector) const;
00041   irtkVector3 operator* (double fScalar) const;
00042   irtkVector3 operator/ (double fScalar) const;
00043   irtkVector3 operator- () const;
00044   friend irtkVector3 operator* (double fScalar, const irtkVector3& rkVector);
00045 
00046   // arithmetic updates
00047   irtkVector3& operator+= (const irtkVector3& rkVector);
00048   irtkVector3& operator-= (const irtkVector3& rkVector);
00049   irtkVector3& operator*= (double fScalar);
00050   irtkVector3& operator/= (double fScalar);
00051 
00052   // vector operations
00053   double Length () const;
00054   double SquaredLength () const;
00055   double Dot (const irtkVector3& rkVector) const;
00056   double Unitize (double fTolerance = 1e-06);
00057   irtkVector3 Cross (const irtkVector3& rkVector) const;
00058   irtkVector3 UnitCross (const irtkVector3& rkVector) const;
00059 
00060   // Gram-Schmidt orthonormalization.
00061   static void Orthonormalize (irtkVector3 akVector[3]);
00062 
00063   // Input W must be initialize to a nonzero vector, output is {U,V,W}
00064   // an orthonormal basis.  A hint is provided about whether or not W
00065   // is already unit length.
00066   static void GenerateOrthonormalBasis (irtkVector3& rkU, irtkVector3& rkV,
00067                                         irtkVector3& rkW, bool bUnitLengthW = true);
00068 
00069   // special points
00070   static const irtkVector3 ZERO;
00071   static const irtkVector3 UNIT_X;
00072   static const irtkVector3 UNIT_Y;
00073   static const irtkVector3 UNIT_Z;
00074 };
00075 
00076 #endif