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 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
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
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
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
00086 void getNeighbors(Cells& cells, const Vec3& pos, unsigned int neighborhoodRadius) const {
00087 SignedIndices indices;
00088 getSignedIndicesNoException(indices, pos);
00089
00090 this->Grid2D<CellType>::getNeighbors(cells, indices, neighborhoodRadius);
00091 }
00092
00093 protected:
00094
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
00112 Plane3D mPlane;
00113 float mXMin;
00114 float mXMax;
00115 float mYMin;
00116 float mYMax;
00117 float mCellSize;
00118 };
00119
00120 #endif