47 lines
1.3 KiB
C++
47 lines
1.3 KiB
C++
#pragma once
|
|
#include "vde/spatial/spatial_index.h"
|
|
#include "vde/core/aabb.h"
|
|
#include <queue>
|
|
#include <limits>
|
|
|
|
namespace vde::spatial {
|
|
using core::Point3D;
|
|
using core::Vector3D;
|
|
using core::Ray3Dd;
|
|
using core::Triangle3D;
|
|
|
|
template <typename T>
|
|
struct RTreeNode {
|
|
AABB3D bbox;
|
|
bool is_leaf = true;
|
|
std::vector<size_t> children; // internal: indices into nodes_
|
|
std::vector<size_t> item_indices; // leaf: indices into items_
|
|
size_t parent = static_cast<size_t>(-1);
|
|
};
|
|
|
|
template <typename T>
|
|
class RTree : public SpatialIndex<T> {
|
|
public:
|
|
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 { return count_; }
|
|
size_t node_count() const { return nodes_.size(); }
|
|
|
|
private:
|
|
void query_range_recursive(size_t node_idx, const AABB3D& range,
|
|
std::vector<T>& result) const;
|
|
|
|
std::vector<T> items_;
|
|
std::vector<AABB3D> item_bounds_;
|
|
std::vector<RTreeNode<T>> nodes_;
|
|
size_t root_idx_ = 0;
|
|
size_t count_ = 0;
|
|
};
|
|
|
|
} // namespace vde::spatial
|