class mola::VoxelStatsMap

Overview

A voxel map of running surface statistics: each cell keeps the mean and the scatter of the points inserted into it, and offers a plane or Gaussian model of the surface inside it.

  • Statistics, not points. One update per touched cell and scan, so insertion is O(points) and cheap enough to run every scan.

  • Equal weight per scan (default): the n points a scan puts in a cell weigh 1/n each, so a scan counts once wherever its density.

  • Maturity: a cell is offered to a matcher only after min_scans_active scans and min_points_active points. While the map itself has received fewer scans than that, the bound is the number received, so a new map is usable from its second scan.

  • Model: a plane if its smallest eigenvalue is below the squared plane_max_thickness and its second one exceeds plane_min_ratio times the first; a Gaussian otherwise. Models are refreshed at insertion, so queries are pure reads.

  • Metric: covariances are in m^2.

Diagnostics: if the environment variable MOLA_VOXELSTATSMAP_FILE names a writable file, one line per inserted scan is appended with the cell counts (touched, new and total; active, planes and Gaussians overall; active and planes within 30 m of the robot). Off by default.

It implements mp2p_icp::NearestCellCapable for mp2p_icp::Matcher_VoxelCell.

The cell model follows the covariance-informed cells of CIO-LIO (running weighted mean and scatter, plane or Gaussian by the eigenvalues), with a bounded neighbor search added for platforms without an inertial prediction.

#include <VoxelStatsMap.h>

class VoxelStatsMap:
    public mrpt::maps::CMetricMap,
    public mp2p_icp::NearestCellCapable,
    public mola::OptionsCapable
{
public:
    // typedefs

    typedef tsl::robin_map<global_index3d_t, Cell, index3d_hash<int32_t>> cells_map_t;
    typedef index3d_t<int32_t> global_index3d_t;

    // structs

    struct Cell;
    struct CellStats;
    struct TCreationOptions;
    struct TInsertionOptions;
    struct TRenderOptions;

    // fields

    static constexpr int32_t MAX_ABS_INDEX = int32_t(1)<<29;
    TCreationOptions creationOptions;
    TInsertionOptions insertionOptions;
    TRenderOptions renderOptions;
    float voxel_size = 0.5f;
    mola::VoxelStatsMap::TInsertionOptions insertionOpts;
    mola::VoxelStatsMap::TRenderOptions renderOpts;

    // construction

    VoxelStatsMap(float voxel_size = 0.5f);
    VoxelStatsMap(const VoxelStatsMap&);
    VoxelStatsMap(VoxelStatsMap&&);

    // methods

    bool isIndexable(double x, double y, double z) const;
    global_index3d_t coordToGlobalIdx(double x, double y, double z) const;
    mrpt::math::TPoint3D globalIdxToCenter(const global_index3d_t& idx) const;
    void setVoxelProperties(float voxel_size);
    float voxelSize() const;

    void insertScan(
        const mrpt::maps::CPointsMap& pts,
        const mrpt::poses::CPose3D& cloudPose,
        const mrpt::math::TPoint3D& robotPosition
        );

    size_t size() const;
    uint32_t scansInserted() const;
    uint32_t effectiveMinScans() const;
    bool isActive(const Cell& c) const;
    const cells_map_t& cells() const;
    std::optional<CellStats> cellStats(const global_index3d_t& idx) const;
    void visitAllCells(const std::function<void(const global_index3d_t&, const Cell&)>& f) const;
    mrpt::math::TBoundingBoxf boundingBox() const;
    virtual CellQuery nn_search_cell(const mrpt::math::TPoint3Df& p_global, bool neighbor_fallback) const;
    std::string asString() const;
    void getVisualizationInto(mrpt::viz::CSetOfObjects& outObj) const;
    bool isEmpty() const;
    void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const;
    const mrpt::maps::CSimplePointsMap* getAsSimplePointsMap() const;
    VoxelStatsMap& operator = (const VoxelStatsMap&);
    VoxelStatsMap& operator = (VoxelStatsMap&&);
    virtual std::map<std::string, mrpt::config::CLoadableOptions*> optionsByName();

    bool trySetCreationOptions(
        const mrpt::config::CConfigFileBase& cfg,
        const std::string& section
        );
};

Inherited Members

public:
    // structs

    struct CellQuery;
    struct CellRef;

    // methods

    NearestCellCapable& operator = (const NearestCellCapable&);
    NearestCellCapable& operator = (NearestCellCapable&&);
    virtual CellQuery nn_search_cell(const mrpt::math::TPoint3Df& p_global, bool neighbor_fallback) const = 0;
    OptionsCapable& operator = (const OptionsCapable&);
    OptionsCapable& operator = (OptionsCapable&&);
    virtual std::map<std::string, mrpt::config::CLoadableOptions*> optionsByName() = 0;

Fields

static constexpr int32_t MAX_ABS_INDEX = int32_t(1)<<29

Largest cell index magnitude accepted (neighbor offsets and index differences then stay far from int32 overflow).

Construction

VoxelStatsMap(float voxel_size = 0.5f)

Parameters:

voxel_size

Cell size [meters]

Methods

bool isIndexable(double x, double y, double z) const

Whether a point can be given a cell index: finite, and within MAX_ABS_INDEX cells of the origin, so index arithmetic cannot overflow.

global_index3d_t coordToGlobalIdx(double x, double y, double z) const

Index of the cell containing a point (see isIndexable()).

mrpt::math::TPoint3D globalIdxToCenter(const global_index3d_t& idx) const

Coordinates of the center of a cell.

void setVoxelProperties(float voxel_size)

Resets the cell size, and clears the map.

void insertScan(
    const mrpt::maps::CPointsMap& pts,
    const mrpt::poses::CPose3D& cloudPose,
    const mrpt::math::TPoint3D& robotPosition
    )

Inserts a point cloud as one scan: pts are given in a frame whose pose in the map is cloudPose. robotPosition is used to prune far cells.

size_t size() const

Number of cells, active or not.

uint32_t scansInserted() const

Scans inserted since the map was last cleared.

uint32_t effectiveMinScans() const

The number of scans a cell needs to be offered to a matcher now.

bool isActive(const Cell& c) const

Whether a cell is offered to matchers.

std::optional<CellStats> cellStats(const global_index3d_t& idx) const

The statistics of a cell, if it exists.

virtual CellQuery nn_search_cell(
    const mrpt::math::TPoint3Df& p_global,
    bool neighbor_fallback
    ) const

Looks up the active cell containing p_global (map frame).

With neighbor_fallback, if that cell is not active, the closest active cell among its 26 neighbors is returned instead, provided its mean lies within one cell diagonal of the query.

The returned pointer is valid until the map is next modified. Must be a pure read, safe to call from several threads at once.

const mrpt::maps::CSimplePointsMap* getAsSimplePointsMap() const

Means of the active cells, for visualization and for the ROS bridge.

virtual std::map<std::string, mrpt::config::CLoadableOptions*> optionsByName()

Maps an options-group name (e.g. “insertionOptions”) to a pointer to the corresponding, live CLoadableOptions member. Pointers remain valid as long as this is alive, and point directly to the map’s actual option members (no copies), so writes through them (e.g. via loadFromConfigFile()) take effect immediately.

Implementations should list every CLoadableOptions member they define, INCLUDING “creationOptions” if present (so it can be discovered/exported generically); however, callers must use trySetCreationOptions(), not a direct write through this pointer, to safely modify creation options.