Struct libnoise::Visualizer

source ·
pub struct Visualizer<const D: usize> { /* private fields */ }
Expand description

A struct for visualizing the output of a generator.

The image feature must be enabled for writing images of visualizations.

This struct represents a simple way to quickly visualize the output of a Generator by building a NoiseBuffer of a given size, populating it with data, and creating an PNG or GIF file visualizing said data.

In the 1D case, the visualization is a grayscale band of one pixel in height and with the provided length. In the 2D case, the visualization is an image of the provided dimensions. In the 3D case, the visualization is an image providing an isometric view on a cube representing the buffer. In the 4D case, the visualization is equivalent to the 3D case, except the result is an animation with the 4th dimension mapping to time.

Note: This struct is meant to be used to get an idea of what a generator is doing. Especially the 1D, 3D, and 4D cases are not suited for usage besides debugging, as the main goal of this library is to provide an efficient and modular way to creating a noise generation pipeline.

The usage of this struct is simple and analogous to that of NoiseBuffer:

// create a generator
let generator = Source::simplex(42);

// create a visualizer and use it to visualize the output of the generator
let path = "output.png";
Visualizer::<3>::new([30, 20, 25], &generator).write_to_file(path).unwrap();

In fact, a visualizer can be created from a NoiseBuffer by simply converting it to a Visualizer:

// create a generator
let generator = Source::simplex(42);

// create a noise buffer
let buf = NoiseBuffer::<3>::new([30, 20, 25], &generator);

// create a visualizer and use it to visualize the output of the generator
let path = "output.png";
Visualizer::from(buf).write_to_file(path);

Implementations§

source§

impl Visualizer<1>

source

pub fn new<G: Generator<1>>(shape: [usize; 1], generator: &G) -> Self

Creates a new Visualizer with the given shape and filled with noise generated by the given generator. For further detail see the struct-level documentation.

source

pub fn write_to_file(&self, path: &str) -> Result<(), ImageError>

Write a PNG file to the given path, visualizing the output of the provided generator. For further detail see the struct-level documentation.

source§

impl Visualizer<2>

source

pub fn new<G: Generator<2>>(shape: [usize; 2], generator: &G) -> Self

Creates a new Visualizer with the given shape and filled with noise generated by the given generator. For further detail see the struct-level documentation.

source

pub fn write_to_file(&self, path: &str) -> Result<(), ImageError>

source§

impl Visualizer<3>

source

pub fn new<G: Generator<3>>(shape: [usize; 3], generator: &G) -> Self

Creates a new Visualizer with the given shape and filled with noise generated by the given generator. For further detail see the struct-level documentation.

source

pub fn write_to_file(&self, path: &str) -> Result<(), ImageError>

Write a PNG file to the given path, visualizing the output of the provided generator. For further detail see the struct-level documentation.

source§

impl Visualizer<4>

source

pub fn new<G: Generator<4>>(shape: [usize; 4], generator: &G) -> Self

Creates a new Visualizer with the given shape and filled with noise generated by the given generator. For further detail see the struct-level documentation.

source

pub fn write_to_file(&self, path: &str) -> Result<(), Error>

Write a GIF file to the given path, visualizing the output of the provided generator. For further detail see the struct-level documentation.

Trait Implementations§

source§

impl<const D: usize> Clone for Visualizer<D>

source§

fn clone(&self) -> Visualizer<D>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const D: usize> Debug for Visualizer<D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const D: usize> From<NoiseBuffer<D>> for Visualizer<D>

source§

fn from(noisebuf: NoiseBuffer<D>) -> Self

Converts to this type from the input type.
source§

impl<const D: usize> Index<&[usize]> for Visualizer<D>

§

type Output = u8

The returned type after indexing.
source§

fn index(&self, index: &[usize]) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<const D: usize> IndexMut<&[usize]> for Visualizer<D>

source§

fn index_mut(&mut self, index: &[usize]) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<const D: usize> RefUnwindSafe for Visualizer<D>

§

impl<const D: usize> Send for Visualizer<D>

§

impl<const D: usize> Sync for Visualizer<D>

§

impl<const D: usize> Unpin for Visualizer<D>

§

impl<const D: usize> UnwindSafe for Visualizer<D>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V