Main MRPT website > C++ reference for MRPT 1.3.2
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes
mrpt::utils::CDynamicGrid< T > Class Template Reference

Detailed Description

template<class T>
class mrpt::utils::CDynamicGrid< T >

A 2D grid of dynamic size which stores any kind of data at each cell.

Template Parameters
TThe type of each cell in the 2D grid.

Definition at line 39 of file CDynamicGrid.h.

#include <mrpt/utils/CDynamicGrid.h>

Inheritance diagram for mrpt::utils::CDynamicGrid< T >:
Inheritance graph

Public Member Functions

 CDynamicGrid (float x_min=-10.0f, float x_max=10.0f, float y_min=-10.0f, float y_max=10.0f, float resolution=0.10f)
 Constructor. More...
 
virtual ~CDynamicGrid ()
 Destructor. More...
 
void setSize (const float x_min, const float x_max, const float y_min, const float y_max, const float resolution, const T *fill_value=NULL)
 Changes the size of the grid, ERASING all previous contents. More...
 
void clear ()
 Erase the contents of all the cells. More...
 
void fill (const T &value)
 Fills all the cells with the same value. More...
 
virtual void resize (float new_x_min, float new_x_max, float new_y_min, float new_y_max, const T &defaultValueNewCells, float additionalMarginMeters=2.0f)
 Changes the size of the grid, maintaining previous contents. More...
 
T * cellByPos (float x, float y)
 Returns a pointer to the contents of a cell given by its coordinates, or NULL if it is out of the map extensions. More...
 
const T * cellByPos (float x, float y) const
 Returns a pointer to the contents of a cell given by its coordinates, or NULL if it is out of the map extensions. More...
 
T * cellByIndex (unsigned int cx, unsigned int cy)
 Returns a pointer to the contents of a cell given by its cell indexes, or NULL if it is out of the map extensions. More...
 
const T * cellByIndex (unsigned int cx, unsigned int cy) const
 Returns a pointer to the contents of a cell given by its cell indexes, or NULL if it is out of the map extensions. More...
 
size_t getSizeX () const
 Returns the horizontal size of grid map in cells count. More...
 
size_t getSizeY () const
 Returns the vertical size of grid map in cells count. More...
 
float getXMin () const
 Returns the "x" coordinate of left side of grid map. More...
 
float getXMax () const
 Returns the "x" coordinate of right side of grid map. More...
 
float getYMin () const
 Returns the "y" coordinate of top side of grid map. More...
 
float getYMax () const
 Returns the "y" coordinate of bottom side of grid map. More...
 
float getResolution () const
 Returns the resolution of the grid map. More...
 
int x2idx (float x) const
 Transform a coordinate values into cell indexes. More...
 
int y2idx (float y) const
 
int xy2idx (float x, float y) const
 
void idx2cxcy (const int &idx, int &cx, int &cy) const
 Transform a global (linear) cell index value into its corresponding (x,y) cell indexes. More...
 
float idx2x (int cx) const
 Transform a cell index into a coordinate value. More...
 
float idx2y (int cy) const
 
int x2idx (float x, float x_min) const
 Transform a coordinate value into a cell index, using a diferent "x_min" value. More...
 
int y2idx (float y, float y_min) const
 
template<class MAT >
void getAsMatrix (MAT &m) const
 Get the entire grid as a matrix. More...
 
virtual float cell2float (const T &c) const
 The user must implement this in order to provide "saveToTextFile" a way to convert each cell into a numeric value. More...
 
bool saveToTextFile (const std::string &fileName) const
 Saves a float representation of the grid (via "cell2float()") to a text file. More...
 

Protected Member Functions

std::vector< T > & m_map_castaway_const () const
 Used only from logically const method that really need to modify the object. More...
 

Protected Attributes

std::vector< T > m_map
 The cells. More...
 
float m_x_min
 
float m_x_max
 
float m_y_min
 
float m_y_max
 
float m_resolution
 
size_t m_size_x
 
size_t m_size_y
 

Constructor & Destructor Documentation

