2026-07-23 05:27:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
#include "vde/spatial/spatial_index.h"
|
2026-07-23 06:19:19 +00:00
|
|
|
#include <memory>
|
2026-07-23 05:27:51 +00:00
|
|
|
|
|
|
|
|
namespace vde::spatial {
|
|
|
|
|
|
2026-07-23 06:19:19 +00:00
|
|
|
template <typename T> struct OctreeNode;
|
|
|
|
|
template <typename T> struct OctreeData;
|
|
|
|
|
|
2026-07-23 05:27:51 +00:00
|
|
|
template <typename T>
|
|
|
|
|
class Octree : public SpatialIndex<T> {
|
|
|
|
|
public:
|
2026-07-23 06:19:19 +00:00
|
|
|
explicit Octree(int max_depth = 8, int max_items = 16);
|
2026-07-23 05:27:51 +00:00
|
|
|
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;
|
2026-07-23 06:19:19 +00:00
|
|
|
size_t size() const override;
|
2026-07-23 05:27:51 +00:00
|
|
|
private:
|
2026-07-23 06:19:19 +00:00
|
|
|
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_;
|
2026-07-23 05:27:51 +00:00
|
|
|
int max_depth_, max_items_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace vde::spatial
|