pcl::getTransformation()
inline Eigen::Affine3f
getTransformation (float x, float y, float z, float roll, float pitch, float yaw)
{
Eigen::Affine3f t;
getTransformation<float> (x, y, z, roll, pitch, yaw, t);
return (t);
}
pcl::getTranslationAndEulerAngles()
inline void
getTranslationAndEulerAngles (const Eigen::Affine3f &t,
float &x, float &y, float &z,
float &roll, float &pitch, float &yaw)
{
getTranslationAndEulerAngles<float> (t, x, y, z, roll, pitch, yaw);
}
// 创建点云智能指针
pcl::PointCloud<PointType>::Ptr cloudKeyPoses3D(new pcl::PointCloud<PointType>());
// 添加单个点
PointType newPoint;
newPoint.x = 1.0;
newPoint.y = 2.0;
newPoint.z = 3.0;
cloudKeyPoses3D->push_back(newPoint);
// 访问点云中的点
// 第一个点的坐标
float x = cloudKeyPoses3D->points[0].x;
float y = cloudKeyPoses3D->points[0].y;
float z = cloudKeyPoses3D->points[0].z;
// 获取点云中点的数量
int numPoints = cloudKeyPoses3D->size();
// 遍历所有点
for(const auto& point : cloudKeyPoses3D->points) {
// 处理每个点
// point.x, point.y, point.z
}
map<int, pair<pcl::PointCloud<PointType>, pcl::PointCloud<PointType>>>
map< // 外层是一个映射
int, // 键:整数类型(比如可以用作帧ID)
pair< // 值:一个配对
pcl::PointCloud<PointType>, // 第一个点云(比如可以存储角点)
pcl::PointCloud<PointType> // 第二个点云(比如可以存储面点)
>
>
// 定义数据结构
map<int, pair<pcl::PointCloud<PointType>, pcl::PointCloud<PointType>>> featureMap;
// 添加数据的方法
void addFeaturesToMap(int frameId,
const pcl::PointCloud<PointType>& cornerPoints,
const pcl::PointCloud<PointType>& surfacePoints) {
// 方法1:使用make_pair直接构造
featureMap[frameId] = make_pair(cornerPoints, surfacePoints);
// 方法2:分别构造
pair<pcl::PointCloud<PointType>, pcl::PointCloud<PointType>> features;
features.first = cornerPoints; // 存储角点
features.second = surfacePoints; // 存储面点
featureMap[frameId] = features;
}
// 访问数据的方法
void accessFeatures(int frameId) {
// 检查键是否存在
if (featureMap.find(frameId) != featureMap.end()) {
// 获取角点
const pcl::PointCloud<PointType>& corners = featureMap[frameId].first;
// 获取面点
const pcl::PointCloud<PointType>& surfaces = featureMap[frameId].second;
cout << "Frame " << frameId << " has "
<< corners.size() << " corner points and "
<< surfaces.size() << " surface points" << endl;
}
}
// 遍历整个map的方法
void traverseFeatureMap() {
for (const auto& item : featureMap) {
int frameId = item.first;
const auto& cornerCloud = item.second.first;
const auto& surfaceCloud = item.second.second;
cout << "Frame " << frameId << ":\n"
<< " Corner points: " << cornerCloud.size() << "\n"
<< " Surface points: " << surfaceCloud.size() << endl;
}
}
// 删除特定帧的数据
void removeFrame(int frameId) {
featureMap.erase(frameId);
}
kdtreeCornerFromMap->nearestKSearch(pointSel, 5, pointSearchInd, pointSearchSqDis);
dtreeCornerFromMap->nearestKSearch
: 这是pcl::KdTreeFLANN
类的一个成员函数,用于在 Kd-tree 中搜索最近邻点。pointSel
: 要查找最近邻点的查询点。它是一个PointType
类型的点。5
: 表示要查找的最近邻点的个数,这里设置为 5,即查找 5 个最近邻点。pointSearchInd
: 一个整数类型的向量,用来存储找到的最近邻点的索引。索引对应于原始点云中的点索引。pointSearchSqDis
: 一个浮点型向量,用来存储找到的最近邻点与查询点之间的平方距离。
总结: 这行代码调用 nearestKSearch
函数,在 kdtreeCornerFromMap
这个 Kd-tree 中查找与 pointSel
点最近的 5 个点。找到的点的索引存储在 pointSearchInd
中,对应的平方距离存储在 pointSearchSqDis
中。