Skip to content

Commit

Permalink
For command line options switch from structopt to clap.
Browse files Browse the repository at this point in the history
  • Loading branch information
wahn committed Nov 5, 2022
1 parent b673b9b commit cf57dc6
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ atomic = "0.5.1"
blend_info = "0.2.9"
# blend_info = { path = "../blend_info" }
byteorder = "1.4.3"
clap = { version = "4.0.19", features = ["derive"] }
crossbeam = "0.8.2"
crossbeam-channel = "0.5.6"
hexf = "0.2.1"
Expand All @@ -32,7 +33,6 @@ pest_derive = "2.4.1"
ply-rs = "0.1.3"
rayon = "1.5.3"
smallvec = "1.10.0"
structopt = "0.3.26"
strum = "0.24.1"
strum_macros = "0.24.3"
typed-arena = "2.0.1"
Expand Down
38 changes: 17 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,23 @@ https://www.rs-pbrt.org/doc/crates/rs_pbrt/index.html
```shell
> cargo build --release --no-default-features
> ./target/release/rs_pbrt --help
rs_pbrt 0.9.8
Parse a PBRT scene file (extension .pbrt) and render it

USAGE:
rs_pbrt [OPTIONS] <path>

FLAGS:
-h, --help Prints help information
-V, --version Prints version information

OPTIONS:
--cropx0 <cropx0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropx1 <cropx1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
--cropy0 <cropy0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropy1 <cropy1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
-i, --integrator <integrator> ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
-t, --nthreads <nthreads> use specified number of threads for rendering [default: 0]
-s, --samples <samples> pixel samples [default: 0]

ARGS:
<path> The path to the file to read
rs_pbrt version 0.9.8 (unknown) [Detected 28 cores]

Physically based rendering (PBR) with Rust

Usage: rs_pbrt [OPTIONS] --path <PATH>

Options:
--cropx0 <CROPX0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropx1 <CROPX1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
--cropy0 <CROPY0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropy1 <CROPY1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
-i, --integrator <INTEGRATOR> ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
-t, --nthreads <NTHREADS> use specified number of threads for rendering [default: 0]
-s, --samples <SAMPLES> pixel samples [default: 0]
-p, --path <PATH> The path to the file to read
-h, --help Print help information
-V, --version Print version information
```

## Test Scenes
Expand Down
47 changes: 24 additions & 23 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,24 @@ you get a simple **usage** message of the main executable ``rs_pbrt``:
# relative path to executable rs_pbrt (assuming release build)
./target/release/rs_pbrt --help
# output
rs_pbrt 0.9.8
Parse a PBRT scene file (extension .pbrt) and render it
USAGE:
rs_pbrt [OPTIONS] <path>
Physically based rendering (PBR) with Rust
Physically based rendering (PBR) with Rust
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
Usage: rs_pbrt [OPTIONS] --path <PATH>
OPTIONS:
--cropx0 <cropx0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropx1 <cropx1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
--cropy0 <cropy0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropy1 <cropy1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
-i, --integrator <integrator> ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
-t, --nthreads <nthreads> use specified number of threads for rendering [default: 0]
-s, --samples <samples> pixel samples [default: 0]
Options:
--cropx0 <CROPX0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropx1 <CROPX1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
--cropy0 <CROPY0> Specify an image crop window <x0 x1 y0 y1> [default: 0.0]
--cropy1 <CROPY1> Specify an image crop window <x0 x1 y0 y1> [default: 1.0]
-i, --integrator <INTEGRATOR> ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
-t, --nthreads <NTHREADS> use specified number of threads for rendering [default: 0]
-s, --samples <SAMPLES> pixel samples [default: 0]
-p, --path <PATH> The path to the file to read
-h, --help Print help information
-V, --version Print version information
ARGS:
<path> The path to the file to read
The **version** can be checked by:

