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 TRIANGLEDISTRIBUTIONHISTOGRAM2D_H_
00037 #define TRIANGLEDISTRIBUTIONHISTOGRAM2D_H_
00038
00039 #include <structureColoring/histograms/Histogram2D.h>
00040 #include <structureColoring/histograms/WeightedIdxVector.h>
00041 #include <assert.h>
00042
00043 class TriangleDistributionHistogram2D : public Histogram2D<float, WeightedIdx, WeightedIdxVector> {
00044 public:
00045 typedef std::pair<float, float> Keys;
00046
00047 TriangleDistributionHistogram2D(const float& minX, const float& maxX, const float& minY, const float& maxY,
00048 const float& binSize, const float& deviation) :
00049 Histogram2D<float, WeightedIdx, WeightedIdxVector> (minX, maxX, minY, maxY, binSize), mDev(deviation) {
00050 }
00051
00052 void addDistributedToBins(const float& xKey, const float& yKey, const WeightedIdx& value) {
00053 addDistributedToBins(std::make_pair(xKey, yKey), value);
00054 }
00055
00056 void addDistributedToBins(const Keys& keys, const WeightedIdx& value){
00057 assert(keys.first >= mMinX);
00058 assert(keys.first <= mMaxX);
00059 assert(keys.second >= mMinY);
00060 assert(keys.second <= mMaxY);
00061 int startIdxX, startIdxY, stopIdxX, stopIdxY;
00062 startIdxX = std::max( 0, (int) floor( ((keys.first - mDev) - mMinX) / mBinSize ) );
00063 startIdxY = std::max( 0, (int) floor( ((keys.second - mDev) - mMinY) / mBinSize ) );
00064 stopIdxX = std::min( (int)mXSpan, (int) ceil( ((keys.first + mDev) - mMinX) / mBinSize ) );
00065 stopIdxY = std::min( (int)mYSpan, (int) ceil( ((keys.second + mDev) - mMinY) / mBinSize ) );
00066
00067
00068 for(int x = startIdxX; x < stopIdxX; ++x){
00069 for(int y = startIdxY; y < stopIdxY; ++y){
00070 size_t loopIndex = getIdx((size_t)x,(size_t) y);
00071 Keys loopKeys = getKeys(loopIndex);
00072
00073 float dist2d = sqrt((keys.first - loopKeys.first) * (keys.first - loopKeys.first)
00074 + (keys.second - loopKeys.second) * (keys.second - loopKeys.second));
00075 float scale = (mDev - dist2d) / mDev;
00076
00077 if (scale > 0.f){
00078 WeightedIdx loopValue(value);
00079 loopValue.weight() *= scale;
00080 mBins[loopIndex] += loopValue;
00081
00082
00083 }
00084 }
00085 }
00086 }
00087
00088 float deviation() const {
00089 return mDev;
00090 }
00091
00092 float& deviation() {
00093 return mDev;
00094 }
00095 private:
00096 float mDev;
00097 };
00098
00099 #endif