Skip to content

Commit e8aba28

Browse files
committed
Add domain CLI argument to convert subcommand
1 parent bc3a014 commit e8aba28

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

splashsurf/src/convert.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::io;
22
use anyhow::anyhow;
33
use anyhow::Context;
4+
use log::info;
45
use splashsurf_lib::nalgebra::Vector3;
5-
use splashsurf_lib::profile;
6+
use splashsurf_lib::{nalgebra, profile, AxisAlignedBoundingBox3d};
67
use std::path::PathBuf;
78
use structopt::StructOpt;
89

@@ -20,6 +21,22 @@ pub struct ConvertSubcommandArgs {
2021
/// Whether to overwrite existing files without asking
2122
#[structopt(long)]
2223
overwrite: bool,
24+
/// Lower corner of the domain of particles to keep, format: domain-min=x_min;y_min;z_min (requires domain-max to be specified)
25+
#[structopt(
26+
long,
27+
number_of_values = 3,
28+
value_delimiter = ";",
29+
requires = "domain-max"
30+
)]
31+
domain_min: Option<Vec<f64>>,
32+
/// Lower corner of the domain of particles to keep, format:domain-max=x_max;y_max;z_max (requires domain-min to be specified)
33+
#[structopt(
34+
long,
35+
number_of_values = 3,
36+
value_delimiter = ";",
37+
requires = "domain-min"
38+
)]
39+
domain_max: Option<Vec<f64>>,
2340
}
2441

2542
/// Executes the `convert` subcommand
@@ -49,6 +66,23 @@ pub fn convert_subcommand(cmd_args: &ConvertSubcommandArgs) -> Result<(), anyhow
4966
)
5067
})?;
5168

69+
// Filter particles by user specified domain
70+
let particle_positions = if let (Some(min), Some(max)) =
71+
(cmd_args.domain_min.clone(), cmd_args.domain_max.clone())
72+
{
73+
let min = nalgebra::convert(Vector3::from_iterator(min));
74+
let max = nalgebra::convert(Vector3::from_iterator(max));
75+
let aabb = AxisAlignedBoundingBox3d::new(min, max);
76+
info!("Filtering out particles outside of {:?}", aabb);
77+
78+
particle_positions
79+
.into_iter()
80+
.filter(|p| aabb.contains_point(p))
81+
.collect()
82+
} else {
83+
particle_positions
84+
};
85+
5286
// Write particles
5387
io::write_particle_positions(
5488
particle_positions.as_slice(),

0 commit comments

Comments
 (0)