Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
displacement_validator_test.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <pcl/PCLPointField.h>
3#include <pcl/point_cloud.h>
4#include <pcl/point_types.h>
5
7#include <utils/cluster.hpp>
8#include <utils/plane.hpp>
9
13class DisplacementValidatorTest : public ::testing::Test {
14protected:
18 void SetUp() override {
19 plane = Plane(0, 0, 1, 0); // Horizontal plane (z=0)
20 }
21
23};
24
28TEST_F(DisplacementValidatorTest, ClusterWithWellDistributedPoints) {
29 const DisplacementValidator validator(0.1, 0.1, 0.25);
30
31 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
32 (void)point_cloud->points.emplace_back(0.0, 0.0, 0.0, 0);
33 (void)point_cloud->points.emplace_back(0.3, 0.7, 0.5, 0);
34
35 Cluster cone_point_cloud = Cluster(point_cloud);
36
37 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
38
39 ASSERT_DOUBLE_EQ(result[0], 1.0);
40 ASSERT_DOUBLE_EQ(result[1], 1.0);
41 ASSERT_DOUBLE_EQ(result[2], 1.0);
42}
43
47TEST_F(DisplacementValidatorTest, BelowThresholdOnXAxis) {
48 const DisplacementValidator validator(0.1, 0.1, 0.25);
49
50 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
51 (void)point_cloud->points.emplace_back(0.3, 0.7, 0.1, 0);
52 (void)point_cloud->points.emplace_back(0.34, 0.5, 0.7, 0);
53 (void)point_cloud->points.emplace_back(0.28, 0.0, 0.5, 0);
54
55 Cluster cone_point_cloud = Cluster(point_cloud);
56
57 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
58
59 ASSERT_LT(result[0], 1.0);
60 ASSERT_GE(result[0], 0.0);
61 ASSERT_DOUBLE_EQ(result[1], 1.0);
62 ASSERT_DOUBLE_EQ(result[2], 1.0);
63}
64
68TEST_F(DisplacementValidatorTest, BelowThresholdOnYAxis) {
69 const DisplacementValidator validator(0.1, 0.1, 0.25);
70
71 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
72 (void)point_cloud->points.emplace_back(0.3, 0.3, 0.1, 0);
73 (void)point_cloud->points.emplace_back(0.7, 0.32, 0.7, 0);
74 (void)point_cloud->points.emplace_back(0.5, 0.34, 0.5, 0);
75
76 Cluster cone_point_cloud = Cluster(point_cloud);
77
78 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
79
80 ASSERT_DOUBLE_EQ(result[0], 1.0);
81 ASSERT_LT(result[1], 1.0);
82 ASSERT_GE(result[1], 0.0);
83 ASSERT_DOUBLE_EQ(result[2], 1.0);
84}
85
89TEST_F(DisplacementValidatorTest, BelowThresholdOnZAxis) {
90 const DisplacementValidator validator(0.1, 0.1, 0.25);
91
92 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
93 (void)point_cloud->points.emplace_back(0.3, 0.7, 0.1, 0);
94 (void)point_cloud->points.emplace_back(0.6, 0.5, 0.17, 0);
95 (void)point_cloud->points.emplace_back(0.9, 0.0, 0.08, 0);
96
97 Cluster cone_point_cloud = Cluster(point_cloud);
98
99 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
100
101 ASSERT_DOUBLE_EQ(result[0], 1.0);
102 ASSERT_DOUBLE_EQ(result[1], 1.0);
103 ASSERT_LT(result[2], 1.0);
104 ASSERT_GE(result[2], 0.0);
105}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
The SizeValidator class is responsible for validating cones based on the minimum distance between the...
std::vector< double > coneValidator(Cluster *cone_point_cloud, Plane &plane) const override
Validates a cone based on the maximum distance between its points in all axis.
Test fixture for DisplacementValidator class.
Plane plane
Plane object for testing.
void SetUp() override
Set up function to initialize a plane.
The Plane class represents a 3D plane defined by its equation ax + by + cz + d = 0.
Definition plane.hpp:12
TEST_F(DisplacementValidatorTest, ClusterWithWellDistributedPoints)
Test case to validate if the cluster is well-distributed across all axes.