@@ -10,7 +10,6 @@ use pyo3::{
1010 prelude:: * ,
1111 types:: { PyDict , PyString } ,
1212} ;
13- use splashsurf:: PipelineResult ;
1413use splashsurf_lib:: {
1514 Aabb3d , GridDecompositionParameters , Index , Real , SpatialDecomposition ,
1615 mesh:: { AttributeData , MeshAttribute } ,
@@ -54,7 +53,7 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
5453 mesh_aabb_min : Option < [ f64 ; 3 ] > ,
5554 mesh_aabb_max : Option < [ f64 ; 3 ] > ,
5655 mesh_aabb_clamp_vertices : bool ,
57- ) -> Result < PipelineResult < I , R > , anyhow:: Error > {
56+ ) -> Result < splashsurf :: reconstruct :: ReconstructionResult < I , R > , anyhow:: Error > {
5857 let aabb = if let ( Some ( aabb_min) , Some ( aabb_max) ) = ( aabb_min, aabb_max) {
5958 // Convert the min and max arrays to Vector3
6059 Some ( Aabb3d :: new (
@@ -65,15 +64,13 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
6564 None
6665 } ;
6766
68- let spatial_decomposition = if use_custom_grid_decomposition {
67+ let spatial_decomposition = use_custom_grid_decomposition. then ( || {
6968 let mut grid_params = GridDecompositionParameters :: default ( ) ;
7069 grid_params. subdomain_num_cubes_per_dim = subdomain_num_cubes_per_dim;
71- Some ( SpatialDecomposition :: UniformGrid ( grid_params) )
72- } else {
73- None
74- } ;
70+ SpatialDecomposition :: UniformGrid ( grid_params)
71+ } ) ;
7572
76- let params: splashsurf_lib :: Parameters < R > = splashsurf_lib:: Parameters {
73+ let params = splashsurf_lib:: Parameters {
7774 particle_radius,
7875 rest_density,
7976 compact_support_radius : R :: from_f64 ( 2.0 ) . unwrap ( ) * smoothing_length * particle_radius,
@@ -96,35 +93,34 @@ fn reconstruction_pipeline_generic<I: Index, R: Real>(
9693 None
9794 } ;
9895
99- let postprocessing_args: splashsurf:: ReconstructionRunnerPostprocessingArgs =
100- splashsurf:: ReconstructionRunnerPostprocessingArgs {
101- check_mesh_closed,
102- check_mesh_manifold,
103- check_mesh_orientation,
104- check_mesh_debug,
105- mesh_cleanup,
106- mesh_cleanup_snap_dist : max_rel_snap_dist,
107- decimate_barnacles,
108- keep_vertices,
109- compute_normals,
110- sph_normals,
111- normals_smoothing_iters,
112- interpolate_attributes : Vec :: new ( ) ,
113- mesh_smoothing_iters,
114- mesh_smoothing_weights,
115- mesh_smoothing_weights_normalization,
116- generate_quads,
117- quad_max_edge_diag_ratio,
118- quad_max_normal_angle,
119- quad_max_interior_angle,
120- output_mesh_smoothing_weights,
121- output_raw_normals,
122- output_raw_mesh,
123- mesh_aabb,
124- mesh_aabb_clamp_vertices,
125- } ;
96+ let postprocessing_args = splashsurf:: reconstruct:: ReconstructionPostprocessingParameters {
97+ check_mesh_closed,
98+ check_mesh_manifold,
99+ check_mesh_orientation,
100+ check_mesh_debug,
101+ mesh_cleanup,
102+ mesh_cleanup_snap_dist : max_rel_snap_dist,
103+ decimate_barnacles,
104+ keep_vertices,
105+ compute_normals,
106+ sph_normals,
107+ normals_smoothing_iters,
108+ interpolate_attributes : Vec :: new ( ) ,
109+ mesh_smoothing_iters,
110+ mesh_smoothing_weights,
111+ mesh_smoothing_weights_normalization,
112+ generate_quads,
113+ quad_max_edge_diag_ratio,
114+ quad_max_normal_angle,
115+ quad_max_interior_angle,
116+ output_mesh_smoothing_weights,
117+ output_raw_normals,
118+ output_raw_mesh,
119+ mesh_aabb,
120+ mesh_aabb_clamp_vertices,
121+ } ;
126122
127- splashsurf:: reconstruction_pipeline (
123+ splashsurf:: reconstruct :: reconstruction_pipeline (
128124 particle_positions,
129125 attributes,
130126 & params,
@@ -227,19 +223,19 @@ pub fn reconstruction_pipeline_py_f32<'py>(
227223 mesh_aabb_min : Option < [ f64 ; 3 ] > ,
228224 mesh_aabb_max : Option < [ f64 ; 3 ] > ,
229225 mesh_aabb_clamp_vertices : bool ,
230- ) -> (
226+ ) -> PyResult < (
231227 Option < TriMeshWithDataF32 > ,
232228 Option < MixedTriQuadMeshWithDataF32 > ,
233229 Option < SurfaceReconstructionF32 > ,
234- ) {
235- let particles: PyReadonlyArray2 < f32 > = particles. extract ( ) . unwrap ( ) ;
230+ ) > {
231+ let particles: PyReadonlyArray2 < f32 > = particles. extract ( ) ? ;
236232
237- let particle_positions = particles. as_slice ( ) . unwrap ( ) ;
233+ let particle_positions = particles. as_slice ( ) ? ;
238234 let particle_positions: & [ Vector3 < f32 > ] = bytemuck:: cast_slice ( particle_positions) ;
239235
240236 let attrs = attrs_conversion ( attributes_to_interpolate) ;
241237
242- let PipelineResult {
238+ let splashsurf :: reconstruct :: ReconstructionResult {
243239 tri_mesh,
244240 tri_quad_mesh,
245241 raw_reconstruction : reconstruction,
@@ -283,25 +279,11 @@ pub fn reconstruction_pipeline_py_f32<'py>(
283279 )
284280 . unwrap ( ) ;
285281
286- let tri_mesh = if let Some ( tri_mesh) = tri_mesh {
287- Some ( TriMeshWithDataF32 :: new ( tri_mesh) )
288- } else {
289- None
290- } ;
291-
292- let tri_quad_mesh = if let Some ( tri_quad_mesh) = tri_quad_mesh {
293- Some ( MixedTriQuadMeshWithDataF32 :: new ( tri_quad_mesh) )
294- } else {
295- None
296- } ;
297-
298- let reconstruction = if let Some ( reconstruction) = reconstruction {
299- Some ( SurfaceReconstructionF32 :: new ( reconstruction) )
300- } else {
301- None
302- } ;
303-
304- ( tri_mesh, tri_quad_mesh, reconstruction)
282+ Ok ( (
283+ tri_mesh. map ( TriMeshWithDataF32 :: new) ,
284+ tri_quad_mesh. map ( MixedTriQuadMeshWithDataF32 :: new) ,
285+ reconstruction. map ( SurfaceReconstructionF32 :: new) ,
286+ ) )
305287}
306288
307289#[ pyfunction]
@@ -354,19 +336,19 @@ pub fn reconstruction_pipeline_py_f64<'py>(
354336 mesh_aabb_min : Option < [ f64 ; 3 ] > ,
355337 mesh_aabb_max : Option < [ f64 ; 3 ] > ,
356338 mesh_aabb_clamp_vertices : bool ,
357- ) -> (
339+ ) -> PyResult < (
358340 Option < TriMeshWithDataF64 > ,
359341 Option < MixedTriQuadMeshWithDataF64 > ,
360342 Option < SurfaceReconstructionF64 > ,
361- ) {
362- let particles: PyReadonlyArray2 < f64 > = particles. extract ( ) . unwrap ( ) ;
343+ ) > {
344+ let particles: PyReadonlyArray2 < f64 > = particles. extract ( ) ? ;
363345
364- let particle_positions = particles. as_slice ( ) . unwrap ( ) ;
346+ let particle_positions = particles. as_slice ( ) ? ;
365347 let particle_positions: & [ Vector3 < f64 > ] = bytemuck:: cast_slice ( particle_positions) ;
366348
367349 let attrs = attrs_conversion ( attributes_to_interpolate) ;
368350
369- let PipelineResult {
351+ let splashsurf :: reconstruct :: ReconstructionResult {
370352 tri_mesh,
371353 tri_quad_mesh,
372354 raw_reconstruction : reconstruction,
@@ -410,23 +392,9 @@ pub fn reconstruction_pipeline_py_f64<'py>(
410392 )
411393 . unwrap ( ) ;
412394
413- let tri_mesh = if let Some ( tri_mesh) = tri_mesh {
414- Some ( TriMeshWithDataF64 :: new ( tri_mesh) )
415- } else {
416- None
417- } ;
418-
419- let tri_quad_mesh = if let Some ( tri_quad_mesh) = tri_quad_mesh {
420- Some ( MixedTriQuadMeshWithDataF64 :: new ( tri_quad_mesh) )
421- } else {
422- None
423- } ;
424-
425- let reconstruction = if let Some ( reconstruction) = reconstruction {
426- Some ( SurfaceReconstructionF64 :: new ( reconstruction) )
427- } else {
428- None
429- } ;
430-
431- ( tri_mesh, tri_quad_mesh, reconstruction)
395+ Ok ( (
396+ tri_mesh. map ( TriMeshWithDataF64 :: new) ,
397+ tri_quad_mesh. map ( MixedTriQuadMeshWithDataF64 :: new) ,
398+ reconstruction. map ( SurfaceReconstructionF64 :: new) ,
399+ ) )
432400}
0 commit comments