mrpt.maps

mrpt.maps — Metric map representations for MRPT.

Provides:
  • CMetricMap : Abstract base class for all metric maps

  • CPointsMap : Abstract base class for point cloud maps

  • CSimplePointsMap : Concrete XYZ point cloud map

  • CGenericPointsMap : XYZ point cloud + arbitrary string-keyed data channels

  • COccupancyGridMap2D : Probabilistic 2D occupancy grid map

  • COccupancyGridMap3D : Dense probabilistic 3D occupancy grid

  • CVoxelMap, CVoxelMapRGB : Sparse voxel occupancy maps

  • COctoMap : OctoMap-based 3D occupancy map

  • CHeightGridMap2D : 2.5D elevation map

  • CBeaconMap, CBeacon : Map of range-only beacons

  • CMultiMetricMap : Container of heterogeneous maps

  • CObservationPointCloud : Observation holding a point cloud map

  • VisualizationParameters, obs_to_viz() : 3D rendering of observations

  • CSimpleMap, TSetOfMetricMapInitializers, … : re-exported from mrpt.obs

Package Contents

class mrpt.maps.CBeacon

C++ API: class mrpt::maps::CBeacon

Bases: mrpt.serialization.CSerializable

The class for storing individual “beacon landmarks” under a variety of 3D position PDF distributions.

property m_ID: int

Beacon ID

getMean() → mrpt.poses.CPoint3D

Mean position of the beacon

class mrpt.maps.CBeaconMap

C++ API: class mrpt::maps::CBeaconMap

Bases: CMetricMap

A class for storing a map of 3D probabilistic beacons, using a Montecarlo, Gaussian, or Sum of Gaussians (SOG) representation (for range-only SLAM).

push_back(beacon: CBeacon) → None

Appends a beacon to the map.

size() → int

Returns the stored landmarks count.

class mrpt.maps.CGenericPointsMap

C++ API: class mrpt::maps::CGenericPointsMap

Bases: CPointsMap

A map of 3D points (X,Y,Z) plus any number of custom, string-keyed per-point data channels.

getPointFieldNames_double() → list[str]

Get list of all double channel names.

getPointFieldNames_float() → list[str]

Get list of all float channel names.

getPointFieldNames_uint16() → list[str]

Get list of all uint16_t channel names.

getPointFieldNames_uint32() → list[str]

List all uint32 channel names (New in MRPT 3.0.0)

getPointFieldNames_uint8() → list[str]

Get list of all uint8_t channel names.

getPointField_double(index: int, fieldName: str) → float

Read the value of a double channel for a given point. Returns 0 if field does not exist.

getPointField_float(index: int, fieldName: str) → float

Read the value of a float channel for a given point. Returns 0 if field does not exist.

getPointField_uint16(index: int, fieldName: str) → int

Read the value of a uint16_t channel for a given point. Returns 0 if field does not exist.

getPointField_uint32(index: int, fieldName: str) → int

Read a uint32 channel value (New in MRPT 3.0.0)

getPointField_uint8(index: int, fieldName: str) → int

Read the value of a uint8_t channel for a given point. Returns 0 if field does not exist.

hasPointField(fieldName: str) → bool

Returns true if the map has a data channel with the given name.

registerField_double(fieldName: str) → bool

Register a new per-point data channel of type float64

registerField_float(fieldName: str) → bool

Register a new per-point data channel of type float32

registerField_uint16(fieldName: str) → bool

Register a new per-point data channel of type uint16

registerField_uint32(fieldName: str) → bool

Register a new per-point data channel of type uint32 (New in MRPT 3.0.0)

registerField_uint8(fieldName: str) → bool

Register a new per-point data channel of type uint8

resize(newLength: int) → None

Resizes all point buffers so they can hold the given number of points: newly created points are set to default values, and old contents are not changed.

setPointField_double(index: int, fieldName: str, value: float) → None

Sets the value of a double channel for a given point.

setPointField_float(index: int, fieldName: str, value: float) → None

Sets the value of a float channel for a given point.

setPointField_uint16(index: int, fieldName: str, value: int) → None

Sets the value of a uint16_t channel for a given point.

setPointField_uint32(index: int, fieldName: str, value: int) → None

Set a uint32 channel value (New in MRPT 3.0.0)