Expand All @@ -146,6 +143,8 @@ The **version** can be checked by:
# print version number
./target/release/rs_pbrt --version
# output
rs_pbrt version 0.9.8 (unknown) [Detected 28 cores]
rs_pbrt 0.9.8
Your first rendered image
Expand All @@ -157,20 +156,22 @@ render a `PNG`_ image (currently always being called ``pbrt.png``):
.. code:: shell
# specifing an input file
./target/release/rs_pbrt ~/git/gitlab/rs-pbrt-test-scenes/pbrt/cornell_box/cornell_box.pbrt
./target/release/rs_pbrt --path ~/git/gitlab/rs-pbrt-test-scenes/pbrt/cornell_box/cornell_box.pbrt
# output
pbrt version 0.9.8 (unknown) [Detected 4 cores]
rs_pbrt version 0.9.8 (unknown) [Detected 28 cores]
Copyright (c) 2016-2022 Jan Douglas Bert Walter.
Rust code based on C++ code by Matt Pharr, Greg Humphreys, and Wenzel Jakob.
Film "image"
"integer xresolution" [500]
"integer yresolution" [500]
Sampler "sobol"
"integer pixelsamples" [8]
Integrator "path"
Integrator "path"
Rendering with 4 thread(s) ...
1024 / 1024 [=======================================================================] 100.00 % 176.58/s
Rendering with 28 thread(s) ...
1024 / 1024 [=======================================================================] 100.00 % 1828.38/s
Writing image "pbrt.png" with bounds Bounds2i { p_min: Point2i { x: 0, y: 0 }, p_max: Point2i { x: 500, y: 500 } }
The resulting image should look like this:
Expand Down Expand Up @@ -205,7 +206,7 @@ the samples per pixel on the command line:
.. code:: shell
./target/release/rs_pbrt --samples 256 ~/git/gitlab/rs-pbrt-test-scenes/pbrt/cornell_box/cornell_box.pbrt
./target/release/rs_pbrt --samples 256 --path ~/git/gitlab/rs-pbrt-test-scenes/pbrt/cornell_box/cornell_box.pbrt
More scenes to render
=====================
Expand Down
23 changes: 10 additions & 13 deletions examples/parse_ass_file.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use pest_derive::*;

// parser
use pest::Parser;

// command line options
use structopt::StructOpt;
use clap::Parser as ClapParser;
use pest::Parser as PestParser;
// pbrt
use rs_pbrt::core::api::{make_accelerator, make_camera, make_film, make_filter, make_sampler};
use rs_pbrt::core::camera::Camera;
Expand Down Expand Up @@ -50,17 +45,18 @@ use std::sync::Arc;
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");

/// Parse a Arnold scene file (extension .ass) and render it.
#[derive(StructOpt)]
struct Cli {
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// samples per pixel
#[structopt(short = "s", long = "samples", default_value = "16")]
#[arg(short = 's', long = "samples", default_value_t = 16)]
samples: u16,
/// The path to the file to read
#[structopt(parse(from_os_str))]
#[arg(long, short)]
path: std::path::PathBuf,
}

#[derive(Parser)]
#[derive(pest_derive::Parser)]
#[grammar = "../examples/ass.pest"]
struct AssParser;

Expand Down Expand Up @@ -252,8 +248,9 @@ fn main() -> std::io::Result<()> {
"parse_ass_file version {} ({}) [Detected {} cores]",
VERSION, git_describe, num_cores
);
println!();
// handle command line options
let args = Cli::from_args();
let args = Args::parse();
let samples_per_pixel: u16 = args.samples;
// default values
let mut node_name: String = String::from(""); // no default name
Expand Down
41 changes: 25 additions & 16 deletions src/bin/parse_blend_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// TODO: use an empty (compass) object as target

// command line options
use structopt::StructOpt;
use clap::Parser;
// std
use std::collections::HashMap;
use std::convert::TryInto;
Expand Down Expand Up @@ -72,43 +72,44 @@ use rs_pbrt::textures::imagemap::ImageTexture;
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");

/// Parse a Blender scene file and render it.
#[derive(StructOpt)]
struct Cli {
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// camera name
#[structopt(short = "c", long = "camera_name")]
#[arg(short = 'c', long = "camera_name")]
camera_name: Option<String>,
/// global light scaling
#[structopt(short = "l", long = "light_scale", default_value = "1.0")]
#[arg(short = 'l', long = "light_scale", default_value = "1.0")]
light_scale: f32,
/// pixel samples
#[structopt(short = "s", long = "samples", default_value = "1")]
#[arg(short = 's', long = "samples", default_value = "1")]
samples: u32,
/// ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
#[structopt(short = "i", long = "integrator")]
#[arg(short = 'i', long = "integrator")]
integrator: Option<String>,
/// max length of a light-carrying path
#[structopt(short = "m", long = "max_depth", default_value = "5")]
#[arg(short = 'm', long = "max_depth", default_value = "5")]
max_depth: u32,
/// bootstrap samples (MLT)
#[structopt(long = "bootstrap_samples", default_value = "100000")]
#[arg(long = "bootstrap_samples", default_value = "100000")]
bootstrap_samples: u32,
/// number of Markov chains (MLT)
#[structopt(long = "chains", default_value = "1000")]
#[arg(long = "chains", default_value = "1000")]
chains: u32,
/// number of path mutations (MLT)
#[structopt(long = "mutations_per_pixel", default_value = "100")]
#[arg(long = "mutations_per_pixel", default_value = "100")]
mutations_per_pixel: u32,
/// prob of discarding path (MLT)
#[structopt(long = "step_probability", default_value = "0.3")]
#[arg(long = "step_probability", default_value = "0.3")]
step_probability: f32,
/// perturbation deviation (MLT)
#[structopt(long = "sigma", default_value = "0.01")]
#[arg(long = "sigma", default_value = "0.01")]
sigma: f32,
/// frequency to write image (SPPM)
#[structopt(long = "write_frequency", default_value = "1")]
#[arg(long = "write_frequency", default_value = "1")]
write_frequency: i32,
/// The path to the file to read
#[structopt(parse(from_os_str))]
#[arg(long, short)]
path: std::path::PathBuf,
}

