cartographer/mapping/2d/map_limits.h

Overview

MapLimits defines the bounds and resolution of a 2D grid map: the cell size in meters, the corner coordinate of the grid, and the number of cells in x and y. It provides conversions between world coordinates and integer cell indices used by all 2D grid types (Grid2D, ProbabilityGrid, TSDF2D) and by the correlative scan matchers. The class is header-only and inlined for performance.

Class: cartographer::mapping::MapLimits

Construction

MapLimits(const double resolution, const Eigen::Vector2d& max,
          const CellLimits& cell_limits);
explicit MapLimits(const proto::MapLimits& map_limits);

Validates that resolution > 0 and both cell dimensions are positive.

Accessors

double resolution() const;              // Cell size in meters (square cells)
const Eigen::Vector2d& max() const;     // Corner; all cells have smaller coords
const CellLimits& cell_limits() const;  // Grid size in number of cells

Coordinate Conversions

// Index of the cell containing 'point' (may be outside the map).
Eigen::Array2i GetCellIndex(const Eigen::Vector2f& point) const {
  return Eigen::Array2i(
      common::RoundToInt((max_.y() - point.y()) / resolution_ - 0.5),
      common::RoundToInt((max_.x() - point.x()) / resolution_ - 0.5));
}

// Center of the cell at 'cell_index' in world coordinates.
Eigen::Vector2f GetCellCenter(const Eigen::Array2i cell_index) const;

// True if 'cell_index' lies within the grid.
bool Contains(const Eigen::Array2i& cell_index) const;

Cell indices are row-major with the top-left cell (index (0, 0)) containing the point (max.x, max.y); the x/y axes are flipped accordingly. Points outside the map produce negative or over-large indices, for which Contains() returns false.

CellLimits

Defined in xy_index.h:

struct CellLimits {
  int num_x_cells = 0;
  int num_y_cells = 0;
};

Serialization

inline proto::MapLimits ToProto(const MapLimits& map_limits);

Serializes resolution, max, and cell_limits into proto::MapLimits (defined in map_limits.proto):

message MapLimits {
  double resolution = 1;
  cartographer.transform.proto.Vector2d max = 2;
  CellLimits cell_limits = 3;
}

The proto form is stored inside proto::Grid2D.limits and is used by Grid2D deserialization.

Usage

// A 50 m x 50 m grid at 5 cm resolution, with 1000 x 1000 cells.
MapLimits limits(0.05, Eigen::Vector2d(50, 50), CellLimits(1000, 1000));

Eigen::Array2i cell = limits.GetCellIndex(Eigen::Vector2f(1.0, 2.0));
Eigen::Vector2f center = limits.GetCellCenter(cell);
bool inside = limits.Contains(cell);

Role in the SLAM Pipeline

  • Grids store their MapLimits and use it for insertion lookups and queries.

  • The correlative scan matchers (SearchParameters) use limits.resolution() to size the search windows and to convert candidate offsets into meters.

  • FastCorrelativeScanMatcher2D uses limits to discretize scans and to center full-submap searches.

  • When a submap is grown or serialized, its limits are stored alongside the cell data.

See Also