template<class T>
mrpt::utils::CDynamicGrid< T >::CDynamicGrid ( float  x_min = -10.0f,
float  x_max = 10.0f,
float  y_min = -10.0f,
float  y_max = 10.0f,
float  resolution = 0.10f 
)
inline

Constructor.

Definition at line 55 of file CDynamicGrid.h.

template<class T>
virtual mrpt::utils::CDynamicGrid< T >::~CDynamicGrid ( )
inlinevirtual

Destructor.

Definition at line 66 of file CDynamicGrid.h.

Member Function Documentation

template<class T>
virtual float mrpt::utils::CDynamicGrid< T >::cell2float ( const T &  c) const
inlinevirtual

The user must implement this in order to provide "saveToTextFile" a way to convert each cell into a numeric value.

Reimplemented in mrpt::maps::CReflectivityGridMap2D.

Definition at line 308 of file CDynamicGrid.h.

template<class T>
T* mrpt::utils::CDynamicGrid< T >::cellByIndex ( unsigned int  cx,
unsigned int  cy 
)
inline

Returns a pointer to the contents of a cell given by its cell indexes, or NULL if it is out of the map extensions.

Definition at line 215 of file CDynamicGrid.h.

Referenced by mrpt::maps::COccupancyGridMap2D::getBasisCell(), mrpt::maps::COccupancyGridMap2D::getVoroniClearance(), mrpt::maps::COccupancyGridMap2D::setBasisCell(), and mrpt::maps::COccupancyGridMap2D::setVoroniClearance().

template<class T>
const T* mrpt::utils::CDynamicGrid< T >::cellByIndex ( unsigned int  cx,
unsigned int  cy 
) const
inline

Returns a pointer to the contents of a cell given by its cell indexes, or NULL if it is out of the map extensions.

Definition at line 224 of file CDynamicGrid.h.

template<class T>
T* mrpt::utils::CDynamicGrid< T >::cellByPos ( float  x,
float  y 
)
inline

Returns a pointer to the contents of a cell given by its coordinates, or NULL if it is out of the map extensions.

Definition at line 189 of file CDynamicGrid.h.

template<class T>
const T* mrpt::utils::CDynamicGrid< T >::cellByPos ( float  x,
float  y 
) const
inline

Returns a pointer to the contents of a cell given by its coordinates, or NULL if it is out of the map extensions.

Definition at line 202 of file CDynamicGrid.h.

template<class T>
void mrpt::utils::CDynamicGrid< T >::clear ( void  )
inline

Erase the contents of all the cells.

Definition at line 100 of file CDynamicGrid.h.

template<class T>
void mrpt::utils::CDynamicGrid< T >::fill ( const T &  value)
inline

Fills all the cells with the same value.

Definition at line 107 of file CDynamicGrid.h.

template<class T>
template<class MAT >
void mrpt::utils::CDynamicGrid< T >::getAsMatrix ( MAT &  m) const
inline

Get the entire grid as a matrix.

Template Parameters
MATThe type of the matrix, typically a mrpt::math::CMatrixDouble.
Parameters
[out]mThe output matrix; will be set automatically to the correct size. Entry (cy,cx) in the matrix contains the grid cell with indices (cx,cy).
Note
This method will compile only for cell types that can be converted to the type of the matrix elements (e.g. double).

Definition at line 297 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::getResolution ( ) const
inline

Returns the resolution of the grid map.

Definition at line 257 of file CDynamicGrid.h.

template<class T>
size_t mrpt::utils::CDynamicGrid< T >::getSizeX ( ) const
inline
template<class T>
size_t mrpt::utils::CDynamicGrid< T >::getSizeY ( ) const
inline
template<class T>
float mrpt::utils::CDynamicGrid< T >::getXMax ( ) const
inline

Returns the "x" coordinate of right side of grid map.

Definition at line 245 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::getXMin ( ) const
inline

Returns the "x" coordinate of left side of grid map.

Definition at line 241 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::getYMax ( ) const
inline

Returns the "y" coordinate of bottom side of grid map.

