Skip to main content

Bvh

Struct Bvh 

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

A bounding-volume hierarchy over a mesh’s triangles.

Built with a surface-area heuristic over binned centroids. Holds its own copy of the triangles’ corners, so the mesh it was built from may be dropped or changed; queries answer about the mesh as it was.

Implementations§

Source§

impl Bvh

Source

pub fn build(mesh: &Triangulation) -> OgeomResult<Self>

Build the hierarchy over a mesh’s triangles.

Degenerate triangles are kept: a nearest query can still land on one, and a ray through one finds it only where it is a proper triangle as the ray sees it.

§Errors

OgeomError::Range if a triangle names a vertex the mesh does not have, and OgeomError::Numeric if a triangle’s corner is not finite.

Source

pub fn of_shape( model: &Model, shape: &Shape, deflection: Deflection, tol: Tolerances, ) -> OgeomResult<Self>

Build the hierarchy over a shape’s triangulation at a deflection.

The triangle indices are those of triangulate for the same arguments, which is deterministic, and Bvh::triangle gives each triangle’s corners without it.

§Errors

As triangulate and Bvh::build.

Source

pub fn triangle_count(&self) -> usize

How many triangles the hierarchy holds.

Source

pub fn is_empty(&self) -> bool

Whether the hierarchy holds no triangle.

Source

pub fn triangle(&self, triangle: u32) -> Option<[Point; 3]>

A triangle’s three corners, or None past the last triangle.

Source

pub fn bounds(&self) -> Aabb

The bounds of every triangle.

Source

pub fn nearest(&self, p: Point, max: f64) -> Option<Hit>

The point on the mesh nearest p, no farther than max; the lowest triangle index among equally near ones. max may be infinite.

Source

pub fn nearest_many(&self, points: &[Point], max: f64) -> Vec<Option<Hit>>

Bvh::nearest for each point, in parallel, answers in point order.

Source

pub fn nearest_where( &self, p: Point, max: f64, keep: impl Fn(u32) -> bool, ) -> Option<Hit>

Bvh::nearest among the triangles keep accepts: the point on them nearest p, no farther than max, the lowest triangle index among equally near ones. The answer is brute force’s over the kept triangles alone, however the tree holds the others.

Source

pub fn nearest_many_where( &self, points: &[Point], max: f64, keep: impl Fn(usize, u32) -> bool + Sync, ) -> Vec<Option<Hit>>

Bvh::nearest_where for each point, in parallel, answers in point order. keep is asked with the point’s index and a triangle.

Source

pub fn within_ball(&self, centre: Point, radius: f64) -> Vec<u32>

Every triangle with a point within radius of centre, in index order.

Source

pub fn triangles_where(&self, test: impl Fn(&Aabb) -> bool) -> Vec<u32>

Every triangle whose bounding box passes test, in index order.

test prunes the walk: a node’s box that fails it is not entered, so test must pass every box that contains a box it passes (a region overlap does, a containment test does not).

Source

pub fn ray( &self, origin: Point, direction: Vector, max: f64, both_sides: bool, ) -> Option<Hit>

The first triangle along a ray, no farther than max along it, and the lowest triangle index among equally far ones.

direction need not be unit length; Hit::distance is measured along it in model units. A triangle faces the ray when the ray meets the side its counter-clockwise winding points out of; with both_sides false only those count. A hit at the origin itself counts, at distance zero. A ray in a triangle’s plane does not hit it, having no area to cross there; in a closed mesh the triangles across the edges it passes through are hit instead.

Source

pub fn rays( &self, origins: &[Point], directions: &[Vector], max: f64, both_sides: bool, ) -> OgeomResult<Vec<Option<Hit>>>

Bvh::ray for each origin and direction, in parallel, answers in input order.

§Errors

OgeomError::Dimension if there are not as many directions as origins.

Source

pub fn hits_along( &self, origin: Point, direction: Vector, max: f64, both_sides: bool, ) -> Vec<Hit>

Every triangle along a ray within max, nearest first, ties in index order. Each is the hit Bvh::ray reports when it is first.

Trait Implementations§

Source§

impl Clone for Bvh

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Bvh

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Bvh

§

impl RefUnwindSafe for Bvh

§

impl Send for Bvh

§

impl Sync 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> 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> Same for T

Source§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.