topologicpy.BVH module

class topologicpy.BVH.AABB(minx: float, miny: float, minz: float, maxx: float, maxy: float, maxz: float)

Bases: object

Axis-aligned bounding box: [minx, miny, minz] .. [maxx, maxy, maxz].

Methods

center()

Returns the centroid of this AABB.

contains_point(p)

Returns True if this AABB contains the input point.

extent()

Returns the X, Y, and Z extents of this AABB.

from_points(pts[, pad])

Creates an AABB from an iterable of 3D points.

overlaps(other)

Returns True if this AABB overlaps the input AABB.

ray_intersect(ro, rd)

Tests ray-box intersection using the slab method.

union(a, b)

Returns the smallest AABB containing both input AABBs.

center() → Tuple[float, float, float]

Returns the centroid of this AABB.

contains_point(p: Tuple[float, float, float]) → bool

Returns True if this AABB contains the input point.

extent() → Tuple[float, float, float]

Returns the X, Y, and Z extents of this AABB.

static from_points(pts: Iterable[Tuple[float, float, float]], pad: float = 0.0) → AABB

Creates an AABB from an iterable of 3D points.

Empty input returns a degenerate AABB at the origin.

maxx: float
maxy: float
maxz: float
minx: float
miny: float
minz: float
overlaps(other: AABB) → bool

Returns True if this AABB overlaps the input AABB.

ray_intersect(ro: Tuple[float, float, float], rd: Tuple[float, float, float]) → Tuple[bool, float, float]

Tests ray-box intersection using the slab method.

Returns
tuple

(hit, tmin, tmax), where point = ro + t*rd.

static union(a: AABB, b: AABB) → AABB

Returns the smallest AABB containing both input AABBs.

class topologicpy.BVH.BVH

Bases: object

Basic Bounding Volume Hierarchy over TopologicPy topologies.

Methods

ByTopologies(*topologies[, maxLeafSize, ...])

Creates a BVH tree from the input topologies.

Clashes(bvh, *topologies[, mantissa, ...])

Returns BVH items whose AABBs overlap the AABBs of the input topologies.

Depth(bvh)

Returns the depth of the BVH tree.

Nearest(bvh, vertex[, mantissa, silent])

Returns the BVH item whose AABB centroid is nearest to the input vertex.

QueryAABB(bvh, query_box)

Returns item indices whose AABBs overlap the input query AABB.

Raycast(bvh, origin, direction[, mantissa, ...])

Returns candidate item indices whose AABBs are intersected by the input ray.

static ByTopologies(*topologies, maxLeafSize: int = 4, tolerance: float = 0.0001, silent: bool = False) → Optional[BVH]

Creates a BVH tree from the input topologies.

Parameters
*topologiestopologic_core.Topology

One or more topologies, or nested lists of topologies, to include in the BVH.

maxLeafSizeint , optional

The maximum number of primitives stored in a leaf node. Default is 4.

tolerancefloat , optional

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 BVH items whose AABBs overlap the AABBs of the input topologies.

This is an AABB-level broad-phase query. Use precise geometric predicates or Boolean operations afterwards when exact intersection classification is required.

static Depth(bvh) → Optional[int]

Returns the depth of the BVH tree.

Parameters
bvhBVH

The BVH tree.

Returns
int

The depth of the BVH tree.

static Nearest(bvh, vertex, mantissa: int = 6, silent: bool = False)

Returns the BVH item whose AABB centroid is nearest to the input vertex.

static QueryAABB(bvh, query_box: AABB)

Returns item indices whose AABBs overlap the input query AABB.

Invalid input returns None. A valid but empty BVH returns an empty list.

static Raycast(bvh, origin, direction: Tuple[float, float, float], mantissa: int = 6, silent: bool = False) → Optional[List[int]]

Returns candidate item indices whose AABBs are intersected by the input ray.

Parameters
bvhBVH

The BVH tree.

origintopologic_core.Vertex

The origin of the ray.

directionlist or tuple

A three-component direction 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

Candidate item indices.