Skip to content

Commit

Permalink
feat(autoware_utils_visualization): split package (#36)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
isamu-takagi authored Mar 6, 2025
1 parent 5099343 commit 417b3cc
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 66 deletions.
1 change: 0 additions & 1 deletion autoware_utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ The ROS module provides utilities for working with ROS messages and nodes:
- **`debug_publisher.hpp`**: A helper class for publishing debug messages with timestamps.
- **`diagnostics_interface.hpp`**: An interface for publishing diagnostic messages.
- **`logger_level_configure.hpp`**: Utility for configuring logger levels dynamically.
- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
- **`msg_covariance.hpp`**: Indices for accessing covariance matrices in ROS messages.
- **`msg_operation.hpp`**: Overloaded operators for quaternion messages.
- **`parameter.hpp`**: Simplifies parameter retrieval and declaration.
Expand Down
69 changes: 8 additions & 61 deletions autoware_utils/include/autoware_utils/ros/marker_helper.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 Tier IV, Inc.
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,67 +15,14 @@
#ifndef AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_
#define AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_

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

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

#include <optional>
#include <string>

namespace autoware_utils
{
inline geometry_msgs::msg::Point create_marker_position(double x, double y, double z)
{
geometry_msgs::msg::Point point;
point.x = x;
point.y = y;
point.z = z;
return point;
}

inline geometry_msgs::msg::Quaternion create_marker_orientation(
double x, double y, double z, double w)
{
geometry_msgs::msg::Quaternion quaternion;
quaternion.x = x;
quaternion.y = y;
quaternion.z = z;
quaternion.w = w;
return quaternion;
}

inline geometry_msgs::msg::Vector3 create_marker_scale(double x, double y, double z)
{
geometry_msgs::msg::Vector3 scale;
scale.x = x;
scale.y = y;
scale.z = z;
return scale;
}

inline std_msgs::msg::ColorRGBA create_marker_color(float r, float g, float b, float a)
{
std_msgs::msg::ColorRGBA color;
color.r = r;
color.g = g;
color.b = b;
color.a = a;
return color;
}

visualization_msgs::msg::Marker create_default_marker(
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
const int32_t type, const geometry_msgs::msg::Vector3 & scale,
const std_msgs::msg::ColorRGBA & color);

visualization_msgs::msg::Marker create_deleted_default_marker(
const rclcpp::Time & now, const std::string & ns, const int32_t id);

void append_marker_array(
const visualization_msgs::msg::MarkerArray & additional_marker_array,
visualization_msgs::msg::MarkerArray * marker_array,
const std::optional<rclcpp::Time> & current_time = {});

} // namespace autoware_utils
// clang-format on
// NOLINTEND

#endif // AUTOWARE_UTILS__ROS__MARKER_HELPER_HPP_
2 changes: 1 addition & 1 deletion autoware_utils/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<depend>autoware_utils_geometry</depend>
<depend>autoware_utils_math</depend>
<depend>autoware_utils_pcl</depend>
<depend>autoware_utils_visualization</depend>
<depend>autoware_vehicle_msgs</depend>
<depend>builtin_interfaces</depend>
<depend>diagnostic_msgs</depend>
Expand All @@ -33,7 +34,6 @@
<depend>tf2_eigen</depend>
<depend>tf2_geometry_msgs</depend>
<depend>unique_identifier_msgs</depend>
<depend>visualization_msgs</depend>

<test_depend>ament_cmake_ros</test_depend>
<test_depend>ament_lint_auto</test_depend>
Expand Down
16 changes: 16 additions & 0 deletions autoware_utils_visualization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.14)
project(autoware_utils_visualization)

find_package(autoware_cmake REQUIRED)
autoware_package()

ament_auto_add_library(${PROJECT_NAME} SHARED
"src/marker_helper.cpp"
)

