class mrpt::obs::CObservation2DRangeScan

A “CObservation”-derived class that represents a 2D range scan measurement (typically from a laser scanner).

The data structures are generic enough to hold a wide variety of 2D scanners and “3D” planar rotating 2D lasers.

These are the most important data fields:

  • These three fields are private data member (since MRPT 1.5.0) for safety and to ensure data consistency. Read them with the backwards-compatible proxies scan, intensity, validRange or (preferred) with the new get_*, set_* and resize() methods:

    • CObservation2DRangeScan::scan -> A vector of float values with all the range measurements (in meters).

    • CObservation2DRangeScan::validRange -> A vector (of identical size to scan ), has non-zeros for those ranges than are valid (i.e. will be zero for non-reflected rays, etc.)

    • CObservation2DRangeScan::intensity -> A vector (of identical size to scan ) a unitless int values representing the relative strength of each return. Higher values indicate a more intense return. This is useful for filtering out low intensity(noisy) returns or detecting intense landmarks.

  • CObservation2DRangeScan::aperture -> The field-of-view of the scanner, in radians (typically, M_PI = 180deg).

  • CObservation2DRangeScan::sensorPose -> The 6D location of the sensor on the robot reference frame (default=at the origin).

**

See also:

CObservation, CPointsMap, T2DScanProperties

#include <mrpt/obs/CObservation2DRangeScan.h>

class CObservation2DRangeScan: public mrpt::obs::CObservation
{
public:
    // typedefs

    typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas;
    typedef std::vector<std::pair<mrpt::math::CPolygon, std::pair<double, double>>> TListExclusionAreasWithRanges;

    //
fields

    float aperture {M_PIf};
    bool rightToLeft {true};
    float maxRange {80.0f};
    mrpt::poses::CPose3D sensorPose;
    float stdError {0.01f};
    float beamAperture {0};
    double deltaPitch {0};

    //
methods

    void resizeScan(const size_t len);

    void resizeScanAndAssign(
        const size_t len,
        const float rangeVal,
        const bool rangeValidity,
        const int32_t rangeIntensity = 0
        );

    size_t getScanSize() const;
    const float& getScanRange(const size_t i) const;
    float& getScanRange(const size_t i);

    void setScanRange(
        const size_t i,
        const float val
        );

    const int32_t& getScanIntensity(const size_t i) const;
    int32_t& getScanIntensity(const size_t i);

    void setScanIntensity(
        const size_t i,
        const int val
        );

    bool getScanRangeValidity(const size_t i) const;

    void setScanRangeValidity(
        const size_t i,
        const bool val
        );

    void getScanProperties(T2DScanProperties& p) const;

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

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

    void loadFromVectors(
        size_t nRays,
        const float* scanRanges,
        const char* scanValidity
        );

    bool isPlanarScan(const double tolerance = 0) const;
    bool hasIntensity() const;
    void setScanHasIntensity(bool setHasIntensityFlag);
    virtual void getSensorPose(mrpt::poses::CPose3D& out_sensorPose) const;
    virtual void setSensorPose(const mrpt::poses::CPose3D& newSensorPose);
    virtual void getDescriptionAsText(std::ostream& o) const;

    void truncateByDistanceAndAngle(
        float min_distance,
        float max_angle,
        float min_height = 0,
        float max_height = 0,
        float h = 0
        );

    void filterByExclusionAreas(const TListExclusionAreas& areas);
    void filterByExclusionAreas(const TListExclusionAreasWithRanges& areas);
    void filterByExclusionAngles(const std::vector<std::pair<double, double>>& angles);
};

Inherited Members

public:
    //
fields

    mrpt::system::TTimeStamp timestamp {mrpt::system::now()};
    std::string sensorLabel;

    //
methods

    mrpt::system::TTimeStamp getTimeStamp() const;
    virtual mrpt::system::TTimeStamp getOriginalReceivedTimeStamp() const;
    virtual void load() const;
    virtual void unload();

    template <class METRICMAP>
    bool insertObservationInto(
        METRICMAP* theMap,
        const mrpt::poses::CPose3D* robotPose = nullptr
        ) const;

    virtual void getSensorPose(mrpt::poses::CPose3D& out_sensorPose) const = 0;
    void getSensorPose(mrpt::math::TPose3D& out_sensorPose) const;
    virtual void setSensorPose(const mrpt::poses::CPose3D& newSensorPose) = 0;
    void setSensorPose(const mrpt::math::TPose3D& newSensorPose);
    virtual void getDescriptionAsText(std::ostream& o) const;
    std::string getDescriptionAsTextValue() const;

Typedefs

