ASCOT5
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
octree.h File Reference

Header file for octree.c. More...

#include "ascot5.h"
#include "list.h"

Go to the source code of this file.

Data Structures

struct  octree_node
 Struct representing single octree node. More...
 

Typedefs

typedef struct octree_node octree_node
 Struct representing single octree node.
 

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

Header file for octree.c.

Definition in file octree.h.

Typedef Documentation

◆ octree_node

typedef struct octree_node octree_node

Struct representing single octree node.

Stores eight child nodes, bounding box of the volume this node encloses, and a linked list containing IDs of triangles belonging to this node.

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.