Definition at line 253 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::getYMin ( ) const
inline

Returns the "y" coordinate of top side of grid map.

Definition at line 249 of file CDynamicGrid.h.

template<class T>
void mrpt::utils::CDynamicGrid< T >::idx2cxcy ( const int &  idx,
int &  cx,
int &  cy 
) const
inline

Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.

Definition at line 266 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::idx2x ( int  cx) const
inline

Transform a cell index into a coordinate value.

Definition at line 274 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::idx2y ( int  cy) const
inline

Definition at line 275 of file CDynamicGrid.h.

template<class T>
std::vector<T>& mrpt::utils::CDynamicGrid< T >::m_map_castaway_const ( ) const
inlineprotected

Used only from logically const method that really need to modify the object.

Definition at line 47 of file CDynamicGrid.h.

template<class T>
virtual void mrpt::utils::CDynamicGrid< T >::resize ( float  new_x_min,
float  new_x_max,
float  new_y_min,
float  new_y_max,
const T &  defaultValueNewCells,
float  additionalMarginMeters = 2.0f 
)
inlinevirtual

Changes the size of the grid, maintaining previous contents.

See also
setSize

Definition at line 115 of file CDynamicGrid.h.

template<class T>
bool mrpt::utils::CDynamicGrid< T >::saveToTextFile ( const std::string &  fileName) const
inline

Saves a float representation of the grid (via "cell2float()") to a text file.

Returns
false on error

Definition at line 314 of file CDynamicGrid.h.

template<class T>
void mrpt::utils::CDynamicGrid< T >::setSize ( const float  x_min,
const float  x_max,
const float  y_min,
const float  y_max,
const float  resolution,
const T *  fill_value = NULL 
)
inline

Changes the size of the grid, ERASING all previous contents.

If fill_value is left as NULL, the contents of cells may be undefined (some will remain with their old values, the new ones will have the default cell value, but the location of old values may change wrt their old places). If fill_value is not NULL, it is assured that all cells will have a copy of that value after resizing.

See also
resize, fill

Definition at line 75 of file CDynamicGrid.h.

template<class T>
int mrpt::utils::CDynamicGrid< T >::x2idx ( float  x) const
inline

Transform a coordinate values into cell indexes.

Definition at line 261 of file CDynamicGrid.h.

template<class T>
int mrpt::utils::CDynamicGrid< T >::x2idx ( float  x,
float  x_min 
) const
inline

Transform a coordinate value into a cell index, using a diferent "x_min" value.

Definition at line 279 of file CDynamicGrid.h.

template<class T>
int mrpt::utils::CDynamicGrid< T >::xy2idx ( float  x,
float  y 
) const
inline

Definition at line 263 of file CDynamicGrid.h.

template<class T>
int mrpt::utils::CDynamicGrid< T >::y2idx ( float  y) const
inline

Definition at line 262 of file CDynamicGrid.h.

template<class T>
int mrpt::utils::CDynamicGrid< T >::y2idx ( float  y,
float  y_min 
) const
inline

Definition at line 284 of file CDynamicGrid.h.

Member Data Documentation

template<class T>
std::vector<T> mrpt::utils::CDynamicGrid< T >::m_map
protected

The cells.

Definition at line 44 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::m_resolution
protected

Definition at line 50 of file CDynamicGrid.h.

template<class T>
size_t mrpt::utils::CDynamicGrid< T >::m_size_x
protected

Definition at line 51 of file CDynamicGrid.h.

template<class T>
size_t mrpt::utils::CDynamicGrid< T >::m_size_y
protected

Definition at line 51 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::m_x_max
protected

Definition at line 49 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::m_x_min
protected

Definition at line 49 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::m_y_max
protected

Definition at line 49 of file CDynamicGrid.h.

template<class T>
float mrpt::utils::CDynamicGrid< T >::m_y_min
protected

Definition at line 49 of file CDynamicGrid.h.




Page generated by Doxygen 1.8.11 for MRPT 1.3.2 SVN: at Mon May 9 06:50:38 UTC 2016