|
| 1 | +// Copyright 2024 Kotaro Uetake. |
| 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 "awviz_plugin/autoware_perception/tracked_objects_display.hpp" |
| 16 | + |
| 17 | +#include <rerun.hpp> |
| 18 | + |
| 19 | +namespace awviz_plugin |
| 20 | +{ |
| 21 | +TrackedObjectsDisplay::TrackedObjectsDisplay() |
| 22 | +: awviz_common::RosTopicDisplay<autoware_perception_msgs::msg::TrackedObjects>() |
| 23 | +{ |
| 24 | +} |
| 25 | + |
| 26 | +void TrackedObjectsDisplay::log_message( |
| 27 | + autoware_perception_msgs::msg::TrackedObjects::ConstSharedPtr msg) |
| 28 | +{ |
| 29 | + stream_->set_time_seconds( |
| 30 | + TIMELINE_NAME, rclcpp::Time(msg->header.stamp.sec, msg->header.stamp.nanosec).seconds()); |
| 31 | + |
| 32 | + const auto entity_path = property_.entity(msg->header.frame_id); |
| 33 | + if (!entity_path) { |
| 34 | + stream_->log(property_.topic(), rerun::TextLog("There is no corresponding entity path")); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + std::vector<rerun::Position3D> centers; |
| 39 | + std::vector<rerun::HalfSize3D> sizes; |
| 40 | + std::vector<rerun::Rotation3D> rotations; |
| 41 | + std::vector<rerun::components::ClassId> class_ids; |
| 42 | + for (const auto & object : msg->objects) { |
| 43 | + const auto & pose = object.kinematics.pose_with_covariance.pose; |
| 44 | + const auto & dimensions = object.shape.dimensions; |
| 45 | + centers.emplace_back(pose.position.x, pose.position.y, pose.position.z); |
| 46 | + sizes.emplace_back(dimensions.x, dimensions.y, dimensions.z); |
| 47 | + rotations.emplace_back(rerun::Quaternion::from_wxyz( |
| 48 | + pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z)); |
| 49 | + class_ids.emplace_back(static_cast<uint16_t>(object.classification.front().label)); |
| 50 | + } |
| 51 | + |
| 52 | + stream_->log( |
| 53 | + entity_path.value(), rerun::Boxes3D::from_centers_and_half_sizes(centers, sizes) |
| 54 | + .with_rotations(rotations) |
| 55 | + .with_class_ids(class_ids)); |
| 56 | +} |
| 57 | +} // namespace awviz_plugin |
| 58 | + |
| 59 | +#include <pluginlib/class_list_macros.hpp> |
| 60 | +PLUGINLIB_EXPORT_CLASS(awviz_plugin::TrackedObjectsDisplay, awviz_common::Display); |
0 commit comments