Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

NgbPercentile.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_Trait_NgbPercentile_h
00002 #define Impala_Core_Array_Trait_NgbPercentile_h
00003 
00004 #include "Core/Array/Pattern/Categories.h"
00005 #include "Core/Array/Pattern/Cnum.h"
00006 #include "Core/Array/Element/E1Cast.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 namespace Trait
00015 {
00016 
00017 
00020 template<class DstArrayT, class SrcArrayT>
00021 class NgbPercentile
00022 {
00023 public:
00024 
00026     typedef Pattern::TagLoop IteratorCategory;
00027 
00029     typedef Pattern::Tag1Phase PhaseCategory;
00030 
00031     typedef typename DstArrayT::StorType DstStorType;
00032     typedef typename DstArrayT::ArithType DstArithType;
00033     typedef typename SrcArrayT::StorType SrcStorType;
00034     typedef typename SrcArrayT::ArithType SrcArithType;
00035 
00037     NgbPercentile(int size, double perc)
00038     {
00039         mSize = size;
00040         mPctIdx = perc * (mSize * mSize);
00041         mValues = new SrcArithType[mSize * mSize];
00042     }
00043 
00045     ~NgbPercentile()
00046     {
00047         if (mValues)
00048             delete [] mValues;
00049     }
00050 
00052     int
00053     Width()
00054     {
00055         return mSize;
00056     }
00057 
00059     int
00060     Height()
00061     {
00062         return mSize;
00063     }
00064 
00066     void
00067     Init(int x, int y, const SrcArithType& value)
00068     {
00069         mI = 0;
00070     }
00071 
00073     void
00074     NextEl(int x, int y, const SrcArithType& value)
00075     {
00076         mValues[mI++] = value;
00077     }
00078 
00080     DstArithType
00081     Result() const
00082     {
00083         std::sort(&mValues[0], &mValues[mSize*mSize]);
00084         return mValues[mPctIdx];
00085     }
00086 
00087 private:
00088     int     mPctIdx;
00089     int     mSize;
00090 
00091     SrcArithType* mValues;
00092     int     mI;
00093 };
00094 
00095 
00096 } // namespace Trait
00097 } // namespace Array
00098 } // namespace Core
00099 } // namespace Impala
00100 
00101 #endif

Generated on Fri Mar 19 09:30:59 2010 for ImpalaSrc by  doxygen 1.5.1