Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
cost_map::CostMap Class Reference

#include <cost_map.hpp>

Public Types

typedef cost_map::Matrix::Scalar DataType
 
typedef cost_map::Matrix Matrix
 

Public Member Functions

void add (const std::string &layer, const DataType value=NO_INFORMATION)
 
void add (const std::string &layer, const Matrix &data)
 
bool addDataFrom (const CostMap &other, bool extendMap, bool overwriteData, bool copyAllLayers, std::vector< std::string > layers=std::vector< std::string >())
 
DataTypeat (const std::string &layer, const Index &index)
 
DataType at (const std::string &layer, const Index &index) const
 
DataTypeatPosition (const std::string &layer, const Position &position)
 
DataType atPosition (const std::string &layer, const Position &position, grid_map::InterpolationMethods interpolation_method=grid_map::InterpolationMethods::INTER_NEAREST) const
 
void clear (const std::string &layer)
 
void clearAll ()
 
void clearBasic ()
 
 CostMap (const std::vector< std::string > &layers)
 
 CostMap ()
 
bool erase (const std::string &layer)
 
bool exists (const std::string &layer) const
 
bool extendToInclude (const CostMap &other)
 
const Matrixget (const std::string &layer) const
 
Matrixget (const std::string &layer)
 
const std::vector< std::string > & getBasicLayers () const
 
const std::string & getFrameId () const
 
bool getIndex (const Position &position, Index &index) const
 
const std::vector< std::string > & getLayers () const
 
const LengthgetLength () const
 
bool getPosition (const Index &index, Position &position) const
 
const PositiongetPosition () const
 
bool getPosition3 (const std::string &layer, const Index &index, Position3 &position) const
 
double getResolution () const
 
const SizegetSize () const
 
const IndexgetStartIndex () const
 
CostMap getSubmap (const Position &position, const Length &length, bool &isSuccess) const
 
CostMap getSubmap (const Position &position, const Length &length, Index &indexInSubmap, bool &isSuccess) const
 
Time getTimestamp () const
 
bool getVector (const std::string &layerPrefix, const Index &index, Eigen::Vector3d &vector) const
 
bool hasSameLayers (const CostMap &other) const
 
bool isInside (const Position &position) const
 
bool isValid (const Index &index) const
 
bool isValid (const Index &index, const std::string &layer) const
 
bool isValid (const Index &index, const std::vector< std::string > &layers) const
 
bool move (const Position &position, std::vector< BufferRegion > &newRegions)
 
bool move (const Position &position)
 
const Matrixoperator[] (const std::string &layer) const
 
Matrixoperator[] (const std::string &layer)
 
void resetTimestamp ()
 
void setBasicLayers (const std::vector< std::string > &basicLayers)
 
void setFrameId (const std::string &frameId)
 
void setGeometry (const Length &length, const double resolution, const Position &position=Position::Zero())
 
void setGeometry (const SubmapGeometry &geometry)
 
void setPosition (const Position &position)
 
void setStartIndex (const Index &startIndex)
 
void setTimestamp (const Time timestamp)
 
virtual ~CostMap ()
 

Private Member Functions

bool atPositionLinearInterpolated (const std::string &layer, const Position &position, float &value) const
 
void clearCols (unsigned int index, unsigned int nCols)
 
void clearRows (unsigned int index, unsigned int nRows)
 
void resize (const Eigen::Array2i &bufferSize)
 

Private Attributes

std::vector< std::string > basicLayers_
 
std::unordered_map< std::string, Matrixdata_
 Grid map data stored as layers of matrices. More...
 
std::string frameId_
 Frame id of the grid map. More...
 
std::vector< std::string > layers_
 Names of the data layers. More...
 
Length length_
 Side length of the map in x- and y-direction [m]. More...
 
Position position_
 Map position in the grid map frame [m]. More...
 
double resolution_
 Map resolution in xy plane [m/cell]. More...
 
Size size_
 Size of the buffer (rows and cols of the data structure). More...
 
Index startIndex_
 Circular buffer start indeces. More...
 
Time timestamp_
 Timestamp of the grid map (nanoseconds). More...
 

Detailed Description

Grid map managing multiple overlaying maps holding float values. Data structure implemented as two-dimensional circular buffer so map can be moved efficiently.

