[−][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
and
ChunkMapReader
only implement 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 `ChunkMap`, but any map that implements // `WriteExtent` can be a copy destination, and any map that implements `ReadExtent` can be a // copy source. let chunk_shape = PointN([16; 3]); let ambient_value = 0; let default_chunk_metadata = (); let mut other_map = ChunkMap3::new( chunk_shape, ambient_value, default_chunk_metadata, FastLz4 { level: 10 } ); copy_extent(&subextent, &map, &mut other_map); let local_cache = LocalChunkCache3::new(); let reader = ChunkMapReader3::new(&other_map, &local_cache); copy_extent(&subextent, &reader, &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 |