pub struct Bvh<T: BHValue, const D: usize> {
pub nodes: Vec<BvhNode<T, D>>,
}
Fields§
§nodes: Vec<BvhNode<T, D>>
The list of nodes of the Bvh
.
Implementations§
source§impl<T: BHValue, const D: usize> Bvh<T, D>
impl<T: BHValue, const D: usize> Bvh<T, D>
sourcepub fn build<Shape: BHShape<T, D>>(shapes: &mut [Shape]) -> Bvh<T, D>
pub fn build<Shape: BHShape<T, D>>(shapes: &mut [Shape]) -> Bvh<T, D>
Creates a new Bvh
from the shapes
slice.
sourcepub 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>
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>
sourcepub fn traverse<'a, Shape: Bounded<T, D>>(
&'a self,
ray: &Ray<T, D>,
shapes: &'a [Shape]
) -> Vec<&Shape>
pub fn traverse<'a, Shape: Bounded<T, D>>( &'a self, ray: &Ray<T, D>, shapes: &'a [Shape] ) -> Vec<&Shape>
sourcepub 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> ⓘ
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 Aabb
s of the elements were hit by ray
.
sourcepub fn pretty_print(&self)
pub fn pretty_print(&self)
Prints the Bvh
in a tree-like visualization.
sourcepub fn is_consistent<Shape: BHShape<T, D>>(&self, shapes: &[Shape]) -> bool
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.
sourcepub fn assert_consistent<Shape: BHShape<T, D>>(&self, shapes: &[Shape])where
T: Display,
pub fn assert_consistent<Shape: BHShape<T, D>>(&self, shapes: &[Shape])where
T: Display,
Assert version of is_consistent
.
sourcepub fn assert_tight_subtree(&self, node_index: usize, outer_aabb: &Aabb<T, D>)
pub fn assert_tight_subtree(&self, node_index: usize, outer_aabb: &Aabb<T, D>)
Check that the Aabb
s in the Bvh
are tight, which means, that parent Aabb
s are not
larger than they should be. This function checks, whether the children of node node_index
lie inside outer_aabb
.
sourcepub fn assert_tight(&self)
pub fn assert_tight(&self)
Check that the Aabb
s in the Bvh
are tight, which means, that parent Aabb
s are not
larger than they should be.
source§impl<T: BHValue, const D: usize> Bvh<T, D>
impl<T: BHValue, const D: usize> Bvh<T, D>
sourcepub fn add_shape<Shape: BHShape<T, D>>(
&mut self,
shapes: &mut [Shape],
new_shape_index: usize
)where
T: Div<Output = T>,
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
sourcepub fn remove_shape<Shape: BHShape<T, D>>(
&mut self,
shapes: &mut [Shape],
deleted_shape_index: usize,
swap_shape: bool
)
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
sourcepub fn update_shapes<'a, Shape: BHShape<T, D>>(
&mut self,
changed_shape_indices: impl IntoIterator<Item = &'a usize> + Copy,
shapes: &mut [Shape]
)
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>
impl<T: BHValue, const D: usize> Bvh<T, D>
sourcepub fn flatten_custom<F, FNodeType>(&self, constructor: &F) -> Vec<FNodeType>
pub fn flatten_custom<F, FNodeType>(&self, constructor: &F) -> Vec<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);
Trait Implementations§
source§impl<T: BHValue + Display, const D: usize> BoundingHierarchy<T, D> for Bvh<T, D>
impl<T: BHValue + Display, const D: usize> BoundingHierarchy<T, D> for Bvh<T, D>
source§fn traverse<'a, Shape: Bounded<T, D>>(
&'a self,
ray: &Ray<T, D>,
shapes: &'a [Shape]
) -> Vec<&Shape>
fn traverse<'a, Shape: Bounded<T, D>>( &'a self, ray: &Ray<T, D>, shapes: &'a [Shape] ) -> Vec<&Shape>
BoundingHierarchy
.
Returns a subset of shapes
, in which the Aabb
s of the elements were hit by ray
. Read moresource§fn pretty_print(&self)
fn pretty_print(&self)
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
fn build_with_executor<Shape: BHShape<T, D>, Executor: FnMut(BvhNodeBuildArgs<'_, Shape, T, D>, BvhNodeBuildArgs<'_, Shape, T, D>)>( shapes: &mut [Shape], executor: Executor ) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.