45 Costmap2D::Costmap2D(
unsigned int cells_size_x,
unsigned int cells_size_y,
double resolution,
46 double origin_x,
double origin_y,
unsigned char default_value) :
47 size_x_(cells_size_x), size_y_(cells_size_y), resolution_(resolution), origin_x_(origin_x),
48 origin_y_(origin_y), costmap_(NULL), default_value_(
default_value)
60 boost::unique_lock<mutex_t> lock(*
access_);
67 boost::unique_lock<mutex_t> lock(*
access_);
69 costmap_ =
new unsigned char[size_x * size_y];
73 double origin_x,
double origin_y)
89 boost::unique_lock<mutex_t> lock(*
access_);
95 boost::unique_lock<mutex_t> lock(*(
access_));
96 unsigned int len = xn - x0;
115 unsigned int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
116 if (!map.
worldToMap(win_origin_x, win_origin_y, lower_left_x, lower_left_y)
117 || !map.
worldToMap(win_origin_x + win_size_x, win_origin_y + win_size_y, upper_right_x, upper_right_y))
123 size_x_ = upper_right_x - lower_left_x;
124 size_y_ = upper_right_y - lower_left_y;
170 size_x_(0), size_y_(0), resolution_(0.0), origin_x_(0.0), origin_y_(0.0), costmap_(NULL)
183 double cells_dist = max(0.0, ceil(world_dist /
resolution_));
184 return (
unsigned int)cells_dist;
263 int cell_ox, cell_oy;
268 if (cell_ox == 0 && cell_oy == 0)
273 double new_grid_ox, new_grid_oy;
282 int lower_left_x, lower_left_y, upper_right_x, upper_right_y;
283 lower_left_x =
min(max(cell_ox, 0), size_x);
284 lower_left_y =
min(max(cell_oy, 0), size_y);
285 upper_right_x =
min(max(cell_ox + size_x, 0), size_x);
286 upper_right_y =
min(max(cell_oy + size_y, 0), size_y);
288 unsigned int cell_size_x = upper_right_x - lower_left_x;
289 unsigned int cell_size_y = upper_right_y - lower_left_y;
292 unsigned char* local_map =
new unsigned char[cell_size_x * cell_size_y];
305 int start_x = lower_left_x - cell_ox;
306 int start_y = lower_left_y - cell_oy;
318 std::vector<MapLocation> map_polygon;
319 for (
unsigned int i = 0; i < polygon.size(); ++i)
322 if (!
worldToMap(polygon[i].x, polygon[i].y, loc.
x, loc.
y))
327 map_polygon.push_back(loc);
330 std::vector<MapLocation> polygon_cells;
336 for (
unsigned int i = 0; i < polygon_cells.size(); ++i)
338 unsigned int index =
getIndex(polygon_cells[i].x, polygon_cells[i].y);
347 for (
unsigned int i = 0; i < polygon.size() - 1; ++i)
349 raytraceLine(cell_gatherer, polygon[i].x, polygon[i].y, polygon[i + 1].x, polygon[i + 1].y);
351 if (!polygon.empty())
353 unsigned int last_index = polygon.size() - 1;
355 raytraceLine(cell_gatherer, polygon[last_index].x, polygon[last_index].y, polygon[0].x, polygon[0].y);
362 if (polygon.size() < 3)
371 while (i < polygon_cells.size() - 1)
373 if (polygon_cells[i].x > polygon_cells[i + 1].x)
375 swap = polygon_cells[i];
376 polygon_cells[i] = polygon_cells[i + 1];
377 polygon_cells[i + 1] =
swap;
389 unsigned int min_x = polygon_cells[0].
x;
390 unsigned int max_x = polygon_cells[polygon_cells.size() - 1].x;
393 for (
unsigned int x = min_x; x <= max_x; ++x)
395 if (i >= polygon_cells.size() - 1)
398 if (polygon_cells[i].y < polygon_cells[i + 1].y)
400 min_pt = polygon_cells[i];
401 max_pt = polygon_cells[i + 1];
405 min_pt = polygon_cells[i + 1];
406 max_pt = polygon_cells[i];
410 while (i < polygon_cells.size() && polygon_cells[i].x == x)
412 if (polygon_cells[i].y < min_pt.
y)
413 min_pt = polygon_cells[i];
414 else if (polygon_cells[i].y > max_pt.
y)
415 max_pt = polygon_cells[i];
421 for (
unsigned int y = min_pt.
y; y <= max_pt.
y; ++y)
425 polygon_cells.push_back(pt);
467 FILE *fp = fopen(file_name.c_str(),
"w");
475 for (
unsigned int iy = 0; iy <
size_y_; iy++)
477 for (
unsigned int ix = 0; ix <
size_x_; ix++)
479 unsigned char cost =
getCost(ix, iy);
480 fprintf(fp,
"%d ", cost);