ViewDesignEngine  3.1.0
高性能 CAD 计算几何引擎
octree.h
浏览该文件的文档.
1 
11 #pragma once
12 #include "vde/core/aabb.h"
14 #include <memory>
15 
16 namespace vde::spatial {
17 using core::Point3D;
18 using core::Vector3D;
19 using core::Ray3Dd;
20 using core::Triangle3D;
21 
22 template <typename T> struct OctreeNode;
23 template <typename T> struct OctreeData;
24 
50 template <typename T>
51 class Octree : public SpatialIndex<T> {
52 public:
59  explicit Octree(int max_depth = 8, int max_items = 16);
60 
69  void build(const std::vector<T>& items) override;
70 
79  void insert(const T& item) override;
80 
87  bool remove(const T& item) override;
88 
97  std::vector<T> query_range(const AABB3D& range) const override;
98 
108  std::vector<T> query_knn(const Point3D& point, size_t k) const override;
109 
118  std::vector<T> query_ray(const Ray3Dd& ray) const override;
119 
123  void clear() override;
124 
130  size_t size() const override;
131 
132 private:
140  void insert_recursive(int node_idx, const T& item, int depth);
141 
150  void subdivide_recursive(int node_idx, int depth);
151 
159  void query_range_recursive(int node_idx, const AABB3D& range,
160  std::vector<T>& result) const;
161 
169  void query_ray_recursive(int node_idx, const Ray3Dd& ray,
170  std::vector<T>& result) const;
171 
178  static Point3D get_position(const T& item);
179 
180  std::shared_ptr<OctreeData<T>> data_;
181  int max_depth_;
182  int max_items_;
183 };
184 
185 } // namespace vde::spatial
八叉树空间索引
Definition: octree.h:51
std::vector< T > query_knn(const Point3D &point, size_t k) const override
K 近邻查询
void insert(const T &item) override
增量插入对象
bool remove(const T &item) override
删除对象
std::vector< T > query_range(const AABB3D &range) const override
范围查询
void clear() override
清空八叉树
void build(const std::vector< T > &items) override
批量构建八叉树
size_t size() const override
当前索引中的对象数量
Octree(int max_depth=8, int max_items=16)
构造八叉树
std::vector< T > query_ray(const Ray3Dd &ray) const override
射线查询
空间索引抽象基类
Definition: spatial_index.h:44
Ray3D< double > Ray3Dd
双精度三维射线
Definition: line.h:141
Triangle< double > Triangle3D
双精度三维三角形
Definition: triangle.h:105
AABB< double > AABB3D
双精度三维包围盒
Definition: aabb.h:131
foundation::Vector3D Vector3D
双精度三维向量(重新导出)
Definition: point.h:49
foundation::Point3D Point3D
双精度三维点(重新导出)
Definition: point.h:31
空间索引抽象基类