-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.rs
434 lines (430 loc) · 17.7 KB
/
cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
//! Command Line Interface module.
//!
//! Provides [`build_cli`] function with all cli
//! desired subcommands and flags, using [`clap`](https://github.com/clap-rs/clap)
//! library.
use clap::{Arg, Command};
/// Default normalization factor.
///
/// When no arguments are provided to `--factor` flag
const FACTOR: &str = "0.2";
/// Default transfer function parameter.
///
/// When no arguments are provided to `--gamma` flag
const GAMMA: &str = "1.0";
/// Default image width.
///
/// When no arguments are provided to `--width` flag
const WIDTH: &str = "640";
/// Default image height.
///
/// When no arguments are provided to `--height` flag
const HEIGHT: &str = "480";
/// Default angle of view (in degrees).
///
/// When no arguments are provided to `--angle-deg` flag
const ANGLE_DEG: &str = "0.0";
/// Default rendering algorithm.
///
/// When no arguments are provided to `--algorithm` flag
const ALGORITHM: &str = "pathtracer";
/// Default number of rays for pathtracer algorithm.
///
/// When no arguments are provided to `--num-of-rays` flag
const NUM_OF_RAYS: &str = "10";
/// Default max depth for pathtracer algorithm.
///
/// When no arguments are provided to `--max-depth` flag
const MAX_DEPTH: &str = "3";
/// Default init seed for random generator.
///
/// When no arguments are provided to `--init-state` flag
const INIT_STATE: &str = "45";
/// Default identifier for random generator sequence.
///
/// When no arguments are provided to `--init-seq` flag
const INIT_SEQ: &str = "45";
/// Default anti-aliasing level.
///
/// When no arguments are provided to `--anti-aliasing` flag
const ANTI_ALIASING: &str = "1";
/// Build a [`clap::Command`](https://docs.rs/clap/latest/clap/type.Command.html)
/// for [`rustracer`](..) crate.
pub fn build_cli() -> Command<'static> {
let cli = Command::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg_required_else_help(true)
.disable_help_subcommand(true)
.dont_collapse_args_in_usage(true)
.propagate_version(true)
.subcommand_required(true)
.subcommand(
Command::new("convert")
.arg_required_else_help(true)
.dont_collapse_args_in_usage(true)
.about("Convert HDR (pfm) image to LDR (ff|png) image")
.arg(
Arg::new("HDR")
.required(true)
.help("Input pfm image")
.long_help("Input pfm file path"),
)
.arg(
Arg::new("LDR")
.required(true)
.help("Output image [possible formats: ff, png]")
.long_help("Output file path [possible formats: ff, png]"),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Print stdout information")
.long_help("Print stdout information"),
)
.arg(
Arg::new("factor")
.short('f')
.long("factor")
.value_name("FACTOR")
.default_value(FACTOR)
.number_of_values(1)
.help("Normalization factor")
.long_help("Luminosity normalization factor"),
)
.arg(
Arg::new("gamma")
.short('g')
.long("gamma")
.value_name("GAMMA")
.default_value(GAMMA)
.number_of_values(1)
.help("Gamma parameter")
.long_help("Gamma transfer function parameter"),
),
)
.subcommand(
Command::new("demo")
.arg_required_else_help(true)
.dont_collapse_args_in_usage(true)
.about("Render a demo scene (hard-coded in main)")
.arg(
Arg::new("OUTPUT")
.required(true)
.help("Output image [possible formats: ff, png]")
.long_help("Output ldr image file path [possible formats: ff, png]"),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Print stdout information")
.long_help("Print stdout information"),
)
.arg(
Arg::new("output-pfm")
.long("output-pfm")
.help("Output also hdr image")
.long_help("Output also pfm file in combination with (ff|png) file"),
)
.arg(
Arg::new("orthogonal")
.long("orthogonal")
.help("Use orthogonal camera instead of perspective camera")
.long_help("Render image with orthogonal view of the scene"),
)
.arg(
Arg::new("width")
.long("width")
.value_name("WIDTH")
.default_value(WIDTH)
.number_of_values(1)
.help("Image width")
.long_help("Width of the image to render"),
)
.arg(
Arg::new("height")
.long("height")
.value_name("HEIGHT")
.default_value(HEIGHT)
.number_of_values(1)
.help("Image height")
.long_help("Height of the image to render"),
)
.arg(
Arg::new("angle-deg")
.long("angle-deg")
.value_name("ANGLE_DEG")
.default_value(ANGLE_DEG)
.number_of_values(1)
.help("View angle (in degrees)")
.long_help("Render the image with this angle (in degrees) of view"),
)
.arg(
Arg::new("factor")
.short('f')
.long("factor")
.value_name("FACTOR")
.default_value(FACTOR)
.number_of_values(1)
.help("Normalization factor")
.long_help("Luminosity normalization factor"),
)
.arg(
Arg::new("gamma")
.short('g')
.long("gamma")
.value_name("GAMMA")
.default_value(GAMMA)
.number_of_values(1)
.help("Gamma parameter")
.long_help("Gamma transfer function parameter"),
)
.arg(
Arg::new("algorithm")
.short('a')
.long("algorithm")
.value_name("ALGORITHM")
.default_value(ALGORITHM)
.number_of_values(1)
.possible_values(["onoff", "flat", "pathtracer"])
.help("Rendering algorithm")
.long_help("Algorithm to use for render the scene: [onoff, flat, pathtracer]"),
)
.arg(
Arg::new("num-of-rays")
.short('n')
.long("--num-of-rays")
.value_name("NUM_OF_RAYS")
.default_value(NUM_OF_RAYS)
.number_of_values(1)
.requires_if("pathtracer", "algorithm")
.help("Number of rays")
.long_help("Number of rays departing from each surface point"),
)
.arg(
Arg::new("max-depth")
.short('m')
.long("--max-depth")
.value_name("MAX_DEPTH")
.default_value(MAX_DEPTH)
.number_of_values(1)
.requires_if("pathtracer", "algorithm")
.help("Maximum depth")
.long_help("Maximum allowed ray depth"),
)
.arg(
Arg::new("init-state")
.long("--init-state")
.value_name("INIT_STATE")
.default_value(INIT_STATE)
.number_of_values(1)
.help("Initial random seed (positive number)")
.long_help(
"Initial seed for the random number generator (positive number)",
),
)
.arg(
Arg::new("init-seq")
.long("--init-seq")
.value_name("INIT_SEQ")
.default_value(INIT_SEQ)
.number_of_values(1)
.help("Identifier of the random sequence (positive number)")
.long_help(
"Identifier of the sequence produced by the random number generator (positive number)",
),
)
.arg(
Arg::new("anti-aliasing")
.long("--anti-aliasing")
.value_name("ANTI_ALIASING")
.default_value(ANTI_ALIASING)
.number_of_values(1)
.help("Anti-aliasing level")
.long_help(
"Anti-aliasing level, corresponds to the square-root of the number of samples per pixel",
),
),
)
.subcommand(
Command::new("render")
.arg_required_else_help(true)
.dont_collapse_args_in_usage(true)
.about("Render a scene from file")
.arg(
Arg::new("INPUT")
.required(true)
.help("Input scene file")
.long_help("Input scene file (formatted as yaml) to build up the scene"),
)
.arg(
Arg::new("OUTPUT")
.required(true)
.help("Output image [possible formats: ff, png]")
.long_help("Output ldr image file path [possible formats: ff, png]"),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Print stdout information")
.long_help("Print stdout information"),
)
.arg(
Arg::new("output-pfm")
.long("output-pfm")
.help("Output also hdr image")
.long_help("Output also pfm file in combination with (ff|png) file"),
)
.arg(
Arg::new("width")
.long("width")
.value_name("WIDTH")
.default_value(WIDTH)
.number_of_values(1)
.help("Image width")
.long_help("Width of the image to render"),
)
.arg(
Arg::new("height")
.long("height")
.value_name("HEIGHT")
.default_value(HEIGHT)
.number_of_values(1)
.help("Image height")
.long_help("Height of the image to render"),
)
.arg(
Arg::new("angle-deg")
.long("angle-deg")
.value_name("ANGLE_DEG")
.default_value(ANGLE_DEG)
.number_of_values(1)
.help("View angle (in degrees)")
.long_help("Render the image with this angle (in degrees) of view"),
)
.arg(
Arg::new("factor")
.short('f')
.long("factor")
.value_name("FACTOR")
.default_value(FACTOR)
.number_of_values(1)
.help("Normalization factor")
.long_help("Luminosity normalization factor"),
)
.arg(
Arg::new("gamma")
.short('g')
.long("gamma")
.value_name("GAMMA")
.default_value(GAMMA)
.number_of_values(1)
.help("Gamma parameter")
.long_help("Gamma transfer function parameter"),
)
.arg(
Arg::new("algorithm")
.short('a')
.long("algorithm")
.value_name("ALGORITHM")
.default_value(ALGORITHM)
.number_of_values(1)
.possible_values(["onoff", "flat", "pathtracer"])
.help("Rendering algorithm")
.long_help("Algorithm to use for render the scene: [onoff, flat, pathtracer]"),
)
.arg(
Arg::new("num-of-rays")
.short('n')
.long("--num-of-rays")
.value_name("NUM_OF_RAYS")
.default_value(NUM_OF_RAYS)
.number_of_values(1)
.requires_if("pathtracer", "algorithm")
.help("Number of rays")
.long_help("Number of rays departing from each surface point"),
)
.arg(
Arg::new("max-depth")
.short('m')
.long("--max-depth")
.value_name("MAX_DEPTH")
.default_value(MAX_DEPTH)
.number_of_values(1)
.requires_if("pathtracer", "algorithm")
.help("Maximum depth")
.long_help("Maximum allowed ray depth"),
)
.arg(
Arg::new("init-state")
.long("--init-state")
.value_name("INIT_STATE")
.default_value(INIT_STATE)
.number_of_values(1)
.help("Initial random seed (positive number)")
.long_help(
"Initial seed for the random number generator (positive number)",
),
)
.arg(
Arg::new("init-seq")
.long("--init-seq")
.value_name("INIT_SEQ")
.default_value(INIT_SEQ)
.number_of_values(1)
.help("Identifier of the random sequence (positive number)")
.long_help(
"Identifier of the sequence produced by the random number generator (positive number)",
),
)
.arg(
Arg::new("anti-aliasing")
.long("--anti-aliasing")
.value_name("ANTI_ALIASING")
.default_value(ANTI_ALIASING)
.number_of_values(1)
.help("Anti-aliasing level")
.long_help(
"Anti-aliasing level, corresponds to the square-root of the number of samples per pixel",
),
),
)
.subcommand(
Command::new("completion")
.hide(true)
.arg_required_else_help(true)
.about("Generate shell completion script")
.arg(
Arg::new("SHELL")
.required(true)
.possible_values(["bash", "fish", "zsh"])
.number_of_values(1)
.help("Shell to generate script for")
.long_help("Specify for which shell completions should be generated")
)
.arg(
Arg::new("output")
.short('o')
.long("output")
.value_name("OUTPUT")
.number_of_values(1)
.help("Specify output script file")
.long_help("Specify an output file for shell completions"),
)
);
cli
}
/// Inherits some useful cli parameters.
///
/// Use it inside [`read_scene_file`](../../scene/struct.Scene.html#method.read_scene_file) to
/// set some standard [`f32`] values.
#[derive(Copy, Clone)]
pub struct Cli {
// Aspect ratio usually `width/height`.
pub aspect_ratio: f32,
// View angle (in degrees) of the scene.
pub angle_deg: f32,
}