[−][src]Module building_blocks_storage::access
Traits defining different ways to access data from generic lattice maps.
The fastest way to iterate over data in an Array is with a simple for loop over array indices, we call them "stride"s:
use building_blocks_core::prelude::*; use building_blocks_storage::prelude::*; let extent = Extent3i::from_min_and_shape(PointN([0; 3]), PointN([100; 3])); let mut map = Array3::fill(extent, 0); for i in 0..extent.num_points() { // Use the `GetMut<Stride>` trait impl of the map. *map.get_mut(Stride(i)) = 1; }
But this may require understanding the array layout.
Often, you only want to iterate over a sub-extent of the map. This can also be done at similar speeds using the ForEach
and ForEachMut
traits:
let subextent = Extent3i::from_min_and_shape(PointN([1; 3]), PointN([98; 3])); // Use the `ForEachMut<[i32; 3], Stride>` trait. map.for_each_mut(&subextent, |_s: Stride, value: &mut i32| { *value = 2 });
Arrays also implement ForEach*<PointN<N>>
and ForEach*<(PointN<N>, Stride)>
. ChunkMap
only implements
ForEach*<PointN<N>>
, because it's ambiguous which chunk a Stride
would apply to.
If you need to copy data between lattice maps, you should use the copy_extent
function. Copies can be done efficiently
because the ReadExtent
and WriteExtent
traits allow lattice maps to define how they would like to be written to or read
from.
// Create another map to copy to/from. We use a `ChunkHashMap`, but any map that implements // `WriteExtent` can be a copy destination, and any map that implements `ReadExtent` can be a // copy source. let builder = ChunkMapBuilder { chunk_shape: PointN([16; 3]), ambient_value: 0, default_chunk_metadata: () }; let mut other_map = builder.build_with_hash_map_storage(); copy_extent(&subextent, &map, &mut other_map); copy_extent(&subextent, &other_map, &mut map);
Traits
ForEach | |
ForEachMut | |
Get | |
GetMut | |
GetUnchecked | |
GetUncheckedMut | |
GetUncheckedMutRelease | |
GetUncheckedRelease | |
ReadExtent | A trait to facilitate the generic implementation of |
WriteExtent | A trait to facilitate the generic implementation of |
Functions
copy_extent | Copy all points in |