setPointField_uint8(index: int, fieldName: str, value: int) → None

Sets the value of a uint8_t channel for a given point.

unregisterField(fieldName: str) → bool

Removes a data channel; returns True if it existed

class mrpt.maps.CHeightGridMap2D(xMin: float = -2.0, xMax: float = 2.0, yMin: float = -2.0, yMax: float = 2.0, resolution: float = 0.1)

C++ API: class mrpt::maps::CHeightGridMap2D

Bases: CMetricMap

Digital Elevation Model (DEM), a mesh or grid representation of a surface which keeps the estimated height for each (x,y) location.

countObservedCells() → int

Return the number of cells with at least one height data inserted.

getAsNumpy() → numpy.ndarray

Returns the heights as an HxW float64 array (NaN for unobserved cells)

getHeight(x: float, y: float) → float | None

Height at a metric position, or None if not observed

getResolution() → float

Returns the resolution of the grid map.

getSizeX() → int

Returns the horizontal size of grid map in cells count.

getSizeY() → int

Returns the vertical size of grid map in cells count.

getXMin() → float

Returns the “x” coordinate of left side of grid map.

getYMin() → float

Returns the “y” coordinate of top side of grid map.

insertIndividualPoint(x: float, y: float, z: float) → bool

Inserts one (x,y,z) point. Returns False if out of the map.

class mrpt.maps.CMetricMap

C++ API: class mrpt::maps::CMetricMap

Bases: mrpt.serialization.CSerializable

Declares a virtual base class for all metric maps storage classes.

genericMapParams: mrpt.obs.TMapGenericParams
GetRuntimeClass() → mrpt.rtti.TRuntimeClassId

Returns information about the class of an object in runtime.

boundingBox() → mrpt.math.TBoundingBox

Bounding box of the map contents

canComputeObservationLikelihood(obs: mrpt.obs.CObservation) → bool

Returns true if this map is able to compute a sensible likelihood function for this observation (i.e. an occupancy grid map cannot with an image).

clear() → None

Erase all the contents of the map.

computeObservationLikelihood(obs: mrpt.obs.CObservation, takenFrom: mrpt.poses.CPose3D) → float

Log-likelihood of an observation taken from a given robot pose

computeObservationsLikelihood(sf: mrpt.obs.CSensoryFrame, takenFrom: mrpt.poses.CPose3D) → float

Log-likelihood of all observations in a CSensoryFrame taken from a given pose

getVisualization() → mrpt.viz.CSetOfObjects

Returns a 3D representation of the map as a CSetOfObjects

getVisualizationInto(outObj: mrpt.viz.CSetOfObjects) → None

Appends a 3D representation of the map to a CSetOfObjects

insertObs(sf: mrpt.obs.CSensoryFrame, robotPose: mrpt.poses.CPose3D | None = None) → bool

Inserts all the observations of a CSensoryFrame. Returns true if any was inserted.

insertObservation(obs: mrpt.obs.CObservation, robotPose: mrpt.poses.CPose3D = None) → bool

Insert an observation into the map. Returns true if the map was updated.

isEmpty() → bool

Returns true if the map is empty/no observation has been inserted.

loadFromSimpleMap(simpleMap: mrpt.obs.CSimpleMap) → None

Clears the map and builds it from all keyframes of a CSimpleMap

saveMetricMapRepresentationToFile(filNamePrefix: str) → None

Saves the map in a format suitable for inspection (e.g. images or text)

class mrpt.maps.CMultiMetricMap

C++ API: class mrpt::maps::CMultiMetricMap

CMultiMetricMap(initializers: mrpt.obs.TSetOfMetricMapInitializers)

Bases: CMetricMap

A set of metric maps of any type, updated and queried together.

property maps: list[CMetricMap]

A list with all the maps (to replace one, use map[i] = newMap)

clearMaps() → None

Removes all maps (clear() only empties them)

mapByIndex(index: int) → CMetricMap

Gets the i-th map.

push_back(map: CMetricMap) → None

Appends a new child map to the list.

setListOfMaps(initializers: mrpt.obs.TSetOfMetricMapInitializers) → None

Replaces all maps with the ones described by a TSetOfMetricMapInitializers

size() → int

Number of child maps.

class mrpt.maps.CObservationPointCloud
class mrpt.maps.CObservationPointCloud(scan: mrpt.obs.CObservation3DRangeScan)

