包括两种计算方法:精确计算和近似计算(思考: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. 大部分人都会做错的经典JS闭包面试题

    由工作中演变而来的面试题 这是一个我工作当中的遇到的一个问题,似乎很有趣,就当做了一道题去面试,发现几乎没人能全部答对并说出原因,遂拿出来聊一聊吧. 先看题目代码: function fun(n,o) ...

  2. Linux第01天

    Linux第01天 1.虚拟机安装linux(centos 32bit) 1.1 虚拟机安装前置工作的准备,如内存.硬盘.CPU分配.镜像下载等 1.2 安装方式(图形界面或者命令行 推荐图形界面即直 ...

  3. [leetcode] 47. Permutations II

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  4. HTTP 头字段总结

    1. Accept: 告诉WEB服务器自己接受什么介质类型,/ 表示任何类型,type/* 表示该类型下的所有子类型,type/sub-type.2. Accept-Charset: 浏览器申明自己接 ...

  5. Node.js-视图引擎【1】-Swig集成express的安装与配置

    node.js视图引擎,选来选去发现Swig最符合我的胃口哈哈. 一.安装Swig视图引擎 npm install -g swig 二.在node.js代码中配置如下 var app = requir ...

  6. 李洪强iOS经典面试题139-Swift

    李洪强iOS经典面试题139-Swift Swift 网上有很多Swift的语法题,但是Swift现在语法还未稳定,所以在这里暂时不贴出语法题,可以自行搜索. Swift和Objective-C的联系 ...

  7. ArrayList 实现删除重复元素(元素为对象类型)

    package 集合; import java.util.ArrayList;import java.util.Iterator; /* * 删除集合中的重复的元素(元素是对象形式的) *  * Li ...

  8. Maya Plugin 编译Maya插件

    Maya自身的功能就已经非常强大了,但是更棒的是它的扩展性非常强,提供API让用户自己来编写插件Plugin.Maya的插件主要是两种,一种是用C++编写的,后缀为".mll",另 ...

  9. *HDU1053 哈夫曼编码

    Entropy Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  10. python与正则表达式

    匹配一个字符: . 任意非\n字符 [...] \d \D digit \s \S space \w \W word 匹配前一个字符的多个: * 0->> + 1->> ? 0 ...