TriangleDistributionHistogram.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Fraunhofer FKIE
00003  *
00004  * Authors: Bastian Gaspers
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  * * Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * * Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * * Neither the name of the Fraunhofer FKIE nor the names of its
00015  *   contributors may be used to endorse or promote products derived from
00016  *   this software without specific prior written permission.
00017  *
00018  * This file is part of the StructureColoring ROS package.
00019  *
00020  * The StructureColoring ROS package is free software:
00021  * you can redistribute it and/or modify it under the terms of the
00022  * GNU Lesser General Public License as published by the Free
00023  * Software Foundation, either version 3 of the License, or
00024  * (at your option) any later version.
00025  *
00026  * The StructureColoring ROS package is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU Lesser General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU Lesser General Public License
00032  * along with The StructureColoring ROS package.
00033  * If not, see <http://www.gnu.org/licenses/>.
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 /* TRIANGLEDISTRIBUTIONHISTOGRAM_H_ */


structure_coloring_fkie
Author(s): Bastian Gaspers
autogenerated on Sun Jan 5 2014 11:38:09