博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[CC]点云密度计算
阅读量:6427 次
发布时间:2019-06-23

本文共 3183 字,大约阅读时间需要 10 分钟。

1.计算点云最近点的平均距离(点云的平均距离)

1 double computeCloudResolution (const pcl::PointCloud
::ConstPtr &cloud) 2 { 3 double res = 0.0; 4 int n_points = 0; 5 int nres; 6 std::vector
indices (2); 7 std::vector
sqr_distances (2); 8 pcl::search::KdTree
tree; 9 tree.setInputCloud (cloud);10 11 for (size_t i = 0; i < cloud->size (); ++i)12 {13 if (! pcl_isfinite ((*cloud)[i].x))14 {15 continue;16 }17 //Considering the second neighbor since the first is the point itself.18 nres = tree.nearestKSearch (i, 2, indices, sqr_distances);19 if (nres == 2)20 {21 res += sqrt (sqr_distances[1]);22 ++n_points;23 }24 }25 if (n_points != 0)26 {27 res /= n_points;28 }29 return res;30 }

 

1 assert(m_app); 2     if (!m_app) 3         return; 4  5     const ccHObject::Container& selectedEntities = m_app->getSelectedEntities(); 6     size_t selNum = selectedEntities.size(); 7     if (selNum!=1) 8     { 9         m_app->dispToConsole("Select only one cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);10         return;11     }12 13     ccHObject* ent = selectedEntities[0];14     assert(ent);15     if (!ent || !ent->isA(CC_TYPES::POINT_CLOUD))16     {17         m_app->dispToConsole("Select a real point cloud!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);18         return;19     }20 21     ccPointCloud* m_cc_cloud = static_cast
(ent);22 23 //input cloud24 unsigned count = m_cc_cloud->size();25 bool hasNorms = m_cc_cloud->hasNormals();26 CCVector3 bbMin, bbMax;27 m_cc_cloud->getBoundingBox(bbMin,bbMax);28 const CCVector3d& globalShift = m_cc_cloud->getGlobalShift();29 double globalScale = m_cc_cloud->getGlobalScale();30 31 pcl::PointCloud
::Ptr pcl_cloud (new pcl::PointCloud
);32 try33 {34 unsigned pointCount = m_cc_cloud->size();35 pcl_cloud->resize(pointCount);36 37 for (unsigned i = 0; i < pointCount; ++i)38 {39 const CCVector3* P = m_cc_cloud->getPoint(i);40 pcl_cloud->at(i).x = static_cast
(P->x);41 pcl_cloud->at(i).y = static_cast
(P->y);42 pcl_cloud->at(i).z = static_cast
(P->z);43 }44 }45 catch(...)46 {47 //any error (memory, etc.)48 pcl_cloud.reset();49 }50 if (!target_indices_ || target_indices_->size () == 0)51 {52 target_indices_.reset (new std::vector
(static_cast
(pcl_cloud->size ())));53 int index = 0;54 for (std::vector
::iterator it = target_indices_->begin (), it_e = target_indices_->end (); it != it_e; it++)55 *it = index++;56 }57 Eigen::Vector4f pt_min, pt_max;58 pcl::getMinMax3D (*pcl_cloud, *target_indices_, pt_min, pt_max);59 double diameter_ = (pt_max - pt_min).norm ();//点云中最远的两个点的距离60 double dis=computeCloudResolution(pcl_cloud);61 m_app->dispToConsole(QString("cross distance (c=%1)\nmean distance(m=%2)").arg(diameter_,0,'f').arg(dis,0,'f'),ccMainAppInterface::STD_CONSOLE_MESSAGE);
CC版

 

转载于:https://www.cnblogs.com/yhlx125/p/5509041.html

你可能感兴趣的文章
20160815001 - 修改字段的长度
查看>>
python基础===python实现截图
查看>>
android实战项目六imageview做一个幻灯片效果
查看>>
cmder 配置
查看>>
Datawhale编程——哈希表
查看>>
ThreadPoolExecutor详解
查看>>
UVa 11300
查看>>
Python--day71--分页功能
查看>>
iOS-数据缓存(转载)
查看>>
SQL多表连接查询
查看>>
VULKAN学习笔记-inter教学四篇
查看>>
spring boot 环境搭建
查看>>
rem 适配
查看>>
Java并发编程:volatile关键字解析
查看>>
UvaLive4255 Guess
查看>>
for in
查看>>
LeetCode 341: Flatten Nested List Iterator
查看>>
linux-菜鸟新手命令(1)
查看>>
CSS3学习之linear-gradient(线性渐变)
查看>>
滑动最小值
查看>>