Skip to content

Commit 417b3cc

Browse files
authored
feat(autoware_utils_visualization): split package (#36)
* feat(autoware_utils_visualization): split package Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * add deprecated message Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> * fix test file glob Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp> --------- Signed-off-by: Takagi, Isamu <isamu.takagi@tier4.jp>
1 parent 5099343 commit 417b3cc

File tree

10 files changed

+285
-66
lines changed

10 files changed

+285
-66
lines changed

autoware_utils/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ The ROS module provides utilities for working with ROS messages and nodes:
3636
- **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps.
3737
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
3838
- **`logger_level_configure.hpp`**: Utility for configuring logger levels dynamically.
39-
- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
4039
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
4140
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
4241
- **`parameter.hpp`**: Simplifies parameter retrieval and declaration.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Tier IV, Inc.
1+
// Copyright 2025 The Autoware Contributors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -15,67 +15,14 @@
1515
#ifndef AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_
1616
#define AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_
1717

18-
#include <rclcpp/time.hpp>
18+
// NOLINTBEGIN(build/namespaces, whitespace/line_length)
19+
// clang-format off
1920

20-
#include <visualization_msgs/msg/marker_array.hpp>
21+
#pragma message("#include <autoware_utils/ros/marker_helper.hpp> is deprecated. Use #include <autoware_utils_visualization/marker_helper.hpp> instead.")
22+
#include <autoware_utils_visualization/marker_helper.hpp>
23+
namespace autoware_utils { using namespace autoware_utils_visualization; }
2124

22-
#include <optional>
23-
#include <string>
24-
25-
namespace autoware_utils
26-
{
27-
inline geometry_msgs::msg::Point create_marker_position(double x, double y, double z)
28-
{
29-
geometry_msgs::msg::Point point;
30-
point.x = x;
31-
point.y = y;
32-
point.z = z;
33-
return point;
34-
}
35-
36-
inline geometry_msgs::msg::Quaternion create_marker_orientation(
37-
double x, double y, double z, double w)
38-
{
39-
geometry_msgs::msg::Quaternion quaternion;
40-
quaternion.x = x;
41-
quaternion.y = y;
42-
quaternion.z = z;
43-
quaternion.w = w;
44-
return quaternion;
45-
}
46-
47-
inline geometry_msgs::msg::Vector3 create_marker_scale(double x, double y, double z)
48-
{
49-
geometry_msgs::msg::Vector3 scale;
50-
scale.x = x;
51-
scale.y = y;
52-
scale.z = z;
53-
return scale;
54-
}
55-
56-
inline std_msgs::msg::ColorRGBA create_marker_color(float r, float g, float b, float a)
57-
{
58-
std_msgs::msg::ColorRGBA color;
59-
color.r = r;
60-
color.g = g;
61-
color.b = b;
62-
color.a = a;
63-
return color;
64-
}
65-
66-
visualization_msgs::msg::Marker create_default_marker(
67-
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
68-
const int32_t type, const geometry_msgs::msg::Vector3 & scale,
69-
const std_msgs::msg::ColorRGBA & color);
70-
71-
visualization_msgs::msg::Marker create_deleted_default_marker(
72-
const rclcpp::Time & now, const std::string & ns, const int32_t id);
73-
74-
void append_marker_array(
75-
const visualization_msgs::msg::MarkerArray & additional_marker_array,
76-
visualization_msgs::msg::MarkerArray * marker_array,
77-
const std::optional<rclcpp::Time> & current_time = {});
78-
79-
} // namespace autoware_utils
25+
// clang-format on
26+
// NOLINTEND
8027

8128
#endif // AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_

autoware_utils/package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<depend>autoware_utils_geometry</depend>
2323
<depend>autoware_utils_math</depend>
2424
<depend>autoware_utils_pcl</depend>
25+
<depend>autoware_utils_visualization</depend>
2526
<depend>autoware_vehicle_msgs</depend>
2627
<depend>builtin_interfaces</depend>
2728
<depend>diagnostic_msgs</depend>
@@ -33,7 +34,6 @@
3334
<depend>tf2_eigen</depend>
3435
<depend>tf2_geometry_msgs</depend>
3536
<depend>unique_identifier_msgs</depend>
36-
<depend>visualization_msgs</depend>
3737

3838
<test_depend>ament_cmake_ros</test_depend>
3939
<test_depend>ament_lint_auto</test_depend>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_utils_visualization)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
ament_auto_add_library(${PROJECT_NAME} SHARED
8+
"src/marker_helper.cpp"
9+
)
10+
11+
if(BUILD_TESTING)
12+
file(GLOB_RECURSE test_files test/*.cpp)
13+
ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files})
14+
endif()
15+
16+
ament_auto_package()
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# autoware_utils_visualization
2+
3+
## Overview
4+
5+
The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
6+
This package provides essential utilities for visualization.
7+
It is extensively used in the Autoware project to handle common tasks such as creating markers for RViz.
8+
9+
## Design
10+
11+
- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_
16+
#define AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_
17+
18+
#include <rclcpp/time.hpp>
19+
20+
#include <visualization_msgs/msg/marker_array.hpp>
21+
22+
#include <optional>
23+
#include <string>
24+
25+
namespace autoware_utils_visualization
26+
{
27+
inline geometry_msgs::msg::Point create_marker_position(double x, double y, double z)
28+
{
29+
geometry_msgs::msg::Point point;
30+
point.x = x;
31+
point.y = y;
32+
point.z = z;
33+
return point;
34+
}
35+
36+
inline geometry_msgs::msg::Quaternion create_marker_orientation(
37+
double x, double y, double z, double w)
38+
{
39+
geometry_msgs::msg::Quaternion quaternion;
40+
quaternion.x = x;
41+
quaternion.y = y;
42+
quaternion.z = z;
43+
quaternion.w = w;
44+
return quaternion;
45+
}
46+
47+
inline geometry_msgs::msg::Vector3 create_marker_scale(double x, double y, double z)
48+
{
49+
geometry_msgs::msg::Vector3 scale;
50+
scale.x = x;
51+
scale.y = y;
52+
scale.z = z;
53+
return scale;
54+
}
55+
56+
inline std_msgs::msg::ColorRGBA create_marker_color(float r, float g, float b, float a)
57+
{
58+
std_msgs::msg::ColorRGBA color;
59+
color.r = r;
60+
color.g = g;
61+
color.b = b;
62+
color.a = a;
63+
return color;
64+
}
65+
66+
visualization_msgs::msg::Marker create_default_marker(
67+
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
68+
const int32_t type, const geometry_msgs::msg::Vector3 & scale,
69+
const std_msgs::msg::ColorRGBA & color);
70+
71+
visualization_msgs::msg::Marker create_deleted_default_marker(
72+
const rclcpp::Time & now, const std::string & ns, const int32_t id);
73+
74+
void append_marker_array(
75+
const visualization_msgs::msg::MarkerArray & additional_marker_array,
76+
visualization_msgs::msg::MarkerArray * marker_array,
77+
const std::optional<rclcpp::Time> & current_time = {});
78+
79+
} // namespace autoware_utils_visualization
80+
81+
#endif // AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>autoware_utils_visualization</name>
5+
<version>1.1.0</version>
6+
<description>The autoware_utils_visualization package</description>
7+
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
8+
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
9+
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
10+
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
11+
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
12+
<license>Apache License 2.0</license>
13+
14+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
15+
<buildtool_depend>autoware_cmake</buildtool_depend>
16+
17+
<depend>rclcpp</depend>
18+
<depend>visualization_msgs</depend>
19+
20+
<test_depend>ament_lint_auto</test_depend>
21+
<test_depend>autoware_lint_common</test_depend>
22+
23+
<export>
24+
<build_type>ament_cmake</build_type>
25+
</export>
26+
</package>

autoware_utils/src/ros/marker_helper.cpp autoware_utils_visualization/src/marker_helper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include "autoware_utils/ros/marker_helper.hpp"
15+
#include "autoware_utils_visualization/marker_helper.hpp"
1616

1717
#include <string>
1818

19-
namespace autoware_utils
19+
namespace autoware_utils_visualization
2020
{
2121
visualization_msgs::msg::Marker create_default_marker(
2222
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
@@ -69,4 +69,4 @@ void append_marker_array(
6969
}
7070
}
7171

72-
} // namespace autoware_utils
72+
} // namespace autoware_utils_visualization
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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

Comments
 (0)