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

Detailed Description

template<class T>
class mrpt::containers::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 38 of file CDynamicGrid.h.

#include <mrpt/containers/CDynamicGrid.h>

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

Public Member Functions

 CDynamicGrid (double x_min=-10.0, double x_max=10.0, double y_min=-10.0f, double y_max=10.0f, double resolution=0.10f)
 Constructor. More...
 
virtual ~CDynamicGrid ()
 Destructor. More...
 
void setSize (const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const T *fill_value=nullptr)
 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 (double new_x_min, double new_x_max, double new_y_min, double new_y_max, const T &defaultValueNewCells, double additionalMarginMeters=2.0)
 Changes the size of the grid, maintaining previous contents. More...
 
T * cellByPos (double x, double y)
 Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the map extensions. More...
 
const T * cellByPos (double x, double y) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
T * cellByIndex (unsigned int cx, unsigned int cy)
 Returns a pointer to the contents of a cell given by its cell indexes, or nullptr 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 nullptr 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...
 
double getXMin () const
 Returns the "x" coordinate of left side of grid map. More...
 
double getXMax () const
 Returns the "x" coordinate of right side of grid map. More...
 
double getYMin () const
 Returns the "y" coordinate of top side of grid map. More...
 
double getYMax () const
 Returns the "y" coordinate of bottom side of grid map. More...
 
double getResolution () const
 Returns the resolution of the grid map. More...
 
int x2idx (double x) const
 Transform a coordinate values into cell indexes. More...
 
int y2idx (double y) const
 
