TriangleDistributionHistogram2D.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 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 //              std::cout << "startX = " << startIdxX << "; stopX = " << stopIdxX << "; startY = "
00067 //                                                                      << startIdxY << "; stopY = " << stopIdxY << "," << std::endl;
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 //                              std::cout << "keys = (" << keys.first << ", " << keys.second << "); loopkeys = (" << loopKeys.first << ", " << loopKeys.second << ");" << std::endl;
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 //                              std::cout << "x = " << x << "; y = " << y << "; loopIndex = " << loopIndex << "; maxIndex = " << mBins.size() << "; scale = " << scale << ";" << std::endl;
00077                                 if (scale > 0.f){
00078                                         WeightedIdx loopValue(value);
00079                                         loopValue.weight() *= scale;
00080                                         mBins[loopIndex] += loopValue;
00081 //                                      std::cout << "Histogram2D, TriangleDistribution, added weight (" << loopValue.weight() << ") to bin with index "
00082 //                                                      << loopIndex << " at keys (" << x << ", " << y << ")"<< std::endl;
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 /* TRIANGLEDISTRIBUTIONHISTOGRAM2D_H_ */


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