载入中...
搜索中...
未找到
Octree.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "spatial/Bounds.h"
6#include "spatial/QueryIds.h"
7
8#include <memory>
9#include <unordered_map>
10#include <vector>
11
12namespace eve::spatial {
13
19public:
21 Octree(float minX, float minY, float minZ, float maxX, float maxY, float maxZ,
22 int maxDepth = 8, int maxPerNode = 8);
24 ~Octree() = default;
25
26 Octree(const Octree &) = delete;
27 Octree &operator=(const Octree &) = delete;
28
30 void clear();
32 bool insert(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
34 bool remove(int id);
36 bool update(int id, float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
38 bool contains(int id) const;
40 int getCount() const { return static_cast<int>(items_.size()); }
41
43 int queryPoint(float x, float y, float z);
45 int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
47 int querySphere(float cx, float cy, float cz, float radius);
48
50 int getResultCount() const { return results_.getCount(); }
52 int getResultId(int index) const { return results_.getId(index); }
53
55 float getMinX() const { return rootBounds_.minX; }
57 float getMinY() const { return rootBounds_.minY; }
59 float getMinZ() const { return rootBounds_.minZ; }
61 float getMaxX() const { return rootBounds_.maxX; }
63 float getMaxY() const { return rootBounds_.maxY; }
65 float getMaxZ() const { return rootBounds_.maxZ; }
67 int getMaxDepth() const { return maxDepth_; }
69 int getMaxPerNode() const { return maxPerNode_; }
70
71private:
72 struct Node {
74 int depth = 0;
75 std::vector<int> itemIds;
76 std::unique_ptr<Node> children[8];
77 bool isLeaf() const { return children[0] == nullptr; }
78 };
79
80 void rebuild();
81 bool insertInto(Node &node, int id, const AABB3 &bounds);
82 void split(Node &node);
83 void collect(Node &node, const AABB3 *box, float cx, float cy, float cz, float radius,
84 bool useSphere);
85 Node *ensureRoot();
86
87 AABB3 rootBounds_;
88 int maxDepth_ = 8;
89 int maxPerNode_ = 8;
90 std::unique_ptr<Node> root_;
91 std::unordered_map<int, AABB3> items_;
92 QueryIds results_;
93};
94
95} // namespace eve::spatial
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float cx
Definition CardTypes.cpp:33
float cy
Definition CardTypes.cpp:34
bool split
Definition CaveMesh.cpp:123
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
float radius
const RoadNode * node
int children
Definition TreeMesh.cpp:295
uint32_t index
std::uint32_t depth
Region octree for 3D AABB broad-phase / scene culling. Same storage rules as QuadTree (smallest fully...
Definition Octree.h:18
Octree(const Octree &)=delete
float getMaxZ() const
Root/world maximum Z.
Definition Octree.h:65
int getMaxPerNode() const
Item capacity before a node splits.
Definition Octree.h:69
float getMinZ() const
Root/world minimum Z.
Definition Octree.h:59
float getMinX() const
Root/world minimum X.
Definition Octree.h:55
float getMaxY() const
Root/world maximum Y.
Definition Octree.h:63
Octree & operator=(const Octree &)=delete
int getResultCount() const
Number of hits from the last query*.
Definition Octree.h:50
int getMaxDepth() const
Maximum subdivision depth.
Definition Octree.h:67
float getMaxX() const
Root/world maximum X.
Definition Octree.h:61
int getResultId(int index) const
Hit id at dense index from the last query*, or -1.
Definition Octree.h:52
float getMinY() const
Root/world minimum Y.
Definition Octree.h:57
int getCount() const
Number of stored ids.
Definition Octree.h:40
~Octree()=default
Releases tree nodes.
Axis-aligned 3D bounding box (min/max inclusive).
Definition Bounds.h:54
glm::vec4 bounds