int xy2idx (double x, double 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...
 
double idx2x (int cx) const
 Transform a cell index into a coordinate value of the cell central point. More...
 
double idx2y (int cy) const
 
template<class MAT >
void getAsMatrix (MAT &m) const
 Get the entire grid as a matrix. More...
 
virtual float cell2float (const T &) 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...
 
template<class STREAM >
void dyngridcommon_writeToStream (STREAM &out) const
 
template<class STREAM >
void dyngridcommon_readFromStream (STREAM &in, bool cast_from_float=false)
 

Protected Attributes

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

Constructor & Destructor Documentation

◆ CDynamicGrid()

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

Constructor.

Definition at line 55 of file CDynamicGrid.h.

◆ ~CDynamicGrid()

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

Destructor.

Definition at line 71 of file CDynamicGrid.h.

Member Function Documentation

◆ cell2float()

template<class T >
virtual float mrpt::containers::CDynamicGrid< T >::cell2float ( const T &  ) 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 320 of file CDynamicGrid.h.

◆ cellByIndex() [1/2]

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

◆ cellByIndex() [2/2]

template<class T >
const T* mrpt::containers::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 nullptr if it is out of the map extensions.

Definition at line 243 of file CDynamicGrid.h.

◆ cellByPos() [1/2]

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

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

Definition at line 211 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTableMultiRes::atan2(), mrpt::maps::CGasConcentrationGridMap2D::getWindAs3DObject(), mrpt::slam::CRejectionSamplingRangeOnlyLocalization::setParams(), and TEST().

◆ cellByPos() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 220 of file CDynamicGrid.h.

◆ clear()

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

◆ dyngridcommon_readFromStream()

template<class T >
template<class STREAM >
void mrpt::containers::CDynamicGrid< T >::dyngridcommon_readFromStream ( STREAM &  in,
bool  cast_from_float = false 
)
inlineprotected

Definition at line 351 of file CDynamicGrid.h.

◆ dyngridcommon_writeToStream()

template<class T >
template<class STREAM >
void mrpt::containers::CDynamicGrid< T >::dyngridcommon_writeToStream ( STREAM &  out) const
inlineprotected

Definition at line 343 of file CDynamicGrid.h.

◆ fill()

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

Fills all the cells with the same value.

Definition at line 117 of file CDynamicGrid.h.

Referenced by mrpt::maps::CGasConcentrationGridMap2D::internal_clear(), and mrpt::slam::CRejectionSamplingRangeOnlyLocalization::setParams().

◆ getAsMatrix()

template<class T >
template<class MAT >
void mrpt::containers::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 309 of file CDynamicGrid.h.

◆ getResolution()

template<class T >
double mrpt::containers::CDynamicGrid< T >::getResolution ( ) const
inline

Returns the resolution of the grid map.

Definition at line 264 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTable::getResolution(), and mrpt::nav::CPTG_DiffDrive_CollisionGridBased::internal_initialize().

◆ getSizeX()

template<class T >
size_t mrpt::containers::CDynamicGrid< T >::getSizeX ( ) const
inline

◆ getSizeY()

template<class T >
size_t mrpt::containers::CDynamicGrid< T >::getSizeY ( ) const
inline

◆ getXMax()

template<class T >
double mrpt::containers::CDynamicGrid< T >::getXMax ( ) const
inline

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

Definition at line 258 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTable::getXMax().

◆ getXMin()

template<class T >
double mrpt::containers::CDynamicGrid< T >::getXMin ( ) const
inline

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

Definition at line 256 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTable::getXMin().

◆ getYMax()

template<class T >
double mrpt::containers::CDynamicGrid< T >::getYMax ( ) const
inline

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

Definition at line 262 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTable::getYMax().

◆ getYMin()

template<class T >
double mrpt::containers::CDynamicGrid< T >::getYMin ( ) const
inline

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

Definition at line 260 of file CDynamicGrid.h.

Referenced by mrpt::math::CAtan2LookUpTable::getYMin().

◆ idx2cxcy()

template<class T >
void mrpt::containers::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 281 of file CDynamicGrid.h.

◆ idx2x()

template<class T >
double mrpt::containers::CDynamicGrid< T >::idx2x ( int  cx) const
inline

Transform a cell index into a coordinate value of the cell central point.

Definition at line 289 of file CDynamicGrid.h.

Referenced by mrpt::nav::CPTG_DiffDrive_CollisionGridBased::internal_initialize(), and mrpt::math::CAtan2LookUpTableMultiRes::resize().

◆ idx2y()

template<class T >
double mrpt::containers::CDynamicGrid< T >::idx2y ( int  cy) const
inline

◆ m_map_castaway_const()

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

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

Definition at line 45 of file CDynamicGrid.h.

◆ resize()

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

Changes the size of the grid, maintaining previous contents.

See also
setSize

Definition at line 127 of file CDynamicGrid.h.

◆ saveToTextFile()

template<class T >
bool mrpt::containers::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 323 of file CDynamicGrid.h.

◆ setSize()

template<class T >
void mrpt::containers::CDynamicGrid< T >::setSize ( const double  x_min,
const double  x_max,
const double  y_min,
const double  y_max,
const double  resolution,
const T *  fill_value = nullptr 
)
inline

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

If fill_value is left as nullptr, 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 nullptr, it is assured that all cells will have a copy of that value after resizing.

See also
resize, fill

Definition at line 82 of file CDynamicGrid.h.

Referenced by mrpt::containers::CDynamicGrid< std::vector< int32_t > >::CDynamicGrid(), and mrpt::nav::CPTG_DiffDrive_CollisionGridBased::internal_initialize().

◆ x2idx()

template<class T >
int mrpt::containers::CDynamicGrid< T >::x2idx ( double  x) const
inline

◆ xy2idx()

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

Definition at line 274 of file CDynamicGrid.h.

◆ y2idx()

template<class T >
int mrpt::containers::CDynamicGrid< T >::y2idx ( double  y) const
inline

Member Data Documentation

◆ m_map

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

◆ m_resolution

template<class T >
double mrpt::containers::CDynamicGrid< T >::m_resolution
protected

◆ m_size_x

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

◆ m_size_y

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

◆ m_x_max

template<class T >
double mrpt::containers::CDynamicGrid< T >::m_x_max
protected

◆ m_x_min

template<class T >
double mrpt::containers::CDynamicGrid< T >::m_x_min
protected

◆ m_y_max

template<class T >
double mrpt::containers::CDynamicGrid< T >::m_y_max
protected

◆ m_y_min

template<class T >
double mrpt::containers::CDynamicGrid< T >::m_y_min
protected



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST