Trait bvh::bounding_hierarchy::BoundingHierarchy
source · pub trait BoundingHierarchy {
fn build<Shape: BHShape>(shapes: &mut [Shape]) -> Self;
fn traverse<'a, Shape: BHShape>(
&'a self,
ray: &Ray,
shapes: &'a [Shape]
) -> Vec<&'_ Shape>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
;
fn pretty_print(&self) { ... }
}
Expand description
This trait defines an acceleration structure with space partitioning. This structure is used to efficiently compute ray-scene intersections.
Required Methods
sourcefn build<Shape: BHShape>(shapes: &mut [Shape]) -> Self
fn build<Shape: BHShape>(shapes: &mut [Shape]) -> Self
Creates a new BoundingHierarchy
from the shapes
slice.
Examples
use bvh::aabb::{AABB, Bounded};
use bvh::bounding_hierarchy::BoundingHierarchy;
use bvh::nalgebra::{Point3, Vector3};
let mut shapes = create_bhshapes();
// Construct a normal `BVH`.
{
use bvh::bvh::BVH;
let bvh = BVH::build(&mut shapes);
}
// Or construct a `FlatBVH`.
{
use bvh::flat_bvh::FlatBVH;
let bvh = FlatBVH::build(&mut shapes);
}
sourcefn traverse<'a, Shape: BHShape>(
&'a self,
ray: &Ray,
shapes: &'a [Shape]
) -> Vec<&'_ Shape>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
fn traverse<'a, Shape: BHShape>(
&'a self,
ray: &Ray,
shapes: &'a [Shape]
) -> Vec<&'_ Shape>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Traverses the BoundingHierarchy
.
Returns a subset of shapes
, in which the AABB
s of the elements were hit by ray
.
Examples
use bvh::aabb::{AABB, Bounded};
use bvh::bounding_hierarchy::BoundingHierarchy;
use bvh::bvh::BVH;
use bvh::nalgebra::{Point3, Vector3};
use bvh::ray::Ray;
let (bvh, shapes) = create_bvh();
let origin = Point3::new(0.0, 0.0, 0.0);
let direction = Vector3::new(1.0, 0.0, 0.0);
let ray = Ray::new(origin, direction);
let hit_shapes = bvh.traverse(&ray, &shapes);
Provided Methods
sourcefn pretty_print(&self)
fn pretty_print(&self)
Prints the BoundingHierarchy
in a tree-like visualization.