Templated class which represents a n-dimensional grid map. Its cells are assumed to be cubic, that is, the size (leaf size) of each cell is the same in every dimension. More...
#include <ndgridmap.hpp>
Public Member Functions | |
nDGridMap (const std::array< unsigned int, ndims > &dimsize, double leafsize=1.0f) | |
void | resize (const std::array< unsigned int, ndims > &dimsize) |
Resizes each dimension of the grid according dimsize. | |
T & | operator[] (unsigned int idx) |
Returns the cell with index idx. | |
double | getLeafSize () const |
Returns the leaf size of the grid. | |
void | setLeafSize (const double leafsize) |
T & | getCell (unsigned int idx) |
Returns the cell with index idx. | |
std::array< unsigned int, ndims > | getDimSizes () const |
Returns the size of each dimension. | |
double | getMinValueInDim (unsigned int idx, unsigned int dim) |
Returns the minimum value of neighbors of cell idx in dimension dim. | |
unsigned int | getNumberNeighborsInDim (int idx, std::array< unsigned int, ndims > &m, unsigned int dim) |
Returns number of valid neighbors for cell idx in dimension dim, stored in m. | |
unsigned int | getNeighbors (unsigned int idx, std::array< unsigned int, 2 *ndims > &neighs) |
Computes the indices of the 4-connectivity neighbors. As it is based on arrays (to improve performance) the number of neighbors found is returned since the neighs array will have always the same size. | |
void | getNeighborsInDim (unsigned int idx, std::array< unsigned int, 2 *ndims > &neighs, unsigned int dim) |
Computes the indices of the 4-connectivity neighbors of cell idx in a specified direction dim. This function is designed to be used within getNeighbors() or getMinValueInDim() since it increments the private member n_neighs and it is only reset in those functions. | |
void | getNeighborsInDim (unsigned int idx, std::array< unsigned int, 2 > &neighs, unsigned int dim) |
Special version (because of neighbors array size) of this function to be used with getMinValueInDim(). | |
unsigned int | idx2coord (unsigned int idx, std::array< unsigned int, ndims > &coords) |
Transforms from index to coordinates. | |
unsigned int | coord2idx (const std::array< unsigned int, ndims > &coords, unsigned int &idx) |
Transforms from coordinates to index. | |
void | showCoords (unsigned int idx) |
Shows the coordinates from an index. | |
void | showCoords (std::array< unsigned int, ndims > coords) |
Shows the coordinates from a set of coordinates. | |
void | showIdx (const std::array< unsigned int, ndims > &coords) |
Shows the index from the coordinates. | |
unsigned int | size () const |
Returns number of cells in the grid. | |
double | getMaxValue () const |
Returns the maximum value of the cells in the grid. | |
bool | isClean () const |
Returns if the grid is clean (ready to use) | |
void | setClean (bool c) |
Sets the state of the grid. True means clean. | |
void | clean () |
Cleans the grid if it is not clean already. Calls Cell::setDefault() | |
void | clear () |
Erases the content of the grid. Must be resized later. | |
std::string | getDimSizesStr () |
Returns "size(dim(0)) \t size(dim(1)) \t...". | |
void | setOccupiedCells (const std::vector< unsigned int > &obs) |
Sets the cells which are occupied. Usually called by grid loaders. | |
void | setOccupiedCells (std::vector< unsigned int > &&obs) |
Sets (by move semantics) the cells which are occupied. Usually called by grid loaders. | |
void | getOccupiedCells (std::vector< unsigned int > &obs) const |
Returns the indices of the occupied cells of the grid. | |
double | getAvgSpeed () |
Returns the avegare velocity ignoring those with 0 velocitie (obstacles). | |
double | getMaxSpeed () |
Returns the maximum speed (occupancy value) in the grid. | |
Static Public Member Functions | |
static constexpr size_t | getNDims () |
Makes the number of dimensions of the grid available at compilation time. | |
Private Attributes | |
std::vector< T > | cells_ |
Main container for the class. | |
std::array< unsigned int, ndims > | dimsize_ |
Size of each dimension. | |
double | leafsize_ |
Real size of the cells. It is assumed that the cells in the grid are cubic. | |
unsigned int | ncells_ |
Number of cells in the grid (size) | |
bool | clean_ |
Flag to indicate if the grid is ready to use. | |
std::array< unsigned int, ndims > | d_ |
Auxiliar array to speed up neighbor and indexing generalization: stores parcial multiplications of dimensions sizes. d_[0] = dimsize_[0]; d_[1] = dimsize_[0]*dimsize_[1]; etc. | |
std::array< unsigned int, 2 > | n_ |
Auxiliar array to speed up neighbor and indexing generalization: for getMinValueInDim() function. | |
unsigned int | n_neighs |
Internal variable that counts the number of neighbors found in every iteration. Modified by getNeighbours(), getNeighborsInDim() and getMinValueInDim() functions. | |
std::vector< unsigned int > | occupied_ |
Caches the occupied cells (obstacles). | |
Friends | |
std::ostream & | operator<< (std::ostream &os, nDGridMap< T, ndims > &g) |
Neighbors precomputation could speed things up.
Improve coord2idx function in order to just pass n coordinates and not an array.
Create d_ with 1 and d_[1] size of X, d_[2] size of Y, etc, to generalize dimensions.
Based on a flat array in which the generalized indexing operations are efficiently implemented, according to this document nDGridMaps It is important to read this document in order to understand the class.
It has 2 template parameters: - the cells employed, should be Cell class or inherited.
Copyright (C) 2014 Javier V. Gomez and Jose Pardeiro www.javiervgomez.com
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition at line 47 of file ndgridmap.hpp.
|
inline |
dimsize | constains the size of each dimension. |
leafsize | real cell size (assumed to be cubic). 1 unit by default. |
Definition at line 70 of file ndgridmap.hpp.