-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoctree.h
51 lines (42 loc) · 1.21 KB
/
octree.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include "cthing.h"
#include "data/tree.h"
#include "math/vec.h"
#include "mem/mpool.h"
CT_BEGIN_DECLS
typedef struct CT_OTNode CT_OTNode;
struct CT_OTNode {
CT_OTNode *children[8];
CT_Vec3f *point;
void *data;
union {
struct {
float x, cx, y, cy, z, cz, w, h, d;
};
float coords[9];
};
size_t type;
};
typedef struct {
CT_OTNode root;
CT_MPool pool;
size_t size;
} CT_Octree;
typedef int (*CT_OTVisitor)(const CT_OTNode *, void *);
int ct_octree_init(CT_Octree *t,
float x,
float y,
float z,
float w,
float h,
float d,
size_t poolSize);
void ct_octree_free(CT_Octree *t);
int ct_octree_insert(CT_Octree *t, const CT_Vec3f *p, const void *data);
int ct_octree_remove(CT_Octree *t, const CT_Vec3f *p);
CT_OTNode *ct_octree_find_leaf(const CT_Octree *t, const CT_Vec3f *p);
void ct_octree_trace_node(const CT_OTNode *t, size_t depth);
void ct_octree_trace(const CT_Octree *t);
int ct_octree_visit_leaves(const CT_Octree *t, CT_OTVisitor visit, void *state);
void ct_octree_visit(const CT_Octree *t, CT_OTVisitor visit, void *state);
CT_END_DECLS