[][src]Trait bvh::bounding_hierarchy::BoundingHierarchy

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>; fn pretty_print(&self) { ... } }

This trait defines an acceleration structure with space partitioning. This structure is used to efficiently compute ray-scene intersections.

Required methods

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);
}

fn traverse<'a, Shape: BHShape>(
    &'a self,
    ray: &Ray,
    shapes: &'a [Shape]
) -> Vec<&Shape>

Traverses the BoundingHierarchy. Returns a subset of shapes, in which the AABBs 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);
Loading content...

Provided methods

fn pretty_print(&self)

Prints the BoundingHierarchy in a tree-like visualization.

Loading content...

Implementors

impl BoundingHierarchy for BVH
[src]

impl BoundingHierarchy for FlatBVH
[src]

fn build<T: BHShape>(shapes: &mut [T]) -> FlatBVH
[src]

A FlatBVH is built from a regular BVH using the [flatten] method.

fn traverse<'a, T: Bounded>(&'a self, ray: &Ray, shapes: &'a [T]) -> Vec<&T>
[src]

Traverses a FlatBVH structure iteratively.

Examples

use bvh::aabb::{AABB, Bounded};
use bvh::bounding_hierarchy::BoundingHierarchy;
use bvh::flat_bvh::FlatBVH;
use bvh::nalgebra::{Point3, Vector3};
use bvh::ray::Ray;

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 mut shapes = create_bhshapes();
let flat_bvh = FlatBVH::build(&mut shapes);
let hit_shapes = flat_bvh.traverse(&ray, &shapes);

fn pretty_print(&self)
[src]

Prints a textual representation of a FlatBVH.

Loading content...