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

A map-like utility for generating and validating neighbor coordinates in a configurable pattern. More...

#include <CallbackMap.h>

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

Public Member Functions

 CallbackMap ()=default
 Default constructor.
 
 CallbackMap (float distanceX, float distanceY, float resolutionM, int neighborCount)
 Construct a CallbackMap with extents, resolution, and neighbor count.
 
int getXCount () const override
 Get the number of cells in the X direction.
 
int getYCount () const override
 Get the number of cells in the Y direction.
 
float getResolution () const override
 Get the map resolution in meters.
 
std::vector< Coordinate< T > > getNeighbors (Coordinate< T > from) const override
 Generate valid neighbor coordinates around a given point.
 
bool isValid (const Coordinate< T > &coord) const override
 Check if a coordinate is valid (not occupied).
 
bool getCell (int x, int y, CellState &state) const override
 Get the cell state at grid coordinates (x, y).
 
Coordinate< T > toWorld (int x, int y) const override
 Convert grid indices to world coordinates.
 
void setIsValidCallback (CellState(*callback)(Coordinate< T >))
 Set the callback for cell validity checking.
 
void setResolution (float resolutionM)
 Set the map resolution in meters.
 
void setNeighborCount (int neighborCount)
 Set the number of neighbors to generate.
 
void setDistanceX (float dx)
 Set the map extent in X direction.
 
void setDistanceY (float dy)
 Set the map extent in Y direction.
 
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 Attributes

int defaultNeighborCount = 36
 
float defaultResolutionM = 1.0f
 
float distanceX = 0
 
float distanceY = 0
 
CellState(* isValidCB )(Coordinate< T > coord) = nullptr
 

Detailed Description

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

A map-like utility for generating and validating neighbor coordinates in a configurable pattern.

CallbackMap generates neighbor coordinates around a given point at a specified distance and angular resolution. It supports a user-provided callback to determine if a coordinate is valid (e.g., obstacle-free).

Typical use: pathfinding, navigation, or virtual occupancy grids where neighbors are not stored but computed on demand.

Template Parameters
TNumeric type for coordinates (default: DistanceM)

Example usage:

CallbackMap<> map(1.0f, 16); // 1m distance, 16 directions
map.setIsValidCallback([](Coordinate<DistanceM> c) { return c.x > 0; });
auto neighbors = map.getNeighbors(Coordinate<DistanceM>(0,0));
A map-like utility for generating and validating neighbor coordinates in a configurable pattern.
Definition: CallbackMap.h:34
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
T x
X coordinate (meters)
Definition: Coordinate.h:71

Constructor & Destructor Documentation

◆ CallbackMap()

CallbackMap ( float  distanceX,
float  distanceY,
float  resolutionM,
int  neighborCount 
)
inline

Construct a CallbackMap with extents, resolution, and neighbor count.

Parameters
distanceXMap extent in X direction (meters)
distanceYMap extent in Y direction (meters)
resolutionMGrid resolution (meters)
neighborCountNumber of neighbors to generate

Member Function Documentation

◆ getCell()

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

Get the cell state at grid coordinates (x, y).

Parameters
xX grid index
yY grid index
stateOutput cell state
Returns
True if cell state is available

Implements IMap< T >.

◆ getNeighbors()

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

Generate valid neighbor coordinates around a given point.

Parameters
fromCenter coordinate
Returns
Vector of valid neighbor coordinates

Implements IMapNeighbors< T >.

◆ getResolution()

float getResolution ( ) const
inlineoverridevirtual

Get the map resolution in meters.

Implements IMap< T >.

◆ getXCount()

int getXCount ( ) const
inlineoverridevirtual

Get the number of cells in the X direction.

Implements IMap< T >.

◆ getYCount()

int getYCount ( ) const
inlineoverridevirtual

Get the number of cells in the Y direction.

Implements IMap< T >.

◆ isValid()

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

Check if a coordinate is valid (not occupied).

Parameters
coordCoordinate to check
Returns
True if valid (not OCCUPIED), false otherwise

Implements IMapNeighbors< T >.

◆ setDistanceX()

void setDistanceX ( float  dx)
inline

Set the map extent in X direction.

Parameters
dxExtent in meters

◆ setDistanceY()

void setDistanceY ( float  dy)
inline

Set the map extent in Y direction.

Parameters
dyExtent in meters

◆ setIsValidCallback()

void setIsValidCallback ( CellState(*)(Coordinate< T >)  callback)
inline

Set the callback for cell validity checking.

Parameters
callbackFunction pointer taking a coordinate and returning CellState

◆ setNeighborCount()

void setNeighborCount ( int  neighborCount)
inline

Set the number of neighbors to generate.

Parameters
neighborCountNumber of neighbors

◆ setResolution()

void setResolution ( float  resolutionM)
inline

Set the map resolution in meters.

Parameters
resolutionMGrid resolution

◆ toWorld()

Coordinate< T > toWorld ( int  x,
int  y 
) const
inlineoverridevirtual

Convert grid indices to world coordinates.

Parameters
xX grid index
yY grid index
Returns
World coordinate

Implements IMap< T >.


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