64ad721ed7
- CMake: INTERFACE 库修复、vde_compile_options 顺序修复 - 命名空间: 所有模块添加 using 声明 - 类型补全: Ray3Dd、Point4D - 头文件: tolerance 泛型化、std::optional include - 警告: 放宽 -Wconversion/-Wsign-conversion - 构建结果: 0 errors, 22/25 tests passed
36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#pragma once
|
|
#include "vde/core/aabb.h"
|
|
#include "vde/spatial/spatial_index.h"
|
|
#include <memory>
|
|
|
|
namespace vde::spatial {
|
|
using core::Point3D;
|
|
using core::Vector3D;
|
|
using core::Ray3Dd;
|
|
using core::Triangle3D;
|
|
|
|
template <typename T> struct OctreeNode;
|
|
template <typename T> struct OctreeData;
|
|
|
|
template <typename T>
|
|
class Octree : public SpatialIndex<T> {
|
|
public:
|
|
explicit Octree(int max_depth = 8, int max_items = 16);
|
|
void build(const std::vector<T>& items) override;
|
|
void insert(const T& item) override;
|
|
bool remove(const T& item) override;
|
|
std::vector<T> query_range(const AABB3D& range) const override;
|
|
std::vector<T> query_knn(const Point3D& point, size_t k) const override;
|
|
std::vector<T> query_ray(const Ray3Dd& ray) const override;
|
|
void clear() override;
|
|
size_t size() const override;
|
|
private:
|
|
void insert_recursive(int node_idx, const T& item, int depth);
|
|
void subdivide_recursive(int node_idx, int depth);
|
|
void query_range_recursive(int node_idx, const AABB3D& range, std::vector<T>& result) const;
|
|
std::shared_ptr<OctreeData<T>> data_;
|
|
int max_depth_, max_items_;
|
|
};
|
|
|
|
} // namespace vde::spatial
|