ardev_types.h

00001 /* -- 2007-05-07 -- 
00002  *  ardev - an augmented reality library for robot developers
00003  *  Copyright 2005-2007 - Toby Collett (ardev _at_ plan9.net.nz)
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU Lesser General Public
00016  *  License along with this library; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
00018  *
00019  */
00020  
00021 #ifndef _ARDEV_TYPES_H_
00022 #define _ARDEV_TYPES_H_
00023 
00024 
00025 #include <math.h>
00026 #include <list>
00027 #include <GL/gl.h>
00028 
00029 #include <libthjc/geometry.h>
00030 #include <libthjc/matrix.h>
00031 #include <libthjc/misc.h>
00032 
00033 using namespace std;
00034 
00035 
00036 // radian <-> degree conversions
00037 #ifndef PI_OVER_ONEEIGHTY
00038 #define PI_OVER_ONEEIGHTY (M_PI/180.0)
00039 #endif
00040 
00041 #ifndef ONEEIGHTY_OVER_PI
00042 #define ONEEIGHTY_OVER_PI (180.0/M_PI)
00043 #endif
00044 
00045 #ifndef RTOD
00046 #define RTOD(x) (x*ONEEIGHTY_OVER_PI)
00047 #endif
00048 
00049 #ifndef DTOR
00050 #define DTOR(x) (x*PI_OVER_ONEEIGHTY)
00051 #endif
00052 
00053 
00054 
00060 class ARPoint
00061 {
00062 public:
00064         ARPoint(double _x, double _y, double _z) {x = _x; y=_y; z=_z;}; 
00066         ARPoint() {x=y=z=0.0;}; 
00067         ARPoint & RotateX(double theta); 
00068         ARPoint & RotateY(double theta); 
00069         ARPoint & RotateZ(double theta); 
00070         ARPoint & RotateYPR(double Y, double P, double R); 
00071         ARPoint & RotateRPY(double R, double P, double Y); 
00072         
00073         double Mag() {return sqrt(x*x + y*y + z*z);}; 
00074         
00076         ARPoint operator + (const ARPoint & rhs) {return ARPoint(x+rhs.x, y+rhs.y, z+rhs.z);}; 
00078         ARPoint operator - (const ARPoint & rhs) const {return ARPoint(x-rhs.x, y-rhs.y, z-rhs.z);}; 
00080         ARPoint & operator += (const ARPoint & rhs) {x+=rhs.x; y+=rhs.y; z+=rhs.z; return *this;}; 
00082         ARPoint & operator *= (const double & rhs) {x*=rhs; y*=rhs; z*=rhs; return * this;};
00084         ARPoint operator * (const double & rhs) {return ARPoint(x*rhs,y*rhs,z*rhs);};
00086         bool operator == (const ARPoint & rhs) const {return x==rhs.x && y==rhs.y && z==rhs.z;};
00087         
00089         double DotProduct(const ARPoint & rhs);
00090         
00092         void Print() const {printf("(%f %f %f)",x,y,z);}; 
00093         
00094         double x; 
00095         double y; 
00096         double z; 
00097 };
00098 
00099 
00103 enum AR_CamType
00104 {
00105         AR_CAMTYPE_SINGLE = 0,
00106         AR_CAMTYPE_LEFT = 1,
00107         AR_CAMTYPE_RIGHT = 2,
00108         AR_CAMTYPE_CONV_EXTERN = 4, // Updated externally
00109         AR_CAMTYPE_CONV_EXTERN_LEFT = 5, // Updated externally
00110         AR_CAMTYPE_CONV_EXTERN_RIGHT = 6, // Updated externally
00111         AR_CAMTYPE_CONV_GL = 8, // Updated internally from previous GL frame
00112         AR_CAMTYPE_CONV_GL_LEFT = 9, // Updated internally from previous GL frame
00113         AR_CAMTYPE_CONV_GL_RIGHT = 10 // Updated internally from previous GL frame
00114 
00115 };
00116 
00119 class ARPosition
00120 {
00121         public:
00123                 ARPosition() {Origin=ARPoint(0,0,0);Direction=ARPoint(0,0,0);};
00125                 ARPosition(ARPoint _Origin, ARPoint _Direction) {Origin=_Origin;Direction=_Direction;};
00127                 ARPoint Origin;
00129                 ARPoint Direction;              
00131                 ARPosition & Transform(const ARPosition & Transform)
00132                 {
00133                         //Origin.RotateRPY(Transform.Direction.x, Transform.Direction.y, Transform.Direction.z);
00134                         Origin.RotateZ(Transform.Direction.z);
00135                         Origin.RotateY(Transform.Direction.y);
00136                         Origin.RotateX(Transform.Direction.x);
00137                         Direction += Transform.Direction;
00138                         Origin += Transform.Origin;
00139                         return * this;
00140                 };
00141                 
00143                 ARPosition & operator += (const ARPosition & rhs) {Origin += rhs.Origin; Direction += rhs.Direction; return *this;}; 
00145                 bool operator == (const ARPosition & rhs) const {return Origin == rhs.Origin && Direction == rhs.Direction;};
00147                 void Print()
00148                 { Origin.Print(); Direction.Print();};
00149 };
00150 
00159 class ARCamera
00160 {
00161         public:
00163                 ARCamera() {Direction=ARPoint(1,0,0);Up=ARPoint(0,0,1);aspect=1;y_fov=M_PI/4;CamType=AR_CAMTYPE_SINGLE;convergance=NULL;separation=NULL;sensor_width=0.008;};
00165                 ARCamera(ARPoint _Origin, ARPoint LookAt, ARPoint _Up, double y_fov, double aspect);
00176                 ARCamera(const char * CalibFile);
00177 
00178                 ARPoint Origin; 
00179                 ARPoint Direction; 
00180                 ARPoint Up; 
00181                 double y_fov; 
00182                 double x_fov; 
00183                 double aspect; 
00184                 double sensor_width; 
00185                 double sensor_height; 
00186                 int frame_width; 
00187                 int frame_height; 
00188                 double FocalDistance; 
00189                 double sx; 
00190                 double sy; 
00191                 
00192                 
00193                 double * convergance; 
00194                 double * separation; 
00195                 
00196                 Matrix R; 
00197                 Matrix RInv; 
00198                 Matrix T; 
00199 
00200                 enum AR_CamType CamType; 
00201 
00203                 void SetDirectionFromPoint(ARPoint _In);
00205                 //double GetDirection() const;
00206                 
00208                 void Print() const {Origin.Print();Direction.Print();Up.Print();printf("\n");};
00209                 
00210                 ARPoint GetCRFPointFromPixel(double x, double y); 
00211                 ARPoint GetWRFDirFromCRF(ARPoint CRFPoint); 
00212 
00213                 double Rx,Ry,Rz;
00214                 double GetRx() {return Rx;};
00215                 double GetRy() {return Ry;};
00216                 double GetRz() {return Rz;};
00217 
00218 };
00219 
00220 
00222 class ARImage{
00223         public:
00225                 ARImage() {DataSize=0;ColourFormat=GL_RGB; x_size=y_size=0; ByteDepth=3; data=NULL;};
00226                 ~ARImage() {delete [] data; data=NULL;};
00227                 unsigned int x_size; 
00228                 unsigned int y_size; 
00229                 unsigned char * data; 
00230                 unsigned char ByteDepth; 
00231                 unsigned int ColourFormat; 
00232         
00233                 unsigned char & GetPixel(int x, int y) {return data[y*x_size*ByteDepth + x];}; 
00234                 const unsigned char & GetPixel(int x, int y) const {return data[y*x_size*ByteDepth + x];}; 
00235                 
00236                 unsigned char * Allocate()
00237                 {
00238                         if (DataSize == x_size*y_size*ByteDepth)
00239                                 return data;
00240                                                         
00241                         delete [] data;
00242                         DataSize = x_size*y_size*ByteDepth;
00243                         return data = new unsigned char[DataSize];
00244                 }; 
00245                 
00246                 int Erase()
00247                 {
00248                         if (data)
00249                                 memset(data,0,x_size*y_size*ByteDepth);
00250                         return 0;
00251                 }; 
00252                 
00254                 ARImage(const ARImage & rhs) 
00255                 {
00256                         //printf("Copy constructor called\n");
00257                         DataSize =0;
00258                         x_size = rhs.x_size; 
00259                         y_size = rhs.y_size; 
00260                         ByteDepth = rhs.ByteDepth;
00261                         //data = NULL;
00262                         if (Allocate())
00263                                 memcpy(data,rhs.data,x_size*y_size*ByteDepth);
00264                 };
00265                 
00267                 ARImage & operator =(const ARImage & rhs) 
00268                 {
00269                         //printf("Assignement operator called\n");
00270                         x_size = rhs.x_size; 
00271                         y_size = rhs.y_size; 
00272                         ByteDepth = rhs.ByteDepth;
00273                         ColourFormat = rhs.ColourFormat;
00274                         Allocate();
00275         
00276                         if (data)
00277                                 memcpy(data,rhs.data,x_size*y_size*ByteDepth);
00278                         
00279                         return *this;
00280                 };
00281                 unsigned int GetDataSize() {return DataSize;}; 
00282         protected:
00283                 unsigned int DataSize; 
00284 
00285                 
00286 };
00287 
00288 
00297 class ARColour
00298 {
00299         public:
00301                 ARColour() {r=g=b=a=1;}; 
00303                 ARColour(float _r, float _g, float _b, float _a) {r=_r;g=_g;b=_b;a=_a;};
00305                 ARColour(float _r, float _g, float _b)  {r=_r;g=_g;b=_b;a=1;};
00306         
00307                 float r; 
00308                 float g; 
00309                 float b; 
00310                 float a; 
00311 };
00312 
00313 
00314 #endif //_ARDEV_TYPES_H_

SourceForge.net Logo Generated on Sat May 12 15:25:43 2007 for ardev by doxygen 1.5.1