Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef TRIANGLEDISTRIBUTIONHISTOGRAM_H_
00037 #define TRIANGLEDISTRIBUTIONHISTOGRAM_H_
00038
00039 #include <structureColoring/histograms/Histogram.h>
00040 #include <structureColoring/histograms/WeightedIdxVector.h>
00041 #include <assert.h>
00042
00043 class TriangleDistributionHistogram : public Histogram<float, WeightedIdx, WeightedIdxVector>{
00044 public:
00045 TriangleDistributionHistogram(const float& min, const float& max, const float& binSize, const float& deviation, const size_t& maxIndex)
00046 : Histogram<float, WeightedIdx, WeightedIdxVector>(min, max, binSize), mDev(deviation), mMaxIndex(maxIndex) {}
00047
00048 typedef std::pair<int, float> IdxNWeight;
00049
00050 void addDistributedToBins(const float& key, const WeightedIdx& value);
00051
00052 float deviation() const {return mDev;}
00053 float& deviation() {return mDev;}
00054 protected:
00055 float mDev;
00056 size_t mMaxIndex;
00057 };
00058
00059 inline void TriangleDistributionHistogram::addDistributedToBins(const float& key, const WeightedIdx& value){
00060 assert(key > mMin);
00061 assert(key < mMax);
00062 int startI = std::max( 0, (int) floor( ((key - mDev) - mMin) / mBinSize ) );
00063 int stopI = std::min( (int)mBins.size(), (int) ceil( ((key + mDev) - mMin) / mBinSize ) );
00064 for(int i = startI; i < stopI; ++i){
00065 float loopKey = getKey(i);
00066 float scale = (mDev - fabsf(loopKey - key)) / mDev;
00067 if(scale > 0.f){
00068 WeightedIdx loopValue(value);
00069 loopValue.weight() *= scale;
00070 mBins[i] += loopValue;
00071 }
00072 }
00073 }
00074
00075 #endif