6#include "TinyRobotics/maps/IMap.h"
7#include "TinyRobotics/utils/Common.h"
9namespace tinyrobotics {
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
33template <
typename T = DistanceM>
45 CallbackMap(
float distanceX,
float distanceY,
float resolutionM,
47 : defaultResolutionM(resolutionM),
48 defaultNeighborCount(neighborCount),
50 distanceY(distanceY) {}
56 return (defaultResolutionM > 0 && distanceX > 0)
57 ?
static_cast<
int>(distanceX / defaultResolutionM)
63 return (defaultResolutionM > 0 && distanceY > 0)
64 ?
static_cast<
int>(distanceY / defaultResolutionM)
69 float getResolution()
const override {
return defaultResolutionM; }
75 std::vector<Coordinate<T>> neighbors;
76 for (
int i = 0; i < defaultNeighborCount; ++i) {
77 float angle = 2.0f *
static_cast<
float>(M_PI) * i / defaultNeighborCount;
78 float dx = defaultResolutionM * std::cos(angle);
79 float dy = defaultResolutionM * std::sin(angle);
80 Coordinate<T> neighbor(from.x + dx, from.y + dy);
82 neighbors.push_back(neighbor);
93 return isValidCB(coord) !=
CellState::OCCUPIED;
107 state = isValidCB(c);
118 return Coordinate<T>(x * defaultResolutionM, y * defaultResolutionM);
125 isValidCB = callback;
130 void setResolution(
float resolutionM) { defaultResolutionM = resolutionM; }
135 defaultNeighborCount = neighborCount;
147 int defaultNeighborCount = 36;
148 float defaultResolutionM = 1.0f;
A map-like utility for generating and validating neighbor coordinates in a configurable pattern.
Definition: CallbackMap.h:34
void setDistanceY(float dy)
Set the map extent in Y direction.
Definition: CallbackMap.h:144
void setNeighborCount(int neighborCount)
Set the number of neighbors to generate.
Definition: CallbackMap.h:134
CallbackMap()=default
Default constructor.
std::vector< Coordinate< T > > getNeighbors(Coordinate< T > from) const override
Generate valid neighbor coordinates around a given point.
Definition: CallbackMap.h:74
void setIsValidCallback(CellState(*callback)(Coordinate< T >))
Set the callback for cell validity checking.
Definition: CallbackMap.h:124
bool isValid(const Coordinate< T > &coord) const override
Check if a coordinate is valid (not occupied).
Definition: CallbackMap.h:91
int getXCount() const override
Get the number of cells in the X direction.
Definition: CallbackMap.h:55
int getYCount() const override
Get the number of cells in the Y direction.
Definition: CallbackMap.h:62
CallbackMap(float distanceX, float distanceY, float resolutionM, int neighborCount)
Construct a CallbackMap with extents, resolution, and neighbor count.
Definition: CallbackMap.h:45
Coordinate< T > toWorld(int x, int y) const override
Convert grid indices to world coordinates.
Definition: CallbackMap.h:117
float getResolution() const override
Get the map resolution in meters.
Definition: CallbackMap.h:69
void setResolution(float resolutionM)
Set the map resolution in meters.
Definition: CallbackMap.h:130
void setDistanceX(float dx)
Set the map extent in X direction.
Definition: CallbackMap.h:140
bool getCell(int x, int y, CellState &state) const override
Get the cell state at grid coordinates (x, y).
Definition: CallbackMap.h:104
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Abstract interface for 2D grid maps and occupancy maps in TinyRobotics.
Definition: IMap.h:79
CellState
Cell state for occupancy grid mapping (e.g., UNKNOWN, FREE, OCCUPIED).
Definition: Common.h:32