mipmap-1d

Crates.iomipmap-1d
lib.rsmipmap-1d
version0.1.0
sourcesrc
created_at2024-05-01 19:22:32.608247
updated_at2024-05-01 19:22:32.608247
descriptionA small data structure to perform 1d-mipmapping (downsampling)
homepage
repository
max_upload_size
id1226779
size7,208
Nikolay Chechulin (NChechulin)

documentation

README

MipMap-1d

This Rust crate provides a small data structure that constructs and holds your 1-dimensional mipmaps. MipMaps are just downsampled versions of your vector. Each level is only half the size of a previous level. Therefore, the entire data structure takes approximately 2x the size of initial data in memory.

The downsampling is currently performed by averaging the pairs of elements (see example below). New ways might be introduced in later versions.

The crate currently works with all major numeric types (thanks to num-traits crate).

This can be used, for example, in plots. If you have a large number of points (lets say, 10M), you clearly can not draw them all on the screen at once. Also, drawing so many requires a lot of computational resources.

What you can do is to use 1d MipMap: you make several downsamples, and choose which one you want to display depending on a zoom level. The more you zoom in, the 'higher resolution' data you display.

Example

use mipmap_1d::MipMap1D;

let data = vec![2, 4, 6, 8, 9];
let mipmap = MipMap1D::new(data);
assert_eq!(mipmap.num_levels(), 4);
assert_eq!(*mipmap.get_level(0).unwrap(), [2, 4, 6, 8, 9]);
assert_eq!(*mipmap.get_level(1).unwrap(), [3, 7, 9]);
assert_eq!(*mipmap.get_level(2).unwrap(), [5, 9]);
assert_eq!(*mipmap.get_level(3).unwrap(), [7]);
assert_eq!(mipmap.get_level(4), None);

Contributing

Currently, the only idea for improvement is to introduce new averaging methods that are used in signal processing. Check issue #1 for details.

Commit count: 0

cargo fmt