ASCOT5
Loading...
Searching...
No Matches
Functions
octree.c File Reference

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_nodeoctree_get (octree_node *node, real p[3])
 Get that leaf node's linked list the given coordinate belongs to.
 

Detailed Description

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.

See also
wall_3d.c

Definition in file octree.c.

Function Documentation

◆ octree_create()

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.

Parameters
nodepointer to parent node from which the octree sprawls
x_minminimum x coordinate of the parent node
x_maxmaximum x coordinate of the parent node
y_minminimum y coordinate of the parent node
y_maxmaximum y coordinate of the parent node
z_minminimum z coordinate of the parent node
z_maxmaximum z coordinate of the parent node
depthlevels 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.

Definition at line 46 of file octree.c.

◆ octree_free()

void octree_free ( octree_node ** node)

Free octree node and all its child nodes.

Deallocates node and its child node recursively. Linked lists are also freed.

Parameters
nodepointer to octree node

Definition at line 91 of file octree.c.

◆ octree_add()

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).

Parameters
nodeoctree node to which or to which child nodes triangle is added to
t1triangle first vertex xyz coordinates
t2triangle second vertex xyz coordinates
t3triangle third vertex xyz coordinates
idtriangle id which is stored in the node(s) the triangle belongs to

Definition at line 123 of file octree.c.

◆ octree_get()

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.

Parameters
nodeoctree node that is traversed
pxyz coordinates of the point
Returns
linked list of the leaf node given point belongs to

Definition at line 164 of file octree.c.