if(BUILD_TESTING)
file(GLOB_RECURSE test_files test/*.cpp)
ament_auto_add_gtest(test_${PROJECT_NAME} ${test_files})
endif()

ament_auto_package()
11 changes: 11 additions & 0 deletions autoware_utils_visualization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# autoware_utils_visualization

## Overview

The **autoware_utils** library is a comprehensive toolkit designed to facilitate the development of autonomous driving applications.
This package provides essential utilities for visualization.
It is extensively used in the Autoware project to handle common tasks such as creating markers for RViz.

## Design

- **`marker_helper.hpp`**: Helper functions for creating and manipulating visualization markers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2020 Tier IV, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_
#define AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_

#include <rclcpp/time.hpp>

#include <visualization_msgs/msg/marker_array.hpp>

#include <optional>
#include <string>

namespace autoware_utils_visualization
{
inline geometry_msgs::msg::Point create_marker_position(double x, double y, double z)
{
geometry_msgs::msg::Point point;
point.x = x;
point.y = y;
point.z = z;
return point;
}

inline geometry_msgs::msg::Quaternion create_marker_orientation(
double x, double y, double z, double w)
{
geometry_msgs::msg::Quaternion quaternion;
quaternion.x = x;
quaternion.y = y;
quaternion.z = z;
quaternion.w = w;
return quaternion;
}

inline geometry_msgs::msg::Vector3 create_marker_scale(double x, double y, double z)
{
geometry_msgs::msg::Vector3 scale;
scale.x = x;
scale.y = y;
scale.z = z;
return scale;
}

inline std_msgs::msg::ColorRGBA create_marker_color(float r, float g, float b, float a)
{
std_msgs::msg::ColorRGBA color;
color.r = r;
color.g = g;
color.b = b;
color.a = a;
return color;
}

visualization_msgs::msg::Marker create_default_marker(
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
const int32_t type, const geometry_msgs::msg::Vector3 & scale,
const std_msgs::msg::ColorRGBA & color);

visualization_msgs::msg::Marker create_deleted_default_marker(
const rclcpp::Time & now, const std::string & ns, const int32_t id);

void append_marker_array(
const visualization_msgs::msg::MarkerArray & additional_marker_array,
visualization_msgs::msg::MarkerArray * marker_array,
const std::optional<rclcpp::Time> & current_time = {});

} // namespace autoware_utils_visualization

#endif // AUTOWARE_UTILS_VISUALIZATION__MARKER_HELPER_HPP_
26 changes: 26 additions & 0 deletions autoware_utils_visualization/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>autoware_utils_visualization</name>
<version>1.1.0</version>
<description>The autoware_utils_visualization package</description>
<maintainer email="egon.kang@autocore.ai">Jian Kang</maintainer>
<maintainer email="ryohsuke.mitsudome@tier4.jp">Ryohsuke Mitsudome</maintainer>
<maintainer email="esteve.fernandez@tier4.jp">Esteve Fernandez</maintainer>
<maintainer email="yutaka.kondo@tier4.jp">Yutaka Kondo</maintainer>
<maintainer email="isamu.takagi@tier4.jp">Takagi, Isamu</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>visualization_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>autoware_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware_utils/ros/marker_helper.hpp"
#include "autoware_utils_visualization/marker_helper.hpp"

#include <string>

namespace autoware_utils
namespace autoware_utils_visualization
{
visualization_msgs::msg::Marker create_default_marker(
const std::string & frame_id, const rclcpp::Time & now, const std::string & ns, const int32_t id,
Expand Down Expand Up @@ -69,4 +69,4 @@ void append_marker_array(
}
}

} // namespace autoware_utils
} // namespace autoware_utils_visualization
118 changes: 118 additions & 0 deletions autoware_utils_visualization/test/cases/marker_helper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright 2025 The Autoware Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "autoware_utils_visualization/marker_helper.hpp"

#include <gtest/gtest.h>

TEST(TestMarkerHelper, CreatePosition)
{
const auto r = autoware_utils_visualization::create_marker_position(0.1, 0.2, 0.3);
EXPECT_DOUBLE_EQ(r.x, 0.1);
EXPECT_DOUBLE_EQ(r.y, 0.2);
EXPECT_DOUBLE_EQ(r.z, 0.3);
}

TEST(TestMarkerHelper, CreateOrientation)
{
const auto r = autoware_utils_visualization::create_marker_orientation(0.1, 0.2, 0.3, 0.4);
EXPECT_DOUBLE_EQ(r.x, 0.1);
EXPECT_DOUBLE_EQ(r.y, 0.2);
EXPECT_DOUBLE_EQ(r.z, 0.3);
EXPECT_DOUBLE_EQ(r.w, 0.4);
}

TEST(TestMarkerHelper, CreateScale)
{
const auto r = autoware_utils_visualization::create_marker_scale(0.1, 0.2, 0.3);
EXPECT_DOUBLE_EQ(r.x, 0.1);
EXPECT_DOUBLE_EQ(r.y, 0.2);
EXPECT_DOUBLE_EQ(r.z, 0.3);
}

TEST(TestMarkerHelper, CreateColor)
{
const auto r = autoware_utils_visualization::create_marker_color(0.1, 0.2, 0.3, 0.4);
EXPECT_FLOAT_EQ(r.r, 0.1);
EXPECT_FLOAT_EQ(r.g, 0.2);
EXPECT_FLOAT_EQ(r.b, 0.3);
EXPECT_FLOAT_EQ(r.a, 0.4);
}

TEST(TestMarkerHelper, CreateDefaultMarker)
{
using visualization_msgs::msg::Marker;
const auto stamp = rclcpp::Time(12345, 67890);
const auto scale = autoware_utils_visualization::create_marker_scale(0.1, 0.2, 0.3);
const auto color = autoware_utils_visualization::create_marker_color(0.1, 0.2, 0.3, 0.4);

const auto m = autoware_utils_visualization::create_default_marker(
"frame", stamp, "ns", 99, Marker::CUBE, scale, color);

EXPECT_EQ(m.header.stamp.sec, 12345);
EXPECT_EQ(m.header.stamp.nanosec, 67890);
EXPECT_EQ(m.header.frame_id, "frame");
EXPECT_EQ(m.ns, "ns");
EXPECT_EQ(m.id, 99);
EXPECT_EQ(m.action, Marker::ADD);
EXPECT_EQ(m.type, Marker::CUBE);
EXPECT_DOUBLE_EQ(m.pose.position.x, 0.0);
EXPECT_DOUBLE_EQ(m.pose.position.y, 0.0);
EXPECT_DOUBLE_EQ(m.pose.position.z, 0.0);
EXPECT_DOUBLE_EQ(m.pose.orientation.x, 0.0);
EXPECT_DOUBLE_EQ(m.pose.orientation.y, 0.0);
EXPECT_DOUBLE_EQ(m.pose.orientation.z, 0.0);
EXPECT_DOUBLE_EQ(m.pose.orientation.w, 1.0);
EXPECT_DOUBLE_EQ(m.scale.x, 0.1);
EXPECT_DOUBLE_EQ(m.scale.y, 0.2);
EXPECT_DOUBLE_EQ(m.scale.z, 0.3);
EXPECT_FLOAT_EQ(m.color.r, 0.1);
EXPECT_FLOAT_EQ(m.color.g, 0.2);
EXPECT_FLOAT_EQ(m.color.b, 0.3);
EXPECT_FLOAT_EQ(m.color.a, 0.4);
}

TEST(TestMarkerHelper, CreateDeleteMarker)
{
using visualization_msgs::msg::Marker;
const auto stamp = rclcpp::Time(12345, 67890);

const auto m = autoware_utils_visualization::create_deleted_default_marker(stamp, "ns", 99);
EXPECT_EQ(m.header.stamp.sec, 12345);
EXPECT_EQ(m.header.stamp.nanosec, 67890);
EXPECT_EQ(m.ns, "ns");
EXPECT_EQ(m.id, 99);
EXPECT_EQ(m.action, Marker::DELETE);
}

TEST(TestMarkerHelper, CreateAppendMarkerArray)
{
visualization_msgs::msg::MarkerArray array1;
visualization_msgs::msg::MarkerArray array2;
array1.markers.resize(2);
array1.markers[0].id = 10;
array1.markers[1].id = 11;
array2.markers.resize(3);
array2.markers[0].id = 20;
array2.markers[1].id = 21;
array2.markers[2].id = 22;

autoware_utils_visualization::append_marker_array(array2, &array1, std::nullopt);
EXPECT_EQ(array1.markers.size(), 5);
EXPECT_EQ(array1.markers[0].id, 10);
EXPECT_EQ(array1.markers[1].id, 11);
EXPECT_EQ(array1.markers[2].id, 20);
EXPECT_EQ(array1.markers[3].id, 21);
EXPECT_EQ(array1.markers[4].id, 22);
}
Loading

0 comments on commit 417b3cc

Please sign in to comment.