MIRA
Namespaces | Classes | Typedefs | Functions
mira::maps Namespace Reference

Namespaces

 polygon
 

Classes

class  CostMap
 
class  GenericPointCloud
 
class  GenericPointCloudConstIterator
 
class  GenericPointCloudIterator
 
class  GridMap
 
struct  GridMapFileInfoWithFrame
 A struct representing some information about a grid map and an additional frame. More...
 
struct  GridMapFileInfoWithFrameAndChannelName
 A struct representing some information about a grid map and an additional channel. More...
 
struct  GridMapInfo
 A struct representing some information about a grid map. More...
 
class  OccupancyGridMapping
 Inserts range scan into an occupancy map. More...
 
union  PCColor
 
class  PCDataField
 
struct  PCDataFieldTypeTrait
 
struct  PCDataFieldTypeTrait< float >
 
struct  PCDataFieldTypeTrait< int32 >
 
struct  PCDataFieldTypeTrait< PCColor >
 
struct  PCDataFieldTypeTrait< uint32 >
 
class  PCFormat
 
struct  PixelTruncateHelper
 
struct  PixelTruncateHelper< T, 1 >
 
class  Point2rgb
 
class  Point3labeled
 
class  Point3normal
 
class  Point3rgb
 
class  PointCloud
 
class  PointCloudConstIterator
 
class  PointCloudIterator
 
struct  RangeScanCone
 Configuration of a sensor cone. More...
 
class  RasterSensorConeVisitor
 
class  VoxelMap
 

Typedefs

typedef std::list< Rect2iDirtyRegions
 Dirty regions stored as vector of rects. More...
 
typedef std::list< Rect2fDirtyRegionsWorld
 
typedef GridMap< uint8OccupancyGrid
 Occupancy Map, typedef for 1 channel GridMap containing 8-bit unsigned integers per cell. More...
 
using OccupancyGridInfo = GridMapInfo
 Backward compatibility aliases. More...
 
using OccupancyGridFileInfoWithFrame = GridMapFileInfoWithFrame
 
using OccupancyGridFileInfoWithFrameAndChannelName = GridMapFileInfoWithFrameAndChannelName
 
typedef PointCloud< Point3normalPointCloud3Normal
 
typedef PointCloud< Point2fPointCloud2
 
typedef PointCloud< Point3fPointCloud3
 
typedef PointCloud< Point2rgbPointCloud2rgb
 
typedef PointCloud< Point3rgbPointCloud3rgb
 
typedef PointCloud< Point3labeledPointCloud3labeled
 

Functions

template<typename Visitor , bool VisitorUsesWorldDistance = true>
void rasterSensorCone (const RangeScanCone &c, float maxRange, float cellSize, Visitor &visitor)
 Function for fast rasterization of sensor cones cell by cell. More...
 
DirtyRegions mergeRegions (DirtyRegions regions)
 
template<typename T , int Channels = 1>
GridMap< T, Channels > loadGridMapFromImage (const Img<> &img, float cellSize, const Point2i &offset, T truncateTo=std::numeric_limits< T >::max())
 Loads the specified image as grid map. More...
 
template<typename T , int Channels = 1>
GridMap< T, Channels > loadGridMapFromFile (const Path &filename, float cellSize, const Point2i &offset, T truncateTo=std::numeric_limits< T >::max())
 Loads the specified image file as grid map. More...
 
template<typename T , int Channels = 1>
GridMap< T, Channels > loadGridMap (const GridMapInfo &info, T truncateTo=std::numeric_limits< T >::max())
 Loads the image specified by info as map. More...
 
template<typename T , int Channels = 1>
GridMap< T, Channels > loadGridMap (const Path &descriptionFilename, T truncateTo=std::numeric_limits< T >::max())
 Loads the image from the description file (specifying an image file) as map. More...
 
