class mrpt::maps::COccupancyGridMap3D

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

This is a faster alternative to COctoMap, but use with caution with limited map extensions, since it could easily exaust available memory.

Each voxel follows a Bernoulli probability distribution: a value of 0 means certainly occupied, 1 means a certainly empty voxel. Initially 0.5 means uncertainty.

An alternative, sparse representation of a 3D map is provided via mrpt::maps::CVoxelMap and mrpt::maps::CVoxelMapRGB

#include <mrpt/maps/COccupancyGridMap3D.h>

class COccupancyGridMap3D:
    public mrpt::maps::CMetricMap,
    public mrpt::maps::CLogOddsGridMap3D,
    public mrpt::maps::NearestNeighborsCapable
{
public:
    // typedefs

    typedef OccGridCellTraits::cellType voxelType;
    typedef OccGridCellTraits::cellTypeUnsigned voxelTypeUnsigned;
    typedef detail::logoddscell_traits<OccGridCellTraits::cellType> traits_t;
    typedef mrpt::containers::CDynamicGrid3D<OccGridCellTraits::cellType> grid_t;

    // enums

    enum TLikelihoodMethod;

    // structs

    struct TRenderingOptions;

    // classes

    class TInsertionOptions;
    class TLikelihoodOptions;

    //
fields

    TInsertionOptions insertionOptions;
    TLikelihoodOptions likelihoodOptions;
    TRenderingOptions renderingOptions;

    // construction

    COccupancyGridMap3D(
        const mrpt::math::TPoint3D& corner_min = {-5.0f, -5.0f, -5.0f},
        const mrpt::math::TPoint3D& corner_max = {5.0f, 5.0f, 5.0f},
        float resolution = 0.25f
        );

    //
methods

    virtual bool nn_has_indices_or_ids() const;
    virtual size_t nn_index_count() const;

    virtual bool nn_single_search(
        const mrpt::math::TPoint3Df& query,
        mrpt::math::TPoint3Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrIDOrID
        ) const;

    virtual bool nn_single_search(
        const mrpt::math::TPoint2Df& query,
        mrpt::math::TPoint2Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrID
        ) const;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint3Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint2Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const;

    virtual void nn_radius_search(
        const mrpt::math::TPoint3Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints
        ) const;

    virtual void nn_radius_search(
        const mrpt::math::TPoint2Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints
        ) const;

    void fill(float default_value = 0.5f);

    void setSize(
        const mrpt::math::TPoint3D& corner_min,
        const mrpt::math::TPoint3D& corner_max,
        double resolution,
        float default_value = 0.5f
        );

    void resizeGrid(
        const mrpt::math::TPoint3D& corner_min,
        const mrpt::math::TPoint3D& corner_max,
        float new_voxels_default_value = 0.5f
        );

    void updateCell(int cx_idx, int cy_idx, int cz_idx, float v);
    void setCellFreeness(unsigned int cx, unsigned int cy, unsigned int cz, float value);
    float getCellFreeness(unsigned int cx, unsigned int cy, unsigned int cz) const;
    void setFreenessByPos(float x, float y, float z, float value);
    float getFreenessByPos(float x, float y, float z) const;
    void insertRay(const mrpt::math::TPoint3D& sensor, const mrpt::math::TPoint3D& end, bool endIsOccupied = true);

    void insertPointCloud(
        const mrpt::math::TPoint3D& sensorCenter,
        const mrpt::maps::CPointsMap& pts,
        const float maxValidRange = std::numeric_limits<float>::max(),
        const std::optional<mrpt::poses::CPose3D>& robotPose = std::nullopt
        );

    void getAsOctoMapVoxels(mrpt::opengl::COctoMapVoxels& gl_obj) const;
    virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& outObj) const;
    virtual mrpt::math::TBoundingBoxf boundingBox() const;
    virtual bool isEmpty() const;

    virtual void determineMatching2D(
        const mrpt::maps::CMetricMap* otherMap,
        const mrpt::poses::CPose2D& otherMapPose,
        mrpt::tfest::TMatchingPairList& correspondences,
        const TMatchingParams& params,
        TMatchingExtraResults& extraResults
        ) const;

    virtual float compute3DMatchingRatio(const mrpt::maps::CMetricMap* otherMap, const mrpt::poses::CPose3D& otherMapPose, const TMatchingRatioParams& params) const;
    virtual void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const;
    virtual std::string asString() const;
    static float l2p(const voxelType l);
    static uint8_t l2p_255(const voxelType l);
    static voxelType p2l(const float p);
};

