Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
npoints_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 NPointsValidatorTest : public ::testing::Test {
14protected:
18 void SetUp() override { plane = Plane(1, 0, 0, 0); }
19
21};
22
26TEST_F(NPointsValidatorTest, ConeWithFewerPointsThanThreshold) {
27 const NPointsValidator validator(4);
28
29 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
30 (void)point_cloud->points.emplace_back(0.3, 0.0, 0.0, 0); // 1 point
31
32 Cluster cone_point_cloud(point_cloud);
33
34 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
35
36 ASSERT_LT(result[0], 1.0);
37}
38
42TEST_F(NPointsValidatorTest, ConeWithExactMinPoints) {
43 const NPointsValidator validator(4);
44
45 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
46 (void)point_cloud->points.insert(point_cloud->points.end(), {{0.3, 0.0, 0.0, 0},
47 {0.5, 0.1, 0.2, 0},
48 {0.1, 0.2, 0.3, 0},
49 {-0.2, -0.3, 0.1, 0}}); // 4 points
50
51 Cluster cone_point_cloud(point_cloud);
52
53 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
54
55 ASSERT_DOUBLE_EQ(result[0], 1.0);
56}
57
61TEST_F(NPointsValidatorTest, ConeWithMorePointsThanThreshold) {
62 const NPointsValidator validator(4);
63
64 const auto point_cloud = std::make_shared<pcl::PointCloud<pcl::PointXYZI>>();
65 (void)point_cloud->points.insert(point_cloud->points.end(), {{0.3, 0.0, 0.0, 0},
66 {0.5, 0.1, 0.2, 0},
67 {0.1, 0.2, 0.3, 0},
68 {-0.2, -0.3, 0.1, 0},
69 {0.4, -0.1, 0.0, 0}}); // 5 points
70
71 Cluster cone_point_cloud(point_cloud);
72
73 std::vector<double> result = validator.coneValidator(&cone_point_cloud, plane);
74
75 ASSERT_DOUBLE_EQ(result[0], 1.0);
76}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
The NPointsValidator class is responsible for validating cones based on the number of points they con...
std::vector< double > coneValidator(Cluster *cone_point_cloud, Plane &plane) const override
Validates a cone based on its number of points.
Test fixture for NPointsValidator class.
void SetUp() override
Set up function to initialize a plane.
Plane plane
Plane object for testing.
The Plane class represents a 3D plane defined by its equation ax + by + cz + d = 0.
Definition plane.hpp:12
TEST_F(NPointsValidatorTest, ConeWithFewerPointsThanThreshold)
Test case to validate a cluster with fewer points than the minimum threshold.