v0.1.0: 初始工程骨架 — 7模块 40头文件 32源文件 17文档 Apache-2.0

This commit is contained in:
ViewDesignEngine
2026-07-23 05:27:51 +00:00
commit 02d0520aa5
133 changed files with 5350 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include "vde/spatial/spatial_index.h"
#include "vde/core/aabb.h"
#include "vde/core/triangle.h"
namespace vde::spatial {
enum class BVHSplitStrategy { Middle, Equal, SAH };
struct BVHBuildOptions {
BVHSplitStrategy strategy = BVHSplitStrategy::SAH;
int leaf_size = 4;
int max_depth = 64;
};
class BVH : public SpatialIndex<Triangle3D> {
public:
explicit BVH(const BVHBuildOptions& opts = {}) : opts_(opts) {}
void build(const std::vector<Triangle3D>& tris) override;
void insert(const Triangle3D& tri) override;
bool remove(const Triangle3D& tri) override;
std::vector<Triangle3D> query_range(const AABB3D& range) const override;
std::vector<Triangle3D> query_knn(const Point3D& point, size_t k) const override;
std::vector<Triangle3D> query_ray(const Ray3Dd& ray) const override;
void clear() override;
size_t size() const override { return primitives_.size(); }
/// Find closest hit along ray
struct HitResult { double t; Triangle3D tri; Point3D point; };
std::optional<HitResult> query_ray_nearest(const Ray3Dd& ray) const;
private:
struct Node {
AABB3D bounds;
int left = -1, right = -1;
int first_prim = 0, prim_count = 0;
bool leaf() const { return left < 0; }
};
std::vector<Node> nodes_;
std::vector<Triangle3D> primitives_;
BVHBuildOptions opts_;
void build_recursive(int node, int first, int count, int depth);
double sah_cost(int n_left, int n_right, const AABB3D& left, const AABB3D& right) const;
};
} // namespace vde::spatial