Inherited Members

public:
    // typedefs

    typedef TCELL cell_t;

    //
fields

    grid_t m_grid;

    //
methods

    virtual bool isEmpty() const = 0;
    virtual void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const = 0;
    virtual std::string asString() const = 0;
    virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& o) const = 0;
    void updateCell_fast_occupied(cell_t* theCell, const cell_t logodd_obs, const cell_t thres);

    void updateCell_fast_occupied(
        const unsigned x,
        const unsigned y,
        const unsigned z,
        const cell_t logodd_obs,
        const cell_t thres
        );

    void updateCell_fast_free(cell_t* theCell, const cell_t logodd_obs, const cell_t thres);

    void updateCell_fast_free(
        const unsigned x,
        const unsigned y,
        const unsigned z,
        const cell_t logodd_obs,
        const cell_t thres
        );

    virtual bool nn_has_indices_or_ids() const = 0;
    virtual size_t nn_index_count() const = 0;

    virtual bool nn_single_search(
        const mrpt::math::TPoint3Df& query,
        mrpt::math::TPoint3Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrIDOrID
        ) const = 0;

    virtual bool nn_single_search(
        const mrpt::math::TPoint2Df& query,
        mrpt::math::TPoint2Df& result,
        float& out_dist_sqr,
        uint64_t& resultIndexOrIDOrID
        ) const = 0;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint3Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const = 0;

    virtual void nn_multiple_search(
        const mrpt::math::TPoint2Df& query,
        const size_t N,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs
        ) const = 0;

    virtual void nn_radius_search(
        const mrpt::math::TPoint3Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint3Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints = 0
        ) const = 0;

    virtual void nn_radius_search(
        const mrpt::math::TPoint2Df& query,
        const float search_radius_sqr,
        std::vector<mrpt::math::TPoint2Df>& results,
        std::vector<float>& out_dists_sqr,
        std::vector<uint64_t>& resultIndicesOrIDs,
        size_t maxPoints = 0
        ) const = 0;

Typedefs

typedef OccGridCellTraits::cellType voxelType

The type of the map voxels:

Fields

TInsertionOptions insertionOptions

With this struct options are provided to the observation insertion process.

See also:

CObservation::insertIntoGridMap

Construction

COccupancyGridMap3D(
    const mrpt::math::TPoint3D& corner_min = {-5.0f, -5.0f, -5.0f},
    const mrpt::math::TPoint3D& corner_max = {5.0f, 5.0f, 5.0f},
    float resolution = 0.25f
    )

Constructor.

Methods

virtual bool nn_has_indices_or_ids() const

Returns true if the rest of nn_* methods will populate the output indices values with 0-based contiguous indices.

Returns false if indices are actually sparse ID numbers without any expectation of they be contiguous or start near zero.

virtual size_t nn_index_count() const

If nn_has_indices_or_ids() returns true, this must return the number of “points” (or whatever entity) the indices correspond to.

Otherwise, the return value should be ignored.

virtual bool nn_single_search(
    const mrpt::math::TPoint3Df& query,
    mrpt::math::TPoint3Df& result,
    float& out_dist_sqr,
    uint64_t& resultIndexOrIDOrID
    ) const

Search for the closest 3D point to a given one.

Parameters:

query

The query input point.

result

The found closest point.

out_dist_sqr

The square Euclidean distance between the query and the returned point.

resultIndexOrID

The index or ID of the result point in the map.

Returns:

True if successful, false if no point was found.

virtual void nn_multiple_search(
    const mrpt::math::TPoint3Df& query,
    const size_t N,
    std::vector<mrpt::math::TPoint3Df>& results,
    std::vector<float>& out_dists_sqr,
    std::vector<uint64_t>& resultIndicesOrIDs
    ) const

Search for the N closest 3D points to a given one.

Parameters:

query

The query input point.

results

The found closest points.

out_dists_sqr

The square Euclidean distances between the query and the returned point.

resultIndicesOrIDs

The indices or IDs of the result points.

virtual void nn_radius_search(
    const mrpt::math::TPoint3Df& query,
    const float search_radius_sqr,
    std::vector<mrpt::math::TPoint3Df>& results,
    std::vector<float>& out_dists_sqr,
    std::vector<uint64_t>& resultIndicesOrIDs,
    size_t maxPoints
    ) const

Radius search for closest 3D points to a given one.

Parameters:

query

The query input point.

search_radius_sqr

The search radius, squared.

results

The found closest points.

out_dists_sqr

The square Euclidean distances between the query and the returned point.

