PlocBuilder

Struct PlocBuilder 

Source
pub struct PlocBuilder {
    pub current_nodes: Vec<Bvh2Node>,
    pub next_nodes: Vec<Bvh2Node>,
    pub mortons: Vec<[u128; 2]>,
}

Fields§

§current_nodes: Vec<Bvh2Node>§next_nodes: Vec<Bvh2Node>§mortons: Vec<[u128; 2]>

Implementations§

Source§

impl PlocBuilder

Source

pub fn full_rebuild( &mut self, bvh: &mut Bvh2, search_distance: PlocSearchDistance, sort_precision: SortPrecision, search_depth_threshold: usize, )

Fully rebuild the bvh from its current leaves.

§Arguments
  • bvh - An existing bvh with valid leaves. Inner nodes are ignored.
  • search_distance - Which search distance should be used when building the ploc.
  • sort_precision - Bits used for ploc radix sort. More bits results in a more accurate but slower sort.
  • search_depth_threshold - Below this depth a search distance of 1 will be used. Set to 0 to bypass and just use search_distance.
Source

pub fn partial_rebuild( &mut self, bvh: &mut Bvh2, should_remove: impl Fn(usize) -> bool, search_distance: PlocSearchDistance, sort_precision: SortPrecision, search_depth_threshold: usize, )

Partially rebuild the bvh. The given set of leaves and the subtrees that do not include any of the given leaves will be built into a new bvh. If the set of leaves is a small enough proportion of the total this can be faster since there may be large portions of the BVH that don’t need to be updated. If the proportion is very high it can be faster to build from scratch instead, avoiding the overhead of doing a partial rebuild. If only a few nodes need to be updated it might be faster and produce a better BVH to selectively reinsert them.

§Arguments
  • bvh - An existing bvh with valid layout (AABBs in the tree above nodes that are to be rebuilt does not need to be correct)
  • should_remove() - should return true for any node that should be include in the rebuild. This includes the entire chain up from any leaves that need to be updated. Use PlocBuilder::compute_rebuild_path_flags() or similar to compute. The leaves should have their new AABB before calling partial_rebuild() but the BVH does not need to be refit to accommodate them.
  • search_distance - Which search distance should be used when building the ploc.
  • sort_precision - Bits used for ploc radix sort. More bits results in a more accurate but slower sort.
  • search_depth_threshold - Below this depth a search distance of 1 will be used. Set to 0 to bypass and just use search_distance.
Source§

impl PlocBuilder

Source

pub fn new() -> PlocBuilder

Initialize a ploc builder. After initial building, keep around this builder to reuse the associated allocations.

Source

pub fn with_capacity(prim_count: usize) -> PlocBuilder

Initialize a ploc builder with pre-allocated capacity for building a bvh with prim_count. After initial building, keep around this builder to reuse the associated allocations.

Source

pub fn build<T: Boundable>( &mut self, search_distance: PlocSearchDistance, aabbs: &[T], indices: Vec<u32>, sort_precision: SortPrecision, search_depth_threshold: usize, ) -> Bvh2

§Arguments
  • search_distance - Which search distance should be used when building the ploc.
  • aabbs - A list of bounding boxes. Should correspond to the number and order of primitives.
  • indices - The list indices used to index into the list of primitives. This allows for flexibility in which primitives are included in the bvh and in what order they are referenced. Often this would just be equivalent to: (0..aabbs.len() as u32).collect::<Vec<_>>()
  • sort_precision - Bits used for ploc radix sort. More bits results in a more accurate but slower sort.
  • search_depth_threshold - Below this depth a search distance of 1 will be used. Set to 0 to bypass and just use PlocSearchDistance. When trying to optimize build time it can be beneficial to limit the search distance for the first few passes as that is when the largest number of primitives are being considered. This pairs are initially found more quickly since it doesn’t need to search as far, and they are also found more often, since the nodes need to both agree to become paired. This also seems to occasionally result in an overall better bvh structure.
Source

pub fn build_with_bvh<T: Boundable>( &mut self, bvh: &mut Bvh2, search_distance: PlocSearchDistance, aabbs: &[T], indices: Vec<u32>, sort_precision: SortPrecision, search_depth_threshold: usize, )

§Arguments
  • bvh - An existing bvh. The builder will clear this bvh and reuse its allocations.
  • search_distance - Which search distance should be used when building the ploc.
  • aabbs - A list of bounding boxes. Should correspond to the number and order of primitives.
  • indices - The list indices used to index into the list of primitives. This allows for flexibility in which primitives are included in the bvh and in what order they are referenced. Often this would just be equivalent to: (0..aabbs.len() as u32).collect::<Vec<_>>()
  • sort_precision - Bits used for ploc radix sort. More bits results in a more accurate but slower sort.
  • search_depth_threshold - Below this depth a search distance of 1 will be used. Set to 0 to bypass and just use PlocSearchDistance. When trying to optimize build time it can be beneficial to limit the search distance for the first few passes as that is when the largest number of primitives are being considered. This pairs are initially found more quickly since it doesn’t need to search as far, and they are also found more often, since the nodes need to both agree to become paired. This also seems to occasionally result in an overall better bvh structure.
Source

pub fn build_ploc<const SEARCH_DISTANCE: usize, T: Boundable>( &mut self, bvh: &mut Bvh2, aabbs: &[T], indices: Vec<u32>, sort_precision: SortPrecision, search_depth_threshold: usize, )

§Arguments
  • bvh - An existing bvh. The builder will clear this bvh and reuse its allocations.
  • aabbs - A list of bounding boxes. Should correspond to the number and order of primitives.
  • sort_precision - Bits used for ploc radix sort. More bits results in a more accurate but slower sort.
  • search_depth_threshold - Below this depth a search distance of 1 will be used. Set to 0 to bypass and just use SEARCH_DISTANCE.

SEARCH_DISTANCE should be <= 32

Source

pub fn build_ploc_from_leaves<const SEARCH_DISTANCE: usize, const REBUILD: bool>( &mut self, bvh: &mut Bvh2, total_aabb: Aabb, sort_precision: SortPrecision, search_depth_threshold: usize, )

Prefer using Bvh2::build(), Bvh2::build_with_bvh(), Bvh2::build_ploc(), Bvh2::partial_rebuild(), or Bvh2::full_rebuild(). This is only public for non-typical usages. REBUILD is for partial BVH rebuilds. In that case inner nodes should be freed by setting them to invalid (with Bvh2Node::set_invalid()) and both respective inner and leaf nodes moved on to PlocBuilder::current_nodes. They must always be removed in pairs with the starting on an odd number. See PlocBuilder::partial_rebuild()

Trait Implementations§

Source§

impl Clone for PlocBuilder

Source§

fn clone(&self) -> PlocBuilder

Returns a duplicate 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 Default for PlocBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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

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.