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
00022 inline int Random(int range)
00023 {
00024 return rand() % range;
00025 }
00026
00027 class Point
00028 {
00029 public:
00030 int x,y;
00031 Point() : x(0),y(0) {}
00032 Point(int ax, int ay) : x(ax),y(ay) {}
00033 Point(const Point& p) : x(p.x),y(p.y) {}
00034 Point& operator=(const Point& p)
00035 {
00036 x=p.x;
00037 y=p.y;
00038 return *this;
00039 }
00040
00041 Point& operator+=(int i)
00042 {
00043 x+=i;
00044 y+=i;
00045 return *this;
00046 }
00047 Point& operator-=(int i)
00048 {
00049 x-=i;
00050 y-=i;
00051 return *this;
00052 }
00053 Point& operator-=(const Point& p)
00054 {
00055 x-=p.x;
00056 y-=p.y;
00057 return *this;
00058 }
00059 Point& operator/=(int i)
00060 {
00061 if(i!=0)
00062 {
00063 x/=i;
00064 y/=i;
00065 return *this;
00066 }
00067 }
00068 Point& operator*=(int i)
00069 {
00070 if(i!=0)
00071 {
00072 x*=i;
00073 y*=i;
00074 return *this;
00075 }
00076 }
00077
00078 int Inproduct()
00079 {
00080 return x*y;
00081 }
00082 };
00083
00085 class Rect
00086 {
00087 public:
00088 int left,top,right,bottom;
00089 Rect()
00090 :left(0),
00091 top(0),
00092 right(0),
00093 bottom(0)
00094 {
00095 }
00096 Rect(int l,int t,int r,int b)
00097 :left(l),
00098 top(t),
00099 right(r),
00100 bottom(b)
00101 {
00102 }
00103 Rect(const Rect& r)
00104 :left(r.left),
00105 top(r.top),
00106 right(r.right),
00107 bottom(r.bottom)
00108 {
00109 }
00110 Rect(const Point& p)
00111 :left(p.x),
00112 top(p.y),
00113 right(p.x),
00114 bottom(p.y)
00115 {
00116 }
00117
00118 int width() const
00119 {
00120 return right-left+1;
00121 }
00122 int height() const
00123 {
00124 return bottom-top+1;
00125 }
00126 Point size() const
00127 {
00128 return Point(width(), height());
00129 }
00130 Point mid() const
00131 {
00132
00133
00134
00135
00136 return Point((left+right+1)/2, (top+bottom+1)/2);
00137 }
00138 void clip(const Rect& clip)
00139 {
00140 if(left<clip.left)
00141 {
00142 left=clip.left;
00143 if(right<left)
00144 right=left;
00145 }
00146 if(top<clip.top)
00147 {
00148 top=clip.top;
00149 if(bottom<top)
00150 bottom=top;
00151 }
00152 if(right>clip.right)
00153 {
00154 right=clip.right;
00155 if(left>right)
00156 left=right;
00157 }
00158 if(bottom>clip.bottom)
00159 {
00160 bottom=clip.bottom;
00161 if(top>bottom)
00162 top=bottom;
00163 }
00164 }
00165 void operator-=(const Rect& r)
00166 {
00167 left -= r.left;
00168 top -= r.top;
00169 right -= r.right;
00170 bottom -= r.bottom;
00171 }
00172 void operator+=(const Rect& r)
00173 {
00174 left += r.left;
00175 top += r.top;
00176 right += r.right;
00177 bottom += r.bottom;
00178 }
00179 void operator+=(const Point& p)
00180 {
00181 left += p.x;
00182 top += p.y;
00183 right += p.x;
00184 bottom += p.y;
00185 }
00186 void operator*=(int i)
00187 {
00188 left *= i;
00189 top *= i;
00190 right *= i;
00191 bottom *= i;
00192 }
00193 void AddBorder(const Point& p)
00194 {
00195 left -= p.x;
00196 top -= p.y;
00197 right += p.x;
00198 bottom += p.y;
00199 }
00200 bool operator==(const Rect& r)
00201 {
00202 if(left==r.left && top==r.top && right==r.right && bottom==r.bottom)
00203 return true;
00204 return false;
00205 }
00206 };
00207
00213 class Position
00214 {
00215 public:
00216 Point translation;
00217 Point size;
00218 double rotation;
00219 double scale;
00220 Position() : rotation(0), scale(0) {}
00221 Position& operator=(const Position& p)
00222 {
00223 translation = p.translation;
00224 size = p.size;
00225 rotation = p.rotation;
00226 scale = p.scale;
00227 return *this;
00228 }
00229 };
00230
00231 }
00232 }
00233 }
00234
00235 #endif //Imapala_Core_Tracking_BasicTypes_h