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 TRIANGLEDISTRIBUTIONHISTOGRAMWITHREMOVE_H_
00037 #define TRIANGLEDISTRIBUTIONHISTOGRAMWITHREMOVE_H_
00038
00039 #include "TriangleDistributionHistogram.h"
00040
00041 class TriangleDistributionHistogramWithRemove : public TriangleDistributionHistogram{
00042 public:
00043 TriangleDistributionHistogramWithRemove(const float& min, const float& max, const float& binSize, const float& deviation,
00044 const size_t& maxIndex)
00045 : TriangleDistributionHistogram(min, max, binSize, deviation, maxIndex), mIndexLUT(LUTType(maxIndex)){}
00046
00047 void addDistributedToBins(const float& key, const WeightedIdx& value);
00048 void removeDistributed(const IdxNWeight& wi, const int& index);
00049 void removeAllFromBin(const float& key);
00050
00051 private:
00052 typedef std::vector<IdxNWeight> IdxWeightPairs;
00053 typedef std::vector<IdxWeightPairs> LUTType;
00054
00055 LUTType mIndexLUT;
00056 };
00057
00058 inline void TriangleDistributionHistogramWithRemove::addDistributedToBins(const float& key, const WeightedIdx& value){
00059 assert(key > mMin);
00060 assert(key < mMax);
00061 int startI = std::max( 0, (int) floor( ((key - mDev) - mMin) / mBinSize ) );
00062 int stopI = std::min( (int)mBins.size(), (int) ceil( ((key + mDev) - mMin) / mBinSize ) );
00063 for(int i = startI; i < stopI; ++i){
00064 float loopKey = getKey(i);
00065 float scale = (mDev - fabsf(loopKey - key)) / mDev;
00066 if(scale > 0.f){
00067 WeightedIdx loopValue(value);
00068 loopValue.weight() *= scale;
00069 mBins[i] += loopValue;
00070 IdxWeightPairs& LUTEntry(mIndexLUT[loopValue.index()]);
00071 if(LUTEntry.size() == LUTEntry.capacity()-1)
00072 LUTEntry.reserve(LUTEntry.size() * 100);
00073 LUTEntry.push_back(std::make_pair(i, loopValue.weight()));
00074 }
00075 }
00076 }
00077
00078 inline void TriangleDistributionHistogramWithRemove::removeDistributed(const IdxNWeight& inw, const int& index){
00079 mBins[inw.first] -= WeightedIdx(inw.second, index);
00080 }
00081
00082 inline void TriangleDistributionHistogramWithRemove::removeAllFromBin(const float& key){
00083 if(key < mMin || key > mMax){
00084 char exchar[255];
00085 sprintf(exchar, "%f < %f < %f", mMin, key, mMax);
00086 std::string exceptiontext(exchar);
00087 throw OutOfRange(exceptiontext);
00088 }
00089 typedef std::vector<int> IdxVector;
00090 IdxVector nodes(mBins[getIdx(key)].nodeIndices());
00091 for(IdxVector::const_iterator bin_it = nodes.begin(); bin_it != nodes.end(); ++bin_it){
00092 for(IdxWeightPairs::const_iterator lut_it = mIndexLUT[*bin_it].begin(); lut_it != mIndexLUT[*bin_it].end(); ++lut_it){
00093 removeDistributed(*lut_it, *bin_it);
00094 }
00095 mIndexLUT[*bin_it].clear();
00096 }
00097 }
00098
00099 #endif