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

HxNgbNonMaxSuppression2d.h

00001 /*
00002  *  Copyright (c) 1999, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Edo Poll                (poll@wins.uva.nl)
00007  */
00008 
00009 #ifndef HxNgbNonMaxSuppression2d_h
00010 #define HxNgbNonMaxSuppression2d_h
00011 
00012 #include "HxClassName.h"
00013 #include "HxSizes.h"
00014 #include "HxCategories.h"
00015 #include "HxCnum.h"
00016 #include "HxTagList.h"
00017 
00018 
00024 template<class ArithT>
00025 class HxNgbNonMaxSuppression2d
00026 {
00027 public:
00028 
00030     typedef HxTagCnum           IteratorCategory;
00031 
00033     typedef HxTag1Phase         PhaseCategory;
00034 
00036     typedef HxCnum          CnumType;
00037 
00038 
00040                             HxNgbNonMaxSuppression2d(HxTagList& tags);
00041 
00043                             ~HxNgbNonMaxSuppression2d();
00044 
00046     HxSizes                 size();
00047 
00049     CnumType                begin();
00050 
00052     CnumType&               end();
00053 
00055     void                    init(int x, int y, const ArithT& value);
00056 
00058     void                    next(int x, int y, const ArithT& value);
00059 
00061     const ArithT&           result() const;
00062 
00064     static HxString         className();
00065 
00066 private:
00067     HxCoord*                _coords;
00068     ArithT                  _resultPix;
00069     const ArithT            _nullPix;
00070     double                  _resultMag;
00071     bool                    _suppressed;
00072     static HxCoord          _coordPairs[12];
00073     CnumType                _end;
00074 };
00075 
00076 template<class ArithT>
00077 inline TYPENAME HxNgbNonMaxSuppression2d<ArithT>::CnumType
00078 HxNgbNonMaxSuppression2d<ArithT>::begin()
00079 {
00080     return CnumType(&_coords[0]);
00081 }
00082 
00083 template<class ArithT>
00084 inline TYPENAME HxNgbNonMaxSuppression2d<ArithT>::CnumType&
00085 HxNgbNonMaxSuppression2d<ArithT>::end()
00086 {
00087     return _end;
00088 }
00089 
00090 #include "HxBreakPoint.h"
00091 
00092 template<class ArithT>
00093 inline void
00094 HxNgbNonMaxSuppression2d<ArithT>::init(int, int, const ArithT& v)
00095 {
00096     HxBreakPoint();
00097     static const double tan22_5 = 0.41421356;
00098     static const double tan67_5 = 2.41421356;
00099 
00100     double x(v.x()), y(v.y());
00101     _resultPix = v;
00102     _resultMag = x*x+y*y;
00103     _suppressed = false;
00104 
00105     if (x != 0) {
00106         double rc = y/x;
00107         double frc = fabs(rc);
00108         int i = (frc < tan22_5) ? 0 : ( (frc < tan67_5) ? 1 : 2 );
00109         if (rc < 0)
00110             i += 3;
00111         _coords = &_coordPairs[i<<1];
00112     } else {
00113         _coords = &_coordPairs[4];
00114     }
00115     _end = &_coords[2];
00116 }
00117 
00118 template<class ArithT>
00119 inline HxString
00120 HxNgbNonMaxSuppression2d<ArithT>::className()
00121 {
00122     static HxString s("nonMaxSuppression");
00123     return s;
00124 }
00125 
00126 template<class ArithT>
00127 inline void
00128 HxNgbNonMaxSuppression2d<ArithT>::next(int, int, const ArithT& v)
00129 {
00130     if ((v.x()*v.x() + v.y()*v.y()) > _resultMag)
00131         _suppressed = true;
00132 }
00133 
00134 template<class ArithT>
00135 inline HxSizes
00136 HxNgbNonMaxSuppression2d<ArithT>::size()
00137 {
00138     return HxSizes(3, 3, 1);
00139 }
00140 
00141 template<class ArithT>
00142 inline const ArithT&
00143 HxNgbNonMaxSuppression2d<ArithT>::result() const
00144 {
00145     return _suppressed ? _nullPix : _resultPix;
00146 }
00147 
00148 #ifdef INC_TEMPLATE_SRC
00149 #include "HxNgbNonMaxSuppression2d.c"
00150 #endif
00151 
00152 #endif

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