feat: Sprint 8 收尾 — KD-Tree/OcTree ray query + mesh QEM 完善
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
#pragma once
|
||||
#include "vde/spatial/spatial_index.h"
|
||||
#include <vector>
|
||||
|
||||
namespace vde::spatial {
|
||||
using core::AABB3D;
|
||||
using core::Point3D;
|
||||
using core::Vector3D;
|
||||
using core::Ray3Dd;
|
||||
using core::Triangle3D;
|
||||
|
||||
template <typename T>
|
||||
class KDTree : public SpatialIndex<T> {
|
||||
@@ -17,8 +20,34 @@ public:
|
||||
std::vector<T> query_ray(const Ray3Dd& ray) const override;
|
||||
void clear() override;
|
||||
size_t size() const override { return items_.size(); }
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
AABB3D bounds;
|
||||
int item_idx = -1; // -1 for internal node; index into items_ for leaf
|
||||
int split_axis = 0;
|
||||
int left = -1;
|
||||
int right = -1;
|
||||
};
|
||||
|
||||
std::vector<T> items_;
|
||||
std::vector<Node> nodes_;
|
||||
int root_ = -1;
|
||||
|
||||
/// Return a representative 3D position for the item (used for spatial ordering)
|
||||
static Point3D get_position(const T& item);
|
||||
|
||||
/// Return an axis-aligned bounding box for the item
|
||||
static AABB3D get_aabb(const T& item);
|
||||
|
||||
/// Test whether the item intersects a ray
|
||||
static bool ray_hits_item(const T& item, const Ray3Dd& ray);
|
||||
|
||||
int build_recursive(int start, int end);
|
||||
void query_range_recursive(int node_idx, const AABB3D& range,
|
||||
std::vector<T>& result) const;
|
||||
void query_ray_recursive(int node_idx, const Ray3Dd& ray,
|
||||
std::vector<T>& result) const;
|
||||
};
|
||||
|
||||
} // namespace vde::spatial
|
||||
|
||||
@@ -24,10 +24,18 @@ public:
|
||||
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;
|
||||
void query_range_recursive(int node_idx, const AABB3D& range,
|
||||
std::vector<T>& result) const;
|
||||
void query_ray_recursive(int node_idx, const Ray3Dd& ray,
|
||||
std::vector<T>& result) const;
|
||||
|
||||
/// Item position helper (for non-Point3D types)
|
||||
static Point3D get_position(const T& item);
|
||||
|
||||
std::shared_ptr<OctreeData<T>> data_;
|
||||
int max_depth_, max_items_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user