#include"octree_sample.h"
#include<vector>
#include<pcl/octree/octree.h>
#include <pcl/kdtree/kdtree_flann.h>
typedef Eigen::aligned_allocator<pcl::PointXYZ> AlignedPointT;
//使用八叉树的体素中心点来精简原始点云(此中心点可能不是点云中的点)
void OctreeSample::OctreeCenter(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr& octree_filter_cloud)
{
pcl::octree::OctreePointCloud<pcl::PointXYZ> octree(m_resolution);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
std::vector<pcl::PointXYZ, AlignedPointT> voxel_centers;
octree.getOccupiedVoxelCenters(voxel_centers);
octree_filter_cloud->width = voxel_centers.size();
octree_filter_cloud->height = 1;
octree_filter_cloud->points.resize(octree_filter_cloud->height * octree_filter_cloud->width);
for (size_t i = 0; i < voxel_centers.size() - 1; i++)
{
octree_filter_cloud->points[i].x = voxel_centers[i].x;
octree_filter_cloud->points[i].y = voxel_centers[i].y;
octree_filter_cloud->points[i].z = voxel_centers[i].z;
}
std::cout << "体素中心点滤波后点云个数为:" << voxel_centers.size() << std::endl;
};
//使用八叉树的体素中心点的最近邻点来精简原始点云(最终获取的点云都还是原始点云数据中的点)
void OctreeSample::OctreeCenterKNN(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr& octknn_filter_cloud)
{
pcl::octree::OctreePointCloud<pcl::PointXYZ> octree(m_resolution);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
std::vector<pcl::PointXYZ, AlignedPointT> voxel_centers;
octree.getOccupiedVoxelCenters(voxel_centers);
//-----------K最近邻搜索------------
//根据下采样的结果,选择距离采样点最近的点作为最终的下采样点
pcl::KdTreeFLANN<pcl::PointXYZ> kdtree;
kdtree.setInputCloud(cloud);
pcl::PointIndicesPtr inds = std::shared_ptr<pcl::PointIndices>(new pcl::PointIndices());//采样后根据最邻近点提取的样本点下标索引
for (size_t i = 0; i < voxel_centers.size(); ++i) {
pcl::PointXYZ searchPoint;
searchPoint.x = voxel_centers[i].x;
searchPoint.y = voxel_centers[i].y;
searchPoint.z = voxel_centers[i].z;
int K = 1;//最近邻搜索
std::vector<int> pointIdxNKNSearch(K);
std::vector<float> pointNKNSquaredDistance(K);
if (kdtree.nearestKSearch(searchPoint, K, pointIdxNKNSearch, pointNKNSquaredDistance) > 0) {
inds->indices.push_back(pointIdxNKNSearch[0]);
}
}
pcl::copyPointCloud(*cloud, inds->indices, *octknn_filter_cloud);
std::cout << "体素中心最近邻点滤波后点云个数为:" << octknn_filter_cloud->points.size() << std::endl;
};
void OctreeSample::visualize_cloud(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr& filter_cloud) {
//-------------------显示点云-----------------------
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("显示点云"));
int v1(0), v2(0);
viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
viewer->setBackgroundColor(0, 0, 0, v1);
viewer->addText("point clouds", 10, 10, "v1_text", v1);
viewer->createViewPort(0.5, 0.0, 1, 1.0, v2);
viewer->setBackgroundColor(0.1, 0.1, 0.1, v2);
viewer->addText("filtered point clouds", 10, 10, "v2_text", v2);
viewer->addPointCloud<pcl::PointXYZ>(cloud, "sample cloud", v1);
viewer->addPointCloud<pcl::PointXYZ>(filter_cloud, "cloud_filtered", v2);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1, 0, 0, "sample cloud", v1);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 1, 0, "cloud_filtered", v2);
//viewer->addCoordinateSystem(1.0);
//viewer->initCameraParameters();
while (!viewer->wasStopped())
{
viewer->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
}
点云侠
- 粉丝: 5w+
- 资源: 82
最新资源
- 【Vite4+Vue3】TypeScript移动端模板2024,极速开发体验,Vant4+Pinia最佳实践
- 【Vite4+Vue3】JavaScript移动端模板2024,零配置极速开发,Vant4+Pinia组合
- 码上抓小说:Python爬虫搞定顶点小说全攻略
- gripper-covers
- python圣诞树代码,有动态3d效果
- comsol 相控阵16阵元聚焦声场仿真 双层结构(水 钢)平界面聚焦频域模型,聚焦点设在第二层介质,坐标(0,10)mm 图1为声压二维分布,图2为深度10mm径向声压分布,图3为钢内中心轴向声压
- 51单片机蓄电池充电保护设计Proteus仿真 功能描述如下:本设计由STC89C52单片机电路+LCD1602液晶显示电路+ACS712电流检测电路+分压电路+PCF8591 AD检测设计+继电器电
- Undertale.apk
- 基于MATLAB的simulink 基于dsp28335的直流电机的驱动模型(配套直流电机) 模型+讲解视频 该模型搭建可直接烧到开发板上,MATLAB版本是2020b,不需要敲写c代码,需要有一定的
- 家庭能源管理matlab 采用matlab编制家庭能源管理程序,包括各种家用电器的调度运行策略,程序通用性好
- Chapter 03 复合数据类型-1(资源)
- 出一个18650圆柱锂电池comsol模型 参数已配置,生热研究
- 白色扁平风格的图片设计资源企业网站源码下载.zip
- 白色扁平风格的温室大棚公司企业网站源码下载.zip
- 白色扁平风格的舞蹈课程学校整站网站源码下载.zip
- 白色扁平风格的夕阳时间轴自然风光模板下载.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页