Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxNgbOpticalFlow.h

00001 /*
00002  *  Copyright (c) 2002, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Leon Todoran            (todoran@science.uva.nl)
00007  */
00008 
00009 #ifndef HxNgbOpticalFlow_h
00010 #define HxNgbOpticalFlow_h
00011 
00012 #include "HxClassName.h"
00013 #include "HxSizes.h"
00014 #include "HxCategories.h"
00015 #include "HxCnum.h"
00016 #include "HxTagList.h"
00017 
00018 
00019 template<class DstT, class SrcT>
00020 class HxNgbOpticalFlow
00021 {
00022 public:
00023 
00025     typedef HxTagLoop           IteratorCategory;
00026 
00028     typedef HxTag1Phase         PhaseCategory;
00029 
00030 
00032                             HxNgbOpticalFlow(HxTagList& tags)
00033                             {
00034                                 _size = HxGetTag(tags, "ngbSize", HxSizes(5, 5, 1));
00035                                 _factor = HxScalarInt(_size.x() * _size.y());
00036                                 _result = HxVec2Double(0,0);
00037                                 
00038                                 //initialize the weighting factors
00039 //w
00040 /*                              _w2[0]  = 0.0625; _w2[1]  = 0.0625; _w2[2]  = 0.0625; _w2[3]  = 0.0625; _w2[4]  = 0.0625;
00041                                 _w2[5]  = 0.0625; _w2[6]  = 0.2500; _w2[7]  = 0.2500; _w2[8]  = 0.2500; _w2[9]  = 0.0625;
00042                                 _w2[10] = 0.0625; _w2[11] = 0.2500; _w2[12] = 0.3750; _w2[13] = 0.2500; _w2[14] = 0.0625;
00043                                 _w2[15] = 0.0625; _w2[16] = 0.2500; _w2[17] = 0.2500; _w2[18] = 0.2500; _w2[19] = 0.0625;
00044                                 _w2[20] = 0.0625; _w2[21] = 0.0625; _w2[22] = 0.0625; _w2[23] = 0.0625; _w2[24] = 0.0625;
00045 */
00046 //wij*wij
00047 /*
00048                                 _w2[0]  = 0.00390625; _w2[1]  = 0.00390625; _w2[2]  = 0.00390625; _w2[3]  = 0.00390625; _w2[4]  = 0.00390625;
00049                                 _w2[5]  = 0.00390625; _w2[6]  = 0.0625; _w2[7]  = 0.0625; _w2[8]  = 0.0625; _w2[9]  = 0.00390625;
00050                                 _w2[10] = 0.00390625; _w2[11] = 0.0625; _w2[12] = 0.140625; _w2[13] = 0.0625; _w2[14] = 0.00390625;
00051                                 _w2[15] = 0.00390625; _w2[16] = 0.0625; _w2[17] = 0.0625; _w2[18] = 0.0625; _w2[19] = 0.00390625;
00052                                 _w2[20] = 0.00390625; _w2[21] = 0.00390625; _w2[22] = 0.00390625; _w2[23] = 0.00390625; _w2[24] = 0.00390625;
00053 */
00054 /*
00055                             0.0195    0.0547    0.0625    0.0547    0.0195
00056                             0.0547    0.1953    0.2266    0.1953    0.0547
00057                             0.0625    0.2266    0.2734    0.2266    0.0625
00058                             0.0547    0.1953    0.2266    0.1953    0.0547
00059                             0.0195    0.0547    0.0625    0.0547    0.0195
00060 */
00061 //w*w
00062                                 _w2[0]  = 0.0195; _w2[1]  = 0.0547; _w2[2]  = 0.0625; _w2[3]  = 0.0547; _w2[4]  = 0.0195;
00063                                 _w2[5]  = 0.0547; _w2[6]  = 0.1953; _w2[7]  = 0.2266; _w2[8]  = 0.1953; _w2[9]  = 0.0547;
00064                                 _w2[10] = 0.0625; _w2[11] = 0.2266; _w2[12] = 0.2734; _w2[13] = 0.2266; _w2[14] = 0.0625;
00065                                 _w2[15] = 0.0547; _w2[16] = 0.1953; _w2[17] = 0.2266; _w2[18] = 0.1953; _w2[19] = 0.0547;
00066                                 _w2[20] = 0.0195; _w2[21] = 0.0547; _w2[22] = 0.0625; _w2[23] = 0.0547; _w2[24] = 0.0195;
00067                             }
00068 
00070     HxSizes                 size()
00071                             {
00072                                 return _size;
00073                             }
00074 
00076     void                    init(int x, int y, const SrcT& v1, const SrcT& v2,
00077                                  const SrcT& v3)
00078                             {
00079                                 _result = HxVec2Double(0,0);
00080                                 _IxIxw2 = HxScalarDouble(0);
00081                                 _IxIyw2 = HxScalarDouble(0);
00082                                 _IxItw2 = HxScalarDouble(0);
00083                                 _IyItw2 = HxScalarDouble(0);
00084                                 _IyIyw2 = HxScalarDouble(0);
00085                                 
00086                                 _idx = 0;
00087                             }
00088 
00090     void                    next(int x, int y, const SrcT& v1, const SrcT& v2,
00091                                  const SrcT& v3)
00092                             {
00093                                 _IxIxw2 += v1*v1*_w2[_idx];
00094                                 _IxIyw2 += v1*v2*_w2[_idx];
00095                                 _IxItw2 += v1*v3*_w2[_idx];
00096                                 _IyItw2 += v2*v3*_w2[_idx];
00097                                 _IyIyw2 += v2*v2*_w2[_idx];
00098 
00099                                 _idx++;
00100                             }
00101 
00103     DstT                    result() const
00104                             {
00105                                 SrcT det = (_IxIxw2*_IyIyw2-_IxIyw2*_IxIyw2);
00106 //                              if(det.x()==0)
00107                                 if(fabs(det.x()) <1E-11)
00108                                     return _result;
00109                                 DstT tmp( ((_IyItw2*_IxIyw2-_IxItw2*_IyIyw2)/det).x() ,
00110                                           ((_IxItw2*_IxIyw2-_IyItw2*_IxIxw2)/det).x() 
00111                                           );
00112 
00113                                 return tmp;
00114                             }
00115 
00117     static HxString         className()
00118                             {
00119                                 return HxString("opticalFlow");
00120                             }
00121 
00122 private:
00123     HxSizes                 _size;
00124     DstT                    _result;
00125     DstT                    _factor;
00126     SrcT                    _IxIyw2;
00127     SrcT                    _IxItw2;
00128     SrcT                    _IyItw2;
00129     SrcT                    _IxIxw2;
00130     SrcT                    _IyIyw2;
00131 
00132     double                  _w2[5*5];
00133     int                     _idx;
00134 };
00135 
00136 #endif

Generated on Tue Feb 3 14:18:40 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001