Data is defined with string keys. Examples are:

Definition at line 34 of file cost_map.hpp.

Member Typedef Documentation

typedef cost_map::Matrix::Scalar cost_map::CostMap::DataType

Storage element type for this map.

Definition at line 38 of file cost_map.hpp.

Storage container type for this map.

Definition at line 39 of file cost_map.hpp.

Constructor & Destructor Documentation

cost_map::CostMap::CostMap ( const std::vector< std::string > &  layers)

Constructor.

Parameters
layersa vector of strings containing the definition/description of the data layer.

Definition at line 19 of file src/lib/cost_map.cpp.

cost_map::CostMap::CostMap ( )

Emtpy constructor.

Definition at line 34 of file src/lib/cost_map.cpp.

cost_map::CostMap::~CostMap ( )
virtual

Destructor.

Definition at line 39 of file src/lib/cost_map.cpp.

Member Function Documentation

void cost_map::CostMap::add ( const std::string &  layer,
const DataType  value = NO_INFORMATION 
)

Add a new empty data layer.

Parameters
layerthe name of the layer. value the value to initialize the cells with.

Definition at line 87 of file src/lib/cost_map.cpp.

void cost_map::CostMap::add ( const std::string &  layer,
const Matrix data 
)

Add a new data layer (if the layer already exists, overwrite its data, otherwise add layer and data).

Parameters
layerthe name of the layer.
datathe data to be added.

Definition at line 92 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::addDataFrom ( const CostMap other,
bool  extendMap,
bool  overwriteData,
bool  copyAllLayers,
std::vector< std::string >  layers = std::vector<std::string>() 
)

Adds data from an other grid map to this grid map

Parameters
otherthe grid map to take data from.
extendMapif true the grid map is resized that the other map fits within.
overwriteDataif true the new data replaces the old values, else only invalid cells are updated.
copyAllLayerif true all layers are used to add data.
layersthe layers that are copied if not all layers are used.
Returns
true if successful.

Definition at line 401 of file src/lib/cost_map.cpp.

DataType & cost_map::CostMap::at ( const std::string &  layer,
const Index index 
)

Get cell data for requested index.

Parameters
layerthe name of the layer to be accessed.
indexthe requested index.
Returns
the data of the cell.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 196 of file src/lib/cost_map.cpp.

DataType cost_map::CostMap::at ( const std::string &  layer,
const Index index 
) const

Get cell data for requested index. Const version form above.

Parameters
layerthe name of the layer to be accessed.
indexthe requested index.
Returns
the data of the cell.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 205 of file src/lib/cost_map.cpp.

DataType & cost_map::CostMap::atPosition ( const std::string &  layer,
const Position position 
)

Get cell data at requested position.

Parameters
layerthe name of the layer to be accessed.
positionthe requested position.
Returns
the data of the cell.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 161 of file src/lib/cost_map.cpp.

DataType cost_map::CostMap::atPosition ( const std::string &  layer,
const Position position,
grid_map::InterpolationMethods  interpolation_method = grid_map::InterpolationMethods::INTER_NEAREST 
) const

Get cell data at requested position. Const version form above.

Parameters
layerthe name of the layer to be accessed.
positionthe requested position.
Returns
the data of the cell.
Exceptions
std::out_of_rangeif no map layer with name layer is present.
std::runtime_errorif the specified interpolation method is not implemented.

Definition at line 170 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::atPositionLinearInterpolated ( const std::string &  layer,
const Position position,
float &  value 
) const
private

Get cell data at requested position, linearly interpolated from 2x2 cells.

Parameters
layerthe name of the layer to be accessed.
positionthe requested position.
valuethe data of the cell.
Returns
true if linear interpolation was successful.

Definition at line 602 of file src/lib/cost_map.cpp.

void cost_map::CostMap::clear ( const std::string &  layer)

Clears all cells (set to NAN) for a layer.

Parameters
layerthe layer to be cleared.

Definition at line 559 of file src/lib/cost_map.cpp.

void cost_map::CostMap::clearAll ( )

Clears all cells of all layers. If basic layers are used, clearBasic() is preferred as it is more efficient. Header information (geometry etc.) remains valid.

Definition at line 575 of file src/lib/cost_map.cpp.

void cost_map::CostMap::clearBasic ( )

