4#ifndef TRAM_SDK_TEMPLATES_OCTREE_H
5#define TRAM_SDK_TEMPLATES_OCTREE_H
26 return nodes.index(new_leaf);
41 for (
int i = 0 ; i < search.
found ; i++) {
55 uint32_t
AddLeaf(T type,
float x,
float y,
float z){
56 return Insert({x, y, z}, type);
64 return Find(result, {x, y, z});
80 Node*
octants[8] = {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr};
97 for (
int i = 0; i < 8; i++)
if (
octants[i])
return true;
116 Node* existing_leaf = octant;
118 if (glm::distance(existing_leaf->
point, leaf->
point) == 0.0f) {
119 std::cout <<
"Point " << leaf->
point.x <<
" " << leaf->
point.y <<
" " << leaf->
point.z <<
" already in tree!" << std::endl;
123 octant =
NewNode(octant_type, parent);
125 Insert(octant, existing_leaf);
139 if (!node->
parent)
return;
142 for (
int i = 0; i < 8; i++) {
158 float distance[4] = {INFINITY, INFINITY, INFINITY, INFINITY};
180 for (
int i = 0 ; i < 8; i++) {
181 if (i != first_octant)
FindNearest(search, parent_node, i);
188 if (!search_node)
return;
190 if (search_node->
IsNode()) {
192 if (search->
found >= 4) {
199 if (search->
found < 4) {
200 float distance = glm::distance(search_node->
point, search->
point);
214 float distance = glm::distance(search_node->
point, search->
point);
228 for (
int i = 0; i < 4; i++) {
311 if (point.y < mid.y) {
312 if (point.x < mid.x) {
313 if (point.z < mid.z) {
319 if (point.z < mid.z) {
326 if (point.x < mid.x) {
327 if (point.z < mid.z) {
333 if (point.z < mid.z) {
369 for (
int i = 0 ; i < 8; i++) {
void Insert(Node *parent, Node *leaf)
Definition: octree.h:108
void Draw()
Definition: octree.h:48
Pool< Node > nodes
Definition: octree.h:102
Node * root
Definition: octree.h:104
void Draw(Node *node)
Definition: octree.h:343
void FindNearest(NearestSearch *search, Node *parent_node, int octant)
Definition: octree.h:185
Node * NewNode(Octant octant, Node *parent)
Definition: octree.h:256
void Remove(Node *node)
Definition: octree.h:136
size_t Find(T *array, vec3 point)
Definition: octree.h:33
Octant
Definition: octree.h:68
@ OCTANT_BOTTOM_RIGHT_FRONT
Definition: octree.h:76
@ OCTANT_BOTTOM_LEFT_BACK
Definition: octree.h:73
@ OCTANT_TOP_RIGHT_FRONT
Definition: octree.h:72
@ OCTANT_TOP_RIGHT_BACK
Definition: octree.h:71
@ OCTANT_TOP_LEFT_BACK
Definition: octree.h:69
@ OCTANT_BOTTOM_LEFT_FRONT
Definition: octree.h:74
@ OCTANT_BOTTOM_RIGHT_BACK
Definition: octree.h:75
@ OCTANT_TOP_LEFT_FRONT
Definition: octree.h:70
void Remove(uint32_t node)
Definition: octree.h:29
Octant GetOctant(vec3 mid, vec3 point)
Definition: octree.h:310
Octree(std::string name, size_t size)
Definition: octree.h:17
void RemoveLeaf(uint32_t leaf_id)
Definition: octree.h:59
uint32_t AddLeaf(T type, float x, float y, float z)
Definition: octree.h:55
size_t FindNearest(T result[], float x, float y, float z)
Definition: octree.h:63
void FindNearest(NearestSearch *search, Node *parent_node)
Definition: octree.h:175
uint32_t Insert(vec3 point, T data)
Definition: octree.h:23
glm::vec3 vec3
Definition: math.h:12
int found
Definition: octree.h:162
Node * nearest[4]
Definition: octree.h:157
float distance[4]
Definition: octree.h:158
float farthest_distance
Definition: octree.h:160
int farthest_index
Definition: octree.h:159
vec3 point
Definition: octree.h:161
Node * parent
Definition: octree.h:82
bool IsNode()
Definition: octree.h:96
float half_extent
Definition: octree.h:86
vec3 point
Definition: octree.h:88
Node * octants[8]
Definition: octree.h:80
vec3 mid_point
Definition: octree.h:84
bool IsLeaf()
Definition: octree.h:92
T data
Definition: octree.h:90