29 #ifndef __OccGridMapBase_h_ 30 #define __OccGridMapBase_h_ 34 #include "../scan/DataPointContainer.h" 35 #include "../util/UtilFunctions.h" 37 #include <Eigen/Geometry> 41 template<
typename ConcreteCellType,
typename ConcreteGr
idFunctions>
48 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 OccGridMapBase(
float mapResolution,
const Eigen::Vector2i& size,
const Eigen::Vector2f& offset)
51 :
GridMapBase<ConcreteCellType>(mapResolution, size, offset)
84 bool isFree(
int xMap,
int yMap)
const 101 ConcreteCellType temp;
102 temp.resetGridCell();
130 Eigen::Affine2f poseTransform((Eigen::Translation2f(
131 mapPose[0], mapPose[1]) * Eigen::Rotation2Df(mapPose[2])));
134 Eigen::Vector2f scanBeginMapf(poseTransform * dataContainer.
getOrigo());
137 Eigen::Vector2i scanBeginMapi(scanBeginMapf[0] + 0.5
f, scanBeginMapf[1] + 0.5
f);
140 int numValidElems = dataContainer.
getSize();
145 for (
int i = 0; i < numValidElems; ++i) {
148 Eigen::Vector2f scanEndMapf(poseTransform * (dataContainer.
getVecEntry(i)));
152 scanEndMapf.array() += (0.5f);
155 Eigen::Vector2i scanEndMapi(scanEndMapf.cast<
int>());
158 if (scanBeginMapi != scanEndMapi){
170 inline void updateLineBresenhami(
const Eigen::Vector2i& beginMap,
const Eigen::Vector2i& endMap,
unsigned int max_length = UINT_MAX){
172 int x0 = beginMap[0];
173 int y0 = beginMap[1];
176 if ((x0 < 0) || (x0 >= this->
getSizeX()) || (y0 < 0) || (y0 >= this->
getSizeY())) {
186 if ((x1 < 0) || (x1 >= this->
getSizeX()) || (y1 < 0) || (y1 >= this->
getSizeY())) {
193 unsigned int abs_dx =
abs(dx);
194 unsigned int abs_dy =
abs(dy);
199 unsigned int startOffset = beginMap.y() * this->
sizeX + beginMap.x();
202 if(abs_dx >= abs_dy){
203 int error_y = abs_dx / 2;
204 bresenham2D(abs_dx, abs_dy, error_y, offset_dx, offset_dy, startOffset);
207 int error_x = abs_dy / 2;
208 bresenham2D(abs_dy, abs_dx, error_x, offset_dy, offset_dx, startOffset);
211 unsigned int endOffset = endMap.y() * this->
sizeX + endMap.x();
218 ConcreteCellType& cell (this->
getCell(offset));
228 ConcreteCellType& cell (this->
getCell(offset));
243 inline void bresenham2D(
unsigned int abs_da,
unsigned int abs_db,
int error_b,
int offset_a,
int offset_b,
unsigned int offset){
247 unsigned int end = abs_da-1;
249 for(
unsigned int i = 0; i < end; ++i){
253 if((
unsigned int)error_b >= abs_da){
void setUpdateFreeFactor(float factor)
bool isOccupied(int index) const
void bresenham2D(unsigned int abs_da, unsigned int abs_db, int error_b, int offset_a, int offset_b, unsigned int offset)
void updateByScan(const DataContainer &dataContainer, const Eigen::Vector3f &robotPoseWorld)
void bresenhamCellOcc(unsigned int offset)
void bresenhamCellFree(unsigned int offset)
DataPointType getOrigo() const
virtual ~OccGridMapBase()
ConcreteGridFunctions concreteGridFunctions
EIGEN_MAKE_ALIGNED_OPERATOR_NEW OccGridMapBase(float mapResolution, const Eigen::Vector2i &size, const Eigen::Vector2f &offset)
bool isOccupied(int xMap, int yMap) const
const DataPointType & getVecEntry(int index) const
ConcreteCellType & getCell(int x, int y)
void updateLineBresenhami(const Eigen::Vector2i &beginMap, const Eigen::Vector2i &endMap, unsigned int max_length=UINT_MAX)
void updateSetOccupied(int index)
void setUpdateOccupiedFactor(float factor)
float getGridProbabilityMap(int index) const
INLINE Rall1d< T, V, S > abs(const Rall1d< T, V, S > &x)
Eigen::Vector3f getMapCoordsPose(const Eigen::Vector3f &worldPose) const
void updateSetFree(int index)
float getObstacleThreshold() const
bool isFree(int xMap, int yMap) const
void updateUnsetFree(int index)
bool isFree(int index) const