class mrpt::nav::CPTG_DiffDrive_CollisionGridBased::CCollisionGrid¶
An internal class for storing the collision grid.
#include <mrpt/nav/tpspace/CPTG_DiffDrive_CollisionGridBased.h> class CCollisionGrid: public mrpt::containers::CDynamicGrid { public: // construction CCollisionGrid( float x_min, float x_max, float y_min, float y_max, float resolution, CPTG_DiffDrive_CollisionGridBased* parent ); // methods bool saveToFile(mrpt::serialization::CArchive* fil, const mrpt::math::CPolygon& computed_robotShape) const; bool loadFromFile(mrpt::serialization::CArchive* fil, const mrpt::math::CPolygon& current_robotShape); const TCollisionCell& getTPObstacle(const float obsX, const float obsY) const; void updateCellInfo( const unsigned int icx, const unsigned int icy, const uint16_t k, const float dist ); void setSize( const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const TCollisionCell* fill_value = nullptr ); void clear(); void fill(const TCollisionCell& value); virtual void resize( double new_x_min, double new_x_max, double new_y_min, double new_y_max, const TCollisionCell& defaultValueNewCells, double additionalMarginMeters = 2.0 ); TCollisionCell* cellByPos(double x, double y); const TCollisionCell* cellByPos(double x, double y) const; TCollisionCell* cellByIndex(unsigned int cx, unsigned int cy); const TCollisionCell* cellByIndex(unsigned int cx, unsigned int cy) const; size_t getSizeX() const; size_t getSizeY() const; double getXMin() const; double getXMax() const; double getYMin() const; double getYMax() const; double getResolution() const; int x2idx(double x) const; void idx2cxcy(int idx, int& cx, int& cy) const; double idx2x(int cx) const; void getAsMatrix(MAT& m) const; virtual float cell2float(const TCollisionCell&) const; bool saveToTextFile(const std::string& fileName) const; };
Methods¶
bool saveToFile(mrpt::serialization::CArchive* fil, const mrpt::math::CPolygon& computed_robotShape) const
Save to file, true = OK.
bool loadFromFile(mrpt::serialization::CArchive* fil, const mrpt::math::CPolygon& current_robotShape)
Load from file, true = OK.
const TCollisionCell& getTPObstacle(const float obsX, const float obsY) const
For an obstacle (x,y), returns a vector with all the pairs (a,d) such as the robot collides.
void updateCellInfo( const unsigned int icx, const unsigned int icy, const uint16_t k, const float dist )
Updates the info into a cell: It updates the cell only if the distance d for the path k is lower than the previous value:
Parameters:
cellInfo |
The index of the cell |
k |
The path index (alpha discreet value) |
d |
The distance (in TP-Space, range 0..1) to collision. |
void setSize( const double x_min, const double x_max, const double y_min, const double y_max, const double resolution, const TCollisionCell* fill_value = nullptr )
Changes the size of the grid, ERASING all previous contents.
If fill_value is left as nullptr, the contents of cells may be undefined (some will remain with their old values, the new ones will have the default cell value, but the location of old values may change wrt their old places). If fill_value is not nullptr, it is assured that all cells will have a copy of that value after resizing.
See also:
void clear()
Erase the contents of all the cells.
void fill(const TCollisionCell& value)
Fills all the cells with the same value.
virtual void resize( double new_x_min, double new_x_max, double new_y_min, double new_y_max, const TCollisionCell& defaultValueNewCells, double additionalMarginMeters = 2.0 )
Changes the size of the grid, maintaining previous contents.
See also:
TCollisionCell* cellByPos(double x, double y)
Returns a pointer to the contents of a cell given by its coordinates, or nullptr if it is out of the map extensions.
const TCollisionCell* cellByPos(double x, double y) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
TCollisionCell* cellByIndex(unsigned int cx, unsigned int cy)
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the map extensions.
const TCollisionCell* cellByIndex(unsigned int cx, unsigned int cy) const
Returns a pointer to the contents of a cell given by its cell indexes, or nullptr if it is out of the map extensions.
size_t getSizeX() const
Returns the horizontal size of grid map in cells count.
size_t getSizeY() const
Returns the vertical size of grid map in cells count.
double getXMin() const
Returns the “x” coordinate of left side of grid map.
double getXMax() const
Returns the “x” coordinate of right side of grid map.
double getYMin() const
Returns the “y” coordinate of top side of grid map.
double getYMax() const
Returns the “y” coordinate of bottom side of grid map.
double getResolution() const
Returns the resolution of the grid map.
int x2idx(double x) const
Transform a coordinate values into cell indexes.
void idx2cxcy(int idx, int& cx, int& cy) const
Transform a global (linear) cell index value into its corresponding (x,y) cell indexes.
double idx2x(int cx) const
Transform a cell index into a coordinate value of the cell central point.
void getAsMatrix(MAT& m) const
Get the entire grid as a matrix.
This method will compile only for cell types that can be converted to the type of the matrix elements (e.g. double).
Parameters:
MAT |
The type of the matrix, typically a mrpt::math::CMatrixDouble. |
m |
The output matrix; will be set automatically to the correct size. Entry (cy,cx) in the matrix contains the grid cell with indices (cx,cy). |
virtual float cell2float(const TCollisionCell&) const
The user must implement this in order to provide “saveToTextFile” a way to convert each cell into a numeric value.
bool saveToTextFile(const std::string& fileName) const
Saves a float representation of the grid (via “cell2float()”) to a text file.
Returns:
false on error