TinyRobotics
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GridBitMap< T > Class Template Reference

A grid map using two bit vectors to represent CellState efficiently. More...

#include <GridBitMap.h>

Inheritance diagram for GridBitMap< T >:
Inheritance graph
[legend]
Collaboration diagram for GridBitMap< T >:
Collaboration graph
[legend]

Classes

struct  Cell
 

Public Member Functions

 GridBitMap (int xCount, int yCount, float resolutionM)
 
 GridBitMap (int xCount, int yCount, Distance resolution)
 
void resize (int newXCount, int newYCount)
 
int getXCount () const
 Get the number of cells in the X direction.
 
int getYCount () const
 Get the number of cells in the Y direction.
 
float getResolution () const
 Get the map resolution (cell size in meters).
 
bool worldToCell (float wx, float wy, Cell &cell) const
 
void cellToWorld (int cx, int cy, float &wx, float &wy) const
 
bool getCell (int cx, int cy, CellState &result) const
 Get the state of a cell by integer indices.
 
void setCell (int cx, int cy, CellState value)
 
bool getCell (const Coordinate< T > &coord, CellState &result) const
 
void setCell (const Coordinate< T > &coord, CellState value)
 
bool isValid (const Coordinate< T > &coord) const
 Check if a coordinate is within the map bounds.
 
std::vector< Coordinate<> > getNeighbors (Coordinate< T > from) const
 Get world coordinates of neighboring cells (for pathfinding or navigation)
 
Coordinate< T > toWorld (int cx, int cy) const override
 Convert cell indices to world coordinates (returns Coordinate<T>)
 
size_t writeTo (Print &out)
 Write map to output.
 
size_t readFrom (Stream &in)
 Read map from input.
 
virtual int getXCount () const =0
 Get the number of cells in the X direction.
 
virtual int getYCount () const =0
 Get the number of cells in the Y direction.
 
virtual float getResolution () const =0
 Get the map resolution (cell size in meters).
 
virtual bool getCell (int x, int y, CellState &state) const =0
 Get the state of a cell by integer indices.
 
virtual Coordinate< T > toWorld (int x, int y) const =0
 Convert cell indices to world coordinates.
 
virtual std::vector< Coordinate< T > > getNeighbors (Coordinate< T > from) const =0
 Get world coordinates of neighboring cells (for pathfinding or navigation).
 
virtual bool isValid (const Coordinate< T > &coord) const =0
 Check if a coordinate is inside the map bounds.
 

Protected Member Functions

std::vector< CellgetNeighborCells (const Coordinate< T > from) const
 Determine all neighboring cells (8-connected) for a given cell coordinate.
 

Protected Attributes

int xCount = 0
 
int yCount = 0
 
float resolution = 0.1f
 
Coordinate< T > origin
 
std::vector< bool > occupied
 
std::vector< bool > free
 
GridMapSerializer< GridBitMap, CellState, T > serializer
 

Detailed Description

template<typename T = DistanceM>
class tinyrobotics::GridBitMap< T >

A grid map using two bit vectors to represent CellState efficiently.

The GridMapBitVector class models the environment as a regular grid of cells, each storing a state (FREE, OCCUPIED, UNKNOWN) using two std::vector<bool> for memory efficiency. So each cell occupies only 2 buts!

CellState encoding:

Template Parameters
TNumeric type for coordinates (default: float)

Member Function Documentation

◆ getCell()

bool getCell ( int  x,
int  y,
CellState state 
) const
inlinevirtual

Get the state of a cell by integer indices.

Parameters
xCell X index
yCell Y index
stateOutput: Cell state (FREE, OCCUPIED, UNKNOWN)
Returns
True if cell is valid, false otherwise.

Implements IMap< T >.

◆ getNeighbors()

std::vector< Coordinate<> > getNeighbors ( Coordinate< T >  from) const
inlinevirtual

Get world coordinates of neighboring cells (for pathfinding or navigation)

Implements IMapNeighbors< T >.

◆ getResolution()

float getResolution ( ) const
inlinevirtual

Get the map resolution (cell size in meters).

Implements IMap< T >.

◆ getXCount()

int getXCount ( ) const
inlinevirtual

Get the number of cells in the X direction.

Implements IMap< T >.

◆ getYCount()

int getYCount ( ) const
inlinevirtual

Get the number of cells in the Y direction.

Implements IMap< T >.

◆ isValid()

bool isValid ( const Coordinate< T > &  coord) const
inlinevirtual

Check if a coordinate is within the map bounds.

Parameters
coordThe coordinate to check.
Returns
true if the coordinate is inside the map, false otherwise.

Implements IMapNeighbors< T >.

◆ toWorld()

Coordinate< T > toWorld ( int  cx,
int  cy 
) const
inlineoverridevirtual

Convert cell indices to world coordinates (returns Coordinate<T>)

Implements IMap< T >.


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