Struct bvh::bvh::Bvh

source ·
pub struct Bvh<T: BHValue, const D: usize> {
    pub nodes: Vec<BvhNode<T, D>>,
}
Expand description

The Bvh data structure. Contains the list of BvhNodes.

Fields§

§nodes: Vec<BvhNode<T, D>>

The list of nodes of the Bvh.

Implementations§

source§

impl<T: BHValue, const D: usize> Bvh<T, D>

source

pub fn build<Shape: BHShape<T, D>>(shapes: &mut [Shape]) -> Bvh<T, D>

Creates a new Bvh from the shapes slice.

source

pub fn build_with_executor<Shape: BHShape<T, D>>( shapes: &mut [Shape], executor: impl FnMut(BvhNodeBuildArgs<'_, Shape, T, D>, BvhNodeBuildArgs<'_, Shape, T, D>) ) -> Bvh<T, D>

Creates a new Bvh from the shapes slice. The executor parameter allows you to parallelize the build of the Bvh. Using something like rayon::join. You must call either build or build_with_executor on both arguments in order to succesfully complete the build.

source

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

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

source

pub fn traverse_iterator<'bvh, 'shape, Shape: Bounded<T, D>>( &'bvh self, ray: &'bvh Ray<T, D>, shapes: &'shape [Shape] ) -> BvhTraverseIterator<'bvh, 'shape, T, D, Shape>

Creates a BvhTraverseIterator to traverse the Bvh. Returns a subset of shapes, in which the Aabbs of the elements were hit by ray.

source

pub fn pretty_print(&self)

Prints the Bvh in a tree-like visualization.

source

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

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.

source

pub fn assert_consistent<Shape: BHShape<T, D>>(&self, shapes: &[Shape])
where T: Display,

Assert version of is_consistent.

source

pub fn assert_tight_subtree(&self, node_index: usize, outer_aabb: &Aabb<T, D>)

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.

source

pub fn assert_tight(&self)

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

source§

impl<T: BHValue, const D: usize> Bvh<T, D>

source

pub fn add_shape<Shape: BHShape<T, D>>( &mut self, shapes: &mut [Shape], new_shape_index: usize )
where T: Div<Output = T>,

Adds a shape with the given index to the BVH Significantly slower at building a BVH than the full build or rebuild option Useful for moving a small subset of nodes around in a large BVH

source

pub fn remove_shape<Shape: BHShape<T, D>>( &mut self, shapes: &mut [Shape], deleted_shape_index: usize, swap_shape: bool )

Removes a shape from the BVH if swap_shape is true, it swaps the shape you are removing with the last shape in the shape slice truncation of the data structure backing the shapes slice must be performed by the user

source

pub fn update_shapes<'a, Shape: BHShape<T, D>>( &mut self, changed_shape_indices: impl IntoIterator<Item = &'a usize> + Copy, shapes: &mut [Shape] )

Fixes bvh

source§

impl<T: BHValue, const D: usize> Bvh<T, D>

source

pub fn flatten_custom<F, FNodeType>(&self, constructor: &F) -> Vec<FNodeType>
where F: Fn(&Aabb<T, D>, u32, u32, u32) -> FNodeType,

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 nalgebra::{Point3, Vector3};
use bvh::ray::Ray;

struct CustomStruct {
    aabb: Aabb<f32,3>,
    entry_index: u32,
    exit_index: u32,
    shape_index: u32,
}

let custom_constructor = |aabb: &Aabb<f32,3>, 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);
source

pub fn flatten(&self) -> FlatBvh<T, D>

Flattens the Bvh so that it can be traversed iteratively.

§Example
use bvh::aabb::{Aabb, Bounded};
use bvh::bvh::Bvh;
use 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§

source§

impl<T: BHValue + Display, const D: usize> BoundingHierarchy<T, D> for Bvh<T, D>

source§

fn build<Shape: BHShape<T, D>>(shapes: &mut [Shape]) -> Bvh<T, D>

Creates a new BoundingHierarchy from the shapes slice. Read more
source§

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

Traverses the BoundingHierarchy. Returns a subset of shapes, in which the Aabbs of the elements were hit by ray. Read more
source§

fn pretty_print(&self)

Prints the BoundingHierarchy in a tree-like visualization.
source§

fn build_with_executor<Shape: BHShape<T, D>, Executor: FnMut(BvhNodeBuildArgs<'_, Shape, T, D>, BvhNodeBuildArgs<'_, Shape, T, D>)>( shapes: &mut [Shape], executor: Executor ) -> Self

Builds the bvh with a custom executor.
source§

impl<T: Clone + BHValue, const D: usize> Clone for Bvh<T, D>

source§

fn clone(&self) -> Bvh<T, D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + BHValue, const D: usize> Debug for Bvh<T, D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, const D: usize> Freeze for Bvh<T, D>

§

impl<T, const D: usize> RefUnwindSafe for Bvh<T, D>
where T: RefUnwindSafe,

§

impl<T, const D: usize> Send for Bvh<T, D>
where T: Send,

§

impl<T, const D: usize> Sync for Bvh<T, D>
where T: Sync,

§

impl<T, const D: usize> Unpin for Bvh<T, D>
where T: Unpin,

§

impl<T, const D: usize> UnwindSafe for Bvh<T, D>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.