Enum bvh::bvh::BvhNode

source ·
pub enum BvhNode<T: BHValue, const D: usize> {
    Leaf {
        parent_index: usize,
        shape_index: usize,
    },
    Node {
        parent_index: usize,
        child_l_index: usize,
        child_l_aabb: Aabb<T, D>,
        child_r_index: usize,
        child_r_aabb: Aabb<T, D>,
    },
}
Expand description

The BvhNode enum that describes a node in a Bvh. It’s either a leaf node and references a shape (by holding its index) or a regular node that has two child nodes. The non-leaf node stores the Aabbs of its children.

Variants§

§

Leaf

Fields

§parent_index: usize

The node’s parent.

§shape_index: usize

The shape contained in this leaf.

Leaf node.

§

Node

Fields

§parent_index: usize

The node’s parent.

§child_l_index: usize

Index of the left subtree’s root node.

§child_l_aabb: Aabb<T, D>

The convex hull of the shapes’ Aabb’s in child_l.

§child_r_index: usize

Index of the right subtree’s root node.

§child_r_aabb: Aabb<T, D>

The convex hull of the shapes’ Aabb’s in child_r.

Inner node.

Implementations§

source§

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

source

pub fn build<S: BHShape<T, D>>(args: BvhNodeBuildArgs<'_, S, T, D>)

Builds a BvhNode recursively using SAH partitioning.

source

pub fn build_with_executor<S: BHShape<T, D>>( args: BvhNodeBuildArgs<'_, S, T, D>, executor: impl FnMut(BvhNodeBuildArgs<'_, S, T, D>, BvhNodeBuildArgs<'_, S, T, D>) )

Builds a BvhNode with a custom executor function using SAH partitioning.

source

pub fn traverse_recursive( nodes: &[BvhNode<T, D>], node_index: usize, ray: &Ray<T, D>, indices: &mut Vec<usize> )

Traverses the Bvh recursively and returns all shapes whose Aabb is intersected by the given Ray.

source§

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

source

pub fn parent(&self) -> usize

Returns the index of the parent node.

source

pub fn parent_mut(&mut self) -> &mut usize

Returns a mutable reference to the parent node index.

source

pub fn child_l(&self) -> usize

Returns the index of the left child node.

source

pub fn child_l_mut(&mut self) -> &mut usize

Returns the index of the left child node.

source

pub fn child_l_aabb(&self) -> Aabb<T, D>

Returns the Aabb of the right child node.

source

pub fn child_l_aabb_mut(&mut self) -> &mut Aabb<T, D>

Returns a mutable reference to the Aabb of the left child node.

source

pub fn child_r(&self) -> usize

Returns the index of the right child node.

source

pub fn child_r_mut(&mut self) -> &mut usize

Returns the index of the right child node.

source

pub fn child_r_aabb(&self) -> Aabb<T, D>

Returns the Aabb of the right child node.

source

pub fn child_r_aabb_mut(&mut self) -> &mut Aabb<T, D>

Returns a mutable reference to the Aabb of the right child node.

source

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

Gets the Aabb for a BvhNode. Returns the shape’s Aabb for leaves, and the joined Aabb of the two children’s Aabb’s for non-leaves.

source

pub fn shape_index(&self) -> Option<usize>

Returns the index of the shape contained within the node if is a leaf, or None if it is an interior node.

source

pub fn shape_index_mut(&mut self) -> Option<&mut usize>

Returns the index of the shape contained within the node if is a leaf, or None if it is an interior node.

source§

impl<T: BHValue + Float, const D: usize> BvhNode<T, D>

source

pub fn flatten_custom<F, FNodeType>( &self, nodes: &[BvhNode<T, D>], vec: &mut Vec<FNodeType>, next_free: usize, constructor: &F ) -> usize
where F: Fn(&Aabb<T, D>, u32, u32, u32) -> FNodeType,

Flattens the Bvh, so that it can be traversed in an iterative manner. This method constructs custom flat nodes using the constructor.

Trait Implementations§

source§

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

source§

fn clone(&self) -> BvhNode<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 BvhNode<T, D>

source§

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

Formats the value using the given formatter. Read more
source§

impl<T: BHValue, const D: usize> PartialEq for BvhNode<T, D>

source§

fn eq(&self, other: &BvhNode<T, D>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Copy + BHValue, const D: usize> Copy for BvhNode<T, D>

Auto Trait Implementations§

§

impl<T, const D: usize> Freeze for BvhNode<T, D>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T, const D: usize> UnwindSafe for BvhNode<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.
source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,