|
| 1 | +// Copyright 2025 The Autoware Contributors |
| 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_utils_visualization/marker_helper.hpp" |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | + |
| 19 | +TEST(TestMarkerHelper, CreatePosition) |
| 20 | +{ |
| 21 | + const auto r = autoware_utils_visualization::create_marker_position(0.1, 0.2, 0.3); |
| 22 | + EXPECT_DOUBLE_EQ(r.x, 0.1); |
| 23 | + EXPECT_DOUBLE_EQ(r.y, 0.2); |
| 24 | + EXPECT_DOUBLE_EQ(r.z, 0.3); |
| 25 | +} |
| 26 | + |
| 27 | +TEST(TestMarkerHelper, CreateOrientation) |
| 28 | +{ |
| 29 | + const auto r = autoware_utils_visualization::create_marker_orientation(0.1, 0.2, 0.3, 0.4); |
| 30 | + EXPECT_DOUBLE_EQ(r.x, 0.1); |
| 31 | + EXPECT_DOUBLE_EQ(r.y, 0.2); |
| 32 | + EXPECT_DOUBLE_EQ(r.z, 0.3); |
| 33 | + EXPECT_DOUBLE_EQ(r.w, 0.4); |
| 34 | +} |
| 35 | + |
| 36 | +TEST(TestMarkerHelper, CreateScale) |
| 37 | +{ |
| 38 | + const auto r = autoware_utils_visualization::create_marker_scale(0.1, 0.2, 0.3); |
| 39 | + EXPECT_DOUBLE_EQ(r.x, 0.1); |
| 40 | + EXPECT_DOUBLE_EQ(r.y, 0.2); |
| 41 | + EXPECT_DOUBLE_EQ(r.z, 0.3); |
| 42 | +} |
| 43 | + |
| 44 | +TEST(TestMarkerHelper, CreateColor) |
| 45 | +{ |
| 46 | + const auto r = autoware_utils_visualization::create_marker_color(0.1, 0.2, 0.3, 0.4); |
| 47 | + EXPECT_FLOAT_EQ(r.r, 0.1); |
| 48 | + EXPECT_FLOAT_EQ(r.g, 0.2); |
| 49 | + EXPECT_FLOAT_EQ(r.b, 0.3); |
| 50 | + EXPECT_FLOAT_EQ(r.a, 0.4); |
| 51 | +} |
| 52 | + |
| 53 | +TEST(TestMarkerHelper, CreateDefaultMarker) |
| 54 | +{ |
| 55 | + using visualization_msgs::msg::Marker; |
| 56 | + const auto stamp = rclcpp::Time(12345, 67890); |
| 57 | + const auto scale = autoware_utils_visualization::create_marker_scale(0.1, 0.2, 0.3); |
| 58 | + const auto color = autoware_utils_visualization::create_marker_color(0.1, 0.2, 0.3, 0.4); |
| 59 | + |
| 60 | + const auto m = autoware_utils_visualization::create_default_marker( |
| 61 | + "frame", stamp, "ns", 99, Marker::CUBE, scale, color); |
| 62 | + |
| 63 | + EXPECT_EQ(m.header.stamp.sec, 12345); |
| 64 | + EXPECT_EQ(m.header.stamp.nanosec, 67890); |
| 65 | + EXPECT_EQ(m.header.frame_id, "frame"); |
| 66 | + EXPECT_EQ(m.ns, "ns"); |
| 67 | + EXPECT_EQ(m.id, 99); |
| 68 | + EXPECT_EQ(m.action, Marker::ADD); |
| 69 | + EXPECT_EQ(m.type, Marker::CUBE); |
| 70 | + EXPECT_DOUBLE_EQ(m.pose.position.x, 0.0); |
| 71 | + EXPECT_DOUBLE_EQ(m.pose.position.y, 0.0); |
| 72 | + EXPECT_DOUBLE_EQ(m.pose.position.z, 0.0); |
| 73 | + EXPECT_DOUBLE_EQ(m.pose.orientation.x, 0.0); |
| 74 | + EXPECT_DOUBLE_EQ(m.pose.orientation.y, 0.0); |
| 75 | + EXPECT_DOUBLE_EQ(m.pose.orientation.z, 0.0); |
| 76 | + EXPECT_DOUBLE_EQ(m.pose.orientation.w, 1.0); |
| 77 | + EXPECT_DOUBLE_EQ(m.scale.x, 0.1); |
| 78 | + EXPECT_DOUBLE_EQ(m.scale.y, 0.2); |
| 79 | + EXPECT_DOUBLE_EQ(m.scale.z, 0.3); |
| 80 | + EXPECT_FLOAT_EQ(m.color.r, 0.1); |
| 81 | + EXPECT_FLOAT_EQ(m.color.g, 0.2); |
| 82 | + EXPECT_FLOAT_EQ(m.color.b, 0.3); |
| 83 | + EXPECT_FLOAT_EQ(m.color.a, 0.4); |
| 84 | +} |
| 85 | + |
| 86 | +TEST(TestMarkerHelper, CreateDeleteMarker) |
| 87 | +{ |
| 88 | + using visualization_msgs::msg::Marker; |
| 89 | + const auto stamp = rclcpp::Time(12345, 67890); |
| 90 | + |
| 91 | + const auto m = autoware_utils_visualization::create_deleted_default_marker(stamp, "ns", 99); |
| 92 | + EXPECT_EQ(m.header.stamp.sec, 12345); |
| 93 | + EXPECT_EQ(m.header.stamp.nanosec, 67890); |
| 94 | + EXPECT_EQ(m.ns, "ns"); |
| 95 | + EXPECT_EQ(m.id, 99); |
| 96 | + EXPECT_EQ(m.action, Marker::DELETE); |
| 97 | +} |
| 98 | + |
| 99 | +TEST(TestMarkerHelper, CreateAppendMarkerArray) |
| 100 | +{ |
| 101 | + visualization_msgs::msg::MarkerArray array1; |
| 102 | + visualization_msgs::msg::MarkerArray array2; |
| 103 | + array1.markers.resize(2); |
| 104 | + array1.markers[0].id = 10; |
| 105 | + array1.markers[1].id = 11; |
| 106 | + array2.markers.resize(3); |
| 107 | + array2.markers[0].id = 20; |
| 108 | + array2.markers[1].id = 21; |
| 109 | + array2.markers[2].id = 22; |
| 110 | + |
| 111 | + autoware_utils_visualization::append_marker_array(array2, &array1, std::nullopt); |
| 112 | + EXPECT_EQ(array1.markers.size(), 5); |
| 113 | + EXPECT_EQ(array1.markers[0].id, 10); |
| 114 | + EXPECT_EQ(array1.markers[1].id, 11); |
| 115 | + EXPECT_EQ(array1.markers[2].id, 20); |
| 116 | + EXPECT_EQ(array1.markers[3].id, 21); |
| 117 | + EXPECT_EQ(array1.markers[4].id, 22); |
| 118 | +} |
0 commit comments