Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

BasicTypes.h

Go to the documentation of this file.
00001 #ifndef Imapala_Core_Tracking_BasicTypes_h
00002 #define Imapala_Core_Tracking_BasicTypes_h
00003 
00004 #include <stdlib.h>
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Tracking
00011 {
00012 
00013 inline int Random(int range)
00014 {
00015     return rand() % range;
00016 }
00017 
00019 class Point
00020 {
00021 public:
00022     int x,y;
00023     Point() : x(0),y(0) {}
00024     Point(int ax, int ay) : x(ax),y(ay) {}
00025     Point(const Point& p) : x(p.x),y(p.y) {}
00026     Point& operator=(const Point& p)
00027     {
00028         x=p.x;
00029         y=p.y;
00030         return *this;
00031     }
00032 
00033     Point& operator+=(int i)
00034     {
00035         x+=i;
00036         y+=i;
00037         return *this;
00038     }
00039     Point& operator-=(int i)
00040     {
00041         x-=i;
00042         y-=i;
00043         return *this;
00044     }
00045     Point& operator-=(const Point& p)
00046     {
00047         x-=p.x;
00048         y-=p.y;
00049         return *this;
00050     }
00051     Point& operator/=(int i)
00052     {
00053         if(i!=0)
00054         {
00055             x/=i;
00056             y/=i;
00057             return *this;
00058         }
00059     }
00060     Point& operator*=(int i)
00061     {
00062         if(i!=0)
00063         {
00064             x*=i;
00065             y*=i;
00066             return *this;
00067         }
00068     }
00069 
00070     int Inproduct()
00071     {
00072         return x*y;
00073     }
00074 };
00075 
00077 class Rect
00078 {
00079 public:
00080     int left,top,right,bottom;
00081     Rect()
00082         :left(0),
00083         top(0),
00084         right(0),
00085         bottom(0)
00086     {
00087     }
00088     Rect(int l,int t,int r,int b)
00089         :left(l),
00090         top(t),
00091         right(r),
00092         bottom(b)
00093     {
00094     }
00095     Rect(const Rect& r)
00096         :left(r.left),
00097         top(r.top),
00098         right(r.right),
00099         bottom(r.bottom)
00100     {
00101     }
00102     Rect(const Point& p)
00103         :left(p.x),
00104         top(p.y),
00105         right(p.x),
00106         bottom(p.y)
00107     {
00108     }
00109 
00110     int width() const
00111     {
00112         return right-left+1;
00113     }
00114     int height() const
00115     {
00116         return bottom-top+1;
00117     }
00118     Point size() const
00119     {
00120         return Point(width(), height());
00121     }
00122     Point mid() const
00123     {
00124         //in case of an even number of pixels width or height there is no
00125         //'middle pixel' so in that case a choice has to be made... we take
00126         //the pixel left and below the mathematical mid to be the middle pixel
00127         //because this works well with convolutions
00128         return Point((left+right+1)/2, (top+bottom+1)/2);
00129     }
00130     void clip(const Rect& clip)
00131     {
00132         if(left<clip.left)
00133         {
00134             left=clip.left;
00135             if(right<left)
00136                 right=left;
00137         }
00138         if(top<clip.top)
00139         {
00140             top=clip.top;
00141             if(bottom<top)
00142                 bottom=top;
00143         }
00144         if(right>clip.right)
00145         {
00146             right=clip.right;
00147             if(left>right)
00148                 left=right;
00149         }
00150         if(bottom>clip.bottom)
00151         {
00152             bottom=clip.bottom;
00153             if(top>bottom)
00154                 top=bottom;
00155         }
00156     }
00157     void operator-=(const Rect& r)
00158     {
00159         left -= r.left;
00160         top -= r.top;
00161         right -= r.right;
00162         bottom -= r.bottom;
00163     }
00164     void operator+=(const Rect& r)
00165     {
00166         left += r.left;
00167         top += r.top;
00168         right += r.right;
00169         bottom += r.bottom;
00170     }
00171     void operator+=(const Point& p)
00172     {
00173         left += p.x;
00174         top += p.y;
00175         right += p.x;
00176         bottom += p.y;
00177     }
00178     void operator*=(int i)
00179     {
00180         left *= i;
00181         top *= i;
00182         right *= i;
00183         bottom *= i;
00184     }
00185     void AddBorder(const Point& p)
00186     {
00187         left -= p.x;
00188         top -= p.y;
00189         right += p.x;
00190         bottom += p.y;
00191     }
00192     bool operator==(const Rect& r)
00193     {
00194         if(left==r.left && top==r.top && right==r.right && bottom==r.bottom)
00195             return true;
00196         return false;
00197     }
00198 };
00199 
00201 class Position
00202 {
00203 public:
00204     Point translation;
00205     Point size;
00206     double rotation;
00207     double scale;
00208     Position() : rotation(0), scale(0) {}
00209     Position& operator=(const Position& p)
00210     {
00211         translation = p.translation;
00212         size = p.size;
00213         rotation = p.rotation;
00214         scale = p.scale;
00215         return *this;
00216     }
00217 };
00218 
00219 } // namespace Tracking
00220 } // namespace Core
00221 } // namespace Impala
00222 
00223 #endif //Imapala_Core_Tracking_BasicTypes_h

Generated on Fri Mar 19 09:31:21 2010 for ImpalaSrc by  doxygen 1.5.1