Go to the documentation of this file.
38 #ifndef COSTMAP_2D_COSTMAP_2D_H_
39 #define COSTMAP_2D_COSTMAP_2D_H_
43 #include <geometry_msgs/Point.h>
44 #include <boost/thread.hpp>
73 Costmap2D(
unsigned int cells_size_x,
unsigned int cells_size_y,
double resolution,
74 double origin_x,
double origin_y,
unsigned char default_value = 0);
116 unsigned char getCost(
unsigned int mx,
unsigned int my)
const;
132 void setCost(
unsigned int mx,
unsigned int my,
unsigned char cost);
141 void mapToWorld(
unsigned int mx,
unsigned int my,
double& wx,
double& wy)
const;
151 bool worldToMap(
double wx,
double wy,
unsigned int& mx,
unsigned int& my)
const;
179 inline unsigned int getIndex(
unsigned int mx,
unsigned int my)
const
190 inline void indexToCells(
unsigned int index,
unsigned int& mx,
unsigned int& my)
const
281 virtual void updateOrigin(
double new_origin_x,
double new_origin_y);
289 void resizeMap(
unsigned int size_x,
unsigned int size_y,
double resolution,
double origin_x,
292 void resetMap(
unsigned int x0,
unsigned int y0,
unsigned int xn,
unsigned int yn);
302 typedef boost::recursive_mutex
mutex_t;
322 template<
typename data_type>
323 void copyMapRegion(data_type* source_map,
unsigned int sm_lower_left_x,
unsigned int sm_lower_left_y,
324 unsigned int sm_size_x, data_type* dest_map,
unsigned int dm_lower_left_x,
325 unsigned int dm_lower_left_y,
unsigned int dm_size_x,
unsigned int region_size_x,
326 unsigned int region_size_y)
329 data_type* sm_index = source_map + (sm_lower_left_y * sm_size_x + sm_lower_left_x);
330 data_type* dm_index = dest_map + (dm_lower_left_y * dm_size_x + dm_lower_left_x);
333 for (
unsigned int i = 0; i < region_size_y; ++i)
335 memcpy(dm_index, sm_index, region_size_x *
sizeof(data_type));
336 sm_index += sm_size_x;
337 dm_index += dm_size_x;
356 virtual void initMaps(
unsigned int size_x,
unsigned int size_y);
367 template<
class ActionType>
368 inline void raytraceLine(ActionType at,
unsigned int x0,
unsigned int y0,
unsigned int x1,
unsigned int y1,
369 unsigned int max_length = UINT_MAX)
374 unsigned int abs_dx = abs(dx);
375 unsigned int abs_dy = abs(dy);
377 int offset_dx =
sign(dx);
380 unsigned int offset = y0 *
size_x_ + x0;
383 double dist = hypot(dx, dy);
384 double scale = (dist == 0.0) ? 1.0 :
std::min(1.0, max_length / dist);
387 if (abs_dx >= abs_dy)
389 int error_y = abs_dx / 2;
390 bresenham2D(at, abs_dx, abs_dy, error_y, offset_dx, offset_dy, offset, (
unsigned int)(scale * abs_dx));
395 int error_x = abs_dy / 2;
396 bresenham2D(at, abs_dy, abs_dx, error_x, offset_dy, offset_dx, offset, (
unsigned int)(scale * abs_dy));
403 template<
class ActionType>
404 inline void bresenham2D(ActionType at,
unsigned int abs_da,
unsigned int abs_db,
int error_b,
int offset_a,
405 int offset_b,
unsigned int offset,
unsigned int max_length)
407 unsigned int end =
std::min(max_length, abs_da);
408 for (
unsigned int i = 0; i < end; ++i)
413 if ((
unsigned int)error_b >= abs_da)
422 inline int sign(
int x)
424 return x > 0 ? 1.0 : -1.0;
442 MarkCell(
unsigned char* costmap,
double* timestamps,
unsigned char value,
double time) :
482 #endif // COSTMAP_2D_COSTMAP_2D_H
double getSizeInMetersX() const
Accessor for the x size of the costmap in meters.
virtual void initMaps(unsigned int size_x, unsigned int size_y)
Initializes the costmap, static_map, and markers data structures.
bool worldToMap(double wx, double wy, unsigned int &mx, unsigned int &my) const
Convert from world coordinates to map coordinates.
unsigned char default_value_
double getSizeInMetersY() const
Accessor for the y size of the costmap in meters.
const Costmap2D & costmap_
virtual ~Costmap2D()
Destructor.
std::vector< MapLocation > & cells_
A 2D costmap provides a mapping between points in the world and their associated "costs".
void mapToWorld(unsigned int mx, unsigned int my, double &wx, double &wy) const
Convert from map coordinates to world coordinates.
unsigned char * getCharMap() const
Will return a pointer to the underlying unsigned char array used as the costmap.
double getOriginX() const
Accessor for the x origin of the costmap.
unsigned char getDefaultValue()
friend class CostmapTester
Costmap2D()
Default constructor.
void polygonOutlineCells(const std::vector< MapLocation > &polygon, std::vector< MapLocation > &polygon_cells)
Get the map cells that make up the outline of a polygon.
MarkCell(unsigned char *costmap, double *timestamps, unsigned char value, double time)
Costmap2D & operator=(const Costmap2D &map)
Overloaded assignment operator.
void resizeMap(unsigned int size_x, unsigned int size_y, double resolution, double origin_x, double origin_y)
void setCost(unsigned int mx, unsigned int my, unsigned char cost)
Set the cost of a cell in the costmap.
void operator()(unsigned int offset)
void operator()(unsigned int offset)
bool saveMap(std::string file_name)
Save the costmap out to a pgm file.
void indexToCells(unsigned int index, unsigned int &mx, unsigned int &my) const
Given an index... compute the associated map coordinates.
PolygonOutlineCells(const Costmap2D &costmap, const unsigned char *char_map, std::vector< MapLocation > &cells)
unsigned int getSizeInCellsY() const
Accessor for the y size of the costmap in cells.
const unsigned char * char_map_
void resetMap(unsigned int x0, unsigned int y0, unsigned int xn, unsigned int yn)
void worldToMapEnforceBounds(double wx, double wy, int &mx, int &my) const
Convert from world coordinates to map coordinates, constraining results to legal bounds.
double getOriginY() const
Accessor for the y origin of the costmap.
bool copyCostmapWindow(const Costmap2D &map, double win_origin_x, double win_origin_y, double win_size_x, double win_size_y)
Turn this costmap into a copy of a window of a costmap passed in.
unsigned int cellDistance(double world_dist)
Given distance in the world... convert it to cells.
virtual void resetMaps()
Resets the costmap and static_map to be unknown space.
virtual void deleteMaps()
Deletes the costmap, static_map, and markers data structures.
void setDefaultValue(unsigned char c)
void raytraceLine(ActionType at, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, unsigned int max_length=UINT_MAX)
Raytrace a line and apply some action at each step.
double getTimeStamp(unsigned int mx, unsigned int my) const
Get the last update timestamp of the cell.
void copyMapRegion(data_type *source_map, unsigned int sm_lower_left_x, unsigned int sm_lower_left_y, unsigned int sm_size_x, data_type *dest_map, unsigned int dm_lower_left_x, unsigned int dm_lower_left_y, unsigned int dm_size_x, unsigned int region_size_x, unsigned int region_size_y)
Copy a region of a source map into a destination map.
double getResolution() const
Accessor for the resolution of the costmap.
virtual void updateOrigin(double new_origin_x, double new_origin_y)
Move the origin of the costmap to a new location.... keeping data when it can.
bool setConvexPolygonCost(const std::vector< geometry_msgs::Point > &polygon, unsigned char cost_value)
Sets the cost of a convex polygon to a desired value.
unsigned int getIndex(unsigned int mx, unsigned int my) const
Given two map coordinates... compute the associated index.
unsigned int getSizeInCellsX() const
Accessor for the x size of the costmap in cells.
void bresenham2D(ActionType at, unsigned int abs_da, unsigned int abs_db, int error_b, int offset_a, int offset_b, unsigned int offset, unsigned int max_length)
A 2D implementation of Bresenham's raytracing algorithm... applies an action at each step.
boost::recursive_mutex mutex_t
void worldToMapNoBounds(double wx, double wy, int &mx, int &my) const
Convert from world coordinates to map coordinates without checking for legal bounds.
void convexFillCells(const std::vector< MapLocation > &polygon, std::vector< MapLocation > &polygon_cells)
Get the map cells that fill a convex polygon.
unsigned char getCost(unsigned int mx, unsigned int my) const
Get the cost of a cell in the costmap.