Expand Down Expand Up @@ -1767,7 +1768,15 @@ fn make_scene(primitives: &Vec<Arc<Primitive>>, lights: Vec<Arc<Light>>) -> Scen
}

fn main() -> std::io::Result<()> {
let args = Cli::from_args();
let num_cores = num_cpus::get();
let git_describe = option_env!("GIT_DESCRIBE").unwrap_or("unknown");
println!(
"parse_blend_file version {} ({}) [Detected {} cores]",
VERSION, git_describe, num_cores
);
println!();
// handle command line options
let args = Args::parse();
let git_describe = option_env!("GIT_DESCRIBE").unwrap_or("unknown");
let num_threads: u8 = num_cpus::get() as u8;
println!(
Expand Down
33 changes: 18 additions & 15 deletions src/bin/rs_pbrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
struct PbrtParser;

// parser
use pest::Parser;
use pest::Parser as PestParser;

// command line options
use structopt::StructOpt;
use clap::Parser as ClapParser;
// pbrt
use rs_pbrt::core::api::{
pbrt_accelerator, pbrt_active_transform_all, pbrt_active_transform_end_time,
Expand All @@ -37,8 +37,9 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;

/// Parse a PBRT scene file (extension .pbrt) and render it.
#[derive(StructOpt)]
struct Cli {
#[derive(clap::Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Specify an image crop window <x0 x1 y0 y1>
#[structopt(long, default_value = "0.0")]
cropx0: f32,
Expand All @@ -52,16 +53,16 @@ struct Cli {
#[structopt(long, default_value = "1.0")]
cropy1: f32,
/// ao, directlighting, whitted, path, bdpt, mlt, sppm, volpath
#[structopt(short = "i", long = "integrator")]
#[structopt(short = 'i', long = "integrator")]
integrator: Option<String>,
/// use specified number of threads for rendering
#[structopt(short = "t", long = "nthreads", default_value = "0")]
#[structopt(short = 't', long = "nthreads", default_value = "0")]
nthreads: u8,
/// pixel samples
#[structopt(short = "s", long = "samples", default_value = "0")]
#[structopt(short = 's', long = "samples", default_value = "0")]
samples: u32,
/// The path to the file to read
#[structopt(parse(from_os_str))]
#[arg(long, short)]
path: std::path::PathBuf,
}

Expand Down Expand Up @@ -887,22 +888,24 @@ fn parse_file(
}

fn main() {
let num_cores = num_cpus::get();
let git_describe = option_env!("GIT_DESCRIBE").unwrap_or("unknown");
println!(
"rs_pbrt version {} ({}) [Detected {} cores]",
VERSION, git_describe, num_cores
);
println!();
// handle command line options
let args = Cli::from_args();
let args = Args::parse();
let pixelsamples: u32 = args.samples;
let number_of_threads: u8 = args.nthreads;
let cropx0: f32 = args.cropx0;
let cropx1: f32 = args.cropx1;
let cropy0: f32 = args.cropy0;
let cropy1: f32 = args.cropy1;
let num_cores = num_cpus::get();
let git_describe = option_env!("GIT_DESCRIBE").unwrap_or("unknown");
println!(
"pbrt version {} ({}) [Detected {} cores]",
VERSION, git_describe, num_cores
);
println!("Copyright (c) 2016-2022 Jan Douglas Bert Walter.");
println!("Rust code based on C++ code by Matt Pharr, Greg Humphreys, and Wenzel Jakob.");
println!();
let (mut api_state, mut bsdf_state) = pbrt_init(
pixelsamples,
number_of_threads,
Expand Down

0 comments on commit cf57dc6

Please sign in to comment.