Skip to content

Commit 9d34fb9

Browse files
committed
Refactor Python API (parameters, enable multi threading by default)
1 parent a6b5657 commit 9d34fb9

File tree

5 files changed

+93
-69
lines changed

5 files changed

+93
-69
lines changed

pysplashsurf/pysplashsurf/__init__.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ def reconstruct_surface(
207207
smoothing_length: float = 2.0,
208208
cube_size: float = 0.5,
209209
iso_surface_threshold: float = 0.6,
210-
enable_multi_threading: bool = False,
210+
multi_threading: bool = True,
211211
global_neighborhood_list: bool = False,
212212
subdomain_grid: bool = True,
213-
auto_disable_subdomain_grid: bool = True,
213+
subdomain_grid_auto_disable: bool = True,
214214
subdomain_num_cubes_per_dim: int = 64,
215215
aabb_min = None,
216216
aabb_max = None,
@@ -239,7 +239,7 @@ def reconstruct_surface(
239239
iso_surface_threshold: float
240240
Threshold for the iso surface
241241
242-
enable_multi_threading: bool
242+
multi_threading: bool
243243
Multi-threading flag
244244
245245
global_neighborhood_list: bool
@@ -248,7 +248,7 @@ def reconstruct_surface(
248248
subdomain_grid: bool
249249
Enable spatial decomposition using by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading
250250
251-
auto_disable_subdomain_grid: bool
251+
subdomain_grid_auto_disable: bool
252252
Whether to automatically disable the subdomain grid if the global domain is too small
253253
254254
subdomain_num_cubes_per_dim: int
@@ -270,14 +270,14 @@ def reconstruct_surface(
270270
if particles.dtype == 'float32':
271271
return reconstruct_surface_f32(particles, particle_radius=particle_radius, rest_density=rest_density,
272272
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
273-
enable_multi_threading=enable_multi_threading, global_neighborhood_list=global_neighborhood_list,
274-
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
273+
multi_threading=multi_threading, global_neighborhood_list=global_neighborhood_list,
274+
subdomain_grid=subdomain_grid, subdomain_grid_auto_disable=subdomain_grid_auto_disable, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
275275
aabb_min=aabb_min, aabb_max=aabb_max)
276276
elif particles.dtype == 'float64':
277277
return reconstruct_surface_f64(particles, particle_radius=particle_radius, rest_density=rest_density,
278278
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
279-
enable_multi_threading=enable_multi_threading, global_neighborhood_list=global_neighborhood_list,
280-
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
279+
multi_threading=multi_threading, global_neighborhood_list=global_neighborhood_list,
280+
subdomain_grid=subdomain_grid, subdomain_grid_auto_disable=subdomain_grid_auto_disable, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
281281
aabb_min=aabb_min, aabb_max=aabb_max)
282282
else:
283283
raise ValueError("Invalid data type (only float32 and float64 are supported, consider explicitly specifying the dtype for particles)")
@@ -525,16 +525,16 @@ def convert_tris_to_quads(
525525

526526

527527
def reconstruction_pipeline(
528-
particles, *, attributes_to_interpolate={}, particle_radius,
528+
particles, *, attributes_to_interpolate=None, particle_radius,
529529
rest_density=1000.0, smoothing_length=2.0, cube_size,
530-
iso_surface_threshold=0.6, enable_multi_threading=True,
530+
iso_surface_threshold=0.6, multi_threading=True,
531531
check_mesh_closed=False, check_mesh_manifold=False,
532532
check_mesh_orientation=False, check_mesh_debug=False,
533533
mesh_smoothing_weights=False, sph_normals=False,
534534
mesh_smoothing_weights_normalization=13.0, mesh_smoothing_iters=None, normals_smoothing_iters=None,
535535
mesh_cleanup=False, mesh_cleanup_snap_dist=None, decimate_barnacles=False, keep_vertices=False,
536536
compute_normals=False, output_raw_normals=False, output_raw_mesh=False, output_mesh_smoothing_weights=False, mesh_aabb_clamp_vertices=False,
537-
subdomain_grid=True, auto_disable_subdomain_grid=True, subdomain_num_cubes_per_dim=64, aabb_min=None, aabb_max=None, mesh_aabb_min=None, mesh_aabb_max=None,
537+
subdomain_grid=True, subdomain_grid_auto_disable=True, subdomain_num_cubes_per_dim=64, aabb_min=None, aabb_max=None, mesh_aabb_min=None, mesh_aabb_max=None,
538538
generate_quads=False, quad_max_edge_diag_ratio=1.75, quad_max_normal_angle=10.0, quad_max_interior_angle=135.0
539539
):
540540
"""Surface reconstruction based on particle positions with subsequent post-processing
@@ -564,7 +564,7 @@ def reconstruction_pipeline(
564564
iso_surface_threshold: float
565565
Threshold for the iso surface
566566
567-
enable_multi_threading: bool
567+
multi_threading: bool
568568
Multi-threading flag
569569
570570
check_mesh_closed: bool
@@ -628,7 +628,7 @@ def reconstruction_pipeline(
628628
subdomain_grid: bool
629629
Enable spatial decomposition using by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading
630630
631-
auto_disable_subdomain_grid: bool
631+
subdomain_grid_auto_disable: bool
632632
Whether to automatically disable the subdomain grid if the global domain is too small
633633
634634
subdomain_num_cubes_per_dim: int
@@ -663,11 +663,14 @@ def reconstruction_pipeline(
663663
tuple[TriMeshWithDataF32 | TriMeshWithDataF64 | MixedTriQuadMeshWithDataF32 | MixedTriQuadMeshWithDataF64, Optional[SurfaceReconstructionF32] | Optional[SurfaceReconstructionF64]]
664664
Mesh with data object and SurfaceReconstruction object containing the reconstructed mesh and used grid
665665
"""
666+
if attributes_to_interpolate is None:
667+
attributes_to_interpolate = {}
668+
666669
if particles.dtype == 'float32':
667670
tri_mesh, tri_quad_mesh, reconstruction = reconstruction_pipeline_f32(particles, attributes_to_interpolate=attributes_to_interpolate, particle_radius=particle_radius, rest_density=rest_density,
668671
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
669-
aabb_min=aabb_min, aabb_max=aabb_max, enable_multi_threading=enable_multi_threading,
670-
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
672+
aabb_min=aabb_min, aabb_max=aabb_max, multi_threading=multi_threading,
673+
subdomain_grid=subdomain_grid, subdomain_grid_auto_disable=subdomain_grid_auto_disable, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
671674
check_mesh_closed=check_mesh_closed, check_mesh_manifold=check_mesh_manifold, check_mesh_orientation=check_mesh_orientation, check_mesh_debug=check_mesh_debug,
672675
mesh_cleanup=mesh_cleanup, mesh_cleanup_snap_dist=mesh_cleanup_snap_dist, decimate_barnacles=decimate_barnacles,
673676
keep_vertices=keep_vertices, compute_normals=compute_normals, sph_normals=sph_normals, normals_smoothing_iters=normals_smoothing_iters,
@@ -684,8 +687,8 @@ def reconstruction_pipeline(
684687
elif particles.dtype == 'float64':
685688
tri_mesh, tri_quad_mesh, reconstruction = reconstruction_pipeline_f64(particles, attributes_to_interpolate=attributes_to_interpolate, particle_radius=particle_radius, rest_density=rest_density,
686689
smoothing_length=smoothing_length, cube_size=cube_size, iso_surface_threshold=iso_surface_threshold,
687-
aabb_min=aabb_min, aabb_max=aabb_max, enable_multi_threading=enable_multi_threading,
688-
use_subdomain_grid=subdomain_grid, auto_disable_subdomain_grid=auto_disable_subdomain_grid, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
690+
aabb_min=aabb_min, aabb_max=aabb_max, multi_threading=multi_threading,
691+
subdomain_grid=subdomain_grid, subdomain_grid_auto_disable=subdomain_grid_auto_disable, subdomain_num_cubes_per_dim=subdomain_num_cubes_per_dim,
689692
check_mesh_closed=check_mesh_closed, check_mesh_manifold=check_mesh_manifold, check_mesh_orientation=check_mesh_orientation, check_mesh_debug=check_mesh_debug,
690693
mesh_cleanup=mesh_cleanup, mesh_cleanup_snap_dist=mesh_cleanup_snap_dist, decimate_barnacles=decimate_barnacles,
691694
keep_vertices=keep_vertices, compute_normals=compute_normals, sph_normals=sph_normals, normals_smoothing_iters=normals_smoothing_iters,

pysplashsurf/pysplashsurf/pysplashsurf.pyi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ class TriMesh3dF32:
418418
r"""
419419
Returns a copy of the `Mx3` array of the vertex indices that make up a triangle
420420
"""
421+
def get_cells(self) -> numpy.typing.NDArray[numpy.uint64]:
422+
r"""
423+
Alias for `get_triangles`
424+
"""
421425
def take_vertices(self) -> numpy.typing.NDArray[numpy.float32]:
422426
r"""
423427
Returns the `Nx3` array of vertex positions by moving it out of the mesh (zero copy)
@@ -426,6 +430,10 @@ class TriMesh3dF32:
426430
r"""
427431
Returns the `Mx3` array of the vertex indices that make up the triangles by moving it out of the mesh (zero copy)
428432
"""
433+
def take_cells(self) -> numpy.typing.NDArray[numpy.uint64]:
434+
r"""
435+
Alias for `take_triangles`
436+
"""
429437
def take_vertices_and_triangles(self) -> tuple:
430438
r"""
431439
Returns a tuple containing the vertices and triangles of the mesh by moving them out of the mesh (zero copy)
@@ -451,6 +459,10 @@ class TriMesh3dF64:
451459
r"""
452460
Returns a copy of the `Mx3` array of the vertex indices that make up a triangle
453461
"""
462+
def get_cells(self) -> numpy.typing.NDArray[numpy.uint64]:
463+
r"""
464+
Alias for `get_triangles`
465+
"""
454466
def take_vertices(self) -> numpy.typing.NDArray[numpy.float64]:
455467
r"""
456468
Returns the `Nx3` array of vertex positions by moving it out of the mesh (zero copy)
@@ -459,6 +471,10 @@ class TriMesh3dF64:
459471
r"""
460472
Returns the `Mx3` array of the vertex indices that make up the triangles by moving it out of the mesh (zero copy)
461473
"""
474+
def take_cells(self) -> numpy.typing.NDArray[numpy.uint64]:
475+
r"""
476+
Alias for `take_triangles`
477+
"""
462478
def take_vertices_and_triangles(self) -> tuple:
463479
r"""
464480
Returns a tuple containing the vertices and triangles of the mesh by moving them out of the mesh (zero copy)

pysplashsurf/src/pipeline.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ fn reconstruction_pipeline_generic<'py, I: Index, R: Real + Element>(
2727
iso_surface_threshold: R,
2828
aabb_min: Option<[R; 3]>,
2929
aabb_max: Option<[R; 3]>,
30-
enable_multi_threading: bool,
31-
use_subdomain_grid: bool,
32-
auto_disable_subdomain_grid: bool,
30+
multi_threading: bool,
31+
subdomain_grid: bool,
32+
subdomain_grid_auto_disable: bool,
3333
subdomain_num_cubes_per_dim: u32,
3434
check_mesh_closed: bool,
3535
check_mesh_manifold: bool,
@@ -120,10 +120,10 @@ fn reconstruction_pipeline_generic<'py, I: Index, R: Real + Element>(
120120
None
121121
};
122122

123-
let spatial_decomposition = if use_subdomain_grid {
123+
let spatial_decomposition = if subdomain_grid {
124124
SpatialDecomposition::UniformGrid(GridDecompositionParameters {
125125
subdomain_num_cubes_per_dim,
126-
auto_disable: auto_disable_subdomain_grid,
126+
auto_disable: subdomain_grid_auto_disable,
127127
})
128128
} else {
129129
SpatialDecomposition::None
@@ -136,7 +136,7 @@ fn reconstruction_pipeline_generic<'py, I: Index, R: Real + Element>(
136136
cube_size: cube_size * particle_radius,
137137
iso_surface_threshold,
138138
particle_aabb: aabb,
139-
enable_multi_threading,
139+
enable_multi_threading: multi_threading,
140140
spatial_decomposition,
141141
global_neighborhood_list: mesh_smoothing_weights,
142142
};
@@ -191,8 +191,8 @@ fn reconstruction_pipeline_generic<'py, I: Index, R: Real + Element>(
191191
#[pyo3(name = "reconstruction_pipeline_f32")]
192192
#[pyo3(signature = (particles, *, attributes_to_interpolate, particle_radius, rest_density,
193193
smoothing_length, cube_size, iso_surface_threshold,
194-
aabb_min = None, aabb_max = None, enable_multi_threading = false,
195-
use_subdomain_grid = true, auto_disable_subdomain_grid = true, subdomain_num_cubes_per_dim = 64,
194+
aabb_min = None, aabb_max = None, multi_threading = true,
195+
subdomain_grid = true, subdomain_grid_auto_disable = true, subdomain_num_cubes_per_dim = 64,
196196
check_mesh_closed = false, check_mesh_manifold = false, check_mesh_orientation = false, check_mesh_debug = false,
197197
mesh_cleanup, mesh_cleanup_snap_dist = None, decimate_barnacles, keep_vertices, compute_normals, sph_normals,
198198
normals_smoothing_iters, mesh_smoothing_iters, mesh_smoothing_weights, mesh_smoothing_weights_normalization,
@@ -210,9 +210,9 @@ pub fn reconstruction_pipeline_py_f32<'py>(
210210
iso_surface_threshold: f32,
211211
aabb_min: Option<[f32; 3]>,
212212
aabb_max: Option<[f32; 3]>,
213-
enable_multi_threading: bool,
214-
use_subdomain_grid: bool,
215-
auto_disable_subdomain_grid: bool,
213+
multi_threading: bool,
214+
subdomain_grid: bool,
215+
subdomain_grid_auto_disable: bool,
216216
subdomain_num_cubes_per_dim: u32,
217217
check_mesh_closed: bool,
218218
check_mesh_manifold: bool,
@@ -257,9 +257,9 @@ pub fn reconstruction_pipeline_py_f32<'py>(
257257
iso_surface_threshold,
258258
aabb_min,
259259
aabb_max,
260-
enable_multi_threading,
261-
use_subdomain_grid,
262-
auto_disable_subdomain_grid,
260+
multi_threading,
261+
subdomain_grid,
262+
subdomain_grid_auto_disable,
263263
subdomain_num_cubes_per_dim,
264264
check_mesh_closed,
265265
check_mesh_manifold,
@@ -298,8 +298,8 @@ pub fn reconstruction_pipeline_py_f32<'py>(
298298
#[pyo3(name = "reconstruction_pipeline_f64")]
299299
#[pyo3(signature = (particles, *, attributes_to_interpolate, particle_radius, rest_density,
300300
smoothing_length, cube_size, iso_surface_threshold,
301-
aabb_min = None, aabb_max = None, enable_multi_threading = false,
302-
use_subdomain_grid = true, auto_disable_subdomain_grid = true, subdomain_num_cubes_per_dim = 64,
301+
aabb_min = None, aabb_max = None, multi_threading = true,
302+
subdomain_grid = true, subdomain_grid_auto_disable = true, subdomain_num_cubes_per_dim = 64,
303303
check_mesh_closed = false, check_mesh_manifold = false, check_mesh_orientation = false, check_mesh_debug = false,
304304
mesh_cleanup, mesh_cleanup_snap_dist = None, decimate_barnacles, keep_vertices, compute_normals, sph_normals,
305305
normals_smoothing_iters, mesh_smoothing_iters, mesh_smoothing_weights, mesh_smoothing_weights_normalization,
@@ -317,9 +317,9 @@ pub fn reconstruction_pipeline_py_f64<'py>(
317317
iso_surface_threshold: f64,
318318
aabb_min: Option<[f64; 3]>,
319319
aabb_max: Option<[f64; 3]>,
320-
enable_multi_threading: bool,
321-
use_subdomain_grid: bool,
322-
auto_disable_subdomain_grid: bool,
320+
multi_threading: bool,
321+
subdomain_grid: bool,
322+
subdomain_grid_auto_disable: bool,
323323
subdomain_num_cubes_per_dim: u32,
324324
check_mesh_closed: bool,
325325
check_mesh_manifold: bool,
@@ -364,9 +364,9 @@ pub fn reconstruction_pipeline_py_f64<'py>(
364364
iso_surface_threshold,
365365
aabb_min,
366366
aabb_max,
367-
enable_multi_threading,
368-
use_subdomain_grid,
369-
auto_disable_subdomain_grid,
367+
multi_threading,
368+
subdomain_grid,
369+
subdomain_grid_auto_disable,
370370
subdomain_num_cubes_per_dim,
371371
check_mesh_closed,
372372
check_mesh_manifold,

0 commit comments

Comments
 (0)