[CC]点云密度计算

包括两种计算方法:精确计算和近似计算(思考:local density=单位面积的点数 vs  local density =1/单个点所占的面积)

每种方法可以实现三种模式的点云密度计算,CC里面的点云计算依赖于 给定的近邻半径所对应的最佳八叉树层级 (通过findBestLevelForAGivenNeighbourhoodSizeExtraction()方法实现)

在GeometricalAnalysisTools类文件中实现。

//volume of a unit sphere
static double s_UnitSphereVolume = 4.0 * M_PI / 3.0;

1.精确计算

 1 int GeometricalAnalysisTools::computeLocalDensity(    GenericIndexedCloudPersist* theCloud,
 2                                                     Density densityType,
 3                                                     PointCoordinateType kernelRadius,
 4                                                     GenericProgressCallback* progressCb/*=0*/,
 5                                                     DgmOctree* inputOctree/*=0*/)
 6 {
 7     if (!theCloud)
 8         return -1;
 9
10     unsigned numberOfPoints = theCloud->size();
11     if (numberOfPoints < 3)
12         return -2;
13
14     //compute the right dimensional coef based on the expected output
15     double dimensionalCoef = 1.0;
16     switch (densityType)
17     {
18     case DENSITY_KNN:
19         dimensionalCoef = 1.0;
20         break;
21     case DENSITY_2D:
22         dimensionalCoef = M_PI * (static_cast<double>(kernelRadius) * kernelRadius);
23         break;
24     case DENSITY_3D:
25         dimensionalCoef = s_UnitSphereVolume * ((static_cast<double>(kernelRadius) * kernelRadius) * kernelRadius);
26         break;
27     default:
28         assert(false);
29         return -5;
30     }
31
32     DgmOctree* theOctree = inputOctree;
33     if (!theOctree)
34     {
35         theOctree = new DgmOctree(theCloud);
36         if (theOctree->build(progressCb) < 1)
37         {
38             delete theOctree;
39             return -3;
40         }
41     }
42
43     theCloud->enableScalarField();
44
45     //determine best octree level to perform the computation
46     unsigned char level = theOctree->findBestLevelForAGivenNeighbourhoodSizeExtraction(kernelRadius);
47
48     //parameters
49     void* additionalParameters[] = {    static_cast<void*>(&kernelRadius),
50                                         static_cast<void*>(&dimensionalCoef) };
51
52     int result = 0;
53
54     if (theOctree->executeFunctionForAllCellsAtLevel(    level,
55                                                         &computePointsDensityInACellAtLevel,
56                                                         additionalParameters,
57                                                         true,
58                                                         progressCb,
59                                                         "Local Density Computation") == 0)
60     {
61         //something went wrong
62         result = -4;
63     }
64
65     if (!inputOctree)
66         delete theOctree;
67
68     return result;
69 }

GeometricalAnalysisTools::computeLocalDensity

 1 //"PER-CELL" METHOD: LOCAL DENSITY
 2 //ADDITIONNAL PARAMETERS (2):
 3 // [0] -> (PointCoordinateType*) kernelRadius : spherical neighborhood radius
 4 // [1] -> (ScalarType*) sphereVolume : spherical neighborhood volume
 5 bool GeometricalAnalysisTools::computePointsDensityInACellAtLevel(    const DgmOctree::octreeCell& cell,
 6                                                                     void** additionalParameters,
 7                                                                     NormalizedProgress* nProgress/*=0*/)
 8 {
 9     //parameter(s)
10     PointCoordinateType radius = *static_cast<PointCoordinateType*>(additionalParameters[0]);
11     double dimensionalCoef = *static_cast<double*>(additionalParameters[1]);
12
13     assert(dimensionalCoef > 0);
14
15     //structure for nearest neighbors search
16     DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
17     nNSS.level = cell.level;
18     nNSS.prepare(radius,cell.parentOctree->getCellSize(nNSS.level));
19     cell.parentOctree->getCellPos(cell.truncatedCode,cell.level,nNSS.cellPos,true);
20     cell.parentOctree->computeCellCenter(nNSS.cellPos,cell.level,nNSS.cellCenter);
21
22     unsigned n = cell.points->size(); //number of points in the current cell
23
24     //for each point in the cell
25     for (unsigned i=0; i<n; ++i)
26     {
27         cell.points->getPoint(i,nNSS.queryPoint);
28
29         //look for neighbors inside a sphere
30         //warning: there may be more points at the end of nNSS.pointsInNeighbourhood than the actual nearest neighbors (neighborCount)!
31         unsigned neighborCount = cell.parentOctree->findNeighborsInASphereStartingFromCell(nNSS,radius,false);
32         //数目/体积
33         ScalarType density = static_cast<ScalarType>(neighborCount/dimensionalCoef);
34         cell.points->setPointScalarValue(i,density);
35
36         if (nProgress && !nProgress->oneStep())
37         {
38             return false;
39         }
40     }
41
42     return true;
43 }

computePointsDensityInACellAtLevel