Bases: mrpt.obs.CObservation

An observation from any sensor that can be summarized as a pointcloud.

property pointcloud: CPointsMap

The point cloud (a CPointsMap)

sensorPose: mrpt.poses.CPose3D
getExternalStorageFile() → str

Returns the external file name of the point cloud, if any.

isExternallyStored() → bool

Returns true if the point cloud is stored in an external file.

class mrpt.maps.COccupancyGridMap2D(xMin: float = -10.0, xMax: float = 10.0, yMin: float = -10.0, yMax: float = 10.0, resolution: float = 0.10000000149011612)

C++ API: class mrpt::maps::COccupancyGridMap2D

Bases: CMetricMap

A 2D occupancy grid map: each cell holds its probability of being occupied.

getAsNumpy() → numpy.ndarray

Returns the occupancy grid as an HxW float32 numpy array (0=occupied, 1=free)

getCell(x: int, y: int) → float

Get occupancy probability [0,1] at cell (x,y)

getPos(x: float, y: float) → float

Get occupancy probability at metric position (x,y)

getResolution() → float

Returns the resolution of the grid map.

getSizeX() → int

Returns the horizontal size of grid map in cells count.

getSizeY() → int

Returns the vertical size of grid map in cells count.

getXMax() → float

Returns the “x” coordinate of right side of grid map.

getXMin() → float

Returns the “x” coordinate of left side of grid map.

getYMax() → float

Returns the “y” coordinate of bottom side of grid map.

getYMin() → float

Returns the “y” coordinate of top side of grid map.

idx2x(arg0: int) → float

Transform a cell index into a coordinate value (center of the cell)

idx2y(arg0: int) → float

Transforms a cell index into a y coordinate (center of the cell).

isEmpty() → bool

Returns true upon map construction or after calling clear(), the return changes to false upon successful insertObservation() or any other method to load data in the map.

loadFromBitmapFile(file: str, resolution: float) → bool

Loads the grid map from an image file, given its resolution and origin.

loadFromROSMapServerYAML(yamlFilePath: str) → bool

Load a ROS map_server YAML + PNG/PGM file pair

saveAsBitmapFile(arg0: str) → bool

Saves the grid map as an image file; the format is given by the file extension.

setCell(x: int, y: int, value: float) → None

Set occupancy probability [0,1] at cell (x,y)

setPos(x: float, y: float, value: float) → None

Set occupancy probability at metric position (x,y)

x2idx(x: float) → int

Transform a coordinate value into a cell index. Uses floor() to correctly handle negative coordinates near zero.

y2idx(y: float) → int

Transforms a y coordinate into a cell index.

class mrpt.maps.COccupancyGridMap3D(corner_min: mrpt.math.TPoint3D = ..., corner_max: mrpt.math.TPoint3D = ..., resolution: float = 0.25)

C++ API: class mrpt::maps::COccupancyGridMap3D

Bases: CMetricMap

A 3D occupancy grid map with a regular, even distribution of voxels.

fill(default_value: float = 0.5) → None

Sets all voxels to a freeness value

getCellFreeness(cx: int, cy: int, cz: int) → float

Freeness probability [0,1] of a voxel by index (1 = free)

getFreenessByPos(x: float, y: float, z: float) → float

Freeness probability [0,1] at a metric position (1 = free)

getResolution() → float

Voxel size (meters)

getSizeX() → int

Number of voxels in X

getSizeY() → int

Number of voxels in Y

getSizeZ() → int

Number of voxels in Z

setCellFreeness(cx: int, cy: int, cz: int, value: float) → None

Sets the freeness probability [0,1] of a voxel by index

setFreenessByPos(x: float, y: float, z: float, value: float) → None

Sets the freeness probability [0,1] at a metric position

class mrpt.maps.COctoMap(resolution: float = 0.1)

C++ API: class mrpt::maps::COctoMap

Bases: CMetricMap

A three-dimensional probabilistic occupancy grid, implemented as an octo-tree with the “octomap” C++ library.

getMetricMax() → mrpt.math.TPoint3D

Maximum value of the bounding box of all known space in x, y, z.

getMetricMin() → mrpt.math.TPoint3D

Minimum value of the bounding box of all known space in x, y, z.

getPointOccupancy(x: float, y: float, z: float) → float | None

