00001 #ifndef Impala_Core_Vector_HistogramAccumulation_h 00002 #define Impala_Core_Vector_HistogramAccumulation_h 00003 00004 #include "Core/Vector/VectorSet.h" 00005 #include "Core/Vector/DivAssign.h" 00006 #include "Core/Vector/Sum.h" 00007 #include "Core/Vector/ElemMax.h" 00008 00009 namespace Impala 00010 { 00011 namespace Core 00012 { 00013 namespace Vector 00014 { 00015 00016 00020 template <class ArrayT> 00021 inline void 00022 HistogramAccumulation(VectorSet<ArrayT>* vs, bool doNormalizeHeight, 00023 bool doNormalizeWeight, bool* filter) 00024 { 00025 for (int i=0 ; i<vs->Size() ; i++) 00026 { 00027 if (filter && (!filter[i])) 00028 continue; 00029 typename VectorSet<ArrayT>::VectorT v = vs->GetVector(i, true); 00030 typename VectorSet<ArrayT>::ElemT* p = v.GetData(); 00031 for (int i=1 ; i<v.Size() ; i++) 00032 p[i] += p[i-1]; 00033 if (doNormalizeHeight || doNormalizeWeight) 00034 { 00035 typename VectorSet<ArrayT>::ElemT factor; 00036 factor = (doNormalizeHeight) ? p[v.Size()-1] : Sum(v); 00037 if (factor == 0) 00038 v = 0; 00039 else 00040 DivAssign(v, factor); 00041 } 00042 } 00043 } 00044 00045 } // namespace Vector 00046 } // namespace Core 00047 } // namespace Impala 00048 00049 #endif