Branch3D module

This module contains the Branch class (one branch of the tree) and the Nodes class

class Branch3D.Branch(mesh, init_node, init_dir, init_tri, l, angle, w, nodes, brother_nodes, Nsegments)[source]

Class that contains a branch of the fractal tree.

Parameters:
  • mesh – an object of the mesh class, where the fractal tree will grow
  • init_node (int) – initial node to grow the branch. This is an index that refers to a node in the nodes.nodes array.
  • init_dir (array) – initial direction to grow the branch. In general, it refers to the direction of the last segment of the mother brach.
  • init_tri (int) – the index of triangle of the mesh where the init_node sits.
  • l (float) – total length of the branch
  • angle (float) – angle (rad) with respect to the init_dir in the plane of the init_tri triangle
  • w (float) – repulsitivity parameter. Controls how much the branches repel each other.
  • nodes – the object of the class nodes that contains all the nodes of the existing branches.
  • brother_nodes (list) – the nodes of the brother and mother branches, to be excluded from the collision detection between branches.
  • Nsegments (int) – number of segments to divide the branch.
child

list – contains the indexes of the child branches. It is not assigned when created.

dir

array – vector direction of the last segment of the branch.

nodes

list – contains the node indices of the branch. The node coordinates can be retrieved using nodes.nodes[i]

triangles

list – contains the indices of the triangles from the mesh where every node of the branch lies.

tri

int – triangle index where last node sits.

growing

bool – False if the branch collide or is out of the surface. True otherwise.

add_node_to_queue(mesh, init_node, dir)[source]

Functions that projects a node in the mesh surface and it to the queue is it lies in the surface.

Parameters:
  • mesh – an object of the mesh class, where the fractal tree will grow
  • init_node (array) – vector that contains the coordinates of the last node added in the branch.
  • dir (array) – vector that contains the direction from the init_node to the node to project.
Returns:

true if the new node is in the triangle.

Return type:

success (bool)

class Branch3D.Nodes(init_node)[source]

A class containing the nodes of the branches plus some fuctions to compute distance related quantities.

Parameters:init_node (array) – an array with the coordinates of the initial node of the first branch.
nodes

list – list of arrays containing the coordinates of the nodes

last_node

int – last added node.

end_nodes

list – a list containing the indices of all end nodes (nodes that are not connected) of the tree.

tree

scipy.spatial.cKDTree – a k-d tree to compute the distance from any point to the closest node in the tree. It is updated once a branch is finished.

collision_tree

scipy.spatial.cKDTree – a k-d tree to compute the distance from any point to the closest node in the tree, except from the brother and mother branches. It is used to check collision between branches.

add_nodes(queue)[source]

This function stores a list of nodes of a branch and returns the node indices. It also updates the tree to compute distances.

Parameters:queue (list) – a list of arrays containing the coordinates of the nodes of one branch.
Returns:the indices of the added nodes.
Return type:nodes_id (list)
collision(point)[source]

This function returns the distance between one point and the closest node in the tree and the index of the closest node using the collision_tree.

Parameters:point (array) – the coordinates of the point to calculate the distance from.
Returns:(distance to the closest node, index of the closest node)
Return type:collision (tuple)
distance_from_node(node)[source]

This function returns the distance from any node to the closest node in the tree.

Parameters:node (int) – the index of the node to calculate the distance from.
Returns:the distance between specified node and the closest node in the tree.
Return type:d (float)
distance_from_point(point)[source]

This function returns the distance from any point to the closest node in the tree.

Parameters:point (array) – the coordinates of the point to calculate the distance from.
Returns:the distance between point and the closest node in the tree.
Return type:d (float)
gradient(point)[source]

This function returns the gradient of the distance from the existing points of the tree from any point. It uses a central finite difference approximation.

Parameters:point (array) – the coordinates of the point to calculate the gradient of the distance from.
Returns:(x,y,z) components of gradient of the distance.
Return type:grad (array)
update_collision_tree(nodes_to_exclude)[source]

This function updates the collision_tree excluding a list of nodes from all the nodes in the tree. If all the existing nodes are excluded, one distant node is added.

Parameters:nodes_to_exclude (list) – contains the nodes to exclude from the tree. Usually it should be the mother and the brother branch nodes.
Returns:none