包括两种计算方法:精确计算和近似计算(思考: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.精确计算

 int GeometricalAnalysisTools::computeLocalDensity(    GenericIndexedCloudPersist* theCloud,
Density densityType,
PointCoordinateType kernelRadius,
GenericProgressCallback* progressCb/*=0*/,
DgmOctree* inputOctree/*=0*/)
{
if (!theCloud)
return -; unsigned numberOfPoints = theCloud->size();
if (numberOfPoints < )
return -; //compute the right dimensional coef based on the expected output
double dimensionalCoef = 1.0;
switch (densityType)
{
case DENSITY_KNN:
dimensionalCoef = 1.0;
break;
case DENSITY_2D:
dimensionalCoef = M_PI * (static_cast<double>(kernelRadius) * kernelRadius);
break;
case DENSITY_3D:
dimensionalCoef = s_UnitSphereVolume * ((static_cast<double>(kernelRadius) * kernelRadius) * kernelRadius);
break;
default:
assert(false);
return -;
} DgmOctree* theOctree = inputOctree;
if (!theOctree)
{
theOctree = new DgmOctree(theCloud);
if (theOctree->build(progressCb) < )
{
delete theOctree;
return -;
}
} theCloud->enableScalarField(); //determine best octree level to perform the computation
unsigned char level = theOctree->findBestLevelForAGivenNeighbourhoodSizeExtraction(kernelRadius); //parameters
void* additionalParameters[] = { static_cast<void*>(&kernelRadius),
static_cast<void*>(&dimensionalCoef) }; int result = ; if (theOctree->executeFunctionForAllCellsAtLevel( level,
&computePointsDensityInACellAtLevel,
additionalParameters,
true,
progressCb,
"Local Density Computation") == )
{
//something went wrong
result = -;
} if (!inputOctree)
delete theOctree; return result;
}

GeometricalAnalysisTools::computeLocalDensity

 //"PER-CELL" METHOD: LOCAL DENSITY
//ADDITIONNAL PARAMETERS (2):
// [0] -> (PointCoordinateType*) kernelRadius : spherical neighborhood radius
// [1] -> (ScalarType*) sphereVolume : spherical neighborhood volume
bool GeometricalAnalysisTools::computePointsDensityInACellAtLevel( const DgmOctree::octreeCell& cell,
void** additionalParameters,
NormalizedProgress* nProgress/*=0*/)
{
//parameter(s)
PointCoordinateType radius = *static_cast<PointCoordinateType*>(additionalParameters[]);
double dimensionalCoef = *static_cast<double*>(additionalParameters[]); assert(dimensionalCoef > ); //structure for nearest neighbors search
DgmOctree::NearestNeighboursSphericalSearchStruct nNSS;
nNSS.level = cell.level;
nNSS.prepare(radius,cell.parentOctree->getCellSize(nNSS.level));
cell.parentOctree->getCellPos(cell.truncatedCode,cell.level,nNSS.cellPos,true);
cell.parentOctree->computeCellCenter(nNSS.cellPos,cell.level,nNSS.cellCenter); unsigned n = cell.points->size(); //number of points in the current cell //for each point in the cell
for (unsigned i=; i<n; ++i)
{
cell.points->getPoint(i,nNSS.queryPoint); //look for neighbors inside a sphere
//warning: there may be more points at the end of nNSS.pointsInNeighbourhood than the actual nearest neighbors (neighborCount)!
unsigned neighborCount = cell.parentOctree->findNeighborsInASphereStartingFromCell(nNSS,radius,false);
//数目/体积
ScalarType density = static_cast<ScalarType>(neighborCount/dimensionalCoef);
cell.points->setPointScalarValue(i,density); if (nProgress && !nProgress->oneStep())
{
return false;
}
} return true;
}

computePointsDensityInACellAtLevel

2. 近似计算

 int GeometricalAnalysisTools::computeLocalDensityApprox(GenericIndexedCloudPersist* theCloud,
Density densityType,
GenericProgressCallback* progressCb/*=0*/,
DgmOctree* inputOctree/*=0*/)
{
if (!theCloud)
return -; unsigned numberOfPoints = theCloud->size();
if (numberOfPoints < )
return -; DgmOctree* theOctree = inputOctree;
if (!theOctree)
{
theOctree = new DgmOctree(theCloud);
if (theOctree->build(progressCb) < )
{
delete theOctree;
return -;
}
} theCloud->enableScalarField(); //determine best octree level to perform the computation
unsigned char level = theOctree->findBestLevelForAGivenPopulationPerCell(); //parameters
void* additionalParameters[] = { static_cast<void*>(&densityType) }; int result = ; if (theOctree->executeFunctionForAllCellsAtLevel( level,
&computeApproxPointsDensityInACellAtLevel,
additionalParameters,
true,
progressCb,
"Approximate Local Density Computation") == )
{
//something went wrong
result = -;
} if (!inputOctree)
delete theOctree; return result;
}
 //"PER-CELL" METHOD: APPROXIMATE LOCAL DENSITY
//ADDITIONAL PARAMETERS (0): NONE
bool GeometricalAnalysisTools::computeApproxPointsDensityInACellAtLevel(const DgmOctree::octreeCell& cell,
void** additionalParameters,
NormalizedProgress* nProgress/*=0*/)
{
//extract additional parameter(s)
Density densityType = *static_cast<Density*>(additionalParameters[]); DgmOctree::NearestNeighboursSearchStruct nNSS;
nNSS.level = cell.level;
nNSS.alreadyVisitedNeighbourhoodSize = ;
nNSS.minNumberOfNeighbors = ;
cell.parentOctree->getCellPos(cell.truncatedCode,cell.level,nNSS.cellPos,true);
cell.parentOctree->computeCellCenter(nNSS.cellPos,cell.level,nNSS.cellCenter); unsigned n = cell.points->size();
for (unsigned i=; i<n; ++i)
{
cell.points->getPoint(i,nNSS.queryPoint); //the first point is always the point itself!
if (cell.parentOctree->findNearestNeighborsStartingFromCell(nNSS) > )
{
double R2 = nNSS.pointsInNeighbourhood[].squareDistd; ScalarType density = NAN_VALUE;
if (R2 > ZERO_TOLERANCE)
{
switch (densityType)
{
case DENSITY_KNN:
{
//we return in fact the (inverse) distance to the nearest neighbor
density = static_cast<ScalarType>(1.0 / sqrt(R2));
}
break;
case DENSITY_2D:
{
//circle area (2D approximation)
double circleArea = M_PI * R2;
density = static_cast<ScalarType>(1.0 / circleArea);
}
break;
case DENSITY_3D:
{
//sphere area
double sphereArea = s_UnitSphereVolume * R2 * sqrt(R2);
density = static_cast<ScalarType>(1.0 / sphereArea);
}
break;
default:
assert(false);
break;
}
}
cell.points->setPointScalarValue(i,density);
}
else
{
//shouldn't happen! Apart if the cloud has only one point...
cell.points->setPointScalarValue(i,NAN_VALUE);
} if (nProgress && !nProgress->oneStep())
{
return false;
}
} return true;
}

computeApproxPointsDensityInACellAtLevel

double R2 = nNSS.pointsInNeighbourhood[1].squareDistd;  //索引为1的点,表示最近邻点。pi点与最近邻点之间距离的平方。

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

  1. 阿里云流计算专场-GitHub上相关文档

    阿里云流计算专场-GitHub路径:https://github.com/Alibaba-Technology/hangzhouYunQi2017ppt

  2. 荣获“5G MEC优秀商用案例奖”,阿里云边缘计算发力新零售

    4月24日,在中国联通合作伙伴大会的 “5G MEC(Mobile Edge Computing,移动边缘计算)边缘云赋能行业数字化转型”分论坛上,阿里云“基于5G边缘计算的新零售应用案例”荣获201 ...

  3. 阿里云函数计算 .NET Core 初体验

    体验了一波阿里云函数计算, 已支持 .NET Core 2.1, 那么按照惯例, 来写个 "Hello World" 吧. 作者注: 开发环境 Windows 10 & V ...

  4. 阿里云函数计算上部署.NET Core 3.1

    使用阿里云ECS或者其他常见的VPS服务部署应用的时候,需要手动配置环境,并且监测ECS的行为,做补丁之类的,搞得有点复杂.好在很多云厂商(阿里云.Azure等)提供了Serverless服务,借助于 ...

  5. 阿里云函数计算 VSCode 使用,及部署 Docusaurus

    代码: https://github.com/ikuokuo/start-serverless 使用简介 产品页开通服务.使用流程,如下: 新手示例,如下: 创建函数 阿里云提供了如下几种方式创建函数 ...

  6. 对端边缘云网络计算模式:透明计算、移动边缘计算、雾计算和Cloudlet

    对端边缘云网络计算模式:透明计算.移动边缘计算.雾计算和Cloudlet 概要 将数据发送到云端进行分析是过去几十年的一个突出趋势,推动了云计算成为主流计算范式.然而,物联网时代设备数量和数据流量的急 ...

  7. 独家对话阿里云函数计算负责人不瞋:你所不知道的 Serverless

    作者 | 杨丽 出品 | 雷锋网产业组 "Serverless 其实离我们并没有那么遥远". 如果你是一名互联网研发人员,那么极有可能了解并应用过 Serverless 这套技术体 ...

  8. 阿里云函数计算发布新功能,支持容器镜像,加速应用 Serverless 进程

    我们先通过一段视频来看看函数计算和容器相结合后,在视频转码场景下的优秀表现.点击观看视频 >> FaaS 的门槛 Serverless 形态的云服务帮助开发者承担了大量复杂的扩缩容.运维. ...

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

    ”云”或者’云滴‘是云模型的基本单元,所谓云是指在其论域上的一个分布,可以用联合概率的形式(x, u)来表示 云模型用三个数据来表示其特征 期望:云滴在论域空间分布的期望,一般用符号Εx表示. 熵:不 ...

随机推荐

  1. SQL中exists、not exists以及in、not in的区别和使用

    exists : 强调的是是否返回结果集,不要求知道返回什么, 比如:   select name from student where sex = 'm' and mark exists(selec ...

  2. (转)Java集合框架:HashMap

    来源:朱小厮 链接:http://blog.csdn.net/u013256816/article/details/50912762 Java集合框架概述 Java集合框架无论是在工作.学习.面试中都 ...

  3. java 猜数字游戏

    作用:猜数字游戏.随机产生1个数字(1~10),大了.小了或者成功后给出提示. 语言:java 工具:eclipse 作者:潇洒鸿图 时间:2016.11.10 >>>>> ...

  4. Java知识点归总一之堆栈

    Java栈与堆 (一天一个知识点2014-07-28) ----对这两个概念的不明好久,终于找到一篇好文,拿来共享 1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方.与C ...

  5. WIN32/API/SDK/MFC四者之间的联系和区别

    上面大家都说Win32是一个子系统,这个当然是对的,不过我们有时候我们所说Win32通俗的就是指32位的Windows系统,从 windows95/98到NT/2000/XP都是32位Windows. ...

  6. JS 生成GUID 方法

    var Guid={NewGuid: function () { var guid = (this._G() + this._G() +"-"+ this._G() +" ...

  7. python 进程和线程

    python中的进程.线程(threading.multiprocessing.Queue.subprocess) Python中的进程与线程 学习知识,我们不但要知其然,还是知其所以然.你做到了你就 ...

  8. Daily Scrum02 12.09

    今天星期一,各们课程要结课了,同时也是众多大作业要提交的时间, 但是我们仍然要继续坚持! 引用拿破仑将军的一句话, 最困难之日便是离成功不远之时! Member 任务进度 下一步工作 吴文会 寻找美术 ...

  9. STM32环境搭建/学习观点/自学方法 入门必看

    文章转自armfly开发板V4软件开发手册,分享学习~ 今天有幸看到armfly的开发板软件开发手册,开头的基础知识,真的很有用,还好有看到,一切都不迟,感悟很多,摘抄部分,学习分享~ 关于开发环境的 ...

  10. vs 调试的时候 使用IP地址,局域网的设备可以访问并调试

    由于项目中主要是用于微信端的访问,所以使用PC来调试就很麻烦,那么就想到用IP地址来调试,那么就手机或者移动端就可以访问,并且进行调试了 那么,主要的设置如下几步: 1. 首先保证你的项目的属性的服务 ...