Struct bvh::bvh::BVH[][src]

pub struct BVH {
    pub nodes: Vec<BVHNode>,
}

The BVH data structure. Contains the list of BVHNodes.

Fields

nodes: Vec<BVHNode>

The list of nodes of the BVH.

Implementations

impl BVH[src]

pub fn build<Shape: BHShape>(shapes: &mut [Shape]) -> BVH[src]

Creates a new BVH from the shapes slice.

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

Traverses the BVH. Returns a subset of shapes, in which the AABBs of the elements were hit by ray.

pub fn traverse_iterator<'a, Shape: Bounded>(
    &'a self,
    ray: &'a Ray,
    shapes: &'a [Shape]
) -> BVHTraverseIterator<'_, Shape>

Notable traits for BVHTraverseIterator<'a, Shape>

impl<'a, Shape: Bounded> Iterator for BVHTraverseIterator<'a, Shape> type Item = &'a Shape;
[src]

Creates a BVHTraverseIterator to traverse the BVH. Returns a subset of shapes, in which the AABBs of the elements were hit by ray.

pub fn pretty_print(&self)[src]

Prints the BVH in a tree-like visualization.

pub fn is_consistent<Shape: BHShape>(&self, shapes: &[Shape]) -> bool[src]

Checks if all children of a node have the correct parent index, and that there is no detached subtree. Also checks if the AABB hierarchy is consistent.

pub fn assert_consistent<Shape: BHShape>(&self, shapes: &[Shape])[src]

Assert version of is_consistent.

pub fn assert_tight_subtree<Shape: BHShape>(
    &self,
    node_index: usize,
    outer_aabb: &AABB,
    shapes: &[Shape]
)
[src]

Check that the AABBs in the BVH are tight, which means, that parent AABBs are not larger than they should be. This function checks, whether the children of node node_index lie inside outer_aabb.

pub fn assert_tight<Shape: BHShape>(&self, shapes: &[Shape])[src]

Check that the AABBs in the BVH are tight, which means, that parent AABBs are not larger than they should be.

impl BVH[src]

pub fn optimize<Shape: BHShape>(
    &mut self,
    refit_shape_indices: &HashSet<usize>,
    shapes: &[Shape]
)
[src]

Optimizes the BVH by batch-reorganizing updated nodes. Based on https://github.com/jeske/SimpleScene/blob/master/SimpleScene/Util/ssBVH/ssBVH.cs

Needs all the scene’s shapes, plus the indices of the shapes that were updated.

impl BVH[src]

pub fn flatten_custom<F, FNodeType>(&self, constructor: &F) -> Vec<FNodeType> where
    F: Fn(&AABB, u32, u32, u32) -> FNodeType, 
[src]

Flattens the BVH so that it can be traversed iteratively. Constructs the flat nodes using the supplied function. This function can be used, when the flat bvh nodes should be of some particular non-default structure. The constructor is fed the following arguments in this order:

1 - &AABB: The enclosing AABB 2 - u32: The index of the nested node 3 - u32: The exit index 4 - u32: The shape index

Example

use bvh::aabb::{AABB, Bounded};
use bvh::bvh::BVH;
use bvh::nalgebra::{Point3, Vector3};
use bvh::ray::Ray;

struct CustomStruct {
    aabb: AABB,
    entry_index: u32,
    exit_index: u32,
    shape_index: u32,
}

let custom_constructor = |aabb: &AABB, entry, exit, shape_index| {
    CustomStruct {
        aabb: *aabb,
        entry_index: entry,
        exit_index: exit,
        shape_index: shape_index,
    }
};

let mut shapes = create_bhshapes();
let bvh = BVH::build(&mut shapes);
let custom_flat_bvh = bvh.flatten_custom(&custom_constructor);

pub fn flatten(&self) -> FlatBVH[src]

Flattens the BVH so that it can be traversed iteratively.

Example

use bvh::aabb::{AABB, Bounded};
use bvh::bvh::BVH;
use bvh::nalgebra::{Point3, Vector3};
use bvh::ray::Ray;

let mut shapes = create_bhshapes();
let bvh = BVH::build(&mut shapes);
let flat_bvh = bvh.flatten();

Trait Implementations

impl BoundingHierarchy for BVH[src]

Auto Trait Implementations

impl RefUnwindSafe for BVH

impl Send for BVH

impl Sync for BVH

impl Unpin for BVH

impl UnwindSafe for BVH

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,