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

HxNgbLocalMode.h

00001 /*
00002  *  Copyright (c) 2002, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Frans Verster (verster@science.uva.nl)
00007  */
00008 
00009 #ifndef HxNgbLocalMode_h
00010 #define HxNgbLocalMode_h
00011 
00012 #include "HxClassName.h"
00013 #include "HxSizes.h"
00014 #include "HxCategories.h"
00015 #include "HxCnum.h"
00016 #include "HxTagList.h"
00017 
00018 inline double norm2sqr(HxScalarDouble val) { return val.x()*val.x(); }
00019 inline double norm2sqr(HxVec2Double val) { return val.x()*val.x()+val.y()*val.y(); }
00020 inline double norm2sqr(HxVec3Double val) { return val.x()*val.x()+val.y()*val.y()+val.z()*val.z(); }
00021 
00022 
00025 template<class DstT, class SrcT>
00026 class HxNgbLocalMode
00027 {
00028 public:
00029 
00031     typedef HxTagLoop           IteratorCategory;
00032 
00034     typedef HxTag1Phase         PhaseCategory;
00035 
00036 
00038                             HxNgbLocalMode(HxTagList& tags) 
00039                             {
00040                                 _size = HxGetTag(tags, "ngbSize", HxSizes(11, 11, 1));
00041                                 if (_size.x()<1&&_size.x()%2!=0&&_size.y()<1&&_size.y()%2!=0&&_size.z()!=1)
00042                                     throw HxString("Error: HxNgbLocalMode kernel must be 2D odd sized");
00043                                 hsx = (_size.x()+0)/2; // e.g. s=11, half=5, xin=[0..11> xwork=[-5..+5]
00044                                 hsy = (_size.y()+0)/2;
00045                                 _tags=tags;
00046                                 double sx = HxGetTag(tags, "sigmax", 2.0);
00047                                 double sy = HxGetTag(tags, "sigmay", 2.0);
00048                                 double sval = HxGetTag(tags, "sigmaval", 10.0);
00049                                 _sigmax = -0.5/sx/sx;
00050                                 _sigmay = -0.5/sy/sy;
00051                                 _sigmaval = -0.5/sval/sval;
00052                             }
00053 
00055     HxSizes                 size()
00056                             {
00057                                 return _size;
00058                             }
00059 
00061     void                    init(int /*x*/, int /*y*/, const SrcT& /*v1*/, const SrcT& v2)
00062                             {
00063                                 _v2=v2;
00064                                 teller = HxScalarDouble(0.0);
00065                                 noemer=0.0;
00066                             }
00067 
00068     void                    check(int i, int j) 
00069                             {
00070                                 if (i<-hsx||i>hsx||j<-hsy||j>hsy)
00071                                     std::cout << "error i=" << i << ", j" << j << std::endl;
00072                             }
00073 
00075     void                    next(int x, int y, const SrcT& v1, const SrcT& /*v2*/)
00076                             {
00077                                 int i=x-hsx;
00078                                 int j=y-hsy;
00079 #ifdef _DEBUG
00080                                 check(i,j);
00081 #endif
00082                                 double po=0;
00083                                 po += i*i*_sigmax;
00084                                 po += j*j*_sigmay;
00085                                 po += norm2sqr(v1-_v2)*_sigmaval;
00086                                 double w=exp(po);
00087                                 teller += v1*DstT(HxScalarDouble(w));
00088                                 noemer += w;
00089                             }
00090 
00092     DstT                    result() const
00093                             {
00094                                 return teller/DstT(HxScalarDouble(noemer));
00095                             }
00096 
00098     static HxString         className()
00099                             {
00100                                 return HxString("localMode");
00101                             }
00102 
00103 private:
00104     HxSizes                 _size;
00105     HxTagList               _tags;
00106     int                     _x, _y;
00107     int                     hsx, hsy; // half kernel size x,y
00108     SrcT                    _v2;
00109     double                  _sigmax, _sigmay, _sigmaval; // calculated from taglist
00110     DstT                    teller;
00111     double                  noemer;
00112 
00113 };
00114 
00115 #endif

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