Clears all cells (set to NAN) for all basic layers. Header information (geometry etc.) remains valid.

Definition at line 568 of file src/lib/cost_map.cpp.

void cost_map::CostMap::clearCols ( unsigned int  index,
unsigned int  nCols 
)
private

Clear a number of columns of the grid map.

Parameters
indexthe left index for the columns to be reset.
nColsthe number of columns to reset.

Definition at line 592 of file src/lib/cost_map.cpp.

void cost_map::CostMap::clearRows ( unsigned int  index,
unsigned int  nRows 
)
private

Clear a number of rows of the grid map.

Parameters
indexthe upper index for the rows to be reset.
nRowsthe number of rows to reset.

Definition at line 582 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::erase ( const std::string &  layer)

Removes a layer from the grid map.

Parameters
layerthe name of the layer to be removed.
Returns
true if successful.

Definition at line 140 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::exists ( const std::string &  layer) const

Checks if data layer exists.

Parameters
layerthe name of the layer.
Returns
true if layer exists, false otherwise.

Definition at line 107 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::extendToInclude ( const CostMap other)

Extends the size of the grip map such that the other grid map fits within.

Parameters
otherthe grid map to extend the size to.
Returns
true if successful.

Definition at line 433 of file src/lib/cost_map.cpp.

const cost_map::Matrix & cost_map::CostMap::get ( const std::string &  layer) const

Returns the grid map data for a layer as matrix.

Parameters
layerthe name of the layer to be returned.
Returns
grid map data as matrix.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 112 of file src/lib/cost_map.cpp.

cost_map::Matrix & cost_map::CostMap::get ( const std::string &  layer)

Returns the grid map data for a layer as non-const. Use this method with care!

Parameters
layerthe name of the layer to be returned.
Returns
grid map data.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 121 of file src/lib/cost_map.cpp.

const std::vector< std::string > & cost_map::CostMap::getBasicLayers ( ) const

Gets the names of the basic layers.

Returns
the names of the basic layers.

Definition at line 74 of file src/lib/cost_map.cpp.

const std::string & cost_map::CostMap::getFrameId ( ) const

Get the frameId of the grid map.

Returns
frameId.

Definition at line 525 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::getIndex ( const Position position,
cost_map::Index index 
) const

Gets the corresponding cell index for a position.

Parameters
[in]positionthe requested position.
[out]indexthe corresponding index.
Returns
true if successful, false if position outside of map.

Definition at line 214 of file src/lib/cost_map.cpp.

const std::vector< std::string > & cost_map::CostMap::getLayers ( ) const

Gets the names of the layers.

Returns
the names of the layers.

Definition at line 156 of file src/lib/cost_map.cpp.

const Eigen::Array2d & cost_map::CostMap::getLength ( ) const

Get the side length of the grid map.

Returns
side length of the grid map.

Definition at line 530 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::getPosition ( const Index index,
cost_map::Position position 
) const

Gets the 2d position of cell specified by the index (x, y of cell position) in the grid map frame.

Parameters
[in]indexthe index of the requested cell.
[out]positionthe position of the data point in the parent frame.
Returns
true if successful, false if index not within range of buffer.

Definition at line 219 of file src/lib/cost_map.cpp.

const Eigen::Vector2d & cost_map::CostMap::getPosition ( ) const

Get the 2d position of the grid map in the grid map frame.

Returns
position of the grid map in the grid map frame.

Definition at line 535 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::getPosition3 ( const std::string &  layer,
const Index index,
cost_map::Position3 position 
) const

Gets the 3d position of a data point (x, y of cell position & cell value as z) in the grid map frame. This is useful for data layers such as elevation.

Parameters
layerthe name of the layer to be accessed.
indexthe index of the requested cell.
positionthe position of the data point in the parent frame.
Returns
true if successful, false if no valid data available.

Definition at line 248 of file src/lib/cost_map.cpp.

double cost_map::CostMap::getResolution ( ) const

Get the resolution of the grid map.

Returns
resolution of the grid map in the xy plane [m/cell].

Definition at line 540 of file src/lib/cost_map.cpp.

const cost_map::Size & cost_map::CostMap::getSize ( ) const

Get the grid map size (rows and cols of the data structure).

Returns
grid map size.