Occupancy probability [0,1] at a point, or None if the point is not in the octree

getResolution() → float

Returns the size of the octomap leaf voxels.

insertPointCloud(points: CPointsMap, sensor_x: float, sensor_y: float, sensor_z: float) → None

Inserts a point cloud as rays from the sensor position

isPointWithinOctoMap(x: float, y: float, z: float) → bool

Check whether the given point lies within the volume covered by the octomap (that is, whether it is “mapped”)

size() → int

Number of octree nodes

updateVoxel(x: float, y: float, z: float, occupied: bool) → None

Updates one voxel with an occupied or free observation

class mrpt.maps.CPointsMap

C++ API: class mrpt::maps::CPointsMap

Bases: CMetricMap

A cloud of points in 2D or 3D, which can be built from a sequence of laser scans or other sensors.

getPoint(i: int) → tuple

Returns (x, y, z) tuple for point i

getPointsAsNumpy() → numpy.ndarray

Returns all points as an Nx3 float32 numpy array

insertPoint(x: float, y: float, z: float = 0.0) → None

Provides a way to insert (append) individual points into the map: the missing fields of child classes (color, weight, etc) are left to their default values.

isEmpty() → bool

Returns true if the map is empty/no observation has been inserted.

load2D_from_text_file(arg0: str) → bool

Load from a text file. Each line should contain an “X Y” coordinate pair, separated by whitespaces.

load3D_from_text_file(arg0: str) → bool

Load from a text file. Each line should contain an “X Y Z” coordinate tuple, separated by whitespaces.

reserve(arg0: int) → None

Reserves memory for a given number of points, without changing the map size.

save2D_to_text_file(arg0: str) → bool

Save to a text file. Each line will contain “X Y” point coordinates.

save3D_to_text_file(arg0: str) → bool

Save to a text file. Each line will contain “X Y Z” point coordinates.

setPointsFromNumpy(arr: numpy.ndarray) → None

Load an Nx3 float32 numpy array into this point cloud

size() → int

Returns the number of points.

class mrpt.maps.CSimpleMap

C++ API: class mrpt::maps::CSimpleMap

Bases: mrpt.serialization.CSerializable

A view-based map: a set of poses and what the robot saw from those poses.

class Keyframe
class Keyframe(pose: mrpt.poses.CPose3DPDF, sf: CSensoryFrame, localTwist: mrpt.math.TTwist3D | None = None)

One keyframe of a CSimpleMap: a pose PDF, a sensory frame and an optional twist.

localTwist: mrpt.math.TTwist3D | None
pose: mrpt.poses.CPose3DPDF
sf: CSensoryFrame
changeCoordinatesOrigin(newOrigin: mrpt.poses.CPose3D) → None

Transforms all keyframe poses so the old origin becomes newOrigin

clear() → None

Remove all stored keyframes.

empty() → bool

Returns true if the map has no keyframes.

get(index: int) → CSimpleMap

Returns the i-th keyframe.

insert(pose: mrpt.poses.CPose3DPDF, sf: CSensoryFrame, localTwist: mrpt.math.TTwist3D | None = None) → None
insert(keyframe: CSimpleMap) → None

Appends a keyframe (pose PDF and sensory frame).

loadFromFile(fileName: str) → bool

Loads a .simplemap file (possibly compressed). Returns False on error.

remove(index: int) → None

Removes the i-th keyframe.

saveToFile(fileName: str) → bool

Saves to a .simplemap file. Returns False on error.

size() → int

Returns the number of keyframes in the map.

class mrpt.maps.CSimplePointsMap

C++ API: class mrpt::maps::CSimplePointsMap

Bases: CPointsMap

A cloud of points in 2D or 3D, which can be built from a sequence of laser scans.

class mrpt.maps.CVoxelMap(resolution: float = 0.05, inner_bits: int = 2, leaf_bits: int = 3)

C++ API: class mrpt::maps::CVoxelMap

Bases: CMetricMap

A sparse 3D occupancy voxel map, with log-odds occupancy per voxel.

getOccupiedVoxels() → CSimplePointsMap

Returns the centers of all occupied voxels as a CSimplePointsMap

getPointOccupancy(x: float, y: float, z: float) → float | None

Occupancy probability [0,1] of the voxel at a point, or None if not observed

