30 #ifndef COSTMAP_CSPACE_COSTMAP_3D_LAYER_FOOTPRINT_H
31 #define COSTMAP_CSPACE_COSTMAP_3D_LAYER_FOOTPRINT_H
40 #include <costmap_cspace_msgs/CSpace3D.h>
41 #include <costmap_cspace_msgs/CSpace3DUpdate.h>
42 #include <geometry_msgs/PolygonStamped.h>
43 #include <nav_msgs/OccupancyGrid.h>
56 using Ptr = std::shared_ptr<Costmap3dLayerFootprint>;
86 const int linear_spread_min_cost =
87 config.
hasMember(
"linear_spread_min_cost") ?
static_cast<int>(config[
"linear_spread_min_cost"]) : 0;
89 static_cast<double>(config[
"linear_expand"]),
90 static_cast<double>(config[
"linear_spread"]),
91 linear_spread_min_cost);
101 const float linear_expand,
102 const float linear_spread,
103 const int linear_spread_min_cost = 0)
150 const float eps = info.linear_resolution / 100.0;
152 for (
size_t yaw = 0; yaw < info.angle; yaw++)
159 f.move(x * info.linear_resolution,
160 y * info.linear_resolution,
161 yaw * info.angular_resolution);
171 const float d =
f.dist(p);
202 const nav_msgs::OccupancyGrid::ConstPtr& map,
212 const nav_msgs::OccupancyGrid::ConstPtr& msg,
217 for (
size_t yaw = 0; yaw < map->info.angle; yaw++)
226 const nav_msgs::OccupancyGrid::ConstPtr& msg)
233 std::lround((msg->info.origin.position.x - map->info.origin.position.x) /
234 map->info.linear_resolution);
236 std::lround((msg->info.origin.position.y - map->info.origin.position.y) /
237 map->info.linear_resolution);
238 const double resolution_scale = msg->info.resolution / map->info.linear_resolution;
240 for (
size_t yaw = 0; yaw < map->info.angle; yaw++)
242 for (
size_t i = 0; i < msg->data.size(); i++)
244 const auto& val = msg->data[i];
248 const int x = std::lround((i % msg->info.width) * resolution_scale);
251 const int y = std::lround((i / msg->info.width) * resolution_scale);
255 const int res_up = std::ceil(resolution_scale);
256 for (
int yp = 0; yp < res_up; yp++)
258 const int y2 = y + oy + yp;
259 if (
static_cast<size_t>(y2) >= map->info.height)
261 for (
int xp = 0; xp < res_up; xp++)
263 const int x2 = x + ox + xp;
264 if (
static_cast<size_t>(x2) >= map->info.width)
267 map->getCost(x2, y2, yaw) = -1;
276 const nav_msgs::OccupancyGrid::ConstPtr& msg,
279 const auto getMaskedRange = [
this, msg](
const int pos,
Rect& result)
281 const int gx = pos % msg->info.width;
282 const int gy = pos / msg->info.width;
283 const int8_t*
const ptr = msg->data.data() + pos;
284 result.x_min = (gx == 0 || (*(ptr - 1) >= *ptr)) ? 0 : -
range_max_;
285 result.x_max = (gx ==
static_cast<int>(msg->info.width) - 1 || (*(ptr + 1) >= *ptr)) ? 0 :
range_max_;
286 result.y_min = (gy == 0 || (*(ptr - msg->info.width) >= *ptr)) ? 0 : -
range_max_;
288 (gy ==
static_cast<int>(msg->info.height) - 1 || (*(ptr + msg->info.width) >= *ptr)) ? 0 :
range_max_;
290 const auto getRange = (msg->info.resolution == map->info.linear_resolution) ?
292 std::function<
void(
const int,
Rect&)>([](
const int,
Rect&) {});
295 std::lround((msg->info.origin.position.x - map->info.origin.position.x) / map->info.linear_resolution);
297 std::lround((msg->info.origin.position.y - map->info.origin.position.y) / map->info.linear_resolution);
298 const double resolution_scale = msg->info.resolution / map->info.linear_resolution;
302 for (
size_t i = 0; i < msg->data.size(); i++)
304 const int gx = std::lround((i % msg->info.width) * resolution_scale) + ox;
305 const int gy = std::lround((i / msg->info.width) * resolution_scale) + oy;
306 if (
static_cast<size_t>(gx) >= map->info.width ||
307 static_cast<size_t>(gy) >= map->info.height)
313 unknown_buf_[i] = msg->data[i] < 0 && map->getCost(gx, gy, yaw) < 0;
317 for (
size_t i = 0; i < msg->data.size(); i++)
319 const int8_t val = msg->data[i];
324 const int gx = std::lround((i % msg->info.width) * resolution_scale) + ox;
325 const int gy = std::lround((i / msg->info.width) * resolution_scale) + oy;
326 if (
static_cast<size_t>(gx) >= map->info.width ||
327 static_cast<size_t>(gy) >= map->info.height)
331 int8_t& m = map->getCost(gx, gy, yaw);
337 const int map_x_min = std::max(gx + range.
x_min, 0);
338 const int map_x_max = std::min(gx + range.
x_max,
static_cast<int>(map->info.width) - 1);
339 const int map_y_min = std::max(gy + range.
y_min, 0);
340 const int map_y_max = std::min(gy + range.
y_max,
static_cast<int>(map->info.height) - 1);
341 for (
int map_y = map_y_min; map_y <= map_y_max; ++map_y)
344 int8_t* cost_addr = &(map->getCost(map_x_min, map_y, yaw));
345 const char* cs_addr = &(
cs_template_.
e(map_x_min - gx, map_y - gy, yaw));
346 for (
int n = 0; n <= map_x_max - map_x_min; ++n, ++cost_addr, ++cs_addr)
348 const int8_t c = *cs_addr * val / 100;
349 if (c > 0 && *cost_addr < c)
360 const int gx = std::lround((i % msg->info.width) * resolution_scale) + ox;
361 const int gy = std::lround((i / msg->info.width) * resolution_scale) + oy;
362 if (
static_cast<size_t>(gx) >= map->info.width ||
363 static_cast<size_t>(gy) >= map->info.height)
365 map->getCost(gx, gy, yaw) = -1;
372 #endif // COSTMAP_CSPACE_COSTMAP_3D_LAYER_FOOTPRINT_H