|
| 1 | +// Copyright 2024 Autoware Foundation |
| 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 STUB_PCD_LOADER_HPP_ |
| 16 | +#define STUB_PCD_LOADER_HPP_ |
| 17 | + |
| 18 | +#include "test_util.hpp" |
| 19 | + |
| 20 | +#include <rclcpp/rclcpp.hpp> |
| 21 | + |
| 22 | +#include "autoware_map_msgs/srv/get_differential_point_cloud_map.hpp" |
| 23 | + |
| 24 | +#include <pcl_conversions/pcl_conversions.h> |
| 25 | + |
| 26 | +#include <algorithm> |
| 27 | +#include <limits> |
| 28 | + |
| 29 | +class StubPcdLoader : public rclcpp::Node |
| 30 | +{ |
| 31 | + using GetDifferentialPointCloudMap = autoware_map_msgs::srv::GetDifferentialPointCloudMap; |
| 32 | + |
| 33 | +public: |
| 34 | + StubPcdLoader() : Node("stub_pcd_loader") |
| 35 | + { |
| 36 | + get_differential_pcd_maps_service_ = create_service<GetDifferentialPointCloudMap>( |
| 37 | + "pcd_loader_service", std::bind( |
| 38 | + &StubPcdLoader::on_service_get_differential_point_cloud_map, this, |
| 39 | + std::placeholders::_1, std::placeholders::_2)); |
| 40 | + } |
| 41 | + |
| 42 | +private: |
| 43 | + rclcpp::Service<GetDifferentialPointCloudMap>::SharedPtr get_differential_pcd_maps_service_; |
| 44 | + |
| 45 | + // NOLINTNEXTLINE |
| 46 | + bool on_service_get_differential_point_cloud_map( |
| 47 | + GetDifferentialPointCloudMap::Request::SharedPtr req, |
| 48 | + GetDifferentialPointCloudMap::Response::SharedPtr res) |
| 49 | + { |
| 50 | + const float offset_x = 100.0f; |
| 51 | + const float offset_y = 100.0f; |
| 52 | + |
| 53 | + // If the requested area is outside of the offset, return an empty response. |
| 54 | + if ( |
| 55 | + req->area.center_x - req->area.radius > offset_x || |
| 56 | + req->area.center_x + req->area.radius < offset_x || |
| 57 | + req->area.center_y - req->area.radius > offset_y || |
| 58 | + req->area.center_y + req->area.radius < offset_y) { |
| 59 | + res->header.frame_id = "map"; |
| 60 | + return true; |
| 61 | + } |
| 62 | + |
| 63 | + autoware_map_msgs::msg::PointCloudMapCellWithID pcd_map_cell_with_id; |
| 64 | + pcd_map_cell_with_id.cell_id = "0"; |
| 65 | + pcl::PointCloud<pcl::PointXYZ> cloud = make_sample_half_cubic_pcd(); |
| 66 | + for (auto & point : cloud.points) { |
| 67 | + point.x += offset_x; |
| 68 | + point.y += offset_y; |
| 69 | + } |
| 70 | + pcd_map_cell_with_id.metadata.min_x = std::numeric_limits<float>::max(); |
| 71 | + pcd_map_cell_with_id.metadata.min_y = std::numeric_limits<float>::max(); |
| 72 | + pcd_map_cell_with_id.metadata.max_x = std::numeric_limits<float>::lowest(); |
| 73 | + pcd_map_cell_with_id.metadata.max_y = std::numeric_limits<float>::lowest(); |
| 74 | + for (const auto & point : cloud.points) { |
| 75 | + pcd_map_cell_with_id.metadata.min_x = std::min(pcd_map_cell_with_id.metadata.min_x, point.x); |
| 76 | + pcd_map_cell_with_id.metadata.min_y = std::min(pcd_map_cell_with_id.metadata.min_y, point.y); |
| 77 | + pcd_map_cell_with_id.metadata.max_x = std::max(pcd_map_cell_with_id.metadata.max_x, point.x); |
| 78 | + pcd_map_cell_with_id.metadata.max_y = std::max(pcd_map_cell_with_id.metadata.max_y, point.y); |
| 79 | + } |
| 80 | + RCLCPP_INFO_STREAM(get_logger(), "cloud size: " << cloud.size()); |
| 81 | + pcl::toROSMsg(cloud, pcd_map_cell_with_id.pointcloud); |
| 82 | + res->new_pointcloud_with_ids.push_back(pcd_map_cell_with_id); |
| 83 | + res->header.frame_id = "map"; |
| 84 | + return true; |
| 85 | + } |
| 86 | +}; |
| 87 | + |
| 88 | +#endif // STUB_PCD_LOADER_HPP_ |
0 commit comments