TriangleDistributionHistogramWithRemove.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 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 /* TRIANGLEDISTRIBUTIONHISTOGRAMWITHREMOVE_H_ */


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