resultIndicesOrIDs

The indices or IDs of the result points.

maxPoints

If !=0, the maximum number of neigbors to return.

void fill(float default_value = 0.5f)

Fills all the voxels with a default value.

void setSize(
    const mrpt::math::TPoint3D& corner_min,
    const mrpt::math::TPoint3D& corner_max,
    double resolution,
    float default_value = 0.5f
    )

Change the size of gridmap, erasing all its previous contents.

Parameters:

resolution

The new size of voxels.

default_value

The value of voxels, tipically 0.5.

See also:

ResizeGrid

void resizeGrid(
    const mrpt::math::TPoint3D& corner_min,
    const mrpt::math::TPoint3D& corner_max,
    float new_voxels_default_value = 0.5f
    )

Change the size of gridmap, maintaining previous contents.

Parameters:

new_voxels_default_value

Value of new voxels, tipically 0.5

See also:

setSize()

void updateCell(int cx_idx, int cy_idx, int cz_idx, float v)

Performs the Bayesian fusion of a new observation of a cell.

See also:

updateInfoChangeOnly, updateCell_fast_occupied, updateCell_fast_free

void setCellFreeness(
    unsigned int cx,
    unsigned int cy,
    unsigned int cz,
    float value
    )

Change the contents [0,1] (0:occupied, 1:free) of a voxel, given its index.

float getCellFreeness(unsigned int cx, unsigned int cy, unsigned int cz) const

Read the real valued [0,1] (0:occupied, 1:free) contents of a voxel, given its index.

void setFreenessByPos(float x, float y, float z, float value)

Change the contents [0,1] of a voxel, given its coordinates.

float getFreenessByPos(float x, float y, float z) const

Read the real valued [0,1] contents of a voxel, given its coordinates.

void insertRay(const mrpt::math::TPoint3D& sensor, const mrpt::math::TPoint3D& end, bool endIsOccupied = true)

Increases the freeness of a ray segment, and the occupancy of the voxel at its end point (unless endIsOccupied=false).

Normally, users would prefer the higher-level method CMetricMap::insertObservation()

void insertPointCloud(
    const mrpt::math::TPoint3D& sensorCenter,
    const mrpt::maps::CPointsMap& pts,
    const float maxValidRange = std::numeric_limits<float>::max(),
    const std::optional<mrpt::poses::CPose3D>& robotPose = std::nullopt
    )

Calls insertRay() for each point in the point cloud, using as sensor central point (the origin of all rays), the given sensorCenter.

Parameters:

maxValidRange

If a point has larger distance from sensorCenter than maxValidRange, it will be considered a non-echo, and NO occupied voxel will be created at the end of the segment.

See also:

insertionOptions parameters are observed in this method.

void getAsOctoMapVoxels(mrpt::opengl::COctoMapVoxels& gl_obj) const

See also:

renderingOptions

virtual void getVisualizationInto(mrpt::opengl::CSetOfObjects& outObj) const

Returns a 3D object representing the map.

See also:

renderingOptions

virtual mrpt::math::TBoundingBoxf boundingBox() const

Returns the bounding box of the metric map, or (0,0,0)-(0,0,0) (the default value of mrpt::math::TBoundingBoxf() if not implemented in the derived class or the map is empty.

virtual bool isEmpty() const

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.

virtual void determineMatching2D(
    const mrpt::maps::CMetricMap* otherMap,
    const mrpt::poses::CPose2D& otherMapPose,
    mrpt::tfest::TMatchingPairList& correspondences,
    const TMatchingParams& params,
    TMatchingExtraResults& extraResults
    ) const

See docs in base class: in this class this always returns 0.

virtual float compute3DMatchingRatio(
    const mrpt::maps::CMetricMap* otherMap,
    const mrpt::poses::CPose3D& otherMapPose,
    const TMatchingRatioParams& params
    ) const

See docs in base class: in this class this always returns 0.

virtual void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const

This virtual method saves the map to a file “filNamePrefix”+< some_file_extension >, as an image or in any other applicable way (Notice that other methods to save the map may be implemented in classes implementing this virtual interface).

virtual std::string asString() const

Returns a short description of the map.

static float l2p(const voxelType l)

Scales an integer representation of the log-odd into a real valued probability in [0,1], using p=exp(l)/(1+exp(l))

static uint8_t l2p_255(const voxelType l)

Scales an integer representation of the log-odd into a linear scale [0,255], using p=exp(l)/(1+exp(l))

static voxelType p2l(const float p)

Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the valid range of voxelType.