Skip to main content

Bvh

Struct Bvh 

Source
pub struct Bvh { /* private fields */ }
Expand description

A reference-counted standalone BVH (RTCBVH). Build target for Bvh::build_scoped.

Not Clone: the result of a build borrows the Bvh exclusively, and a second handle could rebuild and free the arena out from under a live result.

Implementations§

Source§

impl Bvh

Source

pub fn build_scoped<B, F, R>( &mut self, config: &BuildConfig, primitives: &mut Vec<BuildPrimitive>, builder: &B, f: F, ) -> Result<R, Error>
where B: BvhBuilder, F: for<'id> FnOnce(BvhResult<'id, B>) -> R,

Build a BVH over primitives inside a generative scope. The result and any NodePtr handles cannot escape f; return owned data (counts, a Vec, a copied-out tree) instead.

The generative brand makes escaping a handle a compile error, which is what prevents resolving a handle against a different build:

use embree3::{
    Allocator, Bvh, BvhBuilder, BvhNode, BuildConfig, BuildPrimitive, ChildBounds,
    Children, Device,
};
#[derive(Clone, Copy)]
struct Node {
    n: u32,
}
unsafe impl BvhNode for Node {}
struct B;
impl BvhBuilder for B {
    type Node<'id> = Node;
    const MAX_CHILDREN: usize = 2;
    fn create_node<'id>(&self, a: &Allocator<'id>, _n: usize) -> &'id mut Node {
        a.alloc(Node { n: 0 })
    }
    fn set_children<'id>(&self, _n: &mut Node, _c: Children<'id, Node>) {}
    fn set_bounds<'id>(&self, _n: &mut Node, _b: ChildBounds<'_>) {}
    fn create_leaf<'id>(&self, a: &Allocator<'id>, _p: &[BuildPrimitive]) -> &'id mut Node {
        a.alloc(Node { n: 0 })
    }
}
let device = Device::new().unwrap();
let mut bvh = device.create_bvh().unwrap();
let mut prims: Vec<BuildPrimitive> = Vec::new();
// ERROR: a branded handle cannot escape the generative scope.
let _escaped = bvh.build_scoped(&BuildConfig::default(), &mut prims, &B, |r| r.root_ptr());

The cross-build case directly: a handle from one build cannot be resolved by a nested, independent build (their generative brands differ):

use embree3::{
    Allocator, Bvh, BvhBuilder, BvhNode, BuildConfig, BuildPrimitive, ChildBounds,
    Children, Device,
};
#[derive(Clone, Copy)]
struct Node {
    n: u32,
}
unsafe impl BvhNode for Node {}
struct B;
impl BvhBuilder for B {
    type Node<'id> = Node;
    const MAX_CHILDREN: usize = 2;
    fn create_node<'id>(&self, a: &Allocator<'id>, _n: usize) -> &'id mut Node {
        a.alloc(Node { n: 0 })
    }
    fn set_children<'id>(&self, _n: &mut Node, _c: Children<'id, Node>) {}
    fn set_bounds<'id>(&self, _n: &mut Node, _b: ChildBounds<'_>) {}
    fn create_leaf<'id>(&self, a: &Allocator<'id>, _p: &[BuildPrimitive]) -> &'id mut Node {
        a.alloc(Node { n: 0 })
    }
}
let device = Device::new().unwrap();
let mut outer = device.create_bvh().unwrap();
let mut inner = device.create_bvh().unwrap();
let mut po: Vec<BuildPrimitive> = Vec::new();
let mut pi: Vec<BuildPrimitive> = Vec::new();
let cfg = BuildConfig::default();
outer.build_scoped(&cfg, &mut po, &B, |ra| {
    // ERROR: `ra`'s handle has a different brand than `rb`'s scope, so it cannot be
    // passed to `rb.resolve`. (Returns a `Copy` field to isolate that one error.)
    inner.build_scoped(&cfg, &mut pi, &B, |rb| {
        rb.resolve(ra.root_ptr().unwrap()).n
    })
}).unwrap().unwrap();

Trait Implementations§

Source§

impl Drop for Bvh

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Send for Bvh

§

impl !Sync for Bvh

§

impl Freeze for Bvh

§

impl RefUnwindSafe for Bvh

§

impl Unpin for Bvh

§

impl UnsafeUnpin for Bvh

§

impl UnwindSafe for Bvh

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.