Skip to content

Commit 4cced52

Browse files
committed
Supporting reading VTU files
1 parent 8fe99e3 commit 4cced52

7 files changed

Lines changed: 63 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The following changes are present in the `main` branch of the repository and are
88
- Lib: Support for writing particles as BGEO
99
- CLI: Support for new writers in `convert` subcommand
1010
- Lib: Rename `AxisAlignedBoundingBox*d` typedefs to `Aabb3d` and `Aabb2d`
11+
- Lib: Support reading VTU (VTK XML) files
12+
- CLI: Support reconstruction of particles from VTU (VTK XML) files, including attributes
1113

1214
## Version 0.8.0
1315

Cargo.lock

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

splashsurf/src/convert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::path::PathBuf;
1313
/// Command line arguments for the `convert` subcommand
1414
#[derive(Clone, Debug, clap::Parser)]
1515
pub struct ConvertSubcommandArgs {
16-
/// Path to the input file with particles to read (supported formats: .vtk, .bgeo, .ply, .xyz, .json)
16+
/// Path to the input file with particles to read (supported formats: .vtk, .vtu, .bgeo, .ply, .xyz, .json)
1717
#[arg(
1818
long = "particles",
1919
value_parser = value_parser!(PathBuf),

splashsurf/src/io.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn read_particle_positions<R: Real, P: AsRef<Path>>(
6868

6969
match extension.to_lowercase().as_str() {
7070
"vtk" => vtk_format::particles_from_vtk(&input_file),
71+
"vtu" => vtk_format::particles_from_vtk(&input_file),
7172
"xyz" => xyz_format::particles_from_xyz(&input_file),
7273
"ply" => ply_format::particles_from_ply(&input_file),
7374
"bgeo" => bgeo_format::particles_from_bgeo(&input_file),
@@ -115,11 +116,14 @@ pub fn read_particle_positions_with_attributes<R: Real, P: AsRef<Path>>(
115116
"Unable to detect file format of particle input file (file name has to end with supported extension)",
116117
))?.to_str().ok_or(anyhow!("Invalid extension of input file"))?.to_lowercase();
117118

118-
if extension != "vtk" {
119-
return Err(anyhow!(
120-
"Unsupported file format extension \"{}\" for reading particles and attributes",
121-
extension
122-
));
119+
match extension.as_str() {
120+
"vtk" | "vtu" => {}
121+
_ => {
122+
return Err(anyhow!(
123+
"Unsupported file format extension \"{}\" for reading particles and attributes",
124+
extension
125+
));
126+
}
123127
}
124128
}
125129

splashsurf/src/reconstruction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static ARGS_OTHER: &str = "Remaining options";
2929
#[clap(group = clap::ArgGroup::new("input").required(true))]
3030
#[command(next_help_heading = ARGS_OTHER)]
3131
pub struct ReconstructSubcommandArgs {
32-
/// Path to the input file where the particle positions are stored (supported formats: VTK, binary f32 XYZ, PLY, BGEO)
32+
/// Path to the input file where the particle positions are stored (supported formats: VTK 4.2, VTU, binary f32 XYZ, PLY, BGEO)
3333
#[arg(help_heading = ARGS_IO, short = 'i', long, group = "input", value_parser = value_parser!(PathBuf))]
3434
pub input_file: Option<PathBuf>,
3535
/// Path to a sequence of particle files that should be processed, use `{}` in the filename to indicate a placeholder
@@ -183,7 +183,7 @@ pub struct ReconstructSubcommandArgs {
183183
require_equals = true
184184
)]
185185
pub sph_normals: Switch,
186-
/// List of point attribute field names from the input file that should be interpolated to the reconstructed surface. Currently this is only supported for VTK input files.
186+
/// List of point attribute field names from the input file that should be interpolated to the reconstructed surface. Currently this is only supported for VTK and VTU input files.
187187
#[arg(help_heading = ARGS_INTERP, long)]
188188
pub interpolate_attributes: Vec<String>,
189189

splashsurf_lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ numeric_literals = "0.2"
5757
rstar = "0.10"
5858

5959
# IO
60-
vtkio = { version = "0.6", default-features = false, optional = true } # Disable moden XML format for now (hardly used)
60+
vtkio = { version = "0.6", optional = true }
6161
ply-rs = { version = "0.1.3", optional = true }
6262
flate2 = { version = "1.0", optional = true }
6363
nom = { version = "7.1.3", optional = true }

splashsurf_lib/src/io/vtk_format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub fn write_vtk<P: AsRef<Path>>(
188188
title: &str,
189189
) -> Result<(), anyhow::Error> {
190190
let vtk_file = Vtk {
191-
version: Version::new((4, 1)),
191+
version: Version::new((4, 2)),
192192
title: title.to_string(),
193193
file_path: None,
194194
byte_order: ByteOrder::BigEndian,

0 commit comments

Comments
 (0)