Skip to content

Commit df9095f

Browse files
committed
Made return type of public pipeline method its own struct
1 parent 40541c4 commit df9095f

File tree

3 files changed

+47
-32
lines changed

3 files changed

+47
-32
lines changed

pysplashsurf/src/pipeline.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use pyo3::{
1010
prelude::*,
1111
types::{PyDict, PyString},
1212
};
13+
use splashsurf::PipelineResult;
1314
use splashsurf_lib::{
14-
Aabb3d, GridDecompositionParameters, Index, Real, SpatialDecomposition, SurfaceReconstruction,
15-
mesh::{AttributeData, MeshAttribute, MeshWithData, MixedTriQuadMesh3d, TriMesh3d},
15+
Aabb3d, GridDecompositionParameters, Index, Real, SpatialDecomposition,
16+
mesh::{AttributeData, MeshAttribute},
1617
nalgebra::Vector3,
1718
};
1819

@@ -53,14 +54,7 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
5354
mesh_aabb_min: Option<[f64; 3]>,
5455
mesh_aabb_max: Option<[f64; 3]>,
5556
mesh_aabb_clamp_vertices: bool,
56-
) -> Result<
57-
(
58-
Option<MeshWithData<R, TriMesh3d<R>>>,
59-
Option<MeshWithData<R, MixedTriQuadMesh3d<R>>>,
60-
Option<SurfaceReconstruction<I, R>>,
61-
),
62-
anyhow::Error,
63-
> {
57+
) -> Result<PipelineResult<I, R>, anyhow::Error> {
6458
let aabb = if let (Some(aabb_min), Some(aabb_max)) = (aabb_min, aabb_max) {
6559
// Convert the min and max arrays to Vector3
6660
Some(Aabb3d::new(
@@ -245,7 +239,11 @@ pub fn reconstruction_pipeline_py_f32<'py>(
245239

246240
let attrs = attrs_conversion(attributes_to_interpolate);
247241

248-
let (tri_mesh, tri_quad_mesh, reconstruction) = reconstruction_pipeline_generic::<i64, f32>(
242+
let PipelineResult {
243+
tri_mesh,
244+
tri_quad_mesh,
245+
raw_reconstruction: reconstruction,
246+
} = reconstruction_pipeline_generic::<i64, f32>(
249247
particle_positions,
250248
attrs,
251249
particle_radius,
@@ -368,7 +366,11 @@ pub fn reconstruction_pipeline_py_f64<'py>(
368366

369367
let attrs = attrs_conversion(attributes_to_interpolate);
370368

371-
let (tri_mesh, tri_quad_mesh, reconstruction) = reconstruction_pipeline_generic::<i64, f64>(
369+
let PipelineResult {
370+
tri_mesh,
371+
tri_quad_mesh,
372+
raw_reconstruction: reconstruction,
373+
} = reconstruction_pipeline_generic::<i64, f64>(
372374
particle_positions,
373375
attrs,
374376
particle_radius,

splashsurf/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ mod allocator;
77
mod logging;
88

99
pub use reconstruction::arguments::ReconstructionRunnerPostprocessingArgs;
10-
pub use reconstruction::reconstruction_pipeline;
10+
pub use reconstruction::{PipelineResult, reconstruction_pipeline};
1111
pub(crate) use register_counting_allocator;

splashsurf/src/reconstruction.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,16 @@ pub fn reconstruct_subcommand(cmd_args: &ReconstructSubcommandArgs) -> Result<()
420420
result
421421
}
422422

423+
/// Struct to hold the result of the reconstruction pipeline
424+
pub struct PipelineResult<I: Index, R: Real> {
425+
/// Holds the reconstructed tri mesh with data if `generate_quads` was not set
426+
pub tri_mesh: Option<MeshWithData<R, TriMesh3d<R>>>,
427+
/// Holds the reconstructed quad mesh with data if `generate_quads` was set
428+
pub tri_quad_mesh: Option<MeshWithData<R, MixedTriQuadMesh3d<R>>>,
429+
/// Holds the surface reconstruction with no post-processing applied if `output_raw_mesh` was set
430+
pub raw_reconstruction: Option<SurfaceReconstruction<I, R>>,
431+
}
432+
423433
/// Conversion and validation of command line arguments
424434
pub mod arguments {
425435
use super::ReconstructSubcommandArgs;
@@ -944,17 +954,9 @@ pub fn reconstruction_pipeline<I: Index, R: Real>(
944954
attributes: Vec<MeshAttribute<R>>,
945955
params: &splashsurf_lib::Parameters<R>,
946956
postprocessing: &ReconstructionRunnerPostprocessingArgs,
947-
) -> Result<
948-
(
949-
Option<MeshWithData<R, TriMesh3d<R>>>,
950-
Option<MeshWithData<R, MixedTriQuadMesh3d<R>>>,
951-
Option<SurfaceReconstruction<I, R>>,
952-
),
953-
anyhow::Error,
954-
> {
957+
) -> Result<PipelineResult<I, R>, anyhow::Error> {
955958
// Perform the surface reconstruction
956-
let reconstruction =
957-
splashsurf_lib::reconstruct_surface::<I, R>(particle_positions, params)?;
959+
let reconstruction = splashsurf_lib::reconstruct_surface::<I, R>(particle_positions, params)?;
958960

959961
let reconstruction_output = if postprocessing.output_raw_mesh {
960962
Some(reconstruction.clone())
@@ -1323,7 +1325,11 @@ pub fn reconstruction_pipeline<I: Index, R: Real>(
13231325
),
13241326
(None, Some(_mesh)) => {
13251327
info!("Checking for mesh consistency not implemented for quad mesh at the moment.");
1326-
return Ok((None, Some(_mesh.to_owned()), reconstruction_output));
1328+
return Ok(PipelineResult {
1329+
tri_mesh: None,
1330+
tri_quad_mesh: Some(_mesh.to_owned()),
1331+
raw_reconstruction: reconstruction_output,
1332+
});
13271333
}
13281334
_ => unreachable!(),
13291335
} {
@@ -1413,9 +1419,17 @@ pub fn reconstruction_pipeline<I: Index, R: Real>(
14131419
res.point_attributes = std::mem::take(&mut mesh.point_attributes);
14141420
res.cell_attributes = std::mem::take(&mut mesh.cell_attributes);
14151421

1416-
Ok((Some(res), None, reconstruction_output))
1422+
Ok(PipelineResult {
1423+
tri_mesh: Some(res),
1424+
tri_quad_mesh: None,
1425+
raw_reconstruction: reconstruction_output,
1426+
})
14171427
}
1418-
(None, Some(_mesh)) => Ok((None, Some(_mesh.to_owned()), reconstruction_output)),
1428+
(None, Some(_mesh)) => Ok(PipelineResult {
1429+
tri_mesh: None,
1430+
tri_quad_mesh: Some(_mesh.to_owned()),
1431+
raw_reconstruction: reconstruction_output,
1432+
}),
14191433
_ => unreachable!(),
14201434
}
14211435
}
@@ -1442,12 +1456,11 @@ pub(crate) fn reconstruction_pipeline_from_path<I: Index, R: Real>(
14421456
)
14431457
})?;
14441458

1445-
let (tri_mesh, tri_quad_mesh, reconstruction) = reconstruction_pipeline::<I, R>(
1446-
&particle_positions,
1447-
attributes,
1448-
params,
1449-
postprocessing,
1450-
)?;
1459+
let PipelineResult {
1460+
tri_mesh,
1461+
tri_quad_mesh,
1462+
raw_reconstruction: reconstruction,
1463+
} = reconstruction_pipeline::<I, R>(&particle_positions, attributes, params, postprocessing)?;
14511464

14521465
if postprocessing.output_raw_mesh {
14531466
profile!("write surface mesh to file");

0 commit comments

Comments
 (0)