2021SC@SDUSC
Octree.h
注释中文部分是源码解读,分析和问题在源码之后
#include <cstddef>
#include <memory>
#include <vector>
#include "open3d/geometry/Geometry3D.h"
#include "open3d/utility/IJsonConvertible.h"
namespace open3d {
namespace geometry {
class PointCloud;
class VoxelGrid;
// OctreeNode信息类class OctreeNodeInfo
// 简要的OctreeNode信息。
// OctreeNodeInfo即时计算,不与节点一起存储。
class OctreeNodeInfo {
public:
// 默认构造函数
// 所有值初始化为0.
OctreeNodeInfo() : origin_(0, 0, 0), size_(0), depth_(0), child_index_(0) {
}
// 参数化构造函数。
OctreeNodeInfo(const Eigen::Vector3d& origin,// 节点的原点坐标
const double& size,// 节点的大小
const size_t& depth,// 节点到根的深度。根是深度0。
const size_t& child_index)// 子节点索引
: origin_(origin),
size_(size),
depth_(depth),
child_index_(child_index) {
}
~OctreeNodeInfo() {
}
public:
// 节点的原点坐标
Eigen::Vector3d origin_;
// 节点的大小
double size_;
// 节点到根的深度。根是深度0。
size_t depth_;
// 子节点索引
size_t child_index_;
};
// 八叉树类class OctreeNode
// 八叉树节点的基础类。
//设计决策:不要存储节点的来源和大小
//-好:空间效率更高。
//-差:遍历时需要重新计算原点和大小。
class OctreeNode : public utility::IJsonConvertible {
public:
// 默认构造函数
OctreeNode() {
}
virtual ~OctreeNode() {
}
// 工厂函数通过解析json值来构建OctreeNode。
static std::shared_ptr<OctreeNode> ConstructFromJsonValue(
const Json::Value& value);
};
//OctreeInternalNode类,包含OctreeNode子节点。
//子节点排序约定如下。
//为了说明,假设,
// - root_node: origin == (0, 0, 0), size == 2
// - children_[0]: origin == (0, 0, 0), size == 1
// - children_[1]: origin == (1, 0, 0), size == 1, along X-axis next to child 0
// - children_[2]: origin == (0, 1, 0), size == 1, along Y-axis next to child 0
// - children_[3]: origin == (1, 1, 0), size == 1, in X-Y plane
// - children_[4]: origin == (0, 0, 1), size == 1, along Z-axis next to child 0
// - children_[5]: origin == (1, 0, 1), size == 1, in X-Z plane
// - children_[6]: origin == (0, 1, 1), size == 1, in Y-Z plane
// - children_[7]: origin == (1, 1, 1), size == 1, furthest from child 0
class OctreeInternalNode : public OctreeNode {
public:
// 默认构造函数
OctreeInternalNode() : children_(8) {
}
static std::shared_ptr<OctreeNodeInfo> GetInsertionNodeInfo(
const std::shared_ptr<OctreeNodeInfo>& node_info,
const Eigen::Vector3d& point);
//获取lambda函数