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
impl Bvh
Sourcepub fn build(mesh: &Triangulation) -> OgeomResult<Self>
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.
Sourcepub fn of_shape(
model: &Model,
shape: &Shape,
deflection: Deflection,
tol: Tolerances,
) -> OgeomResult<Self>
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.
Sourcepub fn triangle_count(&self) -> usize
pub fn triangle_count(&self) -> usize
How many triangles the hierarchy holds.
Sourcepub fn triangle(&self, triangle: u32) -> Option<[Point; 3]>
pub fn triangle(&self, triangle: u32) -> Option<[Point; 3]>
A triangle’s three corners, or None past the last triangle.
Sourcepub fn nearest(&self, p: Point, max: f64) -> Option<Hit>
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.
Sourcepub fn nearest_many(&self, points: &[Point], max: f64) -> Vec<Option<Hit>>
pub fn nearest_many(&self, points: &[Point], max: f64) -> Vec<Option<Hit>>
Bvh::nearest for each point, in parallel, answers in point order.
Sourcepub fn nearest_where(
&self,
p: Point,
max: f64,
keep: impl Fn(u32) -> bool,
) -> Option<Hit>
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.
Sourcepub fn nearest_many_where(
&self,
points: &[Point],
max: f64,
keep: impl Fn(usize, u32) -> bool + Sync,
) -> Vec<Option<Hit>>
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.
Sourcepub fn within_ball(&self, centre: Point, radius: f64) -> Vec<u32>
pub fn within_ball(&self, centre: Point, radius: f64) -> Vec<u32>
Every triangle with a point within radius of centre, in index
order.
Sourcepub fn triangles_where(&self, test: impl Fn(&Aabb) -> bool) -> Vec<u32>
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).
Sourcepub fn ray(
&self,
origin: Point,
direction: Vector,
max: f64,
both_sides: bool,
) -> Option<Hit>
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.
Trait Implementations§
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.