pub struct VoxelizedVolume { /* private fields */ }Expand description
A dense voxel grid storing the state of every voxel in a cubic volume.
VoxelizedVolume is the intermediate representation used during the voxelization process.
Unlike VoxelSet which only stores filled voxels, VoxelizedVolume stores a complete
dense 3D array where every grid cell has an associated VoxelValue.
§When to Use
Most users should use VoxelSet instead, which is converted from VoxelizedVolume
automatically and is much more memory-efficient. You might want to use VoxelizedVolume
directly if you need to:
- Query the state of ALL voxels, including empty ones
- Implement custom voxel processing algorithms
- Generate visualizations showing both filled and empty voxels
§Memory Usage
VoxelizedVolume stores all voxels in a dense 3D array:
- Memory usage:
O(resolution^3)in 3D orO(resolution^2)in 2D - A 100×100×100 grid requires 1 million voxel entries
For this reason, VoxelSet is usually preferred for storage.
§Conversion
VoxelizedVolume automatically converts to VoxelSet:
use parry3d::transformation::voxelization::{FillMode, VoxelSet, VoxelizedVolume};
use parry3d::shape::Ball;
///
let ball = Ball::new(1.0);
let (vertices, indices) = ball.to_trimesh(10, 10);
// Create dense volume
let volume = VoxelizedVolume::voxelize(
&vertices,
&indices,
10,
FillMode::SurfaceOnly,
false,
);
// Convert to sparse set (automatic via Into trait)
let voxel_set: VoxelSet = volume.into();§Example: Querying All Voxels
use parry3d::transformation::voxelization::{FillMode, VoxelValue, VoxelizedVolume};
use parry3d::shape::Cuboid;
use nalgebra::Vector3;
let cuboid = Cuboid::new(Vector3::new(1.0, 1.0, 1.0));
let (vertices, indices) = cuboid.to_trimesh();
let volume = VoxelizedVolume::voxelize(
&vertices,
&indices,
8,
FillMode::FloodFill { detect_cavities: false },
false,
);
// Count voxels by state
let resolution = volume.resolution();
let mut inside = 0;
let mut surface = 0;
let mut outside = 0;
for i in 0..resolution[0] {
for j in 0..resolution[1] {
for k in 0..resolution[2] {
match volume.voxel(i, j, k) {
VoxelValue::PrimitiveInsideSurface => inside += 1,
VoxelValue::PrimitiveOnSurface => surface += 1,
VoxelValue::PrimitiveOutsideSurface => outside += 1,
_ => {}
}
}
}
}
println!("Inside: {}, Surface: {}, Outside: {}", inside, surface, outside);Implementations§
Source§impl VoxelizedVolume
impl VoxelizedVolume
Sourcepub fn with_voxel_size(
points: &[Point<f32>],
indices: &[[u32; 3]],
voxel_size: f32,
fill_mode: FillMode,
keep_voxel_to_primitives_map: bool,
) -> Self
pub fn with_voxel_size( points: &[Point<f32>], indices: &[[u32; 3]], voxel_size: f32, fill_mode: FillMode, keep_voxel_to_primitives_map: bool, ) -> Self
Voxelizes the given shape described by its boundary: a triangle mesh (in 3D) or polyline (in 2D).
§Parameters
points- The vertex buffer of the boundary of the shape to voxelize.indices- The index buffer of the boundary of the shape to voxelize.resolution- Controls the number of subdivision done along each axis. This number is the number of subdivisions along the axis where the input shape has the largest extent. The other dimensions will have a different automatically-determined resolution (in order to keep the voxels cubic).fill_mode- Controls what is being voxelized.keep_voxel_to_primitives_map- If set totruea map between the voxels and the primitives (3D triangles or 2D segments) it intersects will be computed.
Sourcepub fn voxelize(
points: &[Point<f32>],
indices: &[[u32; 3]],
resolution: u32,
fill_mode: FillMode,
keep_voxel_to_primitives_map: bool,
) -> Self
pub fn voxelize( points: &[Point<f32>], indices: &[[u32; 3]], resolution: u32, fill_mode: FillMode, keep_voxel_to_primitives_map: bool, ) -> Self
Voxelizes the given shape described by its boundary: a triangle mesh (in 3D) or polyline (in 2D).
§Parameters
points- The vertex buffer of the boundary of the shape to voxelize.indices- The index buffer of the boundary of the shape to voxelize.resolution- Controls the number of subdivision done along each axis. This number is the number of subdivisions along the axis where the input shape has the largest extent. The other dimensions will have a different automatically-determined resolution (in order to keep the voxels cubic).fill_mode- Controls what is being voxelized.keep_voxel_to_primitives_map- If set totruea map between the voxels and the primitives (3D triangles or 2D segments) it intersects will be computed.
Sourcepub fn resolution(&self) -> [u32; 3]
pub fn resolution(&self) -> [u32; 3]
The number of voxel subdivisions along each coordinate axis.
Sourcepub fn scale(&self) -> f32
pub fn scale(&self) -> f32
The scale factor that needs to be applied to the voxels of self
in order to give them the size matching the original model’s size.
Sourcepub fn voxel(&self, i: u32, j: u32, k: u32) -> VoxelValue
pub fn voxel(&self, i: u32, j: u32, k: u32) -> VoxelValue
The value of the given voxel.
In 2D, the k argument is ignored.
Sourcepub fn to_trimesh(&self, value: VoxelValue) -> (Vec<Point<f32>>, Vec<[u32; 3]>)
pub fn to_trimesh(&self, value: VoxelValue) -> (Vec<Point<f32>>, Vec<[u32; 3]>)
Naive conversion of all the voxels with the given value to a triangle-mesh.
This conversion is extremely naive: it will simply collect all the 12 triangles forming the faces of each voxel. No actual boundary extraction is done.
Trait Implementations§
Source§impl From<VoxelizedVolume> for VoxelSet
impl From<VoxelizedVolume> for VoxelSet
Source§fn from(shape: VoxelizedVolume) -> Self
fn from(shape: VoxelizedVolume) -> Self
Auto Trait Implementations§
impl Freeze for VoxelizedVolume
impl RefUnwindSafe for VoxelizedVolume
impl Send for VoxelizedVolume
impl Sync for VoxelizedVolume
impl Unpin for VoxelizedVolume
impl UnwindSafe for VoxelizedVolume
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.