topologicpy.BVH module
- class topologicpy.BVH.AABB(minx: float, miny: float, minz: float, maxx: float, maxy: float, maxz: float)
Bases:
objectAxis-aligned bounding box: [minx,miny,minz]..[maxx,maxy,maxz].
Methods
ray_intersect(ro, rd)Ray-box intersection using the 'slab' method.
center
contains_point
extent
from_points
overlaps
union
- center() Tuple[float, float, float]
- contains_point(p: Tuple[float, float, float]) bool
- extent() Tuple[float, float, float]
- maxx: float
- maxy: float
- maxz: float
- minx: float
- miny: float
- minz: float
- ray_intersect(ro: Tuple[float, float, float], rd: Tuple[float, float, float]) Tuple[bool, float, float]
Ray-box intersection using the ‘slab’ method. Returns (hit, tmin, tmax) in ray param t, where point = ro + t*rd.
- class topologicpy.BVH.BVH
Bases:
objectBasic Bounding Volume Hierarchy over TopologicPy topologies.
- Usage:
# 1) Prepare your primitives (Faces, Edges, Cells, etc.) faces = Topology.Faces(some_topology) # or any list of topologies
# 2) Build the BVH bvh = BVH.FromTopologies(faces, max_leaf_size=4, pad=0.0, silent=False)
# 3) AABB query hits = bvh.QueryAABB(AABB(minx, miny, minz, maxx, maxy, maxz))
# 4) Raycast (rough): returns candidate primitive indices cand = bvh.Raycast((ox,oy,oz), (dx,dy,dz))
# 5) Nearest by centroid (coarse) idx, dist = bvh.Nearest((x,y,z)) primitive = bvh.items[idx]
Methods
ByTopologies(*topologies[, maxLeafSize, ...])Creates a BVH Tree from the input list of topologies.
Clashes(bvh, *topologies[, mantissa, ...])Returns candidate primitives (topologies) overlapping the BVH (AABB-level) of the input topologies list.
Depth(bvh)Returns an approximate depth of the BVH.
Nearest(bvh, vertex[, mantissa, silent])Returns the topology with centroid nearest to the input vertex.
QueryAABB(bvh, query_box)Return indices of items whose AABBs overlap query_box.
Raycast(bvh, origin, direction[, mantissa, ...])Returns candidate primitives intersecting the BVH (AABB-level).
- static ByTopologies(*topologies, maxLeafSize: int = 4, tolerance: float = 0.0001, silent: bool = False) BVH
Creates a BVH Tree from the input list of topologies.
- Parameters
- *topologies: tuple
One or more TopologicPy topologies to include in the BVH.
- maxLeafSize: int , optional
The maximum number of primitives stored in a leaf node. Default is 4.
- tolerancefloat , optional
The desired tolerance used as padding around each AABB. Default is 0.0001.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- BVH
The created BVH tree.
- static Clashes(bvh, *topologies, mantissa: int = 6, tolerance: float = 0.0001, silent: bool = False)
Returns candidate primitives (topologies) overlapping the BVH (AABB-level) of the input topologies list. You can follow up with precise TopologicPy geometry intersection if needed.
- Parameters
- bvhBVH
The bvh tree.
- *topologies: (tuple of Topologic topologies)
One or more TopologicPy topologies to include in the BVH. Each topology is automatically analyzed to extract its vertices and compute an axis-aligned bounding box (AABB) for hierarchical spatial indexing.
- mantissaint , optional
The desired length of the mantissa. Default is 6.
- tolerancefloat , optional
The desired tolerance. Default is 0.0001. Tolerance is used for an optional margin added to all sides of each topology’s axis-aligned bounding box (AABB). This helps account for numerical precision errors or slight geometric inaccuracies. A small positive value ensures that closely adjacent or nearly touching primitives are properly enclosed within their bounding boxes. Default is 0.0001.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- list
The list of topologies that broadly interest the input list of topologies.
- static Depth(bvh) int
Returns an approximate depth of the BVH.
- Parameters
- bvhBVH
The bvh tree.
- Returns
- int
The approximate depth of the input bvh tree.
- static Nearest(bvh, vertex, mantissa: int = 6, silent: bool = False)
Returns the topology with centroid nearest to the input vertex. Uses AABB distance lower-bounds to prune search.
- Parameters
- bvhBVH
The bvh tree.
- vertextopologic_core.Vertex
The input vertex.
- mantissaint , optional
The desired length of the mantissa. Default is 6.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- topologic_core.Topology
The topology with centroid nearest to the input vertex.
- static Raycast(bvh, origin, direction: Tuple[float, float, float], mantissa: int = 6, silent: bool = False) List[int]
Returns candidate primitives intersecting the BVH (AABB-level). You can follow up with precise TopologicPy geometry intersection if needed.
- Parameters
- bvhBVH
The bvh tree.
- origintopologic_core.Vertex
The origin of the ray vector
- directiontopologic_core.Vector
The direction of the raycast vector.
- mantissaint , optional
The desired length of the mantissa. Default is 6.
- silentbool , optional
If set to True, error and warning messages are suppressed. Default is False.
- Returns
- list
The list of the indices of the possible candidates interesecting the input ray vector.