From 18d15b0abe4c7ad1015dd46e32a35ffabb909192 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 1 Apr 2025 05:48:19 +0000 Subject: [PATCH] slicer: implement minimal argument parsing --- Cargo.lock | 1 + slicer/Cargo.toml | 1 + slicer/src/main.rs | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf82bd8..06e59ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4491,6 +4491,7 @@ name = "slicer" version = "0.1.0" dependencies = [ "anyhow", + "clap", "common", "criterion", "goo_format", diff --git a/slicer/Cargo.toml b/slicer/Cargo.toml index a90315e..e00e80d 100644 --- a/slicer/Cargo.toml +++ b/slicer/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] anyhow.workspace = true +clap.workspace = true image.workspace = true nalgebra.workspace = true obj-rs.workspace = true diff --git a/slicer/src/main.rs b/slicer/src/main.rs index 5248f1e..3445020 100644 --- a/slicer/src/main.rs +++ b/slicer/src/main.rs @@ -1,11 +1,13 @@ use std::{ fs::{self, File}, io::{stdout, BufReader, Write}, + path::PathBuf, thread, time::Instant, }; use anyhow::Result; +use clap::Parser; use nalgebra::{Vector2, Vector3}; use common::{ @@ -16,9 +18,16 @@ use common::{ use goo_format::{File as GooFile, LayerEncoder}; use slicer::{mesh::load_mesh, slicer::Slicer, Pos}; +#[derive(Parser)] +struct Args { + /// Path to the .stl file + input_file: PathBuf, + /// Path to the .goo file + output_file: PathBuf, +} + fn main() -> Result<()> { - const FILE_PATH: &str = "teapot.stl"; - const OUTPUT_PATH: &str = "output.goo"; + let args = Args::parse(); let slice_config = SliceConfig { format: Format::Goo, @@ -39,7 +48,7 @@ fn main() -> Result<()> { transition_layers: 10, }; - let file = File::open(FILE_PATH)?; + let file = File::open(args.input_file)?; let mut buf = BufReader::new(file); let mut mesh = load_mesh(&mut buf, "stl")?; let (min, max) = mesh.bounds(); @@ -90,7 +99,7 @@ fn main() -> Result<()> { // Once slicing is complete write to a .goo file let mut serializer = DynamicSerializer::new(); goo.join().unwrap().serialize(&mut serializer); - fs::write(OUTPUT_PATH, serializer.into_inner())?; + fs::write(args.output_file, serializer.into_inner())?; println!("\nDone. Elapsed: {:.1}s", now.elapsed().as_secs_f32());