pub struct Octree<T, Idx: TreeIndex> { /* private fields */ }
Expand description
A data structure for partitioning data in a 3D space.
Implementations
sourceimpl<T: LeafMerge, Idx: TreeIndex> Octree<T, Idx>
impl<T: LeafMerge, Idx: TreeIndex> Octree<T, Idx>
sourcepub fn merge_branch(&mut self, branch_idx: Idx) -> Result<&T, Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
pub fn merge_branch(&mut self, branch_idx: Idx) -> Result<&T, Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
Collapse a branch into a leaf by merging all descendant leaf data.
All merges occur between leaf data at the same depth.
sourceimpl<T: LeafSample + Clone, Idx: TreeIndex> Octree<T, Idx>
impl<T: LeafSample + Clone, Idx: TreeIndex> Octree<T, Idx>
sourcepub fn sample_branch(&self, branch_idx: Idx) -> Result<T, Error<'_, Idx>>
pub fn sample_branch(&self, branch_idx: Idx) -> Result<T, Error<'_, Idx>>
Return the merged leaf data of the descendants of a specific branch.
sourceimpl<T, Idx: TreeIndex> Octree<T, Idx>
impl<T, Idx: TreeIndex> Octree<T, Idx>
sourcepub fn max_grid_size() -> Idx
pub fn max_grid_size() -> Idx
The maximum grid size representable by this Octree
sourcepub fn depth_of_unchecked(&self, node: Idx) -> Idx
pub fn depth_of_unchecked(&self, node: Idx) -> Idx
sourcepub fn depth_of(&self, node: Idx) -> Result<Idx, Error<'_, Idx>>
pub fn depth_of(&self, node: Idx) -> Result<Idx, Error<'_, Idx>>
The depth of the node at a specified index.
sourcepub fn branch(&mut self, target: Idx) -> Result<&[Idx; 8], Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
u8: AsPrimitive<Idx>,
Range<Idx>: Iterator,
pub fn branch(&mut self, target: Idx) -> Result<&[Idx; 8], Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
u8: AsPrimitive<Idx>,
Range<Idx>: Iterator,
Divide a voxel into a branch, returning the indices of the new branch’s children.
If the target voxel is already a branch, no changes are made and the existing branch’s children are returned.
The children of a branch are always stored and given in Octant order.
sourcepub fn void(&mut self, target: Idx) -> Vec<T>
pub fn void(&mut self, target: Idx) -> Vec<T>
Clear a voxel and clean up any data it represented. Leaf data is returned as a Vec, if any is removed.
If the voxel is a branch, the branch’s children are voided as well.
sourcepub fn set_leaf(&mut self, target: Idx, data: T) -> Vec<T>where
usize: AsPrimitive<Idx>,
pub fn set_leaf(&mut self, target: Idx, data: T) -> Vec<T>where
usize: AsPrimitive<Idx>,
Set the leaf data of a voxel and, if extant, return its previous leaf data.
If the voxel is a branch, the branch is voided first.
sourcepub fn grow(&mut self, oct: Octant) -> Result<Idx, Error<'_, Idx>>where
u8: AsPrimitive<Idx>,
usize: AsPrimitive<Idx>,
pub fn grow(&mut self, oct: Octant) -> Result<Idx, Error<'_, Idx>>where
u8: AsPrimitive<Idx>,
usize: AsPrimitive<Idx>,
sourcepub fn voxel_at_unchecked(&self, p: &VoxelPoint<Idx>) -> Idxwhere
Idx: Shr<u8, Output = Idx> + ShrAssign<u8> + PartialOrd + From<u8> + Shl<Idx, Output = Idx>,
pub fn voxel_at_unchecked(&self, p: &VoxelPoint<Idx>) -> Idxwhere
Idx: Shr<u8, Output = Idx> + ShrAssign<u8> + PartialOrd + From<u8> + Shl<Idx, Output = Idx>,
Get the index of the deepest voxel encompassing a specific VoxelPoint.
Panics
p
∉ 0..self.grid_size()
sourcepub fn voxel_at<'data>(
&self,
p: &'data VoxelPoint<Idx>
) -> Result<Idx, Error<'data, Idx>>where
Idx: Shr<u8, Output = Idx> + ShrAssign<u8> + PartialOrd + From<u8> + Shl<Idx, Output = Idx>,
pub fn voxel_at<'data>(
&self,
p: &'data VoxelPoint<Idx>
) -> Result<Idx, Error<'data, Idx>>where
Idx: Shr<u8, Output = Idx> + ShrAssign<u8> + PartialOrd + From<u8> + Shl<Idx, Output = Idx>,
Get the index of the deepest voxel encompassing a specific VoxelPoint.
Errors
p
∉ 0..self.grid_size()
sourcepub fn node_at(&self, p: &NodePoint<Idx>) -> Idxwhere
Idx: Shl<Idx, Output = Idx> + ShlAssign<Idx> + From<u8> + Shr<u8, Output = Idx> + ClosedMul + ShrAssign<u8>,
pub fn node_at(&self, p: &NodePoint<Idx>) -> Idxwhere
Idx: Shl<Idx, Output = Idx> + ShlAssign<Idx> + From<u8> + Shr<u8, Output = Idx> + ClosedMul + ShrAssign<u8>,
Get the index of the deepest voxel encompassing a specific NodePoint.
sourcepub fn upcast<NIdx: TreeIndex>(self) -> Octree<T, NIdx>where
usize: AsPrimitive<Idx>,
Idx: AsPrimitive<NIdx>,
pub fn upcast<NIdx: TreeIndex>(self) -> Octree<T, NIdx>where
usize: AsPrimitive<Idx>,
Idx: AsPrimitive<NIdx>,
Convert this tree to one with a wider index type.
sourcepub fn defragment(&mut self)where
usize: AsPrimitive<Idx>,
pub fn defragment(&mut self)where
usize: AsPrimitive<Idx>,
Clean proxy & leaf data by removing empty entries and updating stored indices.
sourcepub fn compress(&mut self)where
usize: AsPrimitive<Idx>,
pub fn compress(&mut self)where
usize: AsPrimitive<Idx>,
Defragment & reallocate self such that only enough memory to store
self
is allocated.
sourcepub fn leaf_unordered(&self) -> impl Iterator<Item = &T>
pub fn leaf_unordered(&self) -> impl Iterator<Item = &T>
Iterate through all leaf data, from oldest to newest.
pub fn node_point_of_unchecked(&self, index: Idx) -> NodePoint<Idx>where
u8: AsPrimitive<Idx>,
sourcepub fn node_point_of(&self, index: Idx) -> Result<NodePoint<Idx>, Error<'_, Idx>>where
u8: AsPrimitive<Idx>,
pub fn node_point_of(&self, index: Idx) -> Result<NodePoint<Idx>, Error<'_, Idx>>where
u8: AsPrimitive<Idx>,
Calculate the NodePoint of a specific node.
sourcepub fn graft_unchecked(&mut self, other: Self, node: Idx)where
usize: AsPrimitive<Idx>,
pub fn graft_unchecked(&mut self, other: Self, node: Idx)where
usize: AsPrimitive<Idx>,
sourcepub fn graft(&mut self, other: Self, node: Idx) -> Result<(), Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
pub fn graft(&mut self, other: Self, node: Idx) -> Result<(), Error<'_, Idx>>where
usize: AsPrimitive<Idx>,
Merge another tree as a branch of this tree.
node
must be the index of a ProxyData::Void node.
Trait Implementations
sourceimpl<T, Idx: TreeIndex> OctreeSlice<T, Idx> for Octree<T, Idx>
impl<T, Idx: TreeIndex> OctreeSlice<T, Idx> for Octree<T, Idx>
sourcefn height(&self) -> Idx
fn height(&self) -> Idx
The number of divisions within this octree.
This can be used to determine the dimensions of the voxel grid represented by the tree.
Examples
If self
consists only of one node (the root), its height is 0.
If the root is a branch, and each child of the root is a leaf (or void), then the tree’s height is 1.
If the root branch has a terminal child branch, the tree’s height is 2.
sourcefn height_from(&self, index: Idx) -> Idx
fn height_from(&self, index: Idx) -> Idx
Auto Trait Implementations
impl<T, Idx> !RefUnwindSafe for Octree<T, Idx>
impl<T, Idx> !Send for Octree<T, Idx>
impl<T, Idx> !Sync for Octree<T, Idx>
impl<T, Idx> Unpin for Octree<T, Idx>where
Idx: Unpin,
impl<T, Idx> UnwindSafe for Octree<T, Idx>where
Idx: UnwindSafe + RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read morefn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read morefn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
self
, then passes self.deref()
into the pipe function.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 morefn 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.impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read morefn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read morefn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read morefn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read morefn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read morefn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read morefn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds. Read morefn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read morefn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read morefn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more