|
| 1 | +// Copyright 2020 Tier IV, Inc. |
| 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 | +#ifndef MARKER_HELPER_HPP_ |
| 16 | +#define MARKER_HELPER_HPP_ |
| 17 | + |
| 18 | +#include <rclcpp/rclcpp.hpp> |
| 19 | + |
| 20 | +#include <visualization_msgs/msg/marker_array.hpp> |
| 21 | + |
| 22 | +#include <string> |
| 23 | + |
| 24 | +namespace vehicle_cmd_gate |
| 25 | +{ |
| 26 | +inline geometry_msgs::msg::Point createMarkerPosition(double x, double y, double z) |
| 27 | +{ |
| 28 | + geometry_msgs::msg::Point point; |
| 29 | + |
| 30 | + point.x = x; |
| 31 | + point.y = y; |
| 32 | + point.z = z; |
| 33 | + |
| 34 | + return point; |
| 35 | +} |
| 36 | + |
| 37 | +inline geometry_msgs::msg::Quaternion createMarkerOrientation( |
| 38 | + double x, double y, double z, double w) |
| 39 | +{ |
| 40 | + geometry_msgs::msg::Quaternion quaternion; |
| 41 | + |
| 42 | + quaternion.x = x; |
| 43 | + quaternion.y = y; |
| 44 | + quaternion.z = z; |
| 45 | + quaternion.w = w; |
| 46 | + |
| 47 | + return quaternion; |
| 48 | +} |
| 49 | + |
| 50 | +inline geometry_msgs::msg::Vector3 createMarkerScale(double x, double y, double z) |
| 51 | +{ |
| 52 | + geometry_msgs::msg::Vector3 scale; |
| 53 | + |
| 54 | + scale.x = x; |
| 55 | + scale.y = y; |
| 56 | + scale.z = z; |
| 57 | + |
| 58 | + return scale; |
| 59 | +} |
| 60 | + |
| 61 | +inline std_msgs::msg::ColorRGBA createMarkerColor(float r, float g, float b, float a) |
| 62 | +{ |
| 63 | + std_msgs::msg::ColorRGBA color; |
| 64 | + |
| 65 | + color.r = r; |
| 66 | + color.g = g; |
| 67 | + color.b = b; |
| 68 | + color.a = a; |
| 69 | + |
| 70 | + return color; |
| 71 | +} |
| 72 | + |
| 73 | +inline visualization_msgs::msg::Marker createMarker( |
| 74 | + const std::string & frame_id, const std::string & ns, const int32_t id, const int32_t type, |
| 75 | + geometry_msgs::msg::Point point, geometry_msgs::msg::Vector3 scale, |
| 76 | + const std_msgs::msg::ColorRGBA & color) |
| 77 | +{ |
| 78 | + visualization_msgs::msg::Marker marker; |
| 79 | + |
| 80 | + marker.header.frame_id = frame_id; |
| 81 | + marker.header.stamp = rclcpp::Time(0); |
| 82 | + marker.ns = ns; |
| 83 | + marker.id = id; |
| 84 | + marker.type = type; |
| 85 | + marker.action = visualization_msgs::msg::Marker::ADD; |
| 86 | + marker.lifetime = rclcpp::Duration::from_seconds(0.2); |
| 87 | + marker.pose.position = point; |
| 88 | + marker.pose.orientation = createMarkerOrientation(0.0, 0.0, 0.0, 1.0); |
| 89 | + marker.scale = scale; |
| 90 | + marker.color = color; |
| 91 | + marker.frame_locked = false; |
| 92 | + |
| 93 | + return marker; |
| 94 | +} |
| 95 | + |
| 96 | +inline visualization_msgs::msg::Marker createStringMarker( |
| 97 | + const std::string & frame_id, const std::string & ns, const int32_t id, const int32_t type, |
| 98 | + geometry_msgs::msg::Point point, geometry_msgs::msg::Vector3 scale, |
| 99 | + const std_msgs::msg::ColorRGBA & color, const std::string text) |
| 100 | +{ |
| 101 | + visualization_msgs::msg::Marker marker; |
| 102 | + |
| 103 | + marker = createMarker(frame_id, ns, id, type, point, scale, color); |
| 104 | + marker.text = text; |
| 105 | + |
| 106 | + return marker; |
| 107 | +} |
| 108 | + |
| 109 | +inline void appendMarkerArray( |
| 110 | + const visualization_msgs::msg::MarkerArray & additional_marker_array, |
| 111 | + visualization_msgs::msg::MarkerArray * marker_array) |
| 112 | +{ |
| 113 | + for (const auto & marker : additional_marker_array.markers) { |
| 114 | + marker_array->markers.push_back(marker); |
| 115 | + } |
| 116 | +} |
| 117 | +} // namespace vehicle_cmd_gate |
| 118 | + |
| 119 | +#endif // MARKER_HELPER_HPP_ |
0 commit comments