insertPointCloudAsEndPoints(points: CPointsMap, sensorPt: mrpt.math.TPoint3D) → None

Inserts a point cloud updating only the end points

insertPointCloudAsRays(points: CPointsMap, sensorPt: mrpt.math.TPoint3D) → None

Inserts a point cloud, marking free space along the rays from sensorPt

updateVoxel(x: float, y: float, z: float, occupied: bool) → None

Updates one voxel with an occupied or free observation

class mrpt.maps.CVoxelMapRGB(resolution: float = 0.05, inner_bits: int = 2, leaf_bits: int = 3)

C++ API: class mrpt::maps::CVoxelMapRGB

Bases: CMetricMap

A sparse 3D occupancy voxel map, with log-odds occupancy and an RGB color per voxel.

getOccupiedVoxels() → CSimplePointsMap

Returns the centers of all occupied voxels as a CSimplePointsMap

getPointOccupancy(x: float, y: float, z: float) → float | None

Occupancy probability [0,1] of the voxel at a point, or None if not observed

insertPointCloudAsEndPoints(points: CPointsMap, sensorPt: mrpt.math.TPoint3D) → None

Inserts a point cloud updating only the end points

insertPointCloudAsRays(points: CPointsMap, sensorPt: mrpt.math.TPoint3D) → None

Inserts a point cloud, marking free space along the rays from sensorPt

updateVoxel(x: float, y: float, z: float, occupied: bool) → None

Updates one voxel with an occupied or free observation

class mrpt.maps.PointCloudRecoloringParameters

Parameters for recolorize3Dpc(), or part of VisualizationParameters if using obs_to_viz()

colorMap: mrpt.img.TColormap
colorMapMaxCoord: float | None
colorMapMinCoord: float | None
colorizeByField: str
invertColorMapping: bool
outlierRejectionPercentile: float | None
class mrpt.maps.TMapGenericParams

C++ API: class mrpt::maps::TMapGenericParams

Bases: mrpt.config.CLoadableOptions, mrpt.serialization.CSerializable

Parameters common to all metric maps.

enableObservationInsertion: bool
enableObservationLikelihood: bool
enableSaveAs3DObject: bool
class mrpt.maps.TMetricMapInitializer

C++ API: struct mrpt::maps::TMetricMapInitializer

Bases: mrpt.config.CLoadableOptions

Base class of the definitions of one metric map (its type and parameters).

genericMapParams: TMapGenericParams
static factory(mapClassName: str) → TMetricMapInitializer

Creates the definition of a map by its class name, e.g. ‘COccupancyGridMap2D’. Requires importing mrpt.maps first, which registers the map types.

getMetricMapClassName() → str

Returns the C++ class name of the map this definition creates

class mrpt.maps.TSetOfMetricMapInitializers

C++ API: class mrpt::maps::TSetOfMetricMapInitializers

Bases: mrpt.config.CLoadableOptions

A set of map definitions, used to build a CMultiMetricMap.

clear() → None

Removes all map definitions.

push_back(mapDefinition: TMetricMapInitializer) → None

Appends a map definition.

size() → int

Returns the number of map definitions.

class mrpt.maps.VisualizationParameters

Here we can customize the way observations will be rendered as 3D objects in obs_to_viz(), obs3Dscan_to_viz(), etc.

axisLimits: float
axisTickFrequency: float
axisTickTextSize: float
colorFromRGBimage: bool
coloring: PointCloudRecoloringParameters
drawSensorPose: bool
onlyPointsWithColor: bool
pointSize: float
points2DscansColor: mrpt.img.TColor
sensorPoseScale: float
showAxis: bool
showPointsIn2Dscans: bool
showSurfaceIn2Dscans: bool
surface2DscansColor: mrpt.img.TColor
mrpt.maps.obs_to_viz(obs: mrpt.obs.CObservation, params: VisualizationParameters = ..., out: mrpt.viz.CSetOfObjects = None) → mrpt.viz.CSetOfObjects
mrpt.maps.obs_to_viz(sf: mrpt.obs.CSensoryFrame, params: VisualizationParameters = ..., out: mrpt.viz.CSetOfObjects = None) → mrpt.viz.CSetOfObjects

Renders all observations of a CSensoryFrame into a CSetOfObjects (a new one if out is None), and returns it