[−][src]Module building_blocks_storage::transform_map
A lattice map that overlays a transformation on top of a delegate lattice map.
As an example use case, say you have a large lattice map that can store various types of voxels, and each type of voxel has some associated data. If that data is even moderately sized, it could take up a lot of space by storing copies at every point of the lattice.
Instead, you can store that data in a "palette" array, and store indices into that array as your voxel data.
use building_blocks_core::prelude::*; use building_blocks_storage::prelude::*; struct BigData([u8; 9001]); let extent = Extent3::from_min_and_shape(PointN([0; 3]), PointN([16; 3])); let mut index_map = Array3::fill(extent, 0u8); *index_map.get_mut(&PointN([0, 0, 1])) = 1; let palette = vec![BigData([1; 9001]), BigData([2; 9001])]; let lookup = |i: u8| palette[i as usize].0[0]; let big_data_map = TransformMap::new(&index_map, &lookup); assert_eq!(big_data_map.get(&PointN([0, 0, 0])), palette[0].0[0]); assert_eq!(big_data_map.get(&PointN([0, 0, 1])), palette[1].0[0]);
TransformMap
also gives us an efficient way of applying transforms to array data during a copy:
let src = Array3::fill(extent, 0); let builder = ChunkMapBuilder { chunk_shape: PointN([4; 3]), ambient_value: 0, default_chunk_metadata: () }; let mut dst = builder.build_with_hash_map_storage(); let tfm = TransformMap::new(&src, &|value: i32| value + 1); copy_extent(&extent, &tfm, &mut dst);
Structs
TransformChunkCopySrcIter | |
TransformMap | A lattice map that delegates look-ups to a different lattice map, then transforms the result
using some |
Type Definitions
TransformChunkCopySrc |