class mrpt::obs::CSensoryFrame

A “sensory frame” is a set of observations taken by the robot approximately at the same time, so they can be considered as a multi-sensor “snapshot” of the environment.

It can contain “observations” of many different kinds.

New observations can be added using:

// Create a smart pointer containing an object of class "CObservationXXX"
CObservationXXX::Ptr    o = std::make_shared<CObservationXXX>();
// o->... // fill it...
CSensoryFrame sf;
sf.insert(o);

The following methods are equivalent for adding new observations to a “sensory frame”:

To examine the objects within a sensory frame, the following methods exist:

Note that shared_ptr<> s to the observations are stored, so a copy of a CSensoryFrame will contain references to the same objects, i.e. copies are shallows copies, not deep copies.

See also:

CObservation

#include <mrpt/obs/CSensoryFrame.h>

class CSensoryFrame: public mrpt::serialization::CSerializable
{
public:
    // typedefs

    typedef std::deque<CObservation::Ptr>::iterator iterator;
    typedef std::deque<CObservation::Ptr>::const_iterator const_iterator;

    // construction

    CSensoryFrame();

    //
methods

    template <class POINTSMAP>
    const POINTSMAP* getAuxPointsMap() const;

    template <class POINTSMAP>
    const POINTSMAP* buildAuxPointsMap(const void* options = nullptr) const;

    void clear();
    bool insertObservationsInto(mrpt::maps::CMetricMap& theMap, const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt) const;
    bool insertObservationsInto(mrpt::maps::CMetricMap::Ptr& theMap, const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt) const;
    void operator += (const CSensoryFrame& sf);
    void operator += (const CObservation::Ptr& obs);
    void push_back(const CObservation::Ptr& obs);
    void insert(const CObservation::Ptr& obs);

    template <typename T>
    T::Ptr getObservationByClass(size_t ith = 0) const;

    const_iterator begin() const;
    const_iterator end() const;
    iterator begin();
    iterator end();
    size_t size() const;
    bool empty() const;
    void eraseByIndex(size_t idx);
    iterator erase(const iterator& it);
    void eraseByLabel(const std::string& label);
    const CObservation::Ptr& getObservationByIndex(size_t idx) const;
    CObservation::Ptr& getObservationByIndex(size_t idx);

    template <typename T>
    T getObservationByIndexAs(size_t idx) const;

    CObservation::Ptr getObservationBySensorLabel(const std::string& label, size_t idx = 0) const;

    template <typename T>
    T getObservationBySensorLabelAs(const std::string& label, size_t idx = 0) const;

    void swap(CSensoryFrame& sf);
};

Typedefs

typedef std::deque<CObservation::Ptr>::iterator iterator

You can use CSensoryFrame::begin to get a iterator to the first element.

typedef std::deque<CObservation::Ptr>::const_iterator const_iterator

You can use CSensoryFrame::begin to get a iterator to the first element.

Construction

CSensoryFrame()

Default ctor.

Methods

template <class POINTSMAP>
const POINTSMAP* getAuxPointsMap() const

Returns the cached points map representation of the scan, if already build with buildAuxPointsMap(), or nullptr otherwise.

Usage:

   mrpt::maps::CPointsMap *map =
obs->getAuxPointsMap<mrpt::maps::CPointsMap>();

See also:

buildAuxPointsMap

template <class POINTSMAP>
const POINTSMAP* buildAuxPointsMap(const void* options = nullptr) const

Returns a cached points map representing this laser scan, building it upon the first call.

Parameters:

options

Can be nullptr to use default point maps’ insertion options, or a pointer to a “CPointsMap::TInsertionOptions” structure to override some params. Usage:

   mrpt::maps::CPointsMap *map =
sf->buildAuxPointsMap<mrpt::maps::CPointsMap>(&options or nullptr);

See also:

getAuxPointsMap

void clear()

Clear the container, so it holds no observations.

bool insertObservationsInto(
    mrpt::maps::CMetricMap& theMap,
    const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
    ) const

Insert all the observations in this SF into a metric map or any kind (see mrpt::maps::CMetricMap).

