TinyRobotics
Loading...
Searching...
No Matches
IMap.h
1#pragma once
2#include <vector>
3
4#include "TinyRobotics/coordinates/Coordinate.h"
5
6namespace tinyrobotics {
7
8/**
9 * @class IMapNeighbors
10 * @ingroup maps
11 * @brief Abstract interface for neighbor queries in map-like data structures.
12 *
13 * Provides a minimal interface for pathfinding and navigation algorithms to
14 * query neighboring coordinates and check coordinate validity. Any map or graph
15 * class that supports neighbor queries can implement this interface, enabling
16 * use with generic planning algorithms (e.g., A*, Dijkstra).
17 *
18 * @tparam T Scalar type for coordinates and math (default: DistanceM)
19 *
20 * ### Required Methods
21 * - getNeighbors(Coordinate<T> from): Return a vector of neighboring
22 * coordinates for a given node.
23 * - isValid(const Coordinate<T>& coord): Return true if the coordinate is valid
24 * (e.g., inside map or graph).
25 */
26template <typename T = DistanceM>
27class IMapNeighbors {
28 public:
29 /**
30 * @brief Get world coordinates of neighboring cells (for pathfinding or
31 * navigation).
32 * @param from The cell coordinate to find neighbors for.
33 * @return Vector of neighboring coordinates.
34 */
35 virtual std::vector<Coordinate<T>> getNeighbors(Coordinate<T> from) const = 0;
36
37 /**
38 * @brief Check if a coordinate is inside the map bounds.
39 * @param coord The coordinate to check.
40 * @return True if valid, false otherwise.
41 */
42 virtual bool isValid(const Coordinate<T>& coord) const = 0;
43};
44
45/**
46 * @class IMap
47 * @ingroup maps
48 * @brief Abstract interface for 2D grid maps and occupancy maps in
49 * TinyRobotics.
50 *
51 * IMap extends IMapNeighbors and provides a comprehensive interface for
52 * grid-based or cell-based maps for frontier exploring. It supports cell
53 * access, coordinate transforms, and neighbor queries, making it suitable for
54 * pathfinding, navigation, and mapping algorithms. All grid or occupancy map
55 * implementations (e.g., GridMap, GridBitMap) should inherit from this
56 * interface and implement all pure virtual methods.
57 *
58 *
59 * Features:
60 * - Query map dimensions and resolution
61 * - Access cell state (FREE, OCCUPIED, UNKNOWN) by index
62 * - Convert cell indices to world coordinates
63 * - Query neighbors and check coordinate validity (from IMapNeighbors)
64 *
65 * @tparam T Scalar type for coordinates and math (default: DistanceM)
66 *
67 * ### Required Methods
68 * - getXCount(), getYCount(): Map dimensions in cells
69 * - getResolution(): Cell size in meters
70 * - getNeighbors(Coordinate<T> from): Neighboring cell coordinates for
71 * pathfinding (from IMapNeighbors)
72 * - isValid(const Coordinate<T>& coord): Check if a coordinate is inside the
73 * map (from IMapNeighbors)
74 * - getCell(int x, int y, CellState& state): Get cell state by index
75 * - toWorld(int x, int y): Convert cell indices to world coordinates
76 */
77
78template <typename T = DistanceM>
79class IMap : public IMapNeighbors<T> {
80 public:
81 /**
82 * @brief Get the number of cells in the X direction.
83 */
84 virtual int getXCount() const = 0;
85
86 /**
87 * @brief Get the number of cells in the Y direction.
88 */
89 virtual int getYCount() const = 0;
90
91 /**
92 * @brief Get the map resolution (cell size in meters).
93 */
94 virtual float getResolution() const = 0;
95
96 /**
97 * @brief Get the state of a cell by integer indices.
98 * @param x Cell X index
99 * @param y Cell Y index
100 * @param state Output: Cell state (FREE, OCCUPIED, UNKNOWN)
101 * @return True if cell is valid, false otherwise.
102 */
103 virtual bool getCell(int x, int y, CellState& state) const = 0;
104
105 /**
106 * @brief Convert cell indices to world coordinates.
107 * @param x Cell X index
108 * @param y Cell Y index
109 * @return World coordinate of the cell center.
110 */
111 virtual Coordinate<T> toWorld(int x, int y) const = 0;
112};
113
114} // namespace tinyrobotics
A generic 3D coordinate class for robotics, navigation, and spatial calculations.
Definition: Coordinate.h:57
Abstract interface for neighbor queries in map-like data structures.
Definition: IMap.h:27
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.
Abstract interface for 2D grid maps and occupancy maps in TinyRobotics.
Definition: IMap.h:79
virtual int getYCount() const =0
Get the number of cells in the Y direction.
virtual bool getCell(int x, int y, CellState &state) const =0
Get the state of a cell by integer indices.
virtual float getResolution() const =0
Get the map resolution (cell size in meters).
virtual Coordinate< T > toWorld(int x, int y) const =0
Convert cell indices to world coordinates.
virtual int getXCount() const =0
Get the number of cells in the X direction.
CellState
Cell state for occupancy grid mapping (e.g., UNKNOWN, FREE, OCCUPIED).
Definition: Common.h:32