Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
centroid_calculation.cpp
Go to the documentation of this file.
2
4 const sensor_msgs::msg::PointCloud2::SharedPtr& point_cloud,
5 const std::vector<int>& point_indices, const Plane& plane) const {
6 Eigen::Vector4f centroid;
7 double sum_x = 0.0;
8 double sum_y = 0.0;
9 double sum_z = 0.0;
10
11 const auto& cloud_data = point_cloud->data;
12
13 for (int idx : point_indices) {
14 float x = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointX(idx)]);
15 float y = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointY(idx)]);
16 float z = *reinterpret_cast<const float*>(&cloud_data[LidarPoint::PointZ(idx)]);
17
18 sum_x += x;
19 sum_y += y;
20 sum_z += z;
21 }
22
23 size_t n = point_indices.size();
24 centroid << sum_x / n, sum_y / n, sum_z / n, 1.0f;
25 return centroid;
26}
Eigen::Vector4f calculate_center(const sensor_msgs::msg::PointCloud2::SharedPtr &point_cloud, const std::vector< int > &point_indices, const Plane &plane=Plane()) const override
Estimates the center position of a cone using centroid calculation.
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)