#![doc = include_str!("../README.md")]
use std::io::Write;
pub mod args;
pub mod error;
#[doc(hidden)]
pub mod convert;
#[doc(hidden)]
pub mod draw;
#[doc(hidden)]
pub mod info;
#[doc(hidden)]
pub mod load;
#[doc(hidden)]
pub mod output;
use args::Command;
use error::MestoloError;
pub const USAGE: &str = "\
usage: mestolo <command> <file> [options]
commands:
info <file> what a cache file, an archive or a .vdb holds
slice <file> --axis x|y|z --at <n> -o <out.png>
a plane of a scalar grid, as PNG
convert <file> -o <out.vdb|out.vtu> [--as vdb|vtu|cache|archive]
the grids as .vdb, a cache file or an archive,
or one grid as .vtu
help this text
options:
--grid <name> the grid, where the file holds more than one
--limit <bytes> the most the file may hold, and its leaves and tiles make when read
and thawed (default 4294967296)
--force replace a file already at the output's path
";
pub fn run(command: &Command, out: &mut impl Write) -> Result<(), MestoloError> {
match command {
Command::Help => Ok(out.write_all(USAGE.as_bytes())?),
Command::Info(input) => info::write(&load::load(input)?, out),
Command::Slice { input, grid, axis, at, output } => {
output::check(output)?;
let loaded = load::load(input)?;
draw::slice(loaded.grid(grid.as_deref())?, *axis, *at, &output.path)
}
Command::Convert { input, grid, format, output } => {
output::check(output)?;
convert::convert(input, grid.as_deref(), *format, &output.path)
}
}
}