template<typename T , int Channels>
void saveGridMapToFile (Path filename, const GridMap< T, Channels > &map, bool fullImagePath=true)
 Saves the specified grid map as image + description xml. More...
 
MIRA_MAPPING_MAPS_EXPORT OccupancyGrid loadOccupancyGrid (const OccupancyGridInfo &info, bool truncateTo254=true)
 Loads the grayscale image specified by info as occupancy map. More...
 
MIRA_MAPPING_MAPS_EXPORT OccupancyGrid loadOccupancyGridFromFile (const Path &filename, float cellSize, const Point2i &offset, bool truncateTo254=true)
 Loads the specified grayscale image from to as occupancy map. More...
 
MIRA_MAPPING_MAPS_EXPORT OccupancyGrid loadOccupancyGridFromImage (const Img<> &img, float cellSize, const Point2i &offset, bool truncateTo254=true)
 Loads the specified grayscale image as occupancy map. More...
 
MIRA_MAPPING_MAPS_EXPORT OccupancyGrid loadOccupancyGridFromGM2File (const Path &filename)
 Loads the specified GM2 map as occupancy map. More...
 
MIRA_MAPPING_MAPS_EXPORT void saveOccupancyGridToFile (Path filename, const OccupancyGrid &map, bool fullImagePath=true)
 Saves the specified occupancy map as grayscale image and description xml. More...
 
template<typename PointType >
PCFormat pointCloudFormat ()
 
template<>
PCFormat pointCloudFormat< Point2f > ()
 
template<>
PCFormat pointCloudFormat< Point3f > ()
 
template<>
PCFormat pointCloudFormat< Eigen::Vector3f > ()
 

Typedef Documentation

◆ DirtyRegions

typedef std::list<Rect2i> DirtyRegions

Dirty regions stored as vector of rects.

◆ DirtyRegionsWorld

typedef std::list<Rect2f> DirtyRegionsWorld

◆ OccupancyGrid

Occupancy Map, typedef for 1 channel GridMap containing 8-bit unsigned integers per cell.

Each cell stores the occupancy values as a single byte coded from 0 (not occupied) to 254 (occupied):

Occupancy value Byte representation 0.0 0 0.5 127 1.0 254

Please note, that the value of 255 is reserved to mark a cell as "uninitialized". Hence, the max. allowed value is 254, representing an occupancy probability of 1.0. When an occupancy map is loaded from an image file, pixels with values larger than 254 will be truncated to 254.

◆ OccupancyGridInfo

Backward compatibility aliases.

◆ OccupancyGridFileInfoWithFrame

◆ OccupancyGridFileInfoWithFrameAndChannelName

◆ PointCloud3Normal

◆ PointCloud2

◆ PointCloud3

◆ PointCloud2rgb

◆ PointCloud3rgb

◆ PointCloud3labeled

Function Documentation

◆ rasterSensorCone()

void rasterSensorCone ( const RangeScanCone c,
float  maxRange,
float  cellSize,
Visitor &  visitor 
)
inline

Function for fast rasterization of sensor cones cell by cell.

This function can be used for all algorithms that need to visit each cell of a sensor cone, like inserting sensor measurements to maps, creating virtual range scans, etc. The function is independent from any data structure or representation (like maps or images). The only assumption is, that the data, map or whatever can be partitioned into regular square cells, where the origin of the coordinate system intersects one cell in the middle of that cell. The size of these cells must be passed via the parameter cellSize.

This function works with subpixel precision, therefore the exact position of the origin of the sensor cone in relation to the coordinate system of the map is necessary. Since the sensor usually is mounted on a robot, the position of the cone origin depends on the sensor's mounting position relative to the robot coordinate system and the pose of the robot. The robot's pose is passed using the parameters x0,y0 and phi0. The sensor's mounting position and its configuration like cone angle is passed in the parameter c.