It calls CObservation::insertObservationInto for all stored observation.

Parameters:

theMap

The map where this observation is to be inserted: the map will be updated.

robotPose

The pose of the robot base for this observation, relative to the target metric map. Set to nullptr (default) to use SE(3) identity, i.e. the origin.

Returns:

Returns true if the map has been updated, or false if this observations have nothing to do with the metric map (e.g. trying to insert an image into a gridmap).

See also:

mrpt::maps::CMetricMap, CObservation::insertObservationInto, CMetricMap::insertObservation

bool insertObservationsInto(
    mrpt::maps::CMetricMap::Ptr& theMap,
    const std::optional<const mrpt::poses::CPose3D>& robotPose = std::nullopt
    ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

void operator += (const CSensoryFrame& sf)

You can use “sf1+=sf2;” to add all observations in sf2 to sf1.

void operator += (const CObservation::Ptr& obs)

You can use “sf+=obs;” to add the observation “obs” to the “sf1”.

void push_back(const CObservation::Ptr& obs)

Insert a new observation to the sensory frame.

void insert(const CObservation::Ptr& obs)

Synonym with push_back()

template <typename T>
T::Ptr getObservationByClass(size_t ith = 0) const

Returns the i’th observation of a given class (or of a descendant class), or nullptr if there is no such observation in the array.

Example:

     CObservationImage::Ptr obs =
m_SF->getObservationByClass<CObservationImage>();

By default (ith=0), the first observation is returned.

const_iterator begin() const

Returns a constant iterator to the first observation: this is an example of usage:

CSensoryFrame  sf;
...
for (CSensoryFrame::const_iterator it=sf.begin();it!=sf.end();++it)
   {
   (*it)->... // (*it) is a "CObservation*"
}
const_iterator end() const

Returns a constant iterator to the end of the list of observations: this is an example of usage:

CSensoryFrame  sf;
...
for (CSensoryFrame::const_iterator it=sf.begin();it!=sf.end();++it)
   {
   (*it)->... // (*it) is a "CObservation*"
}
iterator begin()

Returns a iterator to the first observation: this is an example of usage:

CSensoryFrame  sf;
...
for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
   {
   (*it)->... // (*it) is a "CObservation*"
}
iterator end()

Returns a iterator to the end of the list of observations: this is an example of usage:

CSensoryFrame  sf;
...
for (CSensoryFrame::iterator it=sf.begin();it!=sf.end();++it)
   {
   (*it)->... // (*it) is a "CObservation*"
}
size_t size() const

Returns the number of observations in the list.

bool empty() const

Returns true if there are no observations in the list.

void eraseByIndex(size_t idx)

Removes the i’th observation in the list (0=first).

iterator erase(const iterator& it)

Removes the given observation in the list, and return an iterator to the next element (or this-> end() if it was the last one).

void eraseByLabel(const std::string& label)

Removes all the observations that match a given sensorLabel.

const CObservation::Ptr& getObservationByIndex(size_t idx) const

Returns the i’th observation in the list (0=first).

Parameters:

std::exception

If out of range.

See also:

begin, size

CObservation::Ptr& getObservationByIndex(size_t idx)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template <typename T>
T getObservationByIndexAs(size_t idx) const

Returns the i’th observation in the list (0=first), and as a different smart pointer type:

sf.getObservationByIndexAs<CObservationStereoImages::Ptr>(i);

See also:

begin, size

CObservation::Ptr getObservationBySensorLabel(const std::string& label, size_t idx = 0) const

Returns the i’th observation in the list with the given “sensorLabel” (0=first).

Returns:

The observation, or nullptr if not found.

See also:

begin, size

template <typename T>
T getObservationBySensorLabelAs(
    const std::string& label,
    size_t idx = 0
    ) const

Returns the i’th observation in the list with the given “sensorLabel” (0=first), and as a different smart pointer type:

sf.getObservationBySensorLabelAs<CObservationStereoImages::Ptr>(i);

See also:

begin, size

void swap(CSensoryFrame& sf)

Efficiently swaps the contents of two objects.