Voxvision  1
Creating and manipulating voxel octrees
mtree.h
Go to the documentation of this file.
1 
8 #ifndef __MTREE_H_
9 #define __MTREE_H_
10 #include "../voxvision.h"
11 
17 struct vox_sphere {
18  vox_dot center;
21  vox_dot color;
30  float radius;
33  float sqr_radius;
39 };
40 
41 #ifdef VOXTREES_SOURCE
42 // It's here only for tests
43 //#define MTREE_MAX_CHILDREN 3 // > 2
44 #define MTREE_MAX_CHILDREN 9 // 128 bytes in memory
45 
46 struct vox_mtree_node {
47  struct vox_sphere bounding_sphere;
48  struct vox_mtree_node *parent;
49  unsigned int leaf;
50  unsigned int num;
51  union {
52  // Leave room for extra one which will cause a split
53  struct vox_mtree_node *children[MTREE_MAX_CHILDREN+1];
54  struct vox_sphere *spheres; // Pointer to an array of MAX_CHILDREN+1 spheres
55  } data;
56 };
57 #else
58 struct vox_mtree_node;
59 #endif
60 
73 VOX_EXPORT int vox_mtree_add_sphere (struct vox_mtree_node **nodeptr, const struct vox_sphere *s);
74 
86 VOX_EXPORT int vox_mtree_remove_sphere (struct vox_mtree_node **nodeptr, const struct vox_sphere *s);
87 
91 VOX_EXPORT void vox_mtree_destroy (struct vox_mtree_node *node);
92 
98 VOX_EXPORT void vox_mtree_dump (const struct vox_mtree_node *node);
99 
103 VOX_EXPORT unsigned int vox_mtree_items (const struct vox_mtree_node *node);
104 
112 VOX_EXPORT const struct vox_mtree_node*
113 vox_mtree_contains_sphere (const struct vox_mtree_node *node,
114  const struct vox_sphere *s);
115 
124 VOX_EXPORT void vox_mtree_spheres_containing (const struct vox_mtree_node *node,
125  const vox_dot dot,
126  void (^block)(const struct vox_sphere *s));
127 
142 VOX_EXPORT void
143 vox_mtree_spheres_containing_f (const struct vox_mtree_node *node, const vox_dot dot,
144  void (*callback)(const struct vox_sphere *s, void *arg),
145  void *thunk);
146 #endif
VOX_EXPORT void vox_mtree_spheres_containing(const struct vox_mtree_node *node, const vox_dot dot, void(^block)(const struct vox_sphere *s))
Do a job for all spheres which contain a specific dot.
VOX_EXPORT unsigned int vox_mtree_items(const struct vox_mtree_node *node)
Get a number of items (spheres) in M-tree.
VOX_EXPORT int vox_mtree_add_sphere(struct vox_mtree_node **nodeptr, const struct vox_sphere *s)
Add a sphere to an M-tree.
VOX_EXPORT void vox_mtree_destroy(struct vox_mtree_node *node)
Destroy a tree, freeing all used space.
VOX_EXPORT void vox_mtree_dump(const struct vox_mtree_node *node)
Dump a tree to stdout.
VOX_EXPORT int vox_mtree_remove_sphere(struct vox_mtree_node **nodeptr, const struct vox_sphere *s)
Remove sphere from a tree.
VOX_EXPORT const struct vox_mtree_node * vox_mtree_contains_sphere(const struct vox_mtree_node *node, const struct vox_sphere *s)
Check if a sphere is in a tree.
VOX_EXPORT void vox_mtree_spheres_containing_f(const struct vox_mtree_node *node, const vox_dot dot, void(*callback)(const struct vox_sphere *s, void *arg), void *thunk)
Callback-styled version of vox_mtree_spheres_containing().
Sphere structure.
Definition: mtree.h:17
vox_dot color
Color of the sphere.
Definition: mtree.h:21
float radius
Radius of the sphere.
Definition: mtree.h:30
float sqr_radius
Square of the sphere's radius.
Definition: mtree.h:33
vox_dot center
Center of the sphere.
Definition: mtree.h:18