00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef HxNgbPercentile2d_h
00011 #define HxNgbPercentile2d_h
00012
00013 #include "HxClassName.h"
00014 #include "HxSizes.h"
00015 #include "HxNgbOpCategory.h"
00016 #include "HxTagList.h"
00017
00018
00021 template<class ArithT>
00022 class HxNgbPercentile2d
00023 {
00024 public:
00025
00027 typedef HxNgbLoopTag IteratorCategory;
00028
00030 typedef HxNgb1PhaseTag PhaseCategory;
00031
00033 typedef HxNgbTransInVarTag TransVarianceCategory;
00034
00035
00040 HxNgbPercentile2d(HxTagList& tags);
00041 ~HxNgbPercentile2d();
00042
00043 HxSizes size();
00044 void init();
00045
00046 void next(int x, int y, ArithT value);
00047 ArithT result() const;
00048
00050 static HxString className();
00051
00052 private:
00053 int _pctIdx;
00054 int _size;
00055
00056 ArithT* _values;
00057 int _i;
00058 };
00059
00060 template<class ArithT>
00061 ostream&
00062 operator<<(ostream& os, const HxNgbPercentile2d<ArithT>& pct)
00063 {
00064 return pct.put(os);
00065 }
00066
00067 template<class ArithT>
00068 inline HxString
00069 HxNgbPercentile2d<ArithT>::className()
00070 {
00071 static HxString s("percentile");
00072 return s;
00073 }
00074
00075 template<class ArithT>
00076 inline void
00077 HxNgbPercentile2d<ArithT>::init()
00078 {
00079 _i = 0;
00080 }
00081
00082 template<class ArithT>
00083 inline void
00084 HxNgbPercentile2d<ArithT>::next(int, int, ArithT value)
00085 {
00086 _values[_i++] = value;
00087 }
00088
00089 template<class ArithT>
00090 inline HxSizes
00091 HxNgbPercentile2d<ArithT>::size()
00092 {
00093 return HxSizes(_size, _size, 1);
00094 }
00095
00096 template<class ArithT>
00097 inline ArithT
00098 HxNgbPercentile2d<ArithT>::result() const
00099 {
00100 std::sort(&_values[0], &_values[_size*_size]);
00101 return _values[_pctIdx];
00102 }
00103
00104 #ifdef INC_TEMPLATE_SRC
00105 #include "HxNgbPercentile2d.c"
00106 #endif
00107
00108 #endif