|
| 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 | +#include "tier4_autoware_utils/transform/transforms.hpp" |
| 16 | + |
| 17 | +#include <gtest/gtest.h> |
| 18 | +#include <pcl/point_cloud.h> |
| 19 | +#include <pcl/point_types.h> |
| 20 | + |
| 21 | +#include <thread> |
| 22 | + |
| 23 | +TEST(system, transform_point_cloud) |
| 24 | +{ |
| 25 | + pcl::PointCloud<pcl::PointXYZI> cloud; |
| 26 | + cloud.push_back(pcl::PointXYZI(10.055880, -42.758892, -10.636949, 4)); |
| 27 | + cloud.push_back(pcl::PointXYZI(23.282284, -29.485722, -11.468469, 5)); |
| 28 | + |
| 29 | + Eigen::Matrix<float, 4, 4> transform; |
| 30 | + transform << 0.834513, -0.550923, -0.008474, 89571.148438, 0.550986, 0.834372, 0.015428, |
| 31 | + 42301.179688, -0.001429, -0.017543, 0.999845, -3.157415, 0.000000, 0.000000, 0.000000, 1.000000; |
| 32 | + |
| 33 | + pcl::PointCloud<pcl::PointXYZI> cloud_transformed; |
| 34 | + tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform); |
| 35 | + |
| 36 | + pcl::PointXYZI pt1_gt(89603.187500, 42270.878906, -13.056946, 4); |
| 37 | + |
| 38 | + constexpr float float_error = 0.0001; |
| 39 | + EXPECT_NEAR(cloud_transformed[0].x, pt1_gt.x, float_error); |
| 40 | + EXPECT_NEAR(cloud_transformed[0].y, pt1_gt.y, float_error); |
| 41 | + EXPECT_NEAR(cloud_transformed[0].z, pt1_gt.z, float_error); |
| 42 | + EXPECT_EQ(cloud_transformed[0].intensity, pt1_gt.intensity); |
| 43 | +} |
| 44 | + |
| 45 | +TEST(system, empty_point_cloud) |
| 46 | +{ |
| 47 | + pcl::PointCloud<pcl::PointXYZI> cloud; |
| 48 | + |
| 49 | + Eigen::Matrix<float, 4, 4> transform; |
| 50 | + transform << 0.834513, -0.550923, -0.008474, 89571.148438, 0.550986, 0.834372, 0.015428, |
| 51 | + 42301.179688, -0.001429, -0.017543, 0.999845, -3.157415, 0.000000, 0.000000, 0.000000, 1.000000; |
| 52 | + |
| 53 | + pcl::PointCloud<pcl::PointXYZI> cloud_transformed; |
| 54 | + |
| 55 | + EXPECT_NO_THROW(tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform)); |
| 56 | + EXPECT_NO_FATAL_FAILURE( |
| 57 | + tier4_autoware_utils::transformPointCloud(cloud, cloud_transformed, transform)); |
| 58 | + EXPECT_EQ(cloud_transformed.size(), 0ul); |
| 59 | +} |
0 commit comments