-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
5099343
commit 417b3cc
Showing
10 changed files
with
285 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
81 changes: 81 additions & 0 deletions
81
autoware_utils_visualization/include/autoware_utils_visualization/marker_helper.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
autoware_utils_visualization/test/cases/marker_helper.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.