Definition at line 545 of file src/lib/cost_map.cpp.

const cost_map::Index & cost_map::CostMap::getStartIndex ( ) const

Get the start index of the circular buffer.

Returns
buffer start index.

Definition at line 554 of file src/lib/cost_map.cpp.

CostMap cost_map::CostMap::getSubmap ( const Position position,
const Length length,
bool &  isSuccess 
) const

Gets a submap from the map. The requested submap is specified with the requested location and length.

Parameters
[in]positionthe requested position of the submap (usually the center).
[in]lengththe requested length of the submap.
[out]isSuccesstrue if successful, false otherwise.
Returns
submap (is empty if success is false).

Definition at line 273 of file src/lib/cost_map.cpp.

CostMap cost_map::CostMap::getSubmap ( const Position position,
const Length length,
cost_map::Index indexInSubmap,
bool &  isSuccess 
) const

Gets a submap from the map. The requested submap is specified with the requested location and length.

Parameters
[in]positionthe requested position of the submap (usually the center).
[in]lengththe requested length of the submap.
[out]indexInSubmapthe index of the requested position in the submap.
[out]isSuccesstrue if successful, false otherwise.
Returns
submap (is empty if success is false).

Definition at line 280 of file src/lib/cost_map.cpp.

Time cost_map::CostMap::getTimestamp ( ) const

Get the timestamp of the grid map.

Returns
timestamp in nanoseconds.

Definition at line 510 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::getVector ( const std::string &  layerPrefix,
const Index index,
Eigen::Vector3d &  vector 
) const

Gets the 3d vector of three layers with suffixes 'x', 'y', and 'z'.

Parameters
layerPrefixthe prefix for the layer to bet get as vector.
indexthe index of the requested cell.
vectorthe vector with the values of the data type.
Returns
true if successful, false if no valid data available.

Definition at line 259 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::hasSameLayers ( const CostMap other) const

Checks if another grid map contains the same layers as this grid map. The other grid map could contain more layers than the checked ones. Does not check the selection of basic layers.

Parameters
otherthe other grid map.
Returns
true if the other grid map has the same layers, false otherwise.

Definition at line 79 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::isInside ( const Position position) const

Check if position is within the map boundaries.

Parameters
positionthe position to be checked.
Returns
true if position is within map, false otherwise.

Definition at line 224 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::isValid ( const Index index) const

Checks if the index of all layers defined as basic types are valid, i.e. if all basic types are finite. Returns false if no basic types are defined.

For cost maps, this currently always returns true (cells are always initialised at zero, not nan).

Parameters
indexthe index to check.
Returns
true if cell is valid, false otherwise.

Definition at line 229 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::isValid ( const Index index,
const std::string &  layer 
) const

Checks if cell at index is a valid (finite) for a certain layer.

For cost maps, this currently always returns true (cells are always initialised at zero, not nan).

Parameters
indexthe index to check.
layerthe name of the layer to be checked for validity.
Returns
true if cell is valid, false otherwise.

Definition at line 234 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::isValid ( const Index index,
const std::vector< std::string > &  layers 
) const

Checks if cell at index is a valid (finite) for certain layers.

For cost maps, this currently always returns true (cells are always initialised at zero, not nan).

Parameters
indexthe index to check.
layersthe layers to be checked for validity.
Returns
true if cell is valid, false otherwise.

Definition at line 239 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::move ( const Position position,
std::vector< BufferRegion > &  newRegions 
)

Move the grid map w.r.t. to the grid map frame. Use this to move the grid map boundaries without moving the grid map data. Takes care of all the data handling, such that the grid map data is stationary in the grid map frame.

Parameters
positionthe new location of the grid map in the map frame.
newRegionsthe regions of the newly covered / previously uncovered regions of the buffer.
Returns
true if map has been moved, false otherwise.

Definition at line 327 of file src/lib/cost_map.cpp.

bool cost_map::CostMap::move ( const Position position)

Move the grid map w.r.t. to the grid map frame. Use this to move the grid map boundaries without moving the grid map data. Takes care of all the data handling, such that the grid map data is stationary in the grid map frame.

Parameters
positionthe new location of the grid map in the map frame.
Returns
true if map has been moved, false otherwise.

Definition at line 395 of file src/lib/cost_map.cpp.

