feat: Sprint 8 收尾 — KD-Tree/OcTree ray query + mesh QEM 完善
CI / Build & Test (push) Failing after 30s
CI / Release Build (push) Failing after 28s

This commit is contained in:
茂之钳
2026-07-23 14:08:34 +00:00
parent c4f7407143
commit 762ca66ee3
5 changed files with 738 additions and 135 deletions
+29
View File
@@ -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
+9 -1
View File
@@ -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_;
};