2. 近似计算

 1 int GeometricalAnalysisTools::computeLocalDensityApprox(GenericIndexedCloudPersist* theCloud,
 2                                                         Density densityType,
 3                                                         GenericProgressCallback* progressCb/*=0*/,
 4                                                         DgmOctree* inputOctree/*=0*/)
 5 {
 6     if (!theCloud)
 7         return -1;
 8
 9     unsigned numberOfPoints = theCloud->size();
10     if (numberOfPoints < 3)
11         return -2;
12
13     DgmOctree* theOctree = inputOctree;
14     if (!theOctree)
15     {
16         theOctree = new DgmOctree(theCloud);
17         if (theOctree->build(progressCb) < 1)
18         {
19             delete theOctree;
20             return -3;
21         }
22     }
23
24     theCloud->enableScalarField();
25
26     //determine best octree level to perform the computation
27     unsigned char level = theOctree->findBestLevelForAGivenPopulationPerCell(3);
28
29     //parameters
30     void* additionalParameters[] = { static_cast<void*>(&densityType) };
31
32     int result = 0;
33
34     if (theOctree->executeFunctionForAllCellsAtLevel(    level,
35                                                         &computeApproxPointsDensityInACellAtLevel,
36                                                         additionalParameters,
37                                                         true,
38                                                         progressCb,
39                                                         "Approximate Local Density Computation") == 0)
40     {
41         //something went wrong
42         result = -4;
43     }
44
45     if (!inputOctree)
46         delete theOctree;
47
48     return result;
49 }

 1 //"PER-CELL" METHOD: APPROXIMATE LOCAL DENSITY
 2 //ADDITIONAL PARAMETERS (0): NONE
 3 bool GeometricalAnalysisTools::computeApproxPointsDensityInACellAtLevel(const DgmOctree::octreeCell& cell,
 4                                                                         void** additionalParameters,
 5                                                                         NormalizedProgress* nProgress/*=0*/)
 6 {
 7     //extract additional parameter(s)
 8     Density densityType = *static_cast<Density*>(additionalParameters[0]);
 9
10     DgmOctree::NearestNeighboursSearchStruct nNSS;
11     nNSS.level                                = cell.level;
12     nNSS.alreadyVisitedNeighbourhoodSize    = 0;
13     nNSS.minNumberOfNeighbors                = 2;
14     cell.parentOctree->getCellPos(cell.truncatedCode,cell.level,nNSS.cellPos,true);
15     cell.parentOctree->computeCellCenter(nNSS.cellPos,cell.level,nNSS.cellCenter);
16
17     unsigned n = cell.points->size();
18     for (unsigned i=0; i<n; ++i)
19     {
20         cell.points->getPoint(i,nNSS.queryPoint);
21
22         //the first point is always the point itself!
23         if (cell.parentOctree->findNearestNeighborsStartingFromCell(nNSS) > 1)
24         {
25             double R2 = nNSS.pointsInNeighbourhood[1].squareDistd;
26
27             ScalarType density = NAN_VALUE;
28             if (R2 > ZERO_TOLERANCE)
29             {
30                 switch (densityType)
31                 {
32                 case DENSITY_KNN:
33                     {
34                         //we return in fact the (inverse) distance to the nearest neighbor
35                         density = static_cast<ScalarType>(1.0 / sqrt(R2));
36                     }
37                     break;
38                 case DENSITY_2D:
39                     {
40                         //circle area (2D approximation)
41                         double circleArea = M_PI * R2;
42                         density = static_cast<ScalarType>(1.0 / circleArea);
43                     }
44                     break;
45                 case DENSITY_3D:
46                     {
47                         //sphere area
48                         double sphereArea =  s_UnitSphereVolume * R2 * sqrt(R2);
49                         density = static_cast<ScalarType>(1.0 / sphereArea);
50                     }
51                     break;
52                 default:
53                     assert(false);
54                     break;
55                 }
56             }
57             cell.points->setPointScalarValue(i,density);
58         }
59         else
60         {
61             //shouldn‘t happen! Apart if the cloud has only one point...
62             cell.points->setPointScalarValue(i,NAN_VALUE);
63         }
64
65         if (nProgress && !nProgress->oneStep())
66         {
67             return false;
68         }
69     }
70
71     return true;
72 }

computeApproxPointsDensityInACellAtLevel

时间: 2024-08-06 11:39:30

[CC]点云密度计算的相关文章

点云密度计算

1.计算点云最近点的平均距离(点云的平均距离)http://pointclouds.org/documentation/tutorials/correspondence_grouping.php 1 double computeCloudResolution (const pcl::PointCloud<PointType>::ConstPtr &cloud) 2 { 3 double res = 0.0; 4 int n_points = 0; 5 int nres; 6 std::

Bazaar:阿里云Serverless计算服务探秘

摘要: Serverless 指用户无需管理服务器情况下构建和运行应用程序的一种方式.可见 Serverless 并不是真的不需要服务器,毕竟程序代码不能靠意念来执行,仍然是需要硬件服务器实体来作为运行代码的基础的. 作者:Bazaar项目组 1.     什么是 Serverless "Serverless computing refers to the concept of building and running applications that do not require serve

