Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
height_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 HeightValidatorTest : 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(HeightValidatorTest, ConeWithinSmallHeightThreshold) {
29 const HeightValidator validator(0.1, 0.5, 0.375, 0.5);
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.3, 0);
33
34 Cluster cone_point_cloud = Cluster(point_cloud);
35
36 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
37
38 ASSERT_DOUBLE_EQ(result[0], 1.0);
39 ASSERT_NEAR(result[1], 0.8, 1e-6); // 0.3/0.375
40 ASSERT_FALSE(cone_point_cloud.get_is_large());
41}
42
47TEST_F(HeightValidatorTest, ConeWithinLargeHeightThreshold) {
48 const HeightValidator validator(0.1, 0.5, 0.375, 0.5);
49
50 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
51 (void)point_cloud->points.emplace_back(0.0, 0.0, 0.4, 0);
52
53 Cluster cone_point_cloud = Cluster(point_cloud);
54
55 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
56
57 ASSERT_DOUBLE_EQ(result[0], 1.0);
58 ASSERT_NEAR(result[1], 0.8, 1e-6); // 0.4/0.5
59 ASSERT_TRUE(cone_point_cloud.get_is_large());
60}
61
65TEST_F(HeightValidatorTest, ConeExceedsHeightThreshold) {
66 const HeightValidator validator(0.1, 0.5, 0.375, 0.5);
67
68 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
69 (void)point_cloud->points.emplace_back(0.0, 0.0, 0.6, 0);
70
71 Cluster cone_point_cloud = Cluster(point_cloud);
72
73 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
74
75 ASSERT_LT(result[0], 1.0);
76 ASSERT_GE(result[0], 0.0);
77 ASSERT_DOUBLE_EQ(result[1], 0.0);
78 ASSERT_TRUE(cone_point_cloud.get_is_large());
79}
80
84TEST_F(HeightValidatorTest, ConeBelowHeightThreshold) {
85 const HeightValidator validator(0.1, 0.5, 0.375, 0.5);
86
87 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
88 (void)point_cloud->points.emplace_back(0.0, 0.0, 0.03, 0);
89
90 Cluster cone_point_cloud = Cluster(point_cloud);
91
92 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
93
94 ASSERT_DOUBLE_EQ(result[0], 0.0); // Lower than cap
95 ASSERT_DOUBLE_EQ(result[1], 0.0);
96 ASSERT_FALSE(cone_point_cloud.get_is_large());
97}
98
102TEST_F(HeightValidatorTest, ConeNearMinimumHeight) {
103 const HeightValidator validator(0.1, 0.5, 0.375, 0.5);
104
105 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
106 (void)point_cloud->points.emplace_back(0.0, 0.0, 0.15, 0);
107
108 Cluster cone_point_cloud = Cluster(point_cloud);
109
110 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
111
112 ASSERT_DOUBLE_EQ(result[0], 1.0);
113 ASSERT_NEAR(result[1], 0.4, 1e-6); // 0.15/0.375
114 ASSERT_FALSE(cone_point_cloud.get_is_large());
115}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
bool get_is_large()
Get cluster's corresponding cone size.
Definition cluster.cpp:101
The HeightValidator class is responsible for validating cones based on their height.
std::vector< double > coneValidator(Cluster *cone_point_cloud, Plane &plane) const override
Validates a cone based on its height relative to a plane.
Test fixture for HeightValidator 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(HeightValidatorTest, ConeWithinSmallHeightThreshold)
Test case to validate if the cone height is within the small cone height threshold.