00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef HxNgbNonMaxSuppression2d_h
00010 #define HxNgbNonMaxSuppression2d_h
00011
00012 #include "HxClassName.h"
00013 #include "HxSizes.h"
00014 #include "HxNgbOpCategory.h"
00015 #include "HxCnum.h"
00016 #include "HxTagList.h"
00017
00023 template<class ArithT>
00024 class HxNgbNonMaxSuppression2d
00025 {
00026 public:
00027
00029 typedef HxNgbCnumTag IteratorCategory;
00030
00032 typedef HxNgb1PhaseTag PhaseCategory;
00033
00035 typedef HxNgbTransInVarTag TransVarianceCategory;
00036
00037 typedef HxCnum CnumType;
00038
00039 HxNgbNonMaxSuppression2d(HxTagList& tags);
00040 ~HxNgbNonMaxSuppression2d();
00041
00042 HxSizes size();
00043
00044 CnumType begin();
00045 CnumType& end();
00046
00047 void init(const ArithT& value);
00048 void next(int x, int y, const ArithT& value);
00049 const ArithT& result() const;
00050
00052 static HxString className();
00053
00054 private:
00055 HxCoord* _coords;
00056 ArithT _resultPix;
00057 const ArithT _nullPix;
00058 double _resultMag;
00059 bool _suppressed;
00060 static HxCoord _coordPairs[12];
00061 CnumType _end;
00062 };
00063
00064 template<class ArithT>
00065 inline TYPENAME HxNgbNonMaxSuppression2d<ArithT>::CnumType
00066 HxNgbNonMaxSuppression2d<ArithT>::begin()
00067 {
00068 return CnumType(&_coords[0]);
00069 }
00070
00071 template<class ArithT>
00072 inline TYPENAME HxNgbNonMaxSuppression2d<ArithT>::CnumType&
00073 HxNgbNonMaxSuppression2d<ArithT>::end()
00074 {
00075 return _end;
00076 }
00077
00078 #include "HxBreakPoint.h"
00079
00080 template<class ArithT>
00081 inline void
00082 HxNgbNonMaxSuppression2d<ArithT>::init(const ArithT& v)
00083 {
00084 HxBreakPoint();
00085 static const double tan22_5 = 0.41421356;
00086 static const double tan67_5 = 2.41421356;
00087
00088 double x(v.x()), y(v.y());
00089 _resultPix = v;
00090 _resultMag = x*x+y*y;
00091 _suppressed = false;
00092
00093 if (x != 0) {
00094 double rc = y/x;
00095 double frc = fabs(rc);
00096 int i = (frc < tan22_5) ? 0 : ( (frc < tan67_5) ? 1 : 2 );
00097 if (rc < 0)
00098 i += 3;
00099 _coords = &_coordPairs[i<<1];
00100 } else {
00101 _coords = &_coordPairs[4];
00102 }
00103 _end = &_coords[2];
00104 }
00105
00106 template<class ArithT>
00107 inline HxString
00108 HxNgbNonMaxSuppression2d<ArithT>::className()
00109 {
00110 static HxString s("nonMaxSuppression");
00111 return s;
00112 }
00113
00114 template<class ArithT>
00115 inline void
00116 HxNgbNonMaxSuppression2d<ArithT>::next(int, int, const ArithT& v)
00117 {
00118 if ((v.x()*v.x() + v.y()*v.y()) > _resultMag)
00119 _suppressed = true;
00120 }
00121
00122 template<class ArithT>
00123 inline HxSizes
00124 HxNgbNonMaxSuppression2d<ArithT>::size()
00125 {
00126 return HxSizes(3, 3, 1);
00127 }
00128
00129 template<class ArithT>
00130 inline const ArithT&
00131 HxNgbNonMaxSuppression2d<ArithT>::result() const
00132 {
00133 return _suppressed ? _nullPix : _resultPix;
00134 }
00135
00136 #ifdef INC_TEMPLATE_SRC
00137 #include "HxNgbNonMaxSuppression2d.c"
00138 #endif
00139
00140 #endif