@@ -27,8 +27,8 @@ struct App {
27
27
#[ structopt( short = "g" , long = "spawn-radius" , default_value = "10" ) ]
28
28
spawn_radius : u32 ,
29
29
30
- /// The output formats the scene should be saved as. As of now `javascript`
31
- /// and `povray ` are supported.
30
+ /// The output formats the scene should be saved as. As of now `javascript,
31
+ /// `povray` and `csv ` are supported.
32
32
#[ structopt( short = "s" , long = "scene-format" , default_value = "povray" ) ]
33
33
scene_formats : Vec < SceneFormat > ,
34
34
@@ -41,6 +41,7 @@ struct App {
41
41
enum SceneFormat {
42
42
Povray ,
43
43
Js ,
44
+ Csv ,
44
45
}
45
46
46
47
#[ derive( Debug ) ]
@@ -79,7 +80,7 @@ fn main() -> io::Result<()> {
79
80
dla. add ( & mut rng) ;
80
81
}
81
82
82
- // clear progress line manually
83
+ // clear progress line manually to not install another dep
83
84
println ! (
84
85
"\r {:width$} " ,
85
86
" " ,
@@ -112,6 +113,7 @@ It contains {} particles and its bounding box goes from
112
113
match r {
113
114
SceneFormat :: Povray => save_pov_scene ( & args. output , & scene) ?,
114
115
SceneFormat :: Js => save_js_scene ( & args. output , & scene) ?,
116
+ SceneFormat :: Csv => save_csv_scene ( & args. output , & scene) ?,
115
117
}
116
118
}
117
119
@@ -275,6 +277,25 @@ single object `DLA` that has the `particles` alongside a `camera` and `lights`.
275
277
Ok ( ( ) )
276
278
}
277
279
280
+ fn save_csv_scene ( path : & PathBuf , Scene { dla, .. } : & Scene ) -> io:: Result < ( ) > {
281
+ let path = path. with_extension ( "csv" ) ;
282
+ let mut out = BufWriter :: new ( File :: create ( & path) ?) ;
283
+
284
+ for c in dla. cells ( ) {
285
+ writeln ! ( out, "{},{},{}" , c. x, c. y, c. z) ?;
286
+ }
287
+
288
+ println ! (
289
+ r#"## Csv Scene
290
+
291
+ The positions (x,y,z) of all the cells that form the DLA have been saved as a CSV file ({path}).
292
+ "# ,
293
+ path = path. display( )
294
+ ) ;
295
+
296
+ Ok ( ( ) )
297
+ }
298
+
278
299
impl Scene {
279
300
/// build a scene from a DLA with camera and lights in a completely
280
301
/// arbitrary way.
@@ -346,6 +367,7 @@ impl std::str::FromStr for SceneFormat {
346
367
match s {
347
368
"povray" => Ok ( SceneFormat :: Povray ) ,
348
369
"javascript" | "js" => Ok ( SceneFormat :: Js ) ,
370
+ "csv" => Ok ( SceneFormat :: Csv ) ,
349
371
s => Err ( format ! ( "`{}` is not a valid scene format" , s) ) ,
350
372
}
351
373
}
0 commit comments