The rasterization of the cone is now performed as follows: The sensor cone is approximated by an enclosing isosceles triangle with one vertex in the cone origin. The position of the two other vertices are computed relative to the cone origin using the sensor's orientation and cone angle:

          * cone origin
         / \        ^
        /   \       |
       /     \      |
      /       \     | maxRange
     /.  cone .    |
    /  /  \   |
   /_____________\  v
   enclosing triangle

The size of the triangle is determined by the cone angle and the maxRange. The maxRange parameter determines the max. range that is covered by the cone. However, the arms of the triangle may become longer than this max. range (see ASCII art above) and therefore the rastered region, too. This must be kept in mind to make sure to not read or write beyond the borders of the data.

TODO: a function for obtaining the bounding box of the triangle is needed!

Finally, the triangle is rastered scanline by scanline. For each cell in the scanline a visitor is called that must be passed in as the parameter 'visitor' (for more details on the visitor see below). For each cell the distance to the sensor is provided. Since a cell has a non-zero extent, the min. distance and the max. distance of the cell is passed. For obtaining the distances, the efficient DistantLUT singleton is used.

The actual algorithm for map building or computation of virtual scans must be implemented in the visitor. The visitor must implement the following concept:

concept RasterSensorConeVisitor
{
    void beginScan(float origin_x, float origin_y, const RangeScanSensorConfig& c);
    void beginScanline(int y);
    void operator()(int x, int y, float min_d, float max_d);
};

The method beginScan() is called to tell the visitor the origin of the sensor cone's origin (origin_x, origin_y) and additionally the sensor config c. The visitor will need these origin coordinates since all other methods specify the cell position relative to the origin of the sensor cone. A typical implementation of the visitor will use the coordinates to compute the cell indices of the cone origin in their data/map representation. These indices can then be used to compute the absolute cell indices from the relative ones that are passed by beginScanline() and operator(). beginScanline() is called for each scanline and can be used to obtain a pointer to the corresponding scanline for better performance. Afterwards the ()operator is called for each cell, where the cell's position is specified relative to the cones origin. Additionally, the min. and max. distance of the cell to the sensor 'plane' is passed as third and fourth parameter. The y-coordinate is the same as the one that was specified in beginScanline().

The following example shows a visitor that draws a sensor cone into an image, where the free space is drawn black and the occupied region is drawn white. The other pixels are left unchanged:

class DrawScanToImage
{
public:
    Image image;       // some image
    float cellsize;    // the cellsize
    int x0, y0;        // the position of the origin
    Pixels* scanline;  // pointer to the beginning of the current scanline
    float range;       // the range measurement
    void beginScan(const RangeScanCone& c)
    {
        // compute the position of the cone origin in the image
        // (image origin is in the center of the image)
        x0 = round(c.origin.x() / cellsize) + image.width/2;
        y0 = round(c.origin.y() / cellsize) + image.height/2;
    }
    void beginScanline(int y)
    {
        scanline = image.getScanline(y+y0);
    }
    void operator()(int x, int y, float min_d, float max_d)
    {
        // process only cells that are in front of the sensor reading
        if(min_d<=range) {
            // if the min distance is in front of the measured range
            // and the max distance of the cell is behind that range
            // then the cell was hit and is occupied. If
            // both, min. distance and max. distance are smaller then
            // the sensor beam has traveld through this cell and
            // this cell should be considered as free.
            if(max_d>=range) {
                // draw pixel (x+x0, y+y0) black
                scanline[x+x0] = black;
            } else {
                // draw pixel (x+x0, y+y0) white
                scanline[x+x0] = white;
            }
        }
    }
};
// Usage:
DrawScanToImage visitor;
float maxRange = 5.0f;
visitor.range = 3.0f; // measured 3 meters
// draw the cone:
rasterSensorCone(x,y,phi, c, maxRange, visitor.cellsize, visitor);
Note
For best performance the members of the visitor MUST be INLINE (at least in the same compilation unit where the rasterSensorCone() method is called and therefore its template specialization takes place).

