Autoware.Auto
visualize.hpp
Go to the documentation of this file.
1 // Copyright 2020 Arm Limited
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 <autoware_auto_perception_msgs/msg/bounding_box_array.hpp>
16 #include <visualization_msgs/msg/marker_array.hpp>
17 #include <visualization_msgs/msg/marker.hpp>
19 #include <motion_common/config.hpp>
20 #include <common/types.hpp>
21 #include <string>
22 #include <algorithm>
23 #include <memory>
24 
25 #ifndef OBJECT_COLLISION_ESTIMATOR_NODES__VISUALIZE_HPP_
26 #define OBJECT_COLLISION_ESTIMATOR_NODES__VISUALIZE_HPP_
27 
28 namespace motion
29 {
30 namespace planning
31 {
32 namespace object_collision_estimator_nodes
33 {
34 
40 
41 MarkerArray toVisualizationMarkerArray(const BoundingBoxArray bboxes, const size_t collision_idx)
42 {
43  MarkerArray marker_array{};
44 
45  // delete previous markers
46  // TODO(mitsudome-r): remove delete_marker once lifetime is supported by rviz
47  Marker delete_marker{};
48  delete_marker.header = bboxes.header;
49  delete_marker.ns = "bounding_box";
50  delete_marker.action = Marker::DELETEALL;
51  marker_array.markers.push_back(delete_marker);
52 
53  // create markers for bounding boxes
54  Marker marker{};
55  marker.header = bboxes.header;
56  marker.ns = "bounding_box";
57  marker.type = visualization_msgs::msg::Marker::LINE_STRIP;
58  marker.action = Marker::ADD;
59  marker.lifetime = time_utils::to_message(std::chrono::nanoseconds(100000));
60 
61  for (std::size_t i = 0; i < bboxes.boxes.size(); ++i) {
62  marker.id = static_cast<int32_t>(i);
63  marker.pose.orientation.w = 1.0;
64  if (i < collision_idx) {
65  marker.scale.x = 0.2;
66  marker.color.a = 0.3F;
67  marker.color.r = 0.0F;
68  marker.color.g = 1.0F;
69  marker.color.b = 0.0F;
70  } else if (i == collision_idx) {
71  marker.scale.x = 0.2;
72  marker.color.a = 1.0F;
73  marker.color.r = 1.0F;
74  marker.color.g = 0.0F;
75  marker.color.b = 0.0F;
76  } else {
77  marker.scale.x = 0.2;
78  marker.color.a = 0.3F;
79  marker.color.r = 0.7F;
80  marker.color.g = 0.7F;
81  marker.color.b = 0.7F;
82  }
83  marker.points.clear();
84  const auto box = bboxes.boxes.at(i);
85  for (std::size_t j = 0; j < 4; ++j) {
87  point.x = static_cast<float64_t>(box.corners.at(j).x);
88  point.y = static_cast<float64_t>(box.corners.at(j).y);
89  point.z = static_cast<float64_t>(box.corners.at(j).z);
90  marker.points.push_back(point);
91  }
93  point.x = static_cast<float64_t>(box.corners.at(0).x);
94  point.y = static_cast<float64_t>(box.corners.at(0).y);
95  point.z = static_cast<float64_t>(box.corners.at(0).z);
96  marker.points.push_back(point);
97 
98  marker_array.markers.push_back(marker);
99  }
100 
101  return marker_array;
102 }
103 } // namespace object_collision_estimator_nodes
104 } // namespace planning
105 } // namespace motion
106 
107 #endif // OBJECT_COLLISION_ESTIMATOR_NODES__VISUALIZE_HPP_
autoware::rviz_plugins::object_detection::detail::Marker
visualization_msgs::msg::Marker Marker
Definition: object_polygon_detail.cpp:31
time_utils::to_message
TIME_UTILS_PUBLIC builtin_interfaces::msg::Time to_message(std::chrono::system_clock::time_point t)
Convert from std::chrono::time_point to time message.
Definition: time_utils.cpp:67
autoware::off_map_obstacles_filter_nodes::MarkerArray
visualization_msgs::msg::MarkerArray MarkerArray
Definition: off_map_obstacles_filter_node.cpp:39
types.hpp
This file includes common type definition.
config.hpp
BoundingBoxArray
autoware_auto_perception_msgs::msg::BoundingBoxArray BoundingBoxArray
Definition: tf2_autoware_auto_msgs.hpp:38
autoware::common::types::float32_t
float float32_t
Definition: types.hpp:45
time_utils.hpp
motion
Definition: controller_base.hpp:31
Point
geometry_msgs::msg::Point32 Point
Definition: cluster2d.cpp:28
autoware::common::types::float64_t
double float64_t
Definition: types.hpp:47
motion::planning::object_collision_estimator_nodes::toVisualizationMarkerArray
MarkerArray toVisualizationMarkerArray(const BoundingBoxArray bboxes, const size_t collision_idx)
Definition: visualize.hpp:41