ASCOT5
|
Simple octree for storing triangles. More...
#include <stdlib.h>
#include "ascot5.h"
#include "octree.h"
#include "list.h"
#include "wall/wall_3d.h"
Go to the source code of this file.
Functions | |
void | octree_create (octree_node **node, real x_min, real x_max, real y_min, real y_max, real z_min, real z_max, int depth) |
Create octree of given depth. | |
void | octree_free (octree_node **node) |
Free octree node and all its child nodes. | |
void | octree_add (octree_node *node, real t1[3], real t2[3], real t3[3], int id) |
Add triangle to the node(s) it belongs to. | |
list_int_node * | octree_get (octree_node *node, real p[3]) |
Get that leaf node's linked list the given coordinate belongs to. | |
Simple octree for storing triangles.
In octree each node branches to eight childnodes. Octree is used to repeatedly divide volume to eight boxes of equal size and volume until the volume in the leaf nodes is of desired size. Boxes are aligned to cartesian basis vectors.
This particular octree is intended to be used to group 3D triangles so that a triangle is assigned to an octree node whose volume the triangle belongs to. A triangle belongs to a volume if even one of its vertices is in that volume. One triangle can therefore belong to several octree leaf nodes. Only leaf nodes store triangles.
This module is used for an efficient collision check in 3D wall model.
Definition in file octree.c.
void octree_create | ( | octree_node ** | node, |
real | x_min, | ||
real | x_max, | ||
real | y_min, | ||
real | y_max, | ||
real | z_min, | ||
real | z_max, | ||
int | depth ) |
Create octree of given depth.
This function creates recursively a complete octree hierarchy with given number of levels. Each node have bounding box asigned and there is a small overlap between the boxes to avoid numerical artifact where a point is exactly between two boxes but belongs to neither.
The linked lists on leaf nodes are initialized.
node | pointer to parent node from which the octree sprawls |
x_min | minimum x coordinate of the parent node |
x_max | maximum x coordinate of the parent node |
y_min | minimum y coordinate of the parent node |
y_max | maximum y coordinate of the parent node |
z_min | minimum z coordinate of the parent node |
z_max | maximum z coordinate of the parent node |
depth | levels of octree nodes to be created. If depth=1, this node will be a leaf node. Final volume will be 1/8^(depth-1) th of the initial volume. |
void octree_free | ( | octree_node ** | node | ) |
void octree_add | ( | octree_node * | node, |
real | t1[3], | ||
real | t2[3], | ||
real | t3[3], | ||
int | id ) |
Add triangle to the node(s) it belongs to.
This function uses recursion to travel the octree and find all leaf nodes the given triangle belongs to.In other words, at each step this function determines the child node(s) the triangle belongs to and calls this function for that/those node(s).
node | octree node to which or to which child nodes triangle is added to |
t1 | triangle first vertex xyz coordinates |
t2 | triangle second vertex xyz coordinates |
t3 | triangle third vertex xyz coordinates |
id | triangle id which is stored in the node(s) the triangle belongs to |
list_int_node * octree_get | ( | octree_node * | node, |
real | p[3] ) |
Get that leaf node's linked list the given coordinate belongs to.
This function uses recursion to travel through the octree, determining at each step the correct branch to follow next until the leaf node is found. In other words, at each step this function determines the child node the point belongs to and calls this function for that node.
The point is assumed to belong to the volume of the node used in the argument.
node | octree node that is traversed |
p | xyz coordinates of the point |