typedef std::vector<mrpt::math::CPolygon> TListExclusionAreas

Used in filterByExclusionAreas.

typedef std::vector<std::pair<mrpt::math::CPolygon, std::pair<double, double>>> TListExclusionAreasWithRanges

Used in filterByExclusionAreas.

Fields

float aperture {M_PIf}

The “aperture” or field-of-view of the range finder, in radians (typically M_PI = 180 degrees).

bool rightToLeft {true}

The scanning direction: true=counterclockwise; false=clockwise.

float maxRange {80.0f}

The maximum range allowed by the device, in meters (e.g.

80m, 50m,…)

mrpt::poses::CPose3D sensorPose

The 6D pose of the sensor on the robot at the moment of starting the scan.

float stdError {0.01f}

The “sigma” error of the device in meters, used while inserting the scan in an occupancy grid.

float beamAperture {0}

The aperture of each beam, in radians, used to insert “thick” rays in the occupancy grid.

double deltaPitch {0}

If the laser gathers data by sweeping in the pitch/elevation angle, this holds the increment in “pitch” (=-“elevation”) between the beginning and the end of the scan (the sensorPose member stands for the pose at the beginning of the scan).

Methods

void resizeScan(const size_t len)

Resizes all data vectors to allocate a given number of scan rays.

void resizeScanAndAssign(
    const size_t len,
    const float rangeVal,
    const bool rangeValidity,
    const int32_t rangeIntensity = 0
    )

Resizes all data vectors to allocate a given number of scan rays and assign default values.

size_t getScanSize() const

Get number of scan rays.

const float& getScanRange(const size_t i) const

The range values of the scan, in meters.

Must have same length than validRange

const int32_t& getScanIntensity(const size_t i) const

The intensity values of the scan.

If available, must have same length than validRange

bool getScanRangeValidity(const size_t i) const

It’s false (=0) on no reflected rays, referenced to elements in scan.

void getScanProperties(T2DScanProperties& p) const

Fill out a T2DScanProperties structure with the parameters of this scan.

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 =
obs->buildAuxPointsMap<mrpt::maps::CPointsMap>(&options or nullptr);

See also:

getAuxPointsMap

bool isPlanarScan(const double tolerance = 0) const

Return true if the laser scanner is “horizontal”, so it has an absolute value of “pitch” and “roll” less or equal to the given tolerance (in rads, default=0) (with the normal vector either upwards or downwards).

bool hasIntensity() const

Return true if scan has intensity.

void setScanHasIntensity(bool setHasIntensityFlag)

Marks this scan as having or not intensity data.

virtual void getSensorPose(mrpt::poses::CPose3D& out_sensorPose) const

A general method to retrieve the sensor pose on the robot.

Note that most sensors will return a full (6D) CPose3D, but see the derived classes for more details or special cases.

See also:

setSensorPose

virtual void setSensorPose(const mrpt::poses::CPose3D& newSensorPose)

A general method to change the sensor pose on the robot.

Note that most sensors will use the full (6D) CPose3D, but see the derived classes for more details or special cases.

See also:

getSensorPose

virtual void getDescriptionAsText(std::ostream& o) const

Build a detailed, multi-line textual description of the observation contents and dump it to the output stream.

If overried by derived classes, call base CObservation::getDescriptionAsText() first to show common information.

This is the text that appears in RawLogViewer when selecting an object in the dataset

void truncateByDistanceAndAngle(
    float min_distance,
    float max_angle,
    float min_height = 0,
    float max_height = 0,
    float h = 0
    )

A general method to truncate the scan by defining a minimum valid distance and a maximum valid angle as well as minimun and maximum heights (NOTE: the laser z-coordinate must be provided).

void filterByExclusionAreas(const TListExclusionAreas& areas)

Mark as invalid sensed points that fall within any of a set of “exclusion areas”, given in coordinates relative to the vehicle (taking into account “sensorPose”).

See also:

C2DRangeFinderAbstract::loadExclusionAreas

void filterByExclusionAreas(const TListExclusionAreasWithRanges& areas)

Mark as invalid sensed points that fall within any of a set of “exclusion areas”, given in coordinates relative to the vehicle (taking into account “sensorPose”), AND such as the Z coordinate of the point falls in the range [min,max] associated to each exclusion polygon.

See also:

C2DRangeFinderAbstract::loadExclusionAreas

void filterByExclusionAngles(const std::vector<std::pair<double, double>>& angles)

Mark as invalid the ranges in any of a given set of “forbiden angle ranges”, given as pairs<min_angle,max_angle>.

See also:

C2DRangeFinderAbstract::loadExclusionAreas