Nav2 Navigation Stack - rolling  main
ROS 2 Navigation Stack
vector_object_shapes.cpp
1 // Copyright (c) 2023 Samsung R&D Institute Russia
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "nav2_map_server/vector_object_shapes.hpp"
16 
17 #include <uuid/uuid.h>
18 #include <algorithm>
19 #include <cmath>
20 #include <exception>
21 #include <limits>
22 #include <stdexcept>
23 #include <utility>
24 #include <vector>
25 
26 #include "geometry_msgs/msg/pose_stamped.hpp"
27 
28 #include "nav2_util/occ_grid_utils.hpp"
29 #include "nav2_util/occ_grid_values.hpp"
30 #include "nav2_util/geometry_utils.hpp"
31 #include "nav2_util/raytrace_line_2d.hpp"
32 #include "nav2_ros_common/tf2_factories.hpp"
33 
34 namespace nav2_map_server
35 {
36 
37 // ---------- Shape ----------
38 
39 Shape::Shape(const nav2::LifecycleNode::WeakPtr & node)
40 : type_(UNKNOWN), node_(node)
41 {}
42 
44 {}
45 
46 ShapeType Shape::getType()
47 {
48  return type_;
49 }
50 
52  nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
53 {
54  double wx1, wy1, wx2, wy2;
55  unsigned int mx1, my1, mx2, my2;
56  getBoundaries(wx1, wy1, wx2, wy2);
57  if (
58  !nav2_util::worldToMap(map, wx1, wy1, mx1, my1) ||
59  !nav2_util::worldToMap(map, wx2, wy2, mx2, my2))
60  {
61  return false;
62  }
63 
64  const double origin_x = map->info.origin.position.x;
65  const double resolution = map->info.resolution;
66  const int8_t value = getValue();
67  std::vector<std::pair<double, double>> spans;
68  for (unsigned int my = my1; my <= my2; my++) {
69  double row_x, row_y;
70  nav2_util::mapToWorld(map, mx1, my, row_x, row_y);
71  const auto inside = [&](unsigned int mx) {
72  double wx, wy;
73  nav2_util::mapToWorld(map, mx, my, wx, wy);
74  return isPointInside(wx, wy);
75  };
76  getRowSpans(row_y, spans);
77  int8_t * row = map->data.data() + static_cast<size_t>(my) * map->info.width;
78  for (const auto & [x_begin, x_end] : spans) {
79  // First and last cell whose center is in [x_begin, x_end)
80  const auto center_x = [&](int64_t mx) {
81  double wx, wy;
82  nav2_util::mapToWorld(map, static_cast<unsigned int>(mx), my, wx, wy);
83  return wx;
84  };
85  int64_t lo = static_cast<int64_t>(std::clamp(
86  std::ceil((x_begin - origin_x) / resolution - 0.5),
87  static_cast<double>(mx1), static_cast<double>(mx2)));
88  int64_t hi = static_cast<int64_t>(std::clamp(
89  std::floor((x_end - origin_x) / resolution - 0.5),
90  static_cast<double>(mx1), static_cast<double>(mx2)));
91  // ceil/floor may be off by one when a center lies exactly on the boundary
92  while (lo > mx1 && center_x(lo - 1) >= x_begin) {
93  lo--;
94  }
95  while (lo <= mx2 && center_x(lo) < x_begin) {
96  lo++;
97  }
98  while (hi < mx2 && center_x(hi + 1) < x_end) {
99  hi++;
100  }
101  while (hi >= mx1 && center_x(hi) >= x_end) {
102  hi--;
103  }
104  // Spans may be slightly too wide (circles): trim with the exact test
105  while (lo <= hi && !inside(static_cast<unsigned int>(lo))) {
106  lo++;
107  }
108  while (hi >= lo && !inside(static_cast<unsigned int>(hi))) {
109  hi--;
110  }
111  if (lo <= hi) {
112  processRun(row + lo, static_cast<size_t>(hi - lo + 1), value, overlay_type);
113  }
114  }
115  }
116  return true;
117 }
118 
120  int8_t * cells, const size_t count, const int8_t shape_val,
121  const OverlayType overlay_type)
122 {
123  switch (overlay_type) {
124  case OverlayType::OVERLAY_SEQ:
125  std::fill_n(cells, count, shape_val);
126  return;
127  case OverlayType::OVERLAY_MAX:
128  for (size_t i = 0; i < count; i++) {
129  cells[i] = std::max(cells[i], shape_val);
130  }
131  return;
132  case OverlayType::OVERLAY_MIN:
133  if (shape_val == nav2_util::OCC_GRID_UNKNOWN) {
134  return;
135  }
136  for (size_t i = 0; i < count; i++) {
137  if (cells[i] == nav2_util::OCC_GRID_UNKNOWN || shape_val < cells[i]) {
138  cells[i] = shape_val;
139  }
140  }
141  return;
142  default:
143  throw std::runtime_error{"Unknown overlay type"};
144  }
145 }
146 
147 bool Shape::obtainShapeUUID(const std::string & shape_name, unsigned char * out_uuid)
148 {
149  auto node = node_.lock();
150  if (!node) {
151  throw std::runtime_error{"Failed to lock node"};
152  }
153 
154  try {
155  // Try to get shape UUID from ROS-parameters
156  std::string uuid_str = nav2::declare_or_get_parameter<std::string>(
157  node, shape_name + ".uuid");
158  if (uuid_parse(uuid_str.c_str(), out_uuid) != 0) {
159  RCLCPP_ERROR(
160  node->get_logger(),
161  "[%s] Can not parse UUID string for shape: %s",
162  shape_name.c_str(), uuid_str.c_str());
163  return false;
164  }
165  } catch (const std::exception &) {
166  // If no UUID was specified, generate a new one
167  uuid_generate(out_uuid);
168 
169  char uuid_str[37];
170  uuid_unparse(out_uuid, uuid_str);
171  RCLCPP_INFO(
172  node->get_logger(),
173  "[%s] No UUID is specified for shape. Generating a new one: %s",
174  shape_name.c_str(), uuid_str);
175  }
176 
177  return true;
178 }
179 
180 // ---------- Polygon ----------
181 
182 Polygon::Polygon(
183  const nav2::LifecycleNode::WeakPtr & node)
184 : Shape::Shape(node)
185 {
186  type_ = POLYGON;
187 }
188 
189 int8_t Polygon::getValue() const
190 {
191  return params_->value;
192 }
193 
194 std::string Polygon::getFrameID() const
195 {
196  return params_->header.frame_id;
197 }
198 
199 std::string Polygon::getUUID() const
200 {
201  return unparseUUID(params_->uuid.uuid.data());
202 }
203 
204 bool Polygon::isUUID(const unsigned char * uuid) const
205 {
206  return uuid_compare(params_->uuid.uuid.data(), uuid) == 0;
207 }
208 
209 bool Polygon::isFill() const
210 {
211  return params_->closed;
212 }
213 
214 bool Polygon::obtainParams(const std::string & shape_name)
215 {
216  auto node = node_.lock();
217  if (!node) {
218  throw std::runtime_error{"Failed to lock node"};
219  }
220 
221  if (!params_) {
222  params_ = std::make_shared<nav2_msgs::msg::PolygonObject>();
223  }
224  if (!polygon_) {
225  polygon_ = std::make_shared<geometry_msgs::msg::Polygon>();
226  }
227 
228  params_->header.frame_id = nav2::declare_or_get_parameter(
229  node, shape_name + ".frame_id", std::string{"map"});
230  params_->value = nav2::declare_or_get_parameter(
231  node, shape_name + ".value", static_cast<int>(nav2_util::OCC_GRID_OCCUPIED));
232  params_->closed = nav2::declare_or_get_parameter(
233  node, shape_name + ".closed", true);
234 
235  std::vector<double> poly_row;
236  try {
237  poly_row = nav2::declare_or_get_parameter<std::vector<double>>(
238  node, shape_name + ".points");
239  } catch (const std::exception & ex) {
240  RCLCPP_ERROR(
241  node->get_logger(),
242  "[%s] Error while getting polygon parameters: %s",
243  shape_name.c_str(), ex.what());
244  return false;
245  }
246  // Check for points format correctness
247  if (poly_row.size() < 6 || poly_row.size() % 2 != 0) {
248  RCLCPP_ERROR(
249  node->get_logger(),
250  "[%s] Polygon has incorrect points description",
251  shape_name.c_str());
252  return false;
253  }
254 
255  // Obtain polygon vertices
256  geometry_msgs::msg::Point32 point;
257  bool first = true;
258  for (double val : poly_row) {
259  if (first) {
260  point.x = val;
261  } else {
262  point.y = val;
263  params_->points.push_back(point);
264  }
265  first = !first;
266  }
267 
268  // Filling the polygon_ with obtained points in map's frame
269  polygon_->points = params_->points;
270 
271  // Getting shape UUID
272  return obtainShapeUUID(shape_name, params_->uuid.uuid.data());
273 }
274 
275 nav2_msgs::msg::PolygonObject::SharedPtr Polygon::getParams() const
276 {
277  return params_;
278 }
279 
280 bool Polygon::setParams(const nav2_msgs::msg::PolygonObject::SharedPtr params)
281 {
282  params_ = params;
283 
284  if (!polygon_) {
285  polygon_ = std::make_shared<geometry_msgs::msg::Polygon>();
286  }
287  polygon_->points = params_->points;
288 
289  // If no UUID was specified, generate a new one
290  if (uuid_is_null(params_->uuid.uuid.data())) {
291  uuid_generate(params_->uuid.uuid.data());
292  }
293 
294  return checkConsistency();
295 }
296 
298  const std::string & to_frame,
299  const nav2::TransformBuffer::SharedPtr tf_buffer,
300  const double transform_tolerance)
301 {
302  geometry_msgs::msg::TransformStamped transform;
303  if (!lookupShapeTransform(
304  params_->header, to_frame, tf_buffer, transform_tolerance, transform))
305  {
306  return false;
307  }
308 
309  geometry_msgs::msg::PoseStamped from_pose, to_pose;
310  from_pose.header = params_->header;
311  for (unsigned int i = 0; i < params_->points.size(); i++) {
312  from_pose.pose.position.x = params_->points[i].x;
313  from_pose.pose.position.y = params_->points[i].y;
314  from_pose.pose.position.z = params_->points[i].z;
315  tf2::doTransform(from_pose, to_pose, transform);
316  polygon_->points[i].x = to_pose.pose.position.x;
317  polygon_->points[i].y = to_pose.pose.position.y;
318  polygon_->points[i].z = to_pose.pose.position.z;
319  }
320 
321  return true;
322 }
323 
324 void Polygon::getBoundaries(double & min_x, double & min_y, double & max_x, double & max_y)
325 {
326  min_x = std::numeric_limits<double>::max();
327  min_y = std::numeric_limits<double>::max();
328  max_x = std::numeric_limits<double>::lowest();
329  max_y = std::numeric_limits<double>::lowest();
330 
331  for (auto point : polygon_->points) {
332  min_x = std::min(min_x, static_cast<double>(point.x));
333  min_y = std::min(min_y, static_cast<double>(point.y));
334  max_x = std::max(max_x, static_cast<double>(point.x));
335  max_y = std::max(max_y, static_cast<double>(point.y));
336  }
337 }
338 
339 bool Polygon::isPointInside(const double px, const double py) const
340 {
341  return nav2_util::geometry_utils::isPointInsidePolygon(px, py, polygon_->points);
342 }
343 
345  const double py, std::vector<std::pair<double, double>> & spans) const
346 {
347  // Same edge rule and intersection formula as isPointInsidePolygon()
348  const auto & points = polygon_->points;
349  std::vector<double> crossings;
350  int i = points.size() - 1;
351  for (int j = 0; j < static_cast<int>(points.size()); j++) {
352  if ((py <= points[i].y) == (py > points[j].y)) {
353  crossings.push_back(
354  points[i].x + (py - points[i].y) * (points[j].x - points[i].x) /
355  (points[j].y - points[i].y));
356  }
357  i = j;
358  }
359  std::sort(crossings.begin(), crossings.end());
360 
361  spans.clear();
362  const size_t count = crossings.size();
363  if (count % 2 == 1) {
364  spans.emplace_back(std::numeric_limits<double>::lowest(), crossings[0]);
365  }
366  for (size_t k = 1; k < count; k++) {
367  if ((count - k) % 2 == 1) {
368  spans.emplace_back(crossings[k - 1], crossings[k]);
369  }
370  }
371 }
372 
374  nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
375 {
376  unsigned int mx0, my0, mx1, my1;
377 
378  auto node = node_.lock();
379  if (!node) {
380  throw std::runtime_error{"Failed to lock node"};
381  }
382 
383  if (!nav2_util::worldToMap(map, polygon_->points[0].x, polygon_->points[0].y, mx1, my1)) {
384  RCLCPP_ERROR(
385  node->get_logger(),
386  "[UUID: %s] Can not convert (%f, %f) point to map",
387  getUUID().c_str(), polygon_->points[0].x, polygon_->points[0].y);
388  return;
389  }
390 
391  MapAction ma(map, params_->value, overlay_type);
392  for (unsigned int i = 1; i < polygon_->points.size(); i++) {
393  mx0 = mx1;
394  my0 = my1;
395  if (!nav2_util::worldToMap(map, polygon_->points[i].x, polygon_->points[i].y, mx1, my1)) {
396  RCLCPP_ERROR(
397  node->get_logger(),
398  "[UUID: %s] Can not convert (%f, %f) point to map",
399  getUUID().c_str(), polygon_->points[i].x, polygon_->points[i].y);
400  return;
401  }
402  nav2_util::raytraceLine(ma, mx0, my0, mx1, my1, map->info.width);
403  }
404 }
405 
407 {
408  if (params_->points.size() < 3) {
409  auto node = node_.lock();
410  if (!node) {
411  throw std::runtime_error{"Failed to lock node"};
412  }
413 
414  RCLCPP_ERROR(
415  node->get_logger(),
416  "[UUID: %s] Polygon has incorrect number of vertices: %li",
417  getUUID().c_str(), params_->points.size());
418  return false;
419  }
420 
421  return true;
422 }
423 
424 // ---------- Circle ----------
425 
426 Circle::Circle(
427  const nav2::LifecycleNode::WeakPtr & node)
428 : Shape::Shape(node)
429 {
430  type_ = CIRCLE;
431 }
432 
433 int8_t Circle::getValue() const
434 {
435  return params_->value;
436 }
437 
438 std::string Circle::getFrameID() const
439 {
440  return params_->header.frame_id;
441 }
442 
443 std::string Circle::getUUID() const
444 {
445  return unparseUUID(params_->uuid.uuid.data());
446 }
447 
448 bool Circle::isUUID(const unsigned char * uuid) const
449 {
450  return uuid_compare(params_->uuid.uuid.data(), uuid) == 0;
451 }
452 
453 bool Circle::isFill() const
454 {
455  return params_->fill;
456 }
457 
458 bool Circle::obtainParams(const std::string & shape_name)
459 {
460  auto node = node_.lock();
461  if (!node) {
462  throw std::runtime_error{"Failed to lock node"};
463  }
464 
465  if (!params_) {
466  params_ = std::make_shared<nav2_msgs::msg::CircleObject>();
467  }
468  if (!center_) {
469  center_ = std::make_shared<geometry_msgs::msg::Point32>();
470  }
471 
472  params_->header.frame_id = nav2::declare_or_get_parameter(
473  node, shape_name + ".frame_id", std::string{"map"});
474  params_->value = nav2::declare_or_get_parameter(
475  node, shape_name + ".value", static_cast<int>(nav2_util::OCC_GRID_OCCUPIED));
476  params_->fill = nav2::declare_or_get_parameter(
477  node, shape_name + ".fill", true);
478 
479  std::vector<double> center_row;
480  try {
481  center_row = nav2::declare_or_get_parameter<std::vector<double>>(
482  node, shape_name + ".center");
483  params_->radius = nav2::declare_or_get_parameter<double>(
484  node, shape_name + ".radius");
485  if (params_->radius < 0) {
486  RCLCPP_ERROR(
487  node->get_logger(),
488  "[%s] Circle has incorrect radius less than zero",
489  shape_name.c_str());
490  return false;
491  }
492  } catch (const std::exception & ex) {
493  RCLCPP_ERROR(
494  node->get_logger(),
495  "[%s] Error while getting circle parameters: %s",
496  shape_name.c_str(), ex.what());
497  return false;
498  }
499  // Check for points format correctness
500  if (center_row.size() != 2) {
501  RCLCPP_ERROR(
502  node->get_logger(),
503  "[%s] Circle has incorrect center description",
504  shape_name.c_str());
505  return false;
506  }
507 
508  // Obtain circle center
509  params_->center.x = center_row[0];
510  params_->center.y = center_row[1];
511  // Setting the center_ with obtained circle center in map's frame
512  *center_ = params_->center;
513 
514  // Getting shape UUID
515  return obtainShapeUUID(shape_name, params_->uuid.uuid.data());
516 }
517 
518 nav2_msgs::msg::CircleObject::SharedPtr Circle::getParams() const
519 {
520  return params_;
521 }
522 
523 bool Circle::setParams(const nav2_msgs::msg::CircleObject::SharedPtr params)
524 {
525  params_ = params;
526 
527  if (!center_) {
528  center_ = std::make_shared<geometry_msgs::msg::Point32>();
529  }
530  *center_ = params_->center;
531 
532  // If no UUID was specified, generate a new one
533  if (uuid_is_null(params_->uuid.uuid.data())) {
534  uuid_generate(params_->uuid.uuid.data());
535  }
536 
537  return checkConsistency();
538 }
539 
541  const std::string & to_frame,
542  const nav2::TransformBuffer::SharedPtr tf_buffer,
543  const double transform_tolerance)
544 {
545  geometry_msgs::msg::TransformStamped transform;
546  if (!lookupShapeTransform(
547  params_->header, to_frame, tf_buffer, transform_tolerance, transform))
548  {
549  return false;
550  }
551 
552  geometry_msgs::msg::PoseStamped from_pose, to_pose;
553  from_pose.header = params_->header;
554  from_pose.pose.position.x = params_->center.x;
555  from_pose.pose.position.y = params_->center.y;
556  from_pose.pose.position.z = params_->center.z;
557  tf2::doTransform(from_pose, to_pose, transform);
558  center_->x = to_pose.pose.position.x;
559  center_->y = to_pose.pose.position.y;
560  center_->z = to_pose.pose.position.z;
561 
562  return true;
563 }
564 
565 void Circle::getBoundaries(double & min_x, double & min_y, double & max_x, double & max_y)
566 {
567  min_x = center_->x - params_->radius;
568  min_y = center_->y - params_->radius;
569  max_x = center_->x + params_->radius;
570  max_y = center_->y + params_->radius;
571 }
572 
573 bool Circle::isPointInside(const double px, const double py) const
574 {
575  return ( (px - center_->x) * (px - center_->x) + (py - center_->y) * (py - center_->y) ) <=
576  params_->radius * params_->radius;
577 }
578 
580  const double py, std::vector<std::pair<double, double>> & spans) const
581 {
582  spans.clear();
583  const double dy = py - center_->y;
584  const double half_chord_sq = params_->radius * params_->radius - dy * dy;
585  if (half_chord_sq < 0.0) {
586  return;
587  }
588  const double half_chord = std::sqrt(half_chord_sq);
589  // Pad against rounding, putFill() trims the ends
590  const double padding = std::max(1.0, static_cast<double>(params_->radius)) * 1e-9;
591  spans.emplace_back(center_->x - half_chord - padding, center_->x + half_chord + padding);
592 }
593 
595  nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
596 {
597  unsigned int mcx, mcy;
598  if (!centerToMap(map, mcx, mcy)) {
599  return;
600  }
601 
602  // Implementation of the circle generation algorithm, based on the following work:
603  // Berthold K.P. Horn "Circle generators for display devices"
604  // Computer Graphics and Image Processing 5.2 (1976): 280-288.
605 
606  // Inputs initialization
607  const int r = static_cast<int>(std::round(params_->radius / map->info.resolution));
608  int x = r;
609  int y = 1;
610 
611  // Error initialization
612  int s = -r;
613 
614  // Calculation algorithm
615  while (x > y) { // Calculating only first circle octant
616  // Put 8 points in each octant reflecting symmetrically
617  putPoint(mcx + x, mcy + y, map, overlay_type);
618  putPoint(mcx + y, mcy + x, map, overlay_type);
619  putPoint(mcx - x + 1, mcy + y, map, overlay_type);
620  putPoint(mcx + y, mcy - x + 1, map, overlay_type);
621  putPoint(mcx - x + 1, mcy - y + 1, map, overlay_type);
622  putPoint(mcx - y + 1, mcy - x + 1, map, overlay_type);
623  putPoint(mcx + x, mcy - y + 1, map, overlay_type);
624  putPoint(mcx - y + 1, mcy + x, map, overlay_type);
625 
626  s = s + 2 * y + 1;
627  y++;
628  if (s > 0) {
629  s = s - 2 * x + 2;
630  x--;
631  }
632  }
633 
634  // Corner case for x == y: do not put end points twice
635  if (x == y) {
636  putPoint(mcx + x, mcy + y, map, overlay_type);
637  putPoint(mcx - x + 1, mcy + y, map, overlay_type);
638  putPoint(mcx - x + 1, mcy - y + 1, map, overlay_type);
639  putPoint(mcx + x, mcy - y + 1, map, overlay_type);
640  }
641 }
642 
644 {
645  if (params_->radius < 0.0) {
646  auto node = node_.lock();
647  if (!node) {
648  throw std::runtime_error{"Failed to lock node"};
649  }
650 
651  RCLCPP_ERROR(
652  node->get_logger(),
653  "[UUID: %s] Circle has incorrect radius less than zero",
654  getUUID().c_str());
655  return false;
656  }
657  return true;
658 }
659 
661  nav_msgs::msg::OccupancyGrid::ConstSharedPtr map,
662  unsigned int & mcx, unsigned int & mcy)
663 {
664  auto node = node_.lock();
665  if (!node) {
666  throw std::runtime_error{"Failed to lock node"};
667  }
668 
669  // Get center of circle in map coordinates
670  if (center_->x < map->info.origin.position.x || center_->y < map->info.origin.position.y) {
671  RCLCPP_ERROR(
672  node->get_logger(),
673  "[UUID: %s] Can not convert (%f, %f) circle center to map",
674  getUUID().c_str(), center_->x, center_->y);
675  return false;
676  }
677  // We need the circle center to be always shifted one cell less its logical center
678  // and to avoid any FP-accuracy losing on small values, so we are using another
679  // than nav2_util::worldToMap() approach
680  mcx = static_cast<unsigned int>(
681  std::round((center_->x - map->info.origin.position.x) / map->info.resolution)) - 1;
682  mcy = static_cast<unsigned int>(
683  std::round((center_->y - map->info.origin.position.y) / map->info.resolution)) - 1;
684  if (mcx >= map->info.width || mcy >= map->info.height) {
685  RCLCPP_ERROR(
686  node->get_logger(),
687  "[UUID: %s] Can not convert (%f, %f) point to map",
688  getUUID().c_str(), center_->x, center_->y);
689  return false;
690  }
691 
692  return true;
693 }
694 
695 inline void Circle::putPoint(
696  unsigned int mx, unsigned int my,
697  nav_msgs::msg::OccupancyGrid::SharedPtr map,
698  const OverlayType overlay_type)
699 {
700  processCell(map, my * map->info.width + mx, params_->value, overlay_type);
701 }
702 
703 } // namespace nav2_map_server
bool isUUID(const unsigned char *uuid) const
Checks whether the shape is equal to a given UUID.
int8_t getValue() const
Gets the value of the shape.
bool toFrame(const std::string &to_frame, const nav2::TransformBuffer::SharedPtr tf_buffer, const double transform_tolerance)
Transforms shape coordinates to a new frame.
void putPoint(unsigned int mx, unsigned int my, nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
Put Circle's point on map.
bool isPointInside(const double px, const double py) const
Is the point inside the shape.
std::string getUUID() const
Gets UUID of the shape.
void getBoundaries(double &min_x, double &min_y, double &max_x, double &max_y)
Gets shape box-boundaries.
std::string getFrameID() const
Gets frame ID of the shape.
bool centerToMap(nav_msgs::msg::OccupancyGrid::ConstSharedPtr map, unsigned int &mcx, unsigned int &mcy)
Converts circle center to map coordinates considering FP-accuracy losing on small values when using c...
bool isFill() const
Whether the shape to be filled or only its borders to be put on map.
void getRowSpans(const double py, std::vector< std::pair< double, double >> &spans) const
Gets X-interval covered by the circle on the horizontal line y = py.
nav2_msgs::msg::CircleObject::SharedPtr params_
Input circle parameters (could be in any frame)
bool setParams(const nav2_msgs::msg::CircleObject::SharedPtr params)
Tries to update Circle parameters.
void putBorders(nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
Puts shape borders on map.
nav2_msgs::msg::CircleObject::SharedPtr getParams() const
Gets Circle parameters.
bool checkConsistency()
Checks that shape is consistent for further operation.
geometry_msgs::msg::Point32::SharedPtr center_
Circle center in the map's frame.
bool obtainParams(const std::string &shape_name)
Supporting routine obtaining ROS-parameters for the given vector object.
Functor class used in raytraceLine algorithm.
std::string getUUID() const
Gets UUID of the shape.
void getRowSpans(const double py, std::vector< std::pair< double, double >> &spans) const
Gets X-intervals covered by the polygon on the horizontal line y = py.
void getBoundaries(double &min_x, double &min_y, double &max_x, double &max_y)
Gets shape box-boundaries.
void putBorders(nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
Puts shape borders on map.
bool toFrame(const std::string &to_frame, const nav2::TransformBuffer::SharedPtr tf_buffer, const double transform_tolerance)
Transforms shape coordinates to a new frame.
bool isUUID(const unsigned char *uuid) const
Checks whether the shape is equal to a given UUID.
nav2_msgs::msg::PolygonObject::SharedPtr getParams() const
Gets Polygon parameters.
int8_t getValue() const
Gets the value of the shape.
bool setParams(const nav2_msgs::msg::PolygonObject::SharedPtr params)
Tries to update Polygon parameters.
std::string getFrameID() const
Gets frame ID of the shape.
nav2_msgs::msg::PolygonObject::SharedPtr params_
Input polygon parameters (could be in any frame)
bool checkConsistency()
Checks that shape is consistent for further operation.
bool isPointInside(const double px, const double py) const
Is the point inside the shape.
bool isFill() const
Whether the shape to be filled or only its borders to be put on map.
bool obtainParams(const std::string &shape_name)
Supporting routine obtaining ROS-parameters for the given vector object.
geometry_msgs::msg::Polygon::SharedPtr polygon_
Polygon in the map's frame.
Basic class, other vector objects to be inherited from.
bool obtainShapeUUID(const std::string &shape_name, unsigned char *out_uuid)
Supporting routine obtaining shape UUID from ROS-parameters for the given shape object.
virtual void getBoundaries(double &min_x, double &min_y, double &max_x, double &max_y)=0
Gets shape box-boundaries. Empty virtual method intended to be used in child implementations.
virtual bool isPointInside(const double px, const double py) const =0
Is the point inside the shape. Empty virtual method intended to be used in child implementations.
ShapeType type_
Type of shape.
ShapeType getType()
Returns type of the shape.
nav2::LifecycleNode::WeakPtr node_
VectorObjectServer node.
virtual void getRowSpans(const double py, std::vector< std::pair< double, double >> &spans) const =0
Gets X-intervals covered by the shape on the horizontal line y = py. Intervals may be slightly wider ...
virtual ~Shape()
Shape destructor.
Shape(const nav2::LifecycleNode::WeakPtr &node)
Shape basic class constructor.
bool putFill(nav_msgs::msg::OccupancyGrid::SharedPtr map, const OverlayType overlay_type)
Puts filled shape on map.
static void processRun(int8_t *cells, const size_t count, const int8_t shape_val, const OverlayType overlay_type)
Updates a run of consecutive cells with given shape value according to the overlay type.
virtual int8_t getValue() const =0
Gets the value of the shape. Empty virtual method intended to be used in child implementations.