Skip to content

Commit

Permalink
change structopt to parse, and also
Browse files Browse the repository at this point in the history
add verify data binary which can be used to verify that various config and/or scene files parse
  • Loading branch information
gillett-hernandez committed Jul 7, 2024
1 parent 8d6c463 commit d7207a6
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ visualize_importance_map = ["minifb"]
[dependencies]
anyhow = "~1.0"
bincode = "~1.3"
clap = { version = "4.5.8", features = ["derive"] }
colorgrad = { version = "~0.6", optional = true }
crossbeam = "~0.8"
deepsize = "~0.2"
Expand Down Expand Up @@ -66,7 +67,6 @@ sdfu = { git = "https://github.com/fu5ha/sdfu", optional = true }
serde = { version = "~1.0", features = ["derive"] }
# simplelog = "0.12"
smallvec = "~1.13"
structopt = "~0.3"
tobj = "~4.0"
toml = "~0.8"
tracing = "~0.1"
Expand Down
1 change: 1 addition & 0 deletions data/scenes/cornell_box_metals_and_dielectrics.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ angle = 140
[environment.importance_map]
# width = 2048
# height = 2048
cache = true
width = 512
height = 512

Expand Down
1 change: 1 addition & 0 deletions data/scenes/hdri_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ texture_name = "machine_shop_4k"
[environment.importance_map]
# width = 2048
# height = 2048
cache = true
width = 1024
height = 1024

Expand Down
1 change: 1 addition & 0 deletions data/scenes/test_nonuniform_scale.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ texture_name = "autumn_park_8k"
[environment.importance_map]
# width = 2048
# height = 2048
cache = true
width = 1024
height = 1024

Expand Down
5 changes: 1 addition & 4 deletions data/scenes/white_furnace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ env_sampling_probability = 1.0
[environment]
type = "Constant"
strength = 1.0
[environment.color]
type = "Flat"
strength = 1.0
interpolation_mode = "Linear"
color = "simple_sky_blue"


[[instances]]
Expand Down
15 changes: 7 additions & 8 deletions src/bin/color_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ use crossbeam::channel::{unbounded, Receiver, Sender};
use eframe::egui;
use minifb::{Key, KeyRepeat, Scale, Window, WindowOptions};
use rayon::iter::ParallelIterator;
use structopt::StructOpt;
use clap::Parser;

#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
#[derive(Debug, Parser)]
struct Opt {
#[structopt(long, default_value = "data/config.toml")]
#[arg(long, default_value = "data/config.toml")]
pub config_file: String,
pub width: usize,
pub height: usize,
#[structopt(long, default_value = "")]
#[arg(long, default_value = "")]
pub initial_color: String,
#[structopt(long, default_value = "1.0")]
#[arg(long, default_value = "1.0")]
pub dynamic_range: f32,
}

Expand Down Expand Up @@ -503,7 +502,7 @@ impl View {
}

