hawk.geometry

hawk.geometry#

A bounding-volume hierarchy over triangles, and the closest hit of a ray against it.

build_bvh() builds the tree on the host (NumPy, median split on the longest axis of the centroids) into flat tables. closest_hit() is the traversal as a kernel helper: a stack of node indices in a vector, the box test (hawk.math.ray_aabb()) against the nearest hit so far, and the triangle test (hawk.math.ray_tri()) on each leaf, so it runs on the host and the device alike and nothing in it is a library call. The value is correct, not tuned.

A kernel declares the tables as planes and gets the tree’s static facts from the host object:

bvh = build_bvh(triangles)                    # (n, 3, 3) vertices

@hawk.kernel
def shadow(o: Vector[3], d: Vector[3], tmax: Scalar, y: Mutable[Vector[5]],
           lo: Table[Scalar], hi: Table[Scalar], left: Table[Index],
           right: Table[Index], first: Table[Index], size: Table[Index],
           tri: Table[Scalar]):
    y = closest_hit(bvh.tables(lo, hi, left, right, first, size, tri), o, d, tmax)

bvh.planes() gives the arrays to bind, under the same names. The result is [hit, t, u, v, leaf_position]; bvh.order[leaf_position] is the triangle’s index in the input.

Module Attributes

PLANES

The planes of a tree, in the order BVH.tables() takes them.

Functions

build_bvh(…)

The tree over tris, an (n, 3, 3) array of vertices, with at most leaf triangles in a leaf.

closest_hit(…)

The nearest hit of the ray o + t d, 0 <= t <= tmax, against the tree: [hit, t, u, v, leaf_position], with t = 0 and zeros elsewhere when nothing is hit.

Classes

BVH

A built tree.

BVHTables

A tree's static facts and the kernel's tables that hold its planes.