increase maxRange to make sure we cover the whole scan region actually the arms of the isosceles triangle are extended:

     origin
    ^ * ^
    | |\ \
    | | \ \ arm length = maxRange/cos(cone_angle/2)

maxRange | | \ \ | | \ \ v |____\ v

increase maxRange to make sure we cover the whole scan region actually the arms of the isosceles triangle are extended:

     origin
    ^ * ^
    | |\ \
    | | \ \ arm length = maxRange/cos(cone_angle/2)

maxRange | | \ \ | | \ \ v |____\ v

◆ mergeRegions()

DirtyRegions mira::maps::mergeRegions ( DirtyRegions  regions)

◆ loadGridMapFromImage()

GridMap<T, Channels> mira::maps::loadGridMapFromImage ( const Img<> &  img,
float  cellSize,
const Point2i offset,
truncateTo = std::numeric_limits<T>::max() 
)

Loads the specified image as grid map.

Additionally, the cell size and offset of the map must be specified.

◆ loadGridMapFromFile()

GridMap<T, Channels> mira::maps::loadGridMapFromFile ( const Path filename,
float  cellSize,
const Point2i offset,
truncateTo = std::numeric_limits<T>::max() 
)

Loads the specified image file as grid map.

Additionally, the cell size and offset of the map must be specified.

◆ loadGridMap() [1/2]

GridMap<T, Channels> mira::maps::loadGridMap ( const GridMapInfo info,
truncateTo = std::numeric_limits<T>::max() 
)

Loads the image specified by info as map.

◆ loadGridMap() [2/2]

GridMap<T, Channels> mira::maps::loadGridMap ( const Path descriptionFilename,
truncateTo = std::numeric_limits<T>::max() 
)

Loads the image from the description file (specifying an image file) as map.

The description usually was created by saveGridMapToFile().

◆ saveGridMapToFile()

void mira::maps::saveGridMapToFile ( Path  filename,
const GridMap< T, Channels > &  map,
bool  fullImagePath = true 
)

Saves the specified grid map as image + description xml.

◆ loadOccupancyGrid()

MIRA_MAPPING_MAPS_EXPORT OccupancyGrid mira::maps::loadOccupancyGrid ( const OccupancyGridInfo info,
bool  truncateTo254 = true 
)

Loads the grayscale image specified by info as occupancy map.

◆ loadOccupancyGridFromFile()

MIRA_MAPPING_MAPS_EXPORT OccupancyGrid mira::maps::loadOccupancyGridFromFile ( const Path filename,
float  cellSize,
const Point2i offset,
bool  truncateTo254 = true 
)

Loads the specified grayscale image from to as occupancy map.

Additionally, the cell size of the map must be specified.

◆ loadOccupancyGridFromImage()

MIRA_MAPPING_MAPS_EXPORT OccupancyGrid mira::maps::loadOccupancyGridFromImage ( const Img<> &  img,
float  cellSize,
const Point2i offset,
bool  truncateTo254 = true 
)

Loads the specified grayscale image as occupancy map.

Additionally, the cell size of the map must be specified.

◆ loadOccupancyGridFromGM2File()

MIRA_MAPPING_MAPS_EXPORT OccupancyGrid mira::maps::loadOccupancyGridFromGM2File ( const Path filename)

Loads the specified GM2 map as occupancy map.

◆ saveOccupancyGridToFile()

MIRA_MAPPING_MAPS_EXPORT void mira::maps::saveOccupancyGridToFile ( Path  filename,
const OccupancyGrid map,
bool  fullImagePath = true 
)

Saves the specified occupancy map as grayscale image and description xml.

◆ pointCloudFormat()

PCFormat mira::maps::pointCloudFormat ( )
inline

◆ pointCloudFormat< Point2f >()

◆ pointCloudFormat< Point3f >()

◆ pointCloudFormat< Eigen::Vector3f >()

PCFormat mira::maps::pointCloudFormat< Eigen::Vector3f > ( )
inline