Module building_blocks_storage::transform_map [−][src]
Expand description
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 = Extent3i::from_min_and_shape(Point3i::ZERO, Point3i::fill(16));
let mut index_map = Array3x1::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 = Array3x1::fill(extent, 0);
let chunk_shape = Point3i::fill(4);
let builder = ChunkMapBuilder3x1::new(chunk_shape, 0);
let mut dst = builder.build_with_hash_map_storage();
let tfm = TransformMap::new(&src, |value: i32| value + 1);
copy_extent(&extent, &tfm, &mut dst.lod_view_mut(0));
Structs
A lattice map that delegates look-ups to a different lattice map, then transforms the result
using some Fn(In) -> Out
.