00001 #ifndef Impala_Core_Array_Trait_Functors_h
00002 #define Impala_Core_Array_Trait_Functors_h
00003
00004 #include "Core/Array/Element/E0LargeVal.h"
00005 #include "Core/Array/Element/E0SmallVal.h"
00006 #include "Core/Array/Pattern/Categories.h"
00007 #include "Core/Tracking/BasicTypes.h"
00008 #include "Core/Geometry/PointZ.h"
00009
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace Array
00015 {
00016 namespace Trait
00017 {
00018
00019 class FuncBpoMulPtr
00020 {
00021 public:
00022 typedef Pattern::TagTransInVar TransVarianceCategory;
00023 typedef Pattern::TagCallPointer CallCategory;
00024
00025 FuncBpoMulPtr()
00026 {
00027 }
00028
00029 void
00030 DoIt(double* res, double* x, double* y)
00031 {
00032 for(int i=0 ; i<3 ; i++)
00033 res[i] = x[i] * y[i];
00034 }
00035
00036 };
00037
00040 class FuncBpoAddAssignPtr
00041 {
00042 public:
00043 typedef Pattern::TagTransInVar TransVarianceCategory;
00044 typedef Pattern::TagCallPointer CallCategory;
00045
00046 FuncBpoAddAssignPtr()
00047 {
00048 }
00049
00051 void
00052 DoIt(double* x, double* y)
00053 {
00054 for(int i=0 ; i<3 ; i++)
00055 x[i] += y[i];
00056 }
00057
00058 static void
00059 NeutralElement(double* x)
00060 {
00061 for(int i=0 ; i<3 ; i++)
00062 x[i] += 0;
00063 }
00064 };
00065
00066
00068 class FuncUpoRGB2OOO
00069 {
00070 public:
00071 typedef Pattern::TagTransInVar TransVarianceCategory;
00072 typedef Pattern::TagCallValue CallCategory;
00073
00074 typedef Vec3Int32 DstArithT;
00075 typedef Vec3Int32 SrcArithT;
00076
00077 FuncUpoRGB2OOO()
00078 {
00079 }
00080
00081 Vec3Int32
00082 DoIt(const Vec3Int32& p)
00083 {
00084 int o1,o2,o3;
00085 o1 = (p.X()+p.Y()+p.Z())/3;
00086 if(o1>255)
00087 o1=255;
00088 if(o1<0)
00089 o1=0;
00090 o2 = 127+(p.X()-p.Y())/2;
00091 if(o2>255)
00092 o2=255;
00093 if(o2<0)
00094 o2=0;
00095 o3 = 127+(2*p.Z()-p.X()-p.Y())/4;
00096 if(o3>255)
00097 o3=255;
00098 if(o3<0)
00099 o3=0;
00100 return Vec3Int32(o1, o2, o3);
00101 }
00102 };
00103
00104
00106 class FuncUpoRGB2OOOPtr
00107 {
00108 public:
00109 typedef Pattern::TagTransInVar TransVarianceCategory;
00110 typedef Pattern::TagCallPointer CallCategory;
00111
00112 typedef Vec3Int32 DstArithT;
00113 typedef Vec3Int32 SrcArithT;
00114
00115 FuncUpoRGB2OOOPtr()
00116 {
00117 }
00118
00119 void DoIt(double *ooo, unsigned char* rgb)
00120 {
00121 ooo[0] = ((double)(rgb[0]+rgb[1]+rgb[2]))/3.0;
00122 ooo[1] = ((double)rgb[0]-rgb[1])/2.0;
00123 ooo[2] = ((double)2.0*rgb[2]-rgb[0]-rgb[1])/4.0;
00124 }
00125 };
00126
00127
00129 class FuncUpoOOO2RGB
00130 {
00131 public:
00132 typedef Pattern::TagTransInVar TransVarianceCategory;
00133 typedef Pattern::TagCallValue CallCategory;
00134
00135 typedef Vec3Int32 DstArithT;
00136 typedef Vec3Int32 SrcArithT;
00137
00138 FuncUpoOOO2RGB()
00139 {
00140 }
00141
00142 Vec3Int32
00143 DoIt(const Vec3Int32& p)
00144 {
00145 int o2,o3,r,g,b;
00146 o2 = p.Y() - 127;
00147 o3 = p.Z() - 127;
00148 r = p.X()+o2-(0.666666666666*o3);
00149 if(r<0)
00150 r=0;
00151 if(r>255)
00152 r=255;
00153 g = p.X()-o2-(0.666666666666*o3);
00154 if(g<0)
00155 g=0;
00156 if(g>255)
00157 g=255;
00158 b = p.X()+(1.3333333333*o3);
00159 if(b<0)
00160 b=0;
00161 if(b>255)
00162 b=255;
00163 return Vec3Int32(r, g, b);
00164 }
00165 };
00166
00167
00170 class FuncBpoManhatDist
00171 {
00172 public:
00173 typedef Pattern::TagTransInVar TransVarianceCategory;
00174 typedef Pattern::TagCallPointer CallCategory;
00175
00176 typedef Vec3Int32 DstArithT;
00177 typedef Vec3Int32 Src1ArithT;
00178 typedef Vec3Int32 Src2ArithT;
00179
00180 FuncBpoManhatDist() {}
00181
00182 void
00183 DoIt(double* res, double* p1, double* p2)
00184 {
00185 int i;
00186 double t,dist=0;
00187 for(i=0 ; i<3 ; i++)
00188 {
00189 t = p1[i] - p2[i];
00190 dist += t*t;
00191 }
00192 for(i=0 ; i<3 ; i++)
00193 {
00194 res[i] = dist;
00195 }
00196 }
00197 };
00198
00199
00204 class FuncExportDifference
00205 {
00206 public:
00207 typedef Pattern::TagTransInVar TransVarianceCategory;
00208 typedef Pattern::TagCallPointer CallCategory;
00209
00210 typedef Vec3Int32 DstArithT;
00211 typedef Vec3Int32 Src1ArithT;
00212 typedef Vec3Int32 Src2ArithT;
00213
00214 double mError;
00215
00216 FuncExportDifference() {mError = 0;}
00217
00218 void
00219 DoIt(double* res, double* p1, double* p2)
00220 {
00221 for(int i=0 ; i<3 ; i++)
00222 {
00223 double d;
00224 d = p1[0] - p2[0];
00225 mError += d*d;
00226 }
00227 }
00228 };
00229
00232 template<class ArithT, class DataT>
00233 class FuncExportMinMax
00234 {
00235 public:
00236 typedef Pattern::TagPixOpOut DirectionCategory;
00237 typedef Pattern::TagTransVar TransVarianceCategory;
00238 typedef Pattern::Tag1Phase PhaseCategory;
00239
00240 FuncExportMinMax()
00241 {
00242 Reset();
00243 }
00244
00245 void
00246 DoIt(const ArithT& v, int x, int y)
00247 {
00248 if(v<minVal)
00249 {
00250 minVal = v;
00251 minPos.mX = x;
00252 minPos.mY = y;
00253 }
00254 else
00255 if(v>maxVal)
00256 {
00257 maxVal = v;
00258 maxPos.mX = x;
00259 maxPos.mY = y;
00260 }
00261 }
00262
00263 void Reset()
00264 {
00265 minVal = Element::E0LargeVal<ArithT>(ArithT());
00266 maxVal = Element::E0SmallVal<ArithT>(ArithT());
00267 }
00268
00269 ArithT minVal;
00270 ArithT maxVal;
00271 Geometry::PointZ minPos;
00272 Geometry::PointZ maxPos;
00273 };
00274
00275
00276 class FuncUpoColorCode
00277 {
00278 public:
00279 typedef Pattern::TagTransInVar TransVarianceCategory;
00280 typedef Pattern::TagCallPointer CallCategory;
00281
00282 double mStep;
00283 FuncUpoColorCode(double maxColor)
00284 {
00285 mStep = 255.0 / maxColor;
00286 }
00287
00288 void
00289 DoIt(unsigned char* out, unsigned char* in)
00290 {
00291 if(*in)
00292 {
00293 out[0] = 255;
00294 out[1] = 255 - (*in-1) * mStep;
00295 out[2] = 255 - (*in-1) * mStep;
00296 }
00297 else
00298 {
00299 out[0] = out[1] = out[2] = 0;
00300 }
00301 }
00302
00303 void
00304 DoIt(unsigned char* out, double* in)
00305 {
00306 out[0] = (*in) * mStep;
00307 out[1] = (*in) * mStep;
00308 out[2] = (*in) * mStep;
00309 }
00310
00311 };
00312
00313 }
00314 }
00315 }
00316 }
00317
00318 #endif //Impala_Core_Array_Trait_Functors_h