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

Functors.h

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

Generated on Thu Jan 13 09:04:40 2011 for ImpalaSrc by  doxygen 1.5.1