Skip to content

Commit

Permalink
WIP: Start brainstorming transform tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Notgnoshi committed Nov 26, 2022
1 parent 38c035a commit 178f5aa
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ path = "tools/dla/main.rs"
name = "point-cloud"
path = "tools/point-cloud/main.rs"

[[bin]]
name = "transform"
path = "tools/transform/main.rs"

[dependencies]
clap = {version="4.0", features=["derive"]}
geo = "0.23"
Expand Down
66 changes: 66 additions & 0 deletions tools/transform/cmdline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use clap::{Parser, ValueEnum};
use std::path::PathBuf;

#[derive(Debug, Clone, ValueEnum)]
pub enum GeometryFormat {
Wkt,
WkbHex,
}

#[derive(Debug, Clone, ValueEnum)]
pub enum Projection {
Xy,
Xz,
Yz,
Pca,
Svd,
Identity,
Isometric,
}

/// Perform transformations on geometries
#[derive(Debug, Parser)]
#[clap(name = "transform")]
pub struct CmdlineOptions {
/// Increase logging verbosity. Defaults to ERROR level.
#[clap(short, long, action = clap::ArgAction::Count)]
pub verbosity: u8,

/// Output file to write result to. Defaults to stdout.
#[clap(short, long)]
pub output: Option<PathBuf>,

/// Output geometry format.
#[clap(short = 'O', long, default_value = "wkt")]
pub output_format: GeometryFormat,

/// Input file to read input from. Defaults to stdin.
#[clap(short, long)]
pub input: Option<PathBuf>,

/// Input geometry format.
#[clap(short = 'I', long, default_value = "wkt")]
pub input_format: GeometryFormat,

/// CCW rotation, in degrees.
#[clap(short, long, default_value = "0.0")]
pub rotation: f64,

/// Additive offset in the x direction
#[clap(long, default_value = "0.0")]
pub x_offset: f64,

/// Additive offset in the y direction
#[clap(long, default_value = "0.0")]
pub y_offset: f64,

/// Multiplicative scale in the x direction
#[clap(short, long, default_value = "1.0")]
pub x_scale: f64,

/// Multiplicative scale in the y direction
#[clap(short, long, default_value = "1.0")]
pub y_scale: f64,
// TODO: Add projections
// pub projection: Projection,
}
36 changes: 36 additions & 0 deletions tools/transform/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
mod cmdline;

use clap::Parser;
use generative::stdio::{get_input_reader, get_output_writer};
use generative::wkio::{read_wkt_geometries, write_wkt_geometries};
use stderrlog::ColorChoice;

fn main() {
let args = cmdline::CmdlineOptions::parse();

stderrlog::new()
.verbosity(args.verbosity as usize + 1) // Default to WARN level.
.color(ColorChoice::Auto)
.init()
.expect("Failed to initialize stderrlog");

let writer = get_output_writer(args.output).unwrap();
let reader = get_input_reader(args.input).unwrap();

let geometries = read_wkt_geometries(reader);
write_wkt_geometries(writer, geometries);

// TODO: I don't think there needs to be any flattening
// * linear transforms can be done with the MapCoordsInplace trait on-the-fly
// * projections can be done by collecting CoordsIter into an array, performing the projection,
// and running back over the geometries with MapCoordsInplace to replace the coordinates.
// In either case, I don't think there needs to be a recursive flattener, or a flattened and
// tagged point array.

// TODO: Describe the offset, scale, and rotate as a linear transformation.
// TODO: Determe if it's more efficient (with my problem size) to do it on-the-fly or all at once.
// TODO: Perhaps allow switching between buffered and dynamic approaches? Or perhaps chunk the
// transformations?
// TODO: Projections
// TODO: WKB I/O
}

0 comments on commit 178f5aa

Please sign in to comment.