Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
displacement_validator.cpp
Go to the documentation of this file.
2
3DisplacementValidator::DisplacementValidator(double min_distance_x, double min_distance_y,
4 double min_distance_z)
5 : _min_distance_x_(min_distance_x),
6 _min_distance_y_(min_distance_y),
7 _min_distance_z_(min_distance_z) {}
8
9std::vector<double> DisplacementValidator::coneValidator(Cluster* cone_cluster,
10 [[maybe_unused]] Plane& plane) const {
11 const auto& cloud_data = cone_cluster->get_point_cloud()->data;
12 const auto& indices = cone_cluster->get_point_indices();
13
14 // Initialize min and max with the first point
15 float minX = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointX(indices[0])]);
16 float maxX = minX;
17 float minY = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointY(indices[0])]);
18 float maxY = minY;
19 float minZ = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointZ(indices[0])]);
20 float maxZ = minZ;
21
22 // Loop through all points to find min/max on each axis
23 for (size_t i = 1; i < indices.size(); ++i) {
24 float x = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointX(indices[i])]);
25 float y = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointY(indices[i])]);
26 float z = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointZ(indices[i])]);
27
28 minX = std::min(minX, x);
29 maxX = std::max(maxX, x);
30
31 minY = std::min(minY, y);
32 maxY = std::max(maxY, y);
33
34 minZ = std::min(minZ, z);
35 maxZ = std::max(maxZ, z);
36 }
37
38 // index 0 = ratio between the x axis displacement and the minimum distance for that axis.
39 // index 1 = ratio between the y axis displacement and the minimum distance for that axis.
40 // index 2 = ratio between the z axis displacement and the minimum distance for that axis.
41 return {std::min((maxX - minX) / _min_distance_x_, 1.0),
42 std::min((maxY - minY) / _min_distance_y_, 1.0),
43 std::min((maxZ - minZ) / _min_distance_z_, 1.0)};
44}
Represents a cluster of 3D points using PCL (Point Cloud Library).
Definition cluster.hpp:14
const std::vector< int > & get_point_indices()
Get the Point Cloud data of the cluster.
Definition cluster.cpp:44
const sensor_msgs::msg::PointCloud2::SharedPtr & get_point_cloud()
Get the Point Cloud data of the cluster.
Definition cluster.cpp:46
DisplacementValidator(double min_distance_x, double min_distance_y, double min_distance_z)
Constructs a new DisplacementValidator object with the specified distance threshold for all axis.
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.
The Plane class represents a 3D plane defined by its equation ax + by + cz + d = 0.
Definition plane.hpp:12
constexpr size_t PointZ(size_t idx)
constexpr size_t PointX(size_t idx)
constexpr size_t PointY(size_t idx)