腾讯云高级研究员张雨春:腾讯云城市计算助力行业数字化升级

10月28日FMI 2018人工智能与大数据高峰论坛深圳场圆满落幕,腾讯云高级研究员张雨春从腾讯云城市计算助力行业数字化升级方向进行了精彩的分享. 腾讯云高级研究员张雨春 以下是张雨春演讲内容,飞马网根据现场速记进行了不改变原意的编辑(有删减): 张雨春:大家好!很高兴作为最后一位演讲嘉宾参加这次峰会.今天我给大家带来的分享是<腾讯云城市计算助力行业数字化升级>,城市计算的概念最近几年炒得很热,BAT三家先后提出了AI城市.智慧城市.城市大脑等解决方案.今年7月份,深圳市政府提出了建设新型智慧

jquery弹性云拖动计算功能

jquery弹性云拖动计算功能 西安天互7月份上线了自主研发的弹性云产品,第三代云主机全新上线,新一代存储架构安全稳定,性能更强. 今天来和大家分享下jquery弹性云拖动计算功能:首先html页面必须有的,拖动元素.拖动范围.背景等. 拖动效果分为两种:一是根据鼠标拖动像素的区间范围改变拖动元素的位置,二是拖动元素随着鼠标所在像素的改变而同时改变. 一是根据鼠标拖动像素的区间范围改变元素的位置:获取拖动元素对象,在他的点下元素事件(这里注意:是点下mousedown而不是点击click)函数中

云原生计算基金会宣布 JFrog 为金牌会员

DevOps Expert 加入 CNCF 以进一步实现云原生操作的最佳实践. 2017年12月4日 - 支持和集成 Kubernetes? 和 Prometheus? 等开源技术的云原生计算基金 ?(CNCF?)今天宣布,JFrog 作为金牌会员加入基金会.作为开源和云原生技术的大力支持者,JFrog 利用 Kubernetes 等技术帮助 4000 多名客户以快速,可靠和安全的方式构建和发布软件. "云原生本地计算基金会执行总监 Dan Kohn 表示:"CNCF 很高兴 JFro

【深圳云栖大会】阿里云弹性计算ESSD云盘产品全面解析

摘要: 2018年3月29日,在深圳云栖大会弹性计算技术专场上,来自阿里云弹性计算产品专家崆闻做了主题为<百万级别IOPS云盘产品全面解析>的技术分享,主要就阿里云新一代ESSD云盘的产品特点.适用业务场景和对业务的实际性能提升进行了深度解读. 2018年3月29日,在深圳云栖大会弹性计算技术专场上,来自阿里云弹性计算产品专家崆闻做了主题为<百万级别IOPS云盘产品全面解析>的技术分享,主要就阿里云新一代ESSD云盘的产品特点.适用业务场景和对业务的实际性能提升进行了深度解读. 阿

华为云全新计算实例C6、S6商用,智能加速“引擎”再度开启

华为云全新计算实例C6.S6商用,智能加速"引擎"再度开启近年来,人工智能的快速发展给云计算能力带来新的挑战,数据与训练的指数级增长激发了对算力巨大的需求.同时,随着数字世界向智能世界的转变,行业"+智能"开始成为各行各业构建竞争力的关键所在.4月3日,华为2019"+智能,计算进化 FusionServer Pro 智能服务器"新品发布会举办.在会上,华为云宣布国内首个搭载新一代英特尔?至强?Cascade Lake处理器以及华为自研高性能智能

基于MATLAB实现的云模型计算隶属度

”云”或者’云滴‘是云模型的基本单元,所谓云是指在其论域上的一个分布,可以用联合概率的形式(x, u)来表示 云模型用三个数据来表示其特征 期望:云滴在论域空间分布的期望,一般用符号Εx表示. 熵:不确定程度,由离散程度和模糊程度共同决定,一般用En表示. 超熵: 用来度量熵的不确定性,既熵的熵,一般用符号He表示. 云有两种发生器:正向云发生器和逆向云发生器,分别用来生成足够的云滴和计算云数字特征(Ex, En,He). 正向云发生器: 1.生成以En为期望,以He^2为方差的正态随机数En’

阿里云弹性计算服务ECS基本概念(第二章)

第二章:弹性计算服务ECS基本概念四.ECS产品概念ECS,是由多个并列,又相互关联的产品概念组成,包括在介绍产品概念之前,先需要理解两个重要的逻辑位置概念Region,地域,是阿里云提供云计算服务的城市位置.一般一个Region会覆盖一片区域,如北京地域覆盖华北区域Zone,可用区,是一个Region下,电力和网络独立,软件故障隔离的物理数据中心.可用区的开放,目的是容许用户自行选择资源的分配策略如何选择Rgion和ZoneECS产品概念之间的关系五.ECS实例介绍ECS实例概念与实例规格实例