typeUtils.h

Go to the documentation of this file.
00001 #ifndef TYPE_UTILS_H
00002 #define TYPE_UTILS_H
00003 
00013 #include <math.h>
00014 #include "math_util.h"
00015 
00016 
00020 namespace VXV {
00024   enum Align {
00025     Top =       0x01,
00026     Middle =    0x02,
00027     Bottom =    0x04,
00028     Left =      0x08,
00029     Center =    0x10,
00030     Right =     0x20,
00031   };
00032 
00033   const double DEG2RAD = 2.0 * M_PI / 360.0; 
00034   const double RAD2DEG = 1.0 / DEG2RAD; 
00039   class Grid {
00040   public:
00041     int x;                      
00042     int y;                      
00044     Grid(void) : x(0), y(0) {};
00045 
00052     Grid(int x, int y) : x(x), y(y) {};
00053 
00057     Grid(const Grid* rhs) : x(rhs->x), y(rhs->y) {}
00058 
00059     virtual ~Grid(void) {}
00060 
00064     const Grid& operator+=(const Grid& rhs);
00065 
00069     const Grid operator+(const Grid& rhs) const {
00070       return Grid(this) += rhs;
00071     }
00072 
00076     const Grid& operator-=(const Grid& rhs);
00077 
00081     Grid operator-(const Grid& rhs) const {
00082       return Grid(this) -= rhs;
00083     }
00084 
00088     bool operator==(const Grid& rhs) const {
00089       return (this->x == rhs.x) && (this->y == rhs.y);
00090     }
00091   };
00092 
00093 
00097   class Grid3D : public Grid {
00098   public:
00099     int z;                      
00101     Grid3D(void) : z(0) {};
00102 
00110     Grid3D(int x, int y, int z) : Grid(x, y), z(z) {};
00111 
00118     Grid3D(int x, int y) : Grid(x, y), z(0) {};
00119 
00123     Grid3D(const Grid3D* rhs) : Grid(rhs->x, rhs->y), z(rhs->z) {}
00124 
00128     Grid3D(const Grid& rhs) : Grid(rhs.x, rhs.y), z(0) {}
00129 
00130     virtual ~Grid3D(void) {}
00131 
00135     const Grid3D& operator+=(const Grid3D& rhs);
00136 
00140     const Grid3D operator+(const Grid3D& rhs) const {
00141       return Grid3D(this) += rhs;
00142     }
00143 
00147     const Grid3D& operator-=(const Grid3D& rhs);
00148 
00152     Grid3D operator-(const Grid3D& rhs) const {
00153       return Grid3D(this) -= rhs;
00154     }
00155   };
00156 
00157 
00161   class Direction {
00162     double inner_radian;
00163     Direction(const double radian) : inner_radian(radian) {}
00164 
00165   public:
00166     Direction(void) : inner_radian(0.0) {}
00167 
00173     double getInnerRadian(void) const {
00174       return inner_radian;
00175     }
00176 
00180     Direction(const Direction* rhs) : inner_radian(rhs->inner_radian) {}
00181 
00182     virtual ~Direction(void) {}
00183 
00187     const Direction& operator+=(const Direction& rhs) {
00188       inner_radian += rhs.inner_radian;
00189       return *this;
00190     }
00191 
00195     const Direction operator+(const Direction& rhs) const {
00196       return Direction(this) += rhs;
00197     }
00198 
00202     bool operator==(const Direction& rhs) const {
00203       return (this->to_rad() == rhs.to_rad());
00204     }
00205 
00209     const Direction& operator-=(const Direction& rhs) {
00210       inner_radian -= rhs.inner_radian;
00211       return *this;
00212     }
00213 
00217     Direction operator-(const Direction& rhs) const {
00218       return Direction(this) -= rhs;
00219     }
00220 
00221 
00228     static Direction deg(int degree) {
00229       return Direction(2.0 * M_PI * degree / 360.0);
00230     }
00231 
00238     static Direction rad(double radian) {
00239       return Direction(radian);
00240     }
00241 
00249     const int to_deg(void) const;
00250 
00258     const double to_rad(void) const;
00259   };
00260 
00261 
00265   class Rect : public Grid {
00266   public:
00267     int w;                      
00268     int h;                      
00270     Rect(void) : Grid(0, 0), w(0), h(0) {}
00271 
00275     Rect(int w, int h) : Grid(0, 0), w(w), h(h) {}
00276 
00280     Rect(int x, int y, int w, int h) : VXV::Grid(x, y), w(w), h(h) {}
00281 
00282     virtual ~Rect(void) {}
00283   };
00284 
00285 
00289   class Position : public Grid {
00290   public:
00291     Direction zt;                       
00293     Position(void) {}
00294 
00302     Position(int x, int y, const Direction& zt) : Grid(x, y), zt(zt) {}
00303 
00307     Position(const Position* rhs)
00308       : Grid(rhs->x, rhs->y), zt(rhs->zt) {}
00309 
00313     bool operator==(const Position& rhs) const {
00314       return (this->x == rhs.x) && (this->y == rhs.y) && (this->zt == rhs.zt);
00315     }
00316 
00320     const Position& operator+=(const Position& rhs);
00321 
00325     const Position operator+(const Position& rhs) const {
00326       return Position(this) += rhs;
00327     }
00328 
00332     const Position& operator-=(const Position& rhs);
00333 
00337     const Position operator-(const Position& rhs) const {
00338       return Position(this) -= rhs;
00339     }
00340 
00341     virtual ~Position(void) {}
00342   };
00343 
00344 
00348   class Position3D : public Position {
00349   public:
00350     int z;                      
00351     Direction xt;               
00352     Direction yt;               
00354     Position3D(void) : z(0), xt(Direction()), yt(Direction()) {}
00355 
00366     Position3D(int x, int y, int z, Direction xt, Direction yt, Direction zt)
00367       : Position(x, y, zt), z(z), xt(xt), yt(yt) {}
00368 
00372     Position3D(const Position3D* rhs)
00373       : Position(rhs->x, rhs->y, rhs->zt),
00374         z(rhs->z), xt(rhs->xt), yt(rhs->yt) {}
00375 
00379     Position3D(const Position& rhs)
00380       : Position(rhs),
00381         z(0), xt(Direction()), yt(Direction()) {}
00382 
00386     bool operator==(const Position3D& rhs) const {
00387       return (this->x == rhs.x) && (this->y == rhs.y) && (this->z == rhs.z) &&
00388         (this->xt == rhs.xt) && (this->yt == rhs.yt) && (this->zt == rhs.zt);
00389     }
00390 
00394     const Position3D& operator+=(const Position3D& rhs);
00395 
00399     const Position3D operator+(const Position3D& rhs) const {
00400       return Position3D(this) += rhs;
00401     }
00402 
00406     const Position3D& operator-=(const Position3D& rhs);
00407 
00411     const Position3D operator-(const Position3D& rhs) const {
00412       return Position3D(this) -= rhs;
00413     }
00414 
00415     virtual ~Position3D(void) {}
00416   };
00417 
00424   extern int length(const Grid3D& position);
00425 
00426 
00430   typedef struct {
00431     double a11;                 
00432     double a21;                 
00433     double a31;                 
00434     double a12;                 
00435     double a22;                 
00436     double a32;                 
00437     double a13;                 
00438     double a23;                 
00439     double a33;                 
00441     int a41;                    
00442     int a42;                    
00443     int a43;                    
00444     int a44;                    
00445   } Matrix4D;
00446 
00453   extern Matrix4D createConvertMatrix(const Position3D pos);
00454 
00462   extern void convert(Position3D& converted, const Position3D& input,
00463                       const Matrix4D& matrix);
00464 
00472   extern void convertWithAngle(Position3D& converted, const Position3D& input,
00473                                const Position3D& forMatrix);
00474 }
00475 
00476 #endif /* !TYPE_UTILS_H */
00477 

Generated on Mon Apr 13 22:52:05 2009 by  doxygen 1.5.7.1