fn mvc(opts: Opt) -> Result<(Model, Controller), ()> {
let config: TOMLConfig = match get_settings(opts.config_file) {
let config: TOMLConfig = match get_config(opts.config_file) {
Ok(expr) => expr,
Err(v) => {
error!("couldn't read config.toml, {:?}", v);
Expand Down Expand Up @@ -605,7 +604,7 @@ fn main() {

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");

let opts = Opt::from_args();
let opts = Opt::parse();

let (width, height) = (opts.width, opts.height);
let (mut model, controller) = mvc(opts).expect("failed to construct MVC");
Expand Down
15 changes: 7 additions & 8 deletions src/bin/compare_exr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use root::{
prelude::{f32x4, SimdFloat},
vec2d::Vec2D,
};
use structopt::StructOpt;
use clap::Parser;

fn read_exr_file<P: AsRef<Path>>(name: P) -> Option<Vec2D<f32x4>> {
read_first_rgba_layer_from_file(
Expand All @@ -23,16 +23,15 @@ fn read_exr_file<P: AsRef<Path>>(name: P) -> Option<Vec2D<f32x4>> {
.map(|e| e.layer_data.channel_data.pixels)
}

#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
#[derive(Debug, Parser)]
struct Opt {
#[structopt(long)]
#[arg(long)]
pub compare_file: String,
#[structopt(long)]
#[arg(long)]
pub ground_truth_file: String,
#[structopt(long)]
#[arg(long)]
pub output_file: String,
#[structopt(long, default_value = "absolute_difference")]
#[arg(long, default_value = "absolute_difference")]
pub mode: String,
}

Expand All @@ -54,7 +53,7 @@ impl Mode {
}

fn main() {
let opts = Opt::from_args();
let opts = Opt::parse();

let maybe_image0 = read_exr_file(opts.compare_file);
let maybe_image1 = read_exr_file(opts.ground_truth_file);
Expand Down
24 changes: 11 additions & 13 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate rust_pathtracer as root;

use root::parsing::config::*;
use root::parsing::construct_world;
use root::parsing::get_settings;
use root::parsing::get_config;
use root::renderer::TiledRenderer;
use root::renderer::{NaiveRenderer, Renderer};

Expand All @@ -21,30 +21,28 @@ use std::{fs::File, sync::Arc};
use tracing::level_filters::LevelFilter;
use tracing_subscriber::prelude::*;

// TODO: switch to clap
use structopt::StructOpt;

#[cfg(all(target_os = "windows", feature = "notification"))]
use std::time::{Duration, Instant};
#[cfg(all(target_os = "windows", feature = "notification"))]
use win32_notification::NotificationBuilder;

#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
use clap::Parser;

#[derive(Parser, Debug)]
struct Opt {
#[structopt(long)]
#[arg(long)]
pub scene: Option<String>,

#[structopt(long, default_value = "data/config.toml")]
#[arg(long, default_value = "data/config.toml")]
pub config: String,

#[structopt(short = "n", long)]
#[arg(short = 'n', long)]
pub dry_run: bool,

#[structopt(long, default_value = "warn")]
#[arg(long, default_value = "warn")]
pub stdout_log_level: String,

#[structopt(long, default_value = "info")]
#[arg(long, default_value = "info")]
pub write_log_level: String,
}

Expand Down Expand Up @@ -82,7 +80,7 @@ fn parse_level_filter(level: String, default: LevelFilter) -> LevelFilter {
}

fn main() {
let opts = Opt::from_args();
let opts = Opt::parse();
let stdout_log_level = parse_level_filter(opts.stdout_log_level, LevelFilter::WARN);
let write_log_level = parse_level_filter(opts.write_log_level, LevelFilter::INFO);

Expand Down Expand Up @@ -118,7 +116,7 @@ fn main() {
.expect("Failed to create cache directory. Does this process have permissions?");
}

let mut toml_config: TOMLConfig = match get_settings(opts.config) {
let mut toml_config: TOMLConfig = match get_config(opts.config) {
Ok(expr) => expr,
Err(v) => {
error!("couldn't read config.toml, {:?}", v);
Expand Down
15 changes: 7 additions & 8 deletions src/bin/raymarch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ use std::fs::File;
use std::path::PathBuf;

// third party but non-subject-matter imports
use clap::Parser;
#[cfg(feature = "preview")]
use minifb::WindowOptions;
use pbr::ProgressBar;
use rayon::iter::ParallelIterator;
use structopt::StructOpt;

// our imports
use math::prelude::*;
use root::hittable::{HasBoundingBox, AABB};
use root::parsing::tonemap::TonemapSettings;
use root::parsing::{config::*, construct_world, get_settings, parse_tonemap_settings};
use root::parsing::{config::*, construct_world, get_config, parse_tonemap_settings};
use root::prelude::*;
use root::renderer::output_film;
use root::world::{EnvironmentMap, Material, MaterialEnum};
Expand Down Expand Up @@ -58,12 +58,11 @@ fn deconvert(v: uvVec3) -> f32x4 {
f32x4::from_array([v.x, v.y, v.z, 0.0])
}

#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
#[derive(Debug, Parser)]
struct Opt {
#[structopt(long, default_value = "data/raymarch_config.toml")]
#[arg(long, default_value = "data/raymarch_config.toml")]
pub config: String,
#[structopt(short = "n", long)]
#[arg(short = 'n', long)]
pub dry_run: bool,
}
enum MarchResult {
Expand Down Expand Up @@ -403,9 +402,9 @@ fn main() {
.finish();

tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
let opt = Opt::from_args();
let opt = Opt::parse();

let settings = get_settings(opt.config).unwrap();
let settings = get_config(opt.config).unwrap();

let mut config = Config::from(settings);
let render_settings = config.render_settings[0].clone();
Expand Down
Loading

0 comments on commit d7207a6

Please sign in to comment.