PositionedGrid2D.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 POSITIONEDGRID2D_H_
00037 #define POSITIONEDGRID2D_H_
00038 
00039 #include "Grid2D.h"
00040 #include <structureColoring/structures/Plane3D.h>
00041 #include <structureColoring/histograms/OutOfRangeException.h>
00042 
00043 //#include <iostream>
00044 
00045 template<typename CellType>
00046 class PositionedGrid2D : public Grid2D<CellType>{
00047 public:
00048         typedef OutOfRangeException OutOfRange;
00049         typedef std::pair<unsigned int, unsigned int> Indices;
00050         typedef std::pair<int, int> SignedIndices;
00051         typedef Eigen::Vector3f Vec3;
00052         typedef std::vector<CellType> Cells;
00053 
00054 //constructor
00055         PositionedGrid2D(): mXMin(0.f), mXMax(0.f), mYMin(0.f), mYMax(0.f), mCellSize(0.f){}
00056 
00057         PositionedGrid2D(const Plane3D& plane, const float& xMin, const float& xMax,
00058                         const float& yMin, const float& yMax, const float& cellSize)
00059         : Grid2D<CellType>(std::floor((xMax - xMin)/cellSize)+1, std::floor((yMax - yMin)/cellSize)+1),
00060                 mPlane(plane), mXMin(xMin), mXMax(xMax), mYMin(yMin), mYMax(yMax), mCellSize(cellSize)
00061         {
00062                 mXMax = mXMin + (float)Grid2D<CellType>::getWidth() * cellSize;
00063                 mYMax = mYMin + (float)Grid2D<CellType>::getHeight() * cellSize;
00064         }
00065 
00066 //getter
00067         const Plane3D& getPlane3D() const {return mPlane;}
00068         float getXMin() const {return mXMin;}
00069         float getXMax() const {return mXMax;}
00070         float getYMin() const {return mYMin;}
00071         float getYMax() const {return mYMax;}
00072         float getCellSize() const {return mCellSize;}
00073 
00074         typename Cells::const_reference operator() (const Vec3& pos) const {
00075                 Indices indices;
00076                 getIndices(indices, pos);
00077                 return this->Grid2D<CellType>::operator() (indices);
00078         }
00079         typename Cells::reference operator() (const Vec3& pos) {
00080                 Indices indices;
00081                 getIndices(indices, pos);
00082                 return this->Grid2D<CellType>::operator() (indices);
00083         }
00084 
00085 //calculations
00086         void getNeighbors(Cells& cells, const Vec3& pos, unsigned int neighborhoodRadius) const {
00087                 SignedIndices indices;
00088                 getSignedIndicesNoException(indices, pos);
00089 //              std::cout << "center point of get Neighbors is (" << indices.first << ", " << indices.second << ")" << std::endl;
00090                 this->Grid2D<CellType>::getNeighbors(cells, indices, neighborhoodRadius);
00091         }
00092 
00093 protected:
00094 //helper
00095         void getIndices(Indices& outIndices, const Vec3& pos) const{
00096                 Vec3 transformedPos = mPlane.transformToXYPlane(pos);
00097                 if (transformedPos.x() < mXMin || transformedPos.x() > mXMax
00098                                 || transformedPos.y() < mYMin || transformedPos.y() > mYMax){
00099                         throw OutOfRange("key is out of range");
00100                 }
00101                 outIndices.first = std::floor((transformedPos.x() - mXMin)/mCellSize);
00102                 outIndices.second = std::floor((transformedPos.y() - mYMin)/mCellSize);
00103         }
00104 
00105         void getSignedIndicesNoException(SignedIndices& outIndices, const Vec3& pos) const{
00106                 Vec3 transformedPos = mPlane.transformToXYPlane(pos);
00107                 outIndices.first = std::floor((transformedPos.x() - mXMin)/mCellSize);
00108                 outIndices.second = std::floor((transformedPos.y() - mYMin)/mCellSize);
00109         }
00110 
00111 //members
00112         Plane3D mPlane;
00113         float mXMin;
00114         float mXMax;
00115         float mYMin;
00116         float mYMax;
00117         float mCellSize;
00118 };
00119 
00120 #endif /* POSITIONEDGRID2D_H_ */


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