std::vector<std::vector<int>> LidarObjectSeg::Run(const pcl::PointCloud<pcl::PointXYZI>::Ptr &inCloud) const { if (inCloud->empty()) return {}; std::vector<std::array<double, 3>> gridPoints; GridParam gridParam = this->EstimateGridParam(inCloud, gridPoints); std::multimap<int, int> hashTable = this->UpdateHashTable(gridPoints, gridParam); std::vector<int> clusterIndices(inCloud->size(), -1); int curClusterIdx = 0; START_HOST_TIMING(ExtractClusters) for (std::size_t i = 0; i < inCloud->size(); ++i) { if (clusterIndices[i] >= 0) continue; const auto &curGridPoint = gridPoints[i]; std::vector<int> neighborIndices = this->GetNeighbors(curGridPoint, gridParam, hashTable); for (int neighborIdx : neighborIndices) { if (neighborIdx == i) continue; int curPointVoxelIdx = clusterIndices[i]; int neighborVoxelIdx = clusterIndices[neighborIdx]; if (curPointVoxelIdx >= 0 && neighborVoxelIdx >= 0) { if (curPointVoxelIdx != neighborVoxelIdx) this->MergeClusters(clusterIndices, curPointVoxelIdx, neighborVoxelIdx); } else { if (curPointVoxelIdx < 0) clusterIndices[i] = neighborVoxelIdx; else clusterIndices[neighborIdx] = curPointVoxelIdx; } } if (clusterIndices[i] < 0 && neighborIndices.size() >= numMinPoints_) { for (int neighborIdx : neighborIndices) { clusterIndices[neighborIdx] = curClusterIdx; } curClusterIdx++; } } STOP_HOST_TIMING(ExtractClusters) START_HOST_TIMING(GetAllClusters) std::vector<std::vector<int>> allClusters = this->GetAllClusters(clusterIndices); STOP_HOST_TIMING(GetAllClusters) PRINT_ALL_TIMING() return allClusters; }
时间: 2024-02-15 10:28:50 浏览: 26
这是一个函数,可以接收一个指向 pcl::PointCloud<pcl::PointXYZI> 类型的指针作为参数,函数返回一个 std::vector<std::vector<int>> 类型的对象。在函数内部,首先判断输入点云是否为空,如果为空则直接返回一个空的 std::vector<std::vector<int>> 类型的对象。然后函数会估算点云的网格参数,并根据网格参数更新哈希表。之后,函数会遍历点云中的每个点,如果该点已经被聚类过,则跳过该点;否则,函数会获取该点附近的所有点,然后将这些点分配到同一个聚类中。最后,函数会返回所有聚类的点的索引。
相关问题
pcl::PointCloud<pcl::PointNormal>
`pcl::PointCloud<pcl::PointNormal>` 是 PCL(点云库)中的一种数据结构,用于表示点云中每个点的位置和法线信息。
`pcl::PointCloud<pcl::PointNormal>` 是一个模板类,其中的类型参数 `<pcl::PointNormal>` 表示每个点的数据类型是 `pcl::PointNormal`,即包含位置和法线信息的数据类型。
`pcl::PointNormal` 类是一个结构体,包含了三个成员变量:`x`、`y` 和 `z` 表示点的位置,以及 `normal_x`、`normal_y` 和 `normal_z` 表示点的法线向量。
你可以使用 `pcl::PointCloud<pcl::PointNormal>` 对象来存储点云中每个点的位置和法线信息。例如,你可以定义一个 `pcl::PointCloud<pcl::PointNormal>` 对象来存储一个点云的位置和法线数据:
```cpp
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
// 定义一个包含位置和法线信息的点云对象
pcl::PointCloud<pcl::PointNormal>::Ptr cloud(new pcl::PointCloud<pcl::PointNormal>);
// 填充位置和法线数据
pcl::PointNormal point1;
point1.x = 0.0;
point1.y = 0.0;
point1.z = 0.0;
point1.normal_x = 0.0;
point1.normal_y = 0.0;
point1.normal_z = 1.0;
cloud->push_back(point1);
pcl::PointNormal point2;
point2.x = 1.0;
point2.y = 0.0;
point2.z = 0.0;
point2.normal_x = 1.0;
point2.normal_y = 0.0;
point2.normal_z = 0.0;
cloud->push_back(point2);
// 访问位置和法线数据
for (const auto& point : cloud->points) {
std::cout << "Position: (" << point.x << ", " << point.y << ", " << point.z << ")" << std::endl;
std::cout << "Normal: (" << point.normal_x << ", " << point.normal_y << ", " << point.normal_z << ")" << std::endl;
}
```
在这个示例中,我们首先定义了一个 `pcl::PointCloud<pcl::PointNormal>` 对象 `cloud` 来存储位置和法线信息。
然后,我们创建了两个 `pcl::PointNormal` 对象 `point1` 和 `point2`,并分别为它们的成员变量赋值。
接下来,我们使用 `push_back` 函数将 `point1` 和 `point2` 添加到 `cloud` 点云对象中。
最后,我们可以使用循环遍历 `cloud->points` 来访问每个点的位置和法线数据,并打印出其坐标和法线向量的分量。
注意,在使用 `pcl::PointCloud<pcl::PointNormal>` 时,需要包含相应的头文件 `<pcl/point_cloud.h>` 和 `<pcl/point_types.h>`。
pcl::PointCloud<pcl::Normal>
`pcl::PointCloud<pcl::Normal>` 是 PCL(点云库)中表示法线信息的数据结构。它用于存储点云中每个点的法线向量。
`pcl::PointCloud<pcl::Normal>` 是一个模板类,其中的类型参数 `<pcl::Normal>` 表示每个点的数据类型是 `pcl::Normal`,即表示法线的数据类型。
`pcl::Normal` 类包含了三个成员变量:`normal_x`、`normal_y` 和 `normal_z`,分别表示法线向量在 x、y、z 方向上的分量。
你可以使用 `pcl::PointCloud<pcl::Normal>` 对象来存储点云中每个点的法线信息。例如,你可以定义一个 `pcl::PointCloud<pcl::Normal>` 对象来存储一个点云的法线数据:
```cpp
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
// 定义一个包含法线信息的点云对象
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
// 填充法线数据
pcl::Normal normal1;
normal1.normal_x = 0.0;
normal1.normal_y = 0.0;
normal1.normal_z = 1.0;
normals->push_back(normal1);
pcl::Normal normal2;
normal2.normal_x = 0.0;
normal2.normal_y = 1.0;
normal2.normal_z = 0.0;
normals->push_back(normal2);
// 访问法线数据
for (const auto& normal : normals->points) {
std::cout << "Normal: (" << normal.normal_x << ", " << normal.normal_y << ", " << normal.normal_z << ")" << std::endl;
}
```
在这个示例中,我们首先定义了一个 `pcl::PointCloud<pcl::Normal>` 对象 `normals` 来存储法线信息。
然后,我们创建了两个 `pcl::Normal` 对象 `normal1` 和 `normal2`,并分别为它们的成员变量赋值。
接下来,我们使用 `push_back` 函数将 `normal1` 和 `normal2` 添加到 `normals` 点云对象中。
最后,我们可以使用循环遍历 `normals->points` 来访问每个法线数据,并打印出其 x、y、z 分量。
注意,在使用 `pcl::PointCloud<pcl::Normal>` 时,需要包含相应的头文件 `<pcl/point_types.h>` 和 `<pcl/point_cloud.h>`。