Datastructures¤
Bounding-volume hierarchy¤
compas_model.datastructures.bvh
¤
Classes¤
AABBNode
¤
BVH
¤
Binary bounding volume hierarchy.
Parameters:
-
nodetype(type[BVHNode[T]], default:AABBNode) –The type of bounding volume node to use in the tree.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The number of objects contained by a leaf.
Attributes¤
Methods:¤
from_breps
classmethod
¤
from_breps(
triangles: list[Brep],
nodetype: type[BVHNode[Brep]] = AABBNode,
max_depth: int | None = None,
leafsize: int = 1,
) -> BVH[Brep]
Construct a BVH from a collection of breps.
Parameters:
-
triangles(list[Brep]) –A list of brep objects.
-
nodetype(type[BVHNode[Brep]], default:AABBNode) –The type of node to use during construction.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The maximum number of breps contained in a leaf node.
Returns:
-
BVH–The constructed tree.
from_mesh
staticmethod
¤
from_mesh(
mesh: Mesh,
nodetype: type[BVHNode[list[Point]]] = AABBNode,
max_depth: int | None = None,
leafsize: int = 1,
) -> BVH[list[Point]]
Construct a BVH from a mesh.
Parameters:
-
mesh(Mesh) –A mesh data structure.
-
nodetype(type[BVHNode[list[Point]]], default:AABBNode) –The type of node to use during construction.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The maximum number of mesh faces contained in a leaf node.
Returns:
-
BVH–The constructed tree.
from_meshes
classmethod
¤
from_meshes(
meshes: list[Mesh],
nodetype: type[BVHNode[Mesh]] = AABBNode,
max_depth: int | None = None,
leafsize: int = 1,
) -> BVH[Mesh]
Construct a BVH from a collection of meshes.
Parameters:
-
meshes(list[Mesh]) –A list of mesh objects.
-
nodetype(type[BVHNode[Mesh]], default:AABBNode) –The type of node to use during construction.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The maximum number of meshes contained in a leaf node.
Returns:
-
BVH–The constructed tree.
from_polyhedrons
classmethod
¤
from_polyhedrons(
polyhedrons: list[Polyhedron],
nodetype: type[BVHNode[Polyhedron]] = AABBNode,
max_depth: int | None = None,
leafsize: int = 1,
) -> BVH[Polyhedron]
Construct a BVH from a collection of polyhedrons.
Parameters:
-
polyhedrons(list[Polyhedron]) –A list of polyhedron objects.
-
nodetype(type[BVHNode[Polyhedron]], default:AABBNode) –The type of node to use during construction.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The maximum number of polyhedrons contained in a leaf node.
Returns:
-
BVH–The constructed tree.
from_triangles
staticmethod
¤
from_triangles(
triangles: list[list[Point]],
nodetype: type[BVHNode[list[Point]]] = AABBNode,
max_depth: int | None = None,
leafsize: int = 1,
) -> BVH[list[Point]]
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[BVHNode[list[Point]]], default:AABBNode) –The type of node to use during construction.
-
max_depth(int | None, default:None) –The maximum depth of the tree.
-
leafsize(int, default:1) –The maximum number of triangles contained in a leaf node.
Returns:
-
BVH–The constructed tree.
intersect_box
¤
intersect_line
¤
intersect_sphere
¤
overlap_pairs
¤
overlap_pairs(
other: BVH[U], *, self_collision: bool = False
) -> Generator[tuple[BVHObject[T], BVHObject[U]], None, None]
Yield broad-phase object pairs from overlapping BVH leaves.
Parameters:
-
other(BVH[U]) –The other bounding volume hierarchy.
-
self_collision(bool, default:False) –Enable comparison of a hierarchy with itself. This is ignored when comparing different hierarchies.
Yields:
Raises:
-
ValueError–If a hierarchy is compared with itself without enabling
self_collision.
Notes
The yielded pairs are broad-phase candidates. Their bounding volumes overlap, but the underlying geometry may not. Result ordering is not part of the public contract.
During self-collision traversal, an object is never paired with itself and each unordered object pair is yielded at most once.
BVHNode
¤
Base BVH tree node.
Parameters:
BVHObject
dataclass
¤
Object record stored in a bounding volume hierarchy.
Parameters:
-
key(Hashable) –Identifier of the object in its source collection.
-
centroid(Point) –Representative point used to partition the hierarchy.
-
payload(T) –The application-specific object.
-
points(list[Point]) –Points used to compute bounding volumes.
KD-tree¤
compas_model.datastructures.kdtree
¤
Classes¤
KDTree
¤
A tree for nearest neighbor search in a k-dimensional space.
Parameters:
-
elements(list[Element]) –A list of objects to populate the tree with. The tree is built automatically.
References
Wikipedia, k-d tree: https://en.wikipedia.org/wiki/K-d_tree Dell'Amico, M. KD-Tree for nearest neighbor search in a K-dimensional space (Python recipe): http://code.activestate.com/recipes/577497-kd-tree-for-nearest-neighbor-search-in-a-k-dimensional-space/.
Methods:¤
nearest_neighbor
¤
nearest_neighbors
¤
nearest_neighbors(
point: Point, number: int, distance_sort: bool = False
) -> list[tuple[Element, float]]