template class mrpt::maps::COctoMapBase

Overview

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

This base class represents a 3D map where each voxel may contain an “occupancy” property, RGBD data, etc. depending on the derived class.

As with any other mrpt::maps::CMetricMap, you can obtain a 3D representation of the map calling getAs3DObject() or getAsOctoMapVoxels()

To use octomap’s iterators to go through the voxels, use COctoMap::getOctomap()

The octomap library was presented in [8]

See also:

CMetricMap, the example in “MRPT/mrpt_examples_cpp/octomap_simple”

#include <mrpt/maps/COctoMapBase.h>

template <class octree_t, class octree_node_t>
class COctoMapBase:
    public mrpt::maps::CMetricMap,
    public mrpt::config::OptionsCapable
{
public:
    // typedefs

    typedef COctoMapBase<octree_t, octree_node_t> myself_t;

    // structs

    struct TInsertionOptions;
    struct TLikelihoodOptions;
    struct TRenderingOptions;

    // fields

    TInsertionOptions insertionOptions;
    TLikelihoodOptions likelihoodOptions;
    TRenderingOptions renderingOptions;

    // construction

    COctoMapBase(double resolution);

    // methods

    template <class OCTOMAP_CLASS>
    OCTOMAP_CLASS& getOctomap();

    virtual std::string asString() const;
    virtual std::map<std::string, mrpt::config::CLoadableOptions*> optionsByName();
    virtual void saveMetricMapRepresentationToFile(const std::string& filNamePrefix) const;
    virtual void getVisualizationInto(mrpt::viz::CSetOfObjects& o) const;
    virtual void getAsOctoMapVoxels(mrpt::viz::COctoMapVoxels& gl_obj) const = 0;
    bool getPointOccupancy(const float x, const float y, const float z, double& prob_occupancy) const;
    std::optional<double> getPointOccupancy(float x, float y, float z) const;

    void insertPointCloud(
        const CPointsMap& ptMap,
        const float sensor_x,
        const float sensor_y,
        const float sensor_z
        );

    bool castRay(
        const mrpt::math::TPoint3D& origin,
        const mrpt::math::TPoint3D& direction,
        mrpt::math::TPoint3D& end,
        bool ignoreUnknownCells = false,
        double maxRange = -1.0
        ) const;

    virtual void setOccupancyThres(double prob) = 0;
    virtual void setProbHit(double prob) = 0;
    virtual void setProbMiss(double prob) = 0;
    virtual void setClampingThresMin(double thresProb) = 0;
    virtual void setClampingThresMax(double thresProb) = 0;
    virtual double getOccupancyThres() const = 0;
    virtual float getOccupancyThresLog() const = 0;
    virtual double getProbHit() const = 0;
    virtual float getProbHitLog() const = 0;
    virtual double getProbMiss() const = 0;
    virtual float getProbMissLog() const = 0;
    virtual double getClampingThresMin() const = 0;
    virtual float getClampingThresMinLog() const = 0;
    virtual double getClampingThresMax() const = 0;
    virtual float getClampingThresMaxLog() const = 0;
};

// direct descendants

class CColouredOctoMap;
class COctoMap;

Inherited Members

public:
    // typedefs

    typedef std::shared_ptr<CObject> Ptr;
    typedef std::shared_ptr<const CObject> ConstPtr;
    typedef std::unique_ptr<CObject> UniquePtr;
    typedef std::unique_ptr<const CObject> ConstUniquePtr;
    typedef std::shared_ptr<CSerializable> Ptr;
    typedef std::shared_ptr<const CSerializable> ConstPtr;
    typedef std::shared_ptr<CMetricMap> Ptr;
    typedef std::shared_ptr<const CMetricMap> ConstPtr;

    // fields

    TMapGenericParams genericMapParams;

    // methods

    mrpt::rtti::CObject::Ptr duplicateGetSmartPtr() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    virtual CObject* clone() const = 0;
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    virtual std::string asString() const = 0;
    Visualizable& operator = (const Visualizable&);
    Visualizable& operator = (Visualizable&&);
    virtual void getVisualizationInto(mrpt::viz::CSetOfObjects& o) const = 0;
    std::shared_ptr<mrpt::viz::CSetOfObjects> getVisualization() const;
    virtual const mrpt::rtti::TRuntimeClassId* GetRuntimeClass() const;
    static const mrpt::rtti::TRuntimeClassId& GetRuntimeClassIdStatic();
    void clear();
    virtual bool isEmpty() const = 0;
    virtual auto boundingBox() const;
    void loadFromSimpleMap(const mrpt::maps::CSimpleMap& Map);
    bool insertObservation(const mrpt::obs::CObservation& obs, const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt);
    bool insertObservationPtr(const mrpt::obs::CObservation::Ptr& obs, const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt);
    double computeObservationLikelihood(const mrpt::obs::CObservation& obs, const mrpt::poses::CPose3D& takenFrom) const;
    virtual bool canComputeObservationLikelihood(const mrpt::obs::CObservation& obs) const;
    double computeObservationsLikelihood(const mrpt::obs::CSensoryFrame& sf, const mrpt::poses::CPose3D& takenFrom);
    bool canComputeObservationsLikelihood(const mrpt::obs::CSensoryFrame& sf) 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 void determineMatching3D(
        const mrpt::maps::CMetricMap* otherMap,
        const mrpt::poses::CPose3D& 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 = 0;
    virtual void auxParticleFilterCleanUp();
    virtual float squareDistanceToClosestCorrespondence(float x0, float y0) const;
    OptionsCapable& operator = (const OptionsCapable&);
    OptionsCapable& operator = (OptionsCapable&&);
    virtual std::map<std::string, mrpt::config::CLoadableOptions*> optionsByName() = 0;
    virtual bool trySetCreationOptions(] const mrpt::config::CConfigFileBase& cfg, ] const std::string& section);

Fields

TInsertionOptions insertionOptions

The options used when inserting.

Construction

COctoMapBase(double resolution)

Constructor, defines the resolution of the octomap (length of each voxel side)

Methods

template <class OCTOMAP_CLASS>
OCTOMAP_CLASS& getOctomap()

Get a reference to the internal octomap object.

Example:

mrpt::maps::COctoMap  map;
octomap::OcTree &om = map.getOctomap<octomap::OcTree>();
virtual std::string asString() const

Returns a short description of the map.

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 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.

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 void getVisualizationInto(mrpt::viz::CSetOfObjects& o) const

Returns a 3D object representing the map.

See also:

renderingOptions

virtual void getAsOctoMapVoxels(mrpt::viz::COctoMapVoxels& gl_obj) const = 0

Builds a renderizable representation of the octomap as a mrpt::viz::COctoMapVoxels object.

See also:

renderingOptions

bool getPointOccupancy(
    const float x,
    const float y,
    const float z,
    double& prob_occupancy
    ) const

Get the occupancy probability [0,1] of a point.

Deprecated Use getPointOccupancy(float,float,float) returning optional instead.

Returns:

false if the point is not mapped, in which case the returned “prob” is undefined.

std::optional<double> getPointOccupancy(float x, float y, float z) const

Returns the occupancy probability [0,1] at the given point, or std::nullopt if the point is not mapped.

void insertPointCloud(
    const CPointsMap& ptMap,
    const float sensor_x,
    const float sensor_y,
    const float sensor_z
    )

Update the octomap with a 2D or 3D scan, given directly as a point cloud and the 3D location of the sensor (the origin of the rays) in this map’s frame of reference.

Insertion parameters can be found in insertionOptions.

See also:

The generic observation insertion method CMetricMap::insertObservation()

bool castRay(
    const mrpt::math::TPoint3D& origin,
    const mrpt::math::TPoint3D& direction,
    mrpt::math::TPoint3D& end,
    bool ignoreUnknownCells = false,
    double maxRange = -1.0
    ) const

Performs raycasting in 3d, similar to computeRay().

A ray is cast from origin with a given direction, the first occupied cell is returned (as center coordinate). If the starting coordinate is already occupied in the tree, this coordinate will be returned as a hit.

Parameters:

origin

starting coordinate of ray

direction

A vector pointing in the direction of the raycast. Does not need to be normalized.

end

returns the center of the cell that was hit by the ray, if successful

ignoreUnknownCells

whether unknown cells are ignored. If false (default), the raycast aborts when an unkown cell is hit.

maxRange

Maximum range after which the raycast is aborted (<= 0: no limit, default)

Returns:

whether or not an occupied cell was hit