const cost_map::Matrix & cost_map::CostMap::operator[] ( const std::string &  layer) const

Returns the grid map data for a layer as matrix.

Parameters
layerthe name of the layer to be returned.
Returns
grid map data as matrix.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 130 of file src/lib/cost_map.cpp.

cost_map::Matrix & cost_map::CostMap::operator[] ( const std::string &  layer)

Returns the grid map data for a layer as non-const. Use this method with care!

Parameters
layerthe name of the layer to be returned.
Returns
grid map data.
Exceptions
std::out_of_rangeif no map layer with name layer is present.

Definition at line 135 of file src/lib/cost_map.cpp.

void cost_map::CostMap::resetTimestamp ( )

Resets the timestamp of the grid map (to zero).

Definition at line 515 of file src/lib/cost_map.cpp.

void cost_map::CostMap::resize ( const Eigen::Array2i &  bufferSize)
private

Resize the buffer.

Parameters
bufferSizethe requested buffer size.

Definition at line 647 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setBasicLayers ( const std::vector< std::string > &  basicLayers)

Set the basic layers that need to be valid for a cell to be considered as valid. Also, the basic layers are set to NAN when clearing the cells with clearBasic(). By default the list of basic layers is empty.

Parameters
basicLayersthe list of layers that are the basic layers of the map.

Definition at line 69 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setFrameId ( const std::string &  frameId)

Set the frame id of the grid map.

Parameters
frameIdthe frame id to set.

Definition at line 520 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setGeometry ( const Length length,
const double  resolution,
const Position position = Position::Zero() 
)

Set the geometry of the grid map. Clears all the data.

Parameters
lengththe side lengths in x, and y-direction of the grid map [m].
resolutionthe cell size in [m/cell].
positionthe 2d position of the grid map in the grid map frame [m].

Definition at line 43 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setGeometry ( const SubmapGeometry geometry)

Set the geometry of the grid map from submap geometry information.

Parameters
geometrythe submap geometry information.

Definition at line 64 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setPosition ( const Position position)
inline

Set the position of the grid map.

Parameters
positionthe 2d position of the grid map in the grid map frame [m].

Definition at line 76 of file cost_map.hpp.

void cost_map::CostMap::setStartIndex ( const Index startIndex)

Set the start index of the circular buffer. Use this method with caution!

Returns
buffer start index.

Definition at line 550 of file src/lib/cost_map.cpp.

void cost_map::CostMap::setTimestamp ( const Time  timestamp)

Set the timestamp of the grid map.

Parameters
timestampthe timestamp to set (in nanoseconds).

Definition at line 505 of file src/lib/cost_map.cpp.

Member Data Documentation

std::vector<std::string> cost_map::CostMap::basicLayers_
private

List of layers from data_ that are the basic grid map layers. This means that for a cell to be valid, all basic layers need to be valid. Also, the basic layers are set to NAN when clearing the map with clear().

Definition at line 483 of file cost_map.hpp.

std::unordered_map<std::string, Matrix> cost_map::CostMap::data_
private

Grid map data stored as layers of matrices.

Definition at line 475 of file cost_map.hpp.

std::string cost_map::CostMap::frameId_
private

Frame id of the grid map.

Definition at line 469 of file cost_map.hpp.

std::vector<std::string> cost_map::CostMap::layers_
private

Names of the data layers.

Definition at line 478 of file cost_map.hpp.

Length cost_map::CostMap::length_
private

Side length of the map in x- and y-direction [m].

Definition at line 486 of file cost_map.hpp.

Position cost_map::CostMap::position_
private

Map position in the grid map frame [m].

Definition at line 492 of file cost_map.hpp.

double cost_map::CostMap::resolution_
private

Map resolution in xy plane [m/cell].

Definition at line 489 of file cost_map.hpp.

Size cost_map::CostMap::size_
private

Size of the buffer (rows and cols of the data structure).

Definition at line 495 of file cost_map.hpp.

Index cost_map::CostMap::startIndex_
private

Circular buffer start indeces.

Definition at line 498 of file cost_map.hpp.

Time cost_map::CostMap::timestamp_
private

Timestamp of the grid map (nanoseconds).

Definition at line 472 of file cost_map.hpp.


The documentation for this class was generated from the following files:


cost_map_core
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:03:41