// SPDX-License-Identifier: LGPL-2.0-or-later
// Copyright © EDF R&D / TELECOM ParisTech (ENST-TSI)
#include <DgmOctree.h>
//local
#include <CCMiscTools.h>
#include <GenericProgressCallback.h>
#include <ParallelSort.h>
#include <RayAndBox.h>
#include <ReferenceCloud.h>
#include <ScalarField.h>
//system
#include <cstdio>
#include <utility>
//DGM: tests in progress
//#define COMPUTE_NN_SEARCH_STATISTICS
//#define ADAPTATIVE_BINARY_SEARCH
#ifndef CC_DEBUG
//enables multi-threading handling (Release only)
//requires TBB or QtConcurrent
#if defined(CC_CORE_LIB_USES_QT_CONCURRENT)
#define ENABLE_MT_OCTREE
#include <QThread>
#include <QThreadPool>
#include <QtConcurrentMap>
#include <QCoreApplication>
#elif defined(CC_CORE_LIB_USES_TBB)
#define ENABLE_MT_OCTREE
#include <algorithm>
#include <tbb/parallel_for.h>
#endif
#endif // #ifndef CC_DEBUG
namespace CCCoreLib
{
/**********************************/
/* PRE COMPUTED VALUES AND TABLES */
/**********************************/
//! Const value: ln(2)
static const double LOG_NAT_2 = log(2.0);
//! Pre-computed bit shift values (one for each level)
struct BitShiftValues
{
//! Default initialization
BitShiftValues()
{
//we compute all possible values
for (unsigned char level = 0; level <= DgmOctree::MAX_OCTREE_LEVEL; ++level)
{
values[level] = (3 * (DgmOctree::MAX_OCTREE_LEVEL - level));
}
}
//! Values
unsigned char values[DgmOctree::MAX_OCTREE_LEVEL + 1];
};
static BitShiftValues PRE_COMPUTED_BIT_SHIFT_VALUES;
//! Pre-computed cell codes for all potential cell positions (along a unique dimension)
struct MonoDimensionalCellCodes
{
//! Total number of positions/values
/** There are 1024 possible values at level 10, and 2M. at level 21.
\warning Never pass a 'constant initializer' by reference
**/
static const int VALUE_COUNT = DgmOctree::MAX_OCTREE_LENGTH;
//! Default initialization
MonoDimensionalCellCodes()
{
//we compute all possible values for cell codes
//(along a unique dimension, the other ones are just shifted)
for (int value = 0; value < VALUE_COUNT; ++value)
{
int mask = VALUE_COUNT;
DgmOctree::CellCode code = 0;
for (unsigned char k = 0; k < DgmOctree::MAX_OCTREE_LEVEL; k++)
{
mask >>= 1;
code <<= 3;
if (value & mask)
{
code |= 1;
}
}
values[value] = code;
}
//we compute all possible masks as well! (all dimensions)
//DgmOctree::CellCode baseMask = (1 << (3 * DgmOctree::MAX_OCTREE_LEVEL));
//for (int level = DgmOctree::MAX_OCTREE_LEVEL; level >= 0; --level)
//{
// masks[level] = baseMask - 1;
// baseMask >>= 3;
//}
}
//! Mono-dimensional cell codes
DgmOctree::CellCode values[VALUE_COUNT];
//! Mono-dimensional cell masks
//DgmOctree::CellCode masks[DgmOctree::MAX_OCTREE_LEVEL + 1];
};
static MonoDimensionalCellCodes PRE_COMPUTED_POS_CODES;
#ifdef ENABLE_MT_OCTREE
//! Octree cell description helper struct
struct octreeCellDesc
{
DgmOctree::CellCode truncatedCode;
unsigned i1, i2;
unsigned char level;
};
//! Structure containing objects needed to run octree operations in parallel
struct MultiThreadingWrapper
{
DgmOctree* octree = nullptr;
DgmOctree::octreeCellFunc cell_func = nullptr;
void** userParams = nullptr;
GenericProgressCallback* progressCb = nullptr;
NormalizedProgress* normProgressCb = nullptr;
bool cellFunc_success = true;
void launchOctreeCellFunc(const octreeCellDesc& desc)
{
//skip cell if process is aborted/has failed
if (!cellFunc_success)
{
return;
}
const DgmOctree::cellsContainer& pointsAndCodes = octree->pointsAndTheirCellCodes();
//cell descriptor
DgmOctree::octreeCell cell(octree);
cell.level = desc.level;
cell.index = desc.i1;
cell.truncatedCode = desc.truncatedCode;
if (cell.points->reserve(desc.i2 - desc.i1 + 1))
{
for (unsigned i = desc.i1; i <= desc.i2; ++i)
{
cell.points->addPointIndex(pointsAndCodes[i].theIndex);
}
cellFunc_success &= (*cell_func)(cell, userParams, normProgressCb);
if (normProgressCb)
{
QCoreApplication::processEvents(QEventLoop::EventLoopExec); // to allow the GUI to refresh itself
}
}
else
{
cellFunc_success = false;
}
if (!cellFunc_success)
{
//TODO: display a message to make clear that the cancel order has been acknowledged!
if (progressCb)
{
if (progressCb->textCanBeEdited())
{
progressCb->setInfo("Cancelling...");
}
}
//if (normProgressCb)
//{
// if (!normProgressCb->oneStep())
// {
// cellFunc_success = false;
// return;
// }
//}
}
}
};
#endif
}
using namespace CCCoreLib;
/**********************************/
/* STATIC ACCESSORS */
/**********************************/
unsigned char DgmOctree::GET_BIT_SHIFT(unsigned char level)
{
//return (3 * (DgmOctree::MAX_OCTREE_LEVEL - level));
return PRE_COMPUTED_BIT_SHIFT_VALUES.values[level];
}
int DgmOctree::OCTREE_LENGTH(int level)
{
return (1 << level);
}
DgmOctree::CellCode DgmOctree::GenerateTruncatedCellCode(const Tuple3i& cellPos, unsigned char level)
{
assert( cellPos.x >= 0 && cellPos.x < MonoDimensionalCellCodes::VALUE_COUNT
&& cellPos.y >= 0 && cellPos.y < MonoDimensionalCellCodes::VALUE_COUNT
&& cellPos.z >= 0 && cellPos.z < MonoDimensionalCellCodes::VALUE_COUNT);
const unsigned char shift = MAX_OCTREE_LEVEL - level;
return (
PRE_COMPUTED_POS_CODES.values[cellPos.x << shift]
| (PRE_COMPUTED_POS_CODES.values[cellPos.y << shift] << 1)
| (PRE_COMPUTED_POS_CODES.values[cellPos.z << shift] << 2)
) >> GET_BIT_SHIFT(level);
}
#ifndef OCTREE_CODES_64_BITS
DgmOctree::CellCode DgmOctree::GenerateTruncatedCellCode(const Tuple3s& cellPos, unsigned char level)
{
assert( cellPos.x >= 0 && cellPos.x < MonoDimensionalCellCodes::VALUE_COUNT
&& cellPos.y >= 0 && cellPos.y < MonoDimensionalCellCodes::VALUE_COUNT
&& cellPos.z >= 0 && cellPos.z < MonoDimensionalCellCodes::VALUE_COUNT);
const unsigned char shift = MAX_OCTREE_LEVEL - level;
return
( PRE_COMPUTED_POS_CODES.values[cellPos.x << shift]
| (PRE_COMPUTED_POS_CODES.values[cellPos.y << shift] << 1)
| (PRE_COMPUTED_POS_CODES.values[cellPos.z << shift] << 2)
) >> GET_BIT_SHIFT(level);
}
#endif
static inline DgmOctree::CellCode GenerateCellCodeForDim(int pos)
{
return PRE_COMPUTED_POS_CODES.values[pos];
}
bool DgmOctree::MultiThreadSupport()
{
#ifdef ENABLE_MT_OCTREE
return true;
#else
return false;
#endif
}
/**********************************/
/* EVERYTHING ELSE! */
/**********************************/
DgmOctree::DgmOctree(GenericIndexedCloudPersist* cloud)
: m_theAssociatedCloud(cloud)
, m_numberOfProjectedPoints(0)
, m_nearestPow2(0)
, m_MT_wrapper(nullptr)
{
clear();
#ifdef ENABLE_MT_OCTREE
m_MT_wrapper = new MultiThreadingWrapper;
#endif
assert(m_theAssociatedCloud);
}
DgmOctree::~DgmOctree()
{
#ifdef ENABLE_MT_OCTREE
delete m_MT_wrapper;
m_MT_wrapper = nullptr;
#endif
}
void DgmOctree::clear()
{
//reset internal tables
m_dimMin = m_pointsMin = m_dimMax = m_pointsMax = CCVector3(0, 0, 0);
m_numberOfProjectedPoints = 0;
m_nearestPow2 = 0;
m_thePointsAndTheirCellCodes.resize(0);
memset(m_fillIndexes, 0, sizeof(int)*(MAX_OCTREE_LEVEL + 1) * 6);
memset(m_cellSize, 0, sizeof(PointCoordinateType)*(MAX_OCTREE_LEVEL + 2));
updateCellCountTable();
}
int DgmOctree::build(GenericProgressCallback* progressCb)
{
if (!m_theAssociatedCloud)
{
assert(false);
return -1;
}
if (!m_thePointsAndTheirCellCodes.empty())
{
clear();
}
m_theAssociatedCloud->getBoundingBox(m_pointsMin, m_pointsMax);
m_dimMin = m_pointsMin;
m_dimMax = m_pointsMax;
//we make this bounding-box cubical (+0.1% growth to avoid round-off issues when projecting points in the octree)
CCMiscTools::MakeMinAndMaxCubical(m_dimMin, m_dimMax, 0.001);
return genericBuild(progressCb);
}
int DgmOctree:
没有合适的资源?快使用搜索试试~ 我知道了~
CCCoreLib源码、lib、dll(vs2019编译器)适用于QtCreator工程打开
共102个文件
h:63个
cpp:34个
user:1个
4 下载量 122 浏览量
2023-06-28
16:50:46
上传
评论
收藏 567KB ZIP 举报
温馨提示
CloudCompare软件的核心算法库,使用QtCreator创建的工程 使用VS2019编译器进行编译
资源推荐
资源详情
资源评论
收起资源包目录
CCCoreLib源码、lib、dll(vs2019编译器)适用于QtCreator工程打开 (102个子文件)
DgmOctree.cpp 120KB
DistanceComputationTools.cpp 94KB
RegistrationTools.cpp 52KB
ManualSegmentationTools.cpp 40KB
GeometricalAnalysisTools.cpp 34KB
Neighbourhood.cpp 26KB
CloudSamplingTools.cpp 24KB
PointProjectionTools.cpp 22KB
Kriging.cpp 22KB
ScalarFieldTools.cpp 20KB
KdTree.cpp 16KB
Delaunay2dMesh.cpp 13KB
StatisticalTestingTools.cpp 12KB
CCMiscTools.cpp 11KB
MeshSamplingTools.cpp 10KB
WeibullDistribution.cpp 10KB
TrueKdTree.cpp 9KB
FastMarching.cpp 8KB
AutoSegmentationTools.cpp 7KB
GridAndMeshIntersection.cpp 7KB
SaitoSquaredDistanceTransform.cpp 7KB
ChamferDistanceTransform.cpp 7KB
FastMarchingForPropagation.cpp 6KB
NormalDistribution.cpp 6KB
LocalModel.cpp 5KB
ReferenceCloud.cpp 4KB
SimpleMesh.cpp 4KB
NormalizedProgress.cpp 2KB
ErrorFunction.cpp 2KB
ScalarField.cpp 2KB
DgmOctreeReferenceCloud.cpp 2KB
CCShareable.cpp 1KB
Polyline.cpp 372B
ccRegistrationTools.cpp 96B
CCCoreLib.dll 518KB
DgmOctree.h 50KB
DistanceComputationTools.h 28KB
SquareMatrix.h 28KB
PointCloudTpl.h 17KB
Grid3D.h 16KB
CCGeom.h 16KB
RegistrationTools.h 14KB
CloudSamplingTools.h 13KB
Jacobi.h 12KB
GeometricalAnalysisTools.h 11KB
Neighbourhood.h 10KB
ScalarFieldTools.h 9KB
KdTree.h 9KB
ReferenceCloud.h 8KB
FastMarching.h 7KB
PointProjectionTools.h 7KB
BoundingBox.h 6KB
MeshSamplingTools.h 6KB
StatisticalTestingTools.h 6KB
ManualSegmentationTools.h 5KB
AutoSegmentationTools.h 5KB
Chi2Helper.h 5KB
Delaunay2dMesh.h 5KB
TrueKdTree.h 5KB
GridAndMeshIntersection.h 4KB
ScalarField.h 4KB
GenericProgressCallback.h 4KB
Kriging.h 4KB
WeibullDistribution.h 4KB
GenericCloud.h 4KB
FastMarchingForPropagation.h 4KB
CCConst.h 3KB
SimpleMesh.h 3KB
NormalDistribution.h 3KB
GenericDistribution.h 3KB
ConjugateGradient.h 3KB
GenericIndexedMesh.h 3KB
CCMiscTools.h 3KB
CCMath.h 3KB
DgmOctreeReferenceCloud.h 3KB
SaitoSquaredDistanceTransform.h 3KB
RayAndBox.h 3KB
SimpleTriangle.h 2KB
PointCloud.h 2KB
Garbage.h 2KB
GenericIndexedCloud.h 2KB
GenericMesh.h 2KB
LocalModel.h 2KB
ChamferDistanceTransform.h 2KB
ErrorFunction.h 1KB
GenericIndexedCloudPersist.h 1KB
CCShareable.h 1KB
Polyline.h 856B
GenericTriangle.h 629B
CCPlatform.h 613B
ParallelSort.h 594B
CCCoreLib.h 429B
GenericOctree.h 382B
CCToolbox.h 268B
CCCoreLib_global.h 252B
CCTypes.h 251B
MathTools.h 242B
ccRegistrationTools.h 203B
nanoflann.hpp 71KB
CCCoreLib.lib 371KB
共 102 条
- 1
- 2
资源评论
《雨声》
- 粉丝: 53
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 电力场景安全帽检测数据集VOC+YOLO格式295张2类别.7z
- MISC图片隐写MISC图片隐写MISC图片隐写MISC图片隐写MISC图片隐写.txt
- 七维大脑原理:探索人类心智的多元维度.txt
- 电力场景设备漏油检测数据集VOC+YOLO格式338张1类别.7z
- 基于yolov8+pyqt5实现精美界面支持图片视频和摄像检测源码.zip
- 用C语言为母亲节献上一份特别的祝福.zip
- LCD1602液晶显示屏的深入探索与实用指南.zip
- 基于Matlab人脸肤色定理的教师人数统计+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab霍夫曼变换的表盘读数识别+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab火灾烟雾检测源码带GUI界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功