Skip to content

compas_model.datastructures ¤

Classes¤

AABBNode ¤

AABBNode(objects: list[tuple[int, Point, list[Point]]], **kwargs)

BVH tree node with an axis-aligned bounding box as bounding volume.

Functions¤

compute_box ¤
compute_box() -> Box

Compute the axis-aligned box of the collections of primitives in this node.

Returns:

intersect_box ¤
intersect_box(box: Box) -> Generator[AABBNode, None, None]

Intersect this node with a box to find all intersected descending nodes.

Parameters:

  • box (Box) –

Yields:

intersect_line ¤
intersect_line(line: Line) -> Generator[AABBNode, None, None]

Intersect this node with a line to find all intersected descending nodes.

Parameters:

Yields:

BVH ¤

BVH(
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
    **kwargs,
)

Bounding Volume Hierarchy as a special case of a (binary) tree.

Parameters:

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of boundng volume node to use in the tree.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The number of objects contained by a leaf.

Examples:

>>>

Functions¤

from_breps classmethod ¤
from_breps(
    triangles: list[Brep],
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
) -> BVH

Construct a BVH from a mesh.

Parameters:

  • breps (list[Brep]) –

    A list of brep objects.

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of node to use during construction.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The maximum number of breps contained in a leaf node.

Returns:

from_mesh classmethod ¤
from_mesh(
    mesh: Mesh,
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
) -> BVH

Construct a BVH from a mesh.

Parameters:

  • mesh (Mesh) –

    A mesh data structure.

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of node to use during construction.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The maximum number of mesh faces contained in a leaf node.

Returns:

from_meshes classmethod ¤
from_meshes(
    meshes: list[Mesh],
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
) -> BVH

Construct a BVH from a collection of meshes.

Parameters:

  • meshes (list[Mesh]) –

    A list of mesh objects.

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of node to use during construction.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The maximum number of meshes contained in a leaf node.

Returns:

from_polyhedrons classmethod ¤
from_polyhedrons(
    polyhedrons: list[Polyhedron],
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
) -> BVH

Construct a BVH from a mesh.

Parameters:

  • polyhedrons (list[Polyhedron]) –

    A list of polyhedron objects.

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of node to use during construction.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The maximum number of polyhedrons contained in a leaf node.

Returns:

from_triangles classmethod ¤
from_triangles(
    triangles: list[list[Point]],
    nodetype: Type[AABBNode] | Type[OBBNode] = AABBNode,
    max_depth: int | None = None,
    leafsize: int = 1,
) -> BVH

Construct a BVH from a collection of triangles.

Parameters:

  • triangles (list[list[Point]]) –

    A list of triangles, with each triangle represented by three points.

  • nodetype (Type[AABBNode] | Type[OBBNode], default: AABBNode ) –

    The type of node to use during construction.

  • max_depth (int, default: None ) –

    The maximum depth of the tree.

  • leafsize (int, default: 1 ) –

    The maximum number of triangles contained in a leaf node.

Returns:

intersect_box ¤
intersect_box(box: Box) -> Generator[BVHNode, None, None]

Intersect the tree with a box to find all intersected nodes in descending order.

Parameters:

  • box (Box) –

Yields:

  • BVHNode
intersect_line ¤
intersect_line(line: Line) -> Generator[BVHNode, None, None]

Intersect the tree with a line to find all intersected nodes in descending order.

Parameters:

Yields:

  • BVHNode
intersect_sphere ¤
intersect_sphere(sphere: Sphere) -> Generator[BVHNode, None, None]

Intersect the tree with a sphere to find all intersected nodes in descending order.

Parameters:

Yields:

  • BVHNode
rebuild ¤
rebuild()

Rebuild the tree using the current objects.

refit ¤
refit()

Refit the tree to the current objects.

KDTree ¤

KDTree(elements: list[Element])

A tree for nearest neighbor search in a k-dimensional space.

Parameters:

  • objects (sequence[[float, float, float] | Point]) –

    A list of objects to populate the tree with. If objects are provided, the tree is built automatically. Otherwise, use :meth:build.

Attributes:

  • root (Node) –

    The root node of the built tree. This is the median with respect to the different dimensions of the tree.

Notes

For more info, see [1] and [2].

References

.. [1] Wikipedia. k-d tree. Available at: https://en.wikipedia.org/wiki/K-d_tree. .. [2] Dell'Amico, M. KD-Tree for nearest neighbor search in a K-dimensional space (Python recipe). Available at: http://code.activestate.com/recipes/577497-kd-tree-for-nearest-neighbor-search-in-a-k-dimensional-space/.

Functions¤

nearest_neighbor ¤
nearest_neighbor(
    point: Point, exclude: list[Element] | None = None
) -> tuple[Element, float]

Find the nearest neighbor to a given point, excluding neighbors that have already been found.

Parameters:

  • point (Point) –

    The base point.

  • exclude (list[Element], default: None ) –

    A sequence of point identified by their label to exclude from the search.

Returns:

  • tuple[Element, float]

    XYZ coordinates of the nearest neighbor. Label of the nearest neighbor. Distance to the base point.

nearest_neighbors ¤
nearest_neighbors(
    point: Point, number: int, distance_sort: bool = False
) -> list[tuple[Element, float]]

Find the N nearest neighbors to a given point.

Parameters:

  • point (Point) –

    The base point.

  • number (int) –

    The number of nearest neighbors.

  • distance_sort (bool, default: False ) –

    Sort the nearest neighbors by distance to the base point.

Returns:

OBBNode ¤

OBBNode(objects: list[tuple[int, Point, list[Point]]], **kwargs)

BVH tree node with an axis-aligned bounding box as bounding volume.

Functions¤

compute_box ¤
compute_box() -> Box

Compute the oriented box of the collections of primitives in this node.

Returns:

intersect_box ¤
intersect_box(box: Box) -> Generator[OBBNode, None, None]

Intersect this node with a box to find all intersected descending nodes.

Parameters:

  • box (Box) –

Yields:

intersect_line ¤
intersect_line(line: Line) -> Generator[OBBNode, None, None]

Intersect this node with a line to find all intersected descending nodes.

Parameters:

Yields:

intersect_sphere ¤
intersect_sphere(sphere: Sphere) -> Generator[OBBNode, None, None]

Intersect this node with a line to find all intersected descending nodes.

Parameters:

Yields: