Skip to content

Commit

Permalink
WIP: Start Urquhart tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Notgnoshi committed Nov 29, 2022
1 parent 4791c83 commit e16bbc6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ path = "tools/transform/main.rs"
name = "triangulate"
path = "tools/triangulate/main.rs"

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

[dependencies]
clap = {version="4.0", features=["derive"]}
delaunator = "1.0"
Expand Down
30 changes: 30 additions & 0 deletions tools/urquhart/cmdline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use clap::Parser;
use generative::wkio::GeometryFormat;
use std::path::PathBuf;

/// Generate the Urquhart graph of the given geometries
///
/// Approximates the point cloud's relative neighborhood.
#[derive(Debug, Parser)]
#[clap(name = "urquhart", verbatim_doc_comment)]
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_t = GeometryFormat::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_t = GeometryFormat::Wkt)]
pub input_format: GeometryFormat,
}
32 changes: 32 additions & 0 deletions tools/urquhart/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mod cmdline;

use clap::Parser;
use generative::flatten::flatten_geometries_into_points;
use generative::stdio::{get_input_reader, get_output_writer};
use generative::triangulation::triangulate;
use generative::wkio::read_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 reader = get_input_reader(&args.input).unwrap();
let geometries = read_geometries(reader, &args.input_format); // lazily loaded

let points = flatten_geometries_into_points(geometries);
let triangulation = triangulate(points);
let urquhart = triangulation.urquhart();

// TODO: Graph serialization. Two options:
// 1. The edge list
// 2. TGF
// TODO: While we're at it, refactor the DLA graph serialization too?

let writer = get_output_writer(&args.output).unwrap();
}

0 comments on commit e16bbc6

Please sign in to comment.