Skip to content

Commit df35c49

Browse files
committed
Update documentation
1 parent 6b070c4 commit df35c49

File tree

8 files changed

+353
-93
lines changed

8 files changed

+353
-93
lines changed

pysplashsurf/pysplashsurf/docs/source/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@
7575

7676
always_document_param_types = True
7777
always_use_bars_union = True
78+
79+
napoleon_use_rtype = False
80+
napoleon_include_special_with_doc = True
81+
7882
# typehints_document_rtype = False
7983
# typehints_use_rtype = False
8084
# typehints_use_signature = True

pysplashsurf/pysplashsurf/pysplashsurf.pyi

Lines changed: 173 additions & 45 deletions
Large diffs are not rendered by default.

pysplashsurf/src/marching_cubes.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@ use crate::uniform_grid::PyUniformGrid;
1111
use crate::utils;
1212
use crate::utils::IndexT;
1313

14-
/// Checks the consistency of a reconstructed surface mesh (watertightness, manifoldness), optionally returns a string with details if problems are found
14+
/// Checks the consistency of a reconstructed surface mesh (watertightness, manifoldness), optionally returns a string with details, if problems are found
15+
///
16+
/// Parameters
17+
/// ----------
18+
/// mesh
19+
/// The triangle mesh to check for consistency.
20+
/// grid
21+
/// The uniform grid that was used for the marching cubes triangulation of the input mesh.
22+
/// check_closed
23+
/// Flag to enable checking if the mesh is closed (watertight).
24+
/// check_manifold
25+
/// Flag to enable checking if the mesh is manifold (i.e. has no non-manifold vertices & edges).
26+
/// debug
27+
/// Flag to enable additional debug output during the consistency checks.
28+
///
29+
/// Returns
30+
/// -------
31+
/// An optional string with details about the problems found during the consistency checks.
32+
/// If no problems are found, None is returned.
1533
#[gen_stub_pyfunction]
1634
#[pyfunction]
1735
#[pyo3(name = "check_mesh_consistency")]
@@ -73,6 +91,18 @@ pub fn check_mesh_consistency<'py>(
7391
///
7492
/// The function is currently single-threaded. The SPH surface reconstruction functions :py:func:`reconstruction_pipeline`
7593
/// and :py:func:`reconstruct_surface` improve performance by processing multiple patches in parallel.
94+
///
95+
/// Parameters
96+
/// ----------
97+
/// values : numpy.ndarray
98+
/// A three-dimensional numpy array of shape (nx, ny, nz) containing the scalar values at the vertices
99+
/// of the marching cubes grid.
100+
/// iso_surface_threshold
101+
/// The iso-surface threshold value used to determine the surface.
102+
/// cube_size
103+
/// The size of each cube/voxel of the marching cubes grid. Determines the scaling of the resulting mesh.
104+
/// translation
105+
/// An optional translation vector [tx, ty, tz] applied to the entire mesh after scaling.
76106
#[gen_stub_pyfunction]
77107
#[pyfunction]
78108
#[pyo3(name = "marching_cubes")]

pysplashsurf/src/neighborhood_search.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ impl PyNeighborhoodLists {
5252
}
5353

5454
/// Performs a neighborhood search using spatial hashing (multithreaded implementation)
55+
///
56+
/// Parameters
57+
/// ----------
58+
/// particles : numpy.ndarray
59+
/// A two-dimensional numpy array of shape (N, 3) containing the positions of the particles.
60+
/// domain
61+
/// An axis-aligned bounding box (AABB) of the particles used for spatial hashing.
62+
/// The neighborhood search fails if particles are outside the domain.
63+
/// search_radius
64+
/// The radius per particle where other particles are considered neighbors.
5565
#[gen_stub_pyfunction]
5666
#[pyfunction]
5767
#[pyo3(name = "neighborhood_search_spatial_hashing_parallel")]

pysplashsurf/src/pipeline.rs

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,85 +27,81 @@ use crate::utils::{IndexT, pyerr_unsupported_scalar};
2727
/// Parameters
2828
/// ----------
2929
/// particles : numpy.ndarray
30-
/// A two-dimensional numpy array of shape (N, 3) containing the positions of the particles.
30+
/// A two-dimensional numpy array of shape (N, 3) containing the positions of the particles.
3131
/// attributes_to_interpolate
32-
/// Dictionary containing all attributes to interpolate. The keys are the attribute names and the values are the corresponding 1D/2D arrays.\n
33-
/// The arrays must have the same length as the number of particles. \n
34-
/// Supported array types are 2D float32/float64 arrays for vector attributes and 1D uint64/float32/float64 arrays for scalar attributes.
32+
/// Dictionary containing all attributes to interpolate. The keys are the attribute names and the values are the corresponding 1D/2D arrays.
33+
/// The arrays must have the same length as the number of particles.
34+
/// Supported array types are 2D float32/float64 arrays for vector attributes and 1D uint64/float32/float64 arrays for scalar attributes.
3535
/// particle_radius
36-
/// Particle radius
36+
/// Particle radius.
3737
/// rest_density
38-
/// Rest density of the fluid
38+
/// Rest density of the fluid.
3939
/// smoothing_length
40-
/// Smoothing length of the fluid in multiples of the particle radius (compact support radius of SPH kernel will be twice the smoothing length)
40+
/// Smoothing length of the SPH kernel in multiples of the particle radius (compact support radius of SPH kernel will be twice the smoothing length).
4141
/// cube_size
42-
/// Size of the cubes used for the marching cubes grid in multiples of the particle radius
42+
/// Size of the cubes (voxels) used for the marching cubes grid in multiples of the particle radius.
4343
/// iso_surface_threshold
44-
/// Threshold for the iso surface
44+
/// Threshold of the SPH interpolation of the "color field" where the iso surface should be extracted.
4545
/// aabb_min
46-
/// Lower corner of the AABB of particles to consider in the reconstruction
46+
/// Lower corner [x,y,z] of the AABB of particles that are active in the reconstruction.
4747
/// aabb_max
48-
/// Upper corner of the AABB of particles to consider in the reconstruction
48+
/// Upper corner [x,y,z] of the AABB of particles to consider in the reconstruction.
4949
/// multi_threading
50-
/// Multi-threading
50+
/// Flag to enable multi-threading for the reconstruction and post-processing steps.
5151
/// subdomain_grid
52-
/// Enable spatial decomposition using by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading
52+
/// Flag to enable spatial decomposition by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading.
5353
/// subdomain_grid_auto_disable
54-
/// Whether to automatically disable the subdomain grid if the global domain is too small
54+
/// Flag to automatically disable the subdomain grid if the global domain is too small.
5555
/// subdomain_num_cubes_per_dim
56-
/// Each subdomain will be a cube consisting of this number of MC cube cells along each coordinate axis
56+
/// Number of marching cubes voxels along each coordinate axis in each subdomain if the subdomain grid is enabled.
5757
/// check_mesh_closed
58-
/// Enable checking the final mesh for holes
58+
/// Flag to enable checking the final mesh for holes.
5959
/// check_mesh_manifold
60-
/// Enable checking the final mesh for non-manifold edges and vertices
60+
/// Flag to enable checking the final mesh for non-manifold edges and vertices.
6161
/// check_mesh_orientation
62-
/// Enable checking the final mesh for inverted triangles (compares angle between vertex normals and adjacent face normals)
62+
/// Flag to enable checking the final mesh for inverted triangles (compares angle between vertex normals and adjacent face normals).
6363
/// check_mesh_debug
64-
/// Enable additional debug output for the check-mesh operations (has no effect if no other check-mesh option is enabled)
64+
/// Flag to enable additional debug output for the check-mesh operations (has no effect if no other check-mesh option is enabled).
6565
/// mesh_cleanup
66-
/// Flag to perform mesh cleanup\n
67-
/// This implements the method from “Compact isocontours from sampled data” (Moore, Warren; 1992)
66+
/// Flag to enable marching cubes mesh cleanup. This implements the method from "Compact isocontours from sampled data" (Moore, Warren; 1992).
6867
/// mesh_cleanup_snap_dist
69-
/// If MC mesh cleanup is enabled, vertex snapping can be limited to this distance relative to the MC edge length (should be in range of [0.0,0.5])
68+
/// If marching cubes mesh cleanup is enabled, this limits vertex snapping to the specified distance relative to the MC edge length (should be in range of [0.0,0.5]).
7069
/// decimate_barnacles
71-
/// Flag to perform barnacle decimation\n
72-
/// For details see “Weighted Laplacian Smoothing for Surface Reconstruction of Particle-based Fluids” (Löschner, Böttcher, Jeske, Bender; 2023).
70+
/// Flag to perform barnacle decimation. For details see "Weighted Laplacian Smoothing for Surface Reconstruction of Particle-based Fluids" (Löschner, Böttcher, Jeske, Bender; 2023).
7371
/// keep_vertices
74-
/// Flag to keep any vertices without connectivity resulting from mesh cleanup or decimation step
72+
/// Flag to retain any vertices without connectivity resulting from mesh cleanup or decimation step instead of filtering them out.
7573
/// compute_normals
76-
/// Flag to compute normals\n
77-
/// If set to True, the normals will be computed and stored in the mesh.
74+
/// Flag to enable computation of vertex normals on the final mesh.
7875
/// sph_normals
79-
/// Flag to compute normals using SPH interpolation instead of geometry-based normals.
76+
/// Flag to enable computation of normals using SPH interpolation (gradient of the color field) instead of geometry-based normals.
8077
/// normals_smoothing_iters
81-
/// Number of Laplacian smoothing iterations for the normal field
78+
/// Number of Laplacian smoothing iterations to perform on the normal field.
8279
/// mesh_smoothing_iters
83-
/// Number of Laplacian smoothing iterations for the mesh
80+
/// Number of Laplacian smoothing iterations to perform on the mesh vertices.
8481
/// mesh_smoothing_weights
85-
/// Flag to compute mesh smoothing weights\n
86-
/// This implements the method from “Weighted Laplacian Smoothing for Surface Reconstruction of Particle-based Fluids” (Löschner, Böttcher, Jeske, Bender; 2023).
82+
/// Flag to enable computation and usage of mesh smoothing weights according to "Weighted Laplacian Smoothing for Surface Reconstruction of Particle-based Fluids" (Löschner, Böttcher, Jeske, Bender; 2023).
8783
/// mesh_smoothing_weights_normalization
88-
/// Normalization value for the mesh smoothing weights
84+
/// Normalization value for the mesh smoothing weights.
8985
/// generate_quads
90-
/// Enable trying to convert triangles to quads if they meet quality criteria
86+
/// Flag to enable conversion of triangles to quads depending on geometric criteria.
9187
/// quad_max_edge_diag_ratio
92-
/// Maximum allowed ratio of quad edge lengths to its diagonals to merge two triangles to a quad (inverse is used for minimum)
88+
/// Maximum allowed ratio of quad edge lengths to its diagonals to merge two triangles to a quad (inverse is used for minimum).
9389
/// quad_max_normal_angle
94-
/// Maximum allowed angle (in degrees) between triangle normals to merge them to a quad
90+
/// Maximum allowed angle (in degrees) between triangle normals to merge them to a quad.
9591
/// quad_max_interior_angle
96-
/// Maximum allowed vertex interior angle (in degrees) inside a quad to merge two triangles to a quad
92+
/// Maximum allowed vertex interior angle (in degrees) inside a quad to merge two triangles to a quad.
9793
/// output_mesh_smoothing_weights
98-
/// Flag to store the mesh smoothing weights if smoothing weights are computed.
94+
/// Flag to attach and return the smoothing weights as a mesh attribute if smoothing weights are computed.
9995
/// output_raw_normals
100-
/// Flag to output the raw normals in addition to smoothed normals if smoothing of normals is enabled
96+
/// Flag to output the raw normals in addition to smoothed normals if smoothing of normals is enabled.
10197
/// output_raw_mesh
102-
/// When true, also return the SurfaceReconstruction object with no post-processing applied
98+
/// Flag to return a copy of the raw mesh before any post-processing steps (inside the returned reconstruction object).
10399
/// mesh_aabb_min
104-
/// Smallest corner of the axis-aligned bounding box for the mesh
100+
/// Lower corner [x,y,z] of the axis-aligned bounding box for the mesh, triangles fully outside this box will be removed.
105101
/// mesh_aabb_max
106-
/// Largest corner of the axis-aligned bounding box for the mesh
102+
/// Upper corner [x,y,z] of the axis-aligned bounding box for the mesh, triangles fully outside this box will be removed.
107103
/// mesh_aabb_clamp_vertices
108-
/// Flag to clamp the vertices of the mesh to the AABB
104+
/// Flag to clamp the vertices of the mesh to the AABB in addition to removing triangles outside the AABB.
109105
///
110106
#[gen_stub_pyfunction]
111107
#[pyfunction]

pysplashsurf/src/postprocessing.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ use crate::utils::*;
1717
///
1818
/// This operation creates a new mesh and does not modify the input mesh.
1919
/// Angles are specified in degrees.
20+
///
21+
/// Parameters
22+
/// ----------
23+
/// mesh
24+
/// The triangle mesh to convert to a mixed triangle-quad mesh.
25+
/// non_squareness_limit
26+
/// Maximum allowed ratio of quad edge lengths to its diagonals to merge two triangles to a quad (inverse is used for minimum).
27+
/// normal_angle_limit
28+
/// Maximum allowed angle (in degrees) between triangle normals to merge them to a quad.
29+
/// max_interior_angle
30+
/// Maximum allowed vertex interior angle (in degrees) inside a quad to merge two triangles to a quad.
2031
#[gen_stub_pyfunction]
2132
#[pyfunction]
2233
#[pyo3(name = "convert_tris_to_quads")]
@@ -80,6 +91,20 @@ pub fn convert_tris_to_quads<'py>(
8091
/// Laplacian smoothing of mesh vertices with feature weights
8192
///
8293
/// The smoothing is performed inplace and modifies the vertices of the given mesh.
94+
///
95+
/// Parameters
96+
/// ----------
97+
/// mesh
98+
/// The triangle mesh to smooth.
99+
/// vertex_connectivity
100+
/// The vertex-vertex connectivity of the mesh, required for efficient smoothing.
101+
/// iterations
102+
/// The number of smoothing iterations to perform.
103+
/// beta
104+
/// Factor used for blending the original vertex position with the smoothed position.
105+
/// weights
106+
/// A one-dimensional array of weights per vertex that influence the smoothing.
107+
/// The weight is multiplied with beta.
83108
#[gen_stub_pyfunction]
84109
#[pyfunction]
85110
#[pyo3(name = "laplacian_smoothing_parallel")]
@@ -126,6 +151,15 @@ pub fn laplacian_smoothing_parallel<'py>(
126151
/// Laplacian smoothing of a normal field
127152
///
128153
/// The smoothing is performed inplace and modifies the given normal array.
154+
///
155+
/// Parameters
156+
/// ----------
157+
/// normals
158+
/// A two-dimensional array of shape (N, 3) containing the normals to smooth.
159+
/// vertex_connectivity
160+
/// The vertex-vertex connectivity of the mesh, required for efficient smoothing.
161+
/// iterations
162+
/// The number of smoothing iterations to perform.
129163
#[gen_stub_pyfunction]
130164
#[pyfunction]
131165
#[pyo3(name = "laplacian_smoothing_normals_parallel")]
@@ -165,6 +199,13 @@ pub fn laplacian_smoothing_normals_parallel<'py>(
165199
/// The decimation is performed inplace and modifies the given mesh.
166200
/// Returns the vertex-vertex connectivity of the decimated mesh which can be used for other
167201
/// post-processing steps.
202+
///
203+
/// Parameters
204+
/// ----------
205+
/// mesh
206+
/// The triangle mesh to decimate.
207+
/// keep_vertices
208+
/// Flag to retain any vertices without connectivity resulting from decimation instead of filtering them out.
168209
#[gen_stub_pyfunction]
169210
#[pyfunction]
170211
#[pyo3(name = "barnacle_decimation")]
@@ -203,6 +244,19 @@ pub fn barnacle_decimation<'py>(
203244
/// The method is designed specifically for meshes generated by Marching Cubes.
204245
/// See Moore and Warren: `Mesh Displacement: An Improved Contouring Method for Trivariate Data <https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.49.5214&rep=rep1&type=pdf>`_ (1991)
205246
/// or Moore and Warren: "Compact Isocontours from Sampled Data" in "Graphics Gems III" (1992).
247+
///
248+
/// Parameters
249+
/// ----------
250+
/// mesh
251+
/// The triangle mesh to simplify.
252+
/// grid
253+
/// The uniform grid that was used for the marching cubes triangulation of the input mesh.
254+
/// max_rel_snap_dist
255+
/// Optional maximum relative snapping distance (relative to the grid cell size) to merge close vertices.
256+
/// max_iter
257+
/// The maximum number of iterations of cleanup to perform.
258+
/// keep_vertices
259+
/// Flag to retain any vertices without connectivity resulting from simplification instead of filtering them out.
206260
#[gen_stub_pyfunction]
207261
#[pyfunction]
208262
#[pyo3(name = "marching_cubes_cleanup")]

pysplashsurf/src/reconstruction.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,41 @@ impl PySurfaceReconstruction {
101101
/// Performs a surface reconstruction from the given particles without additional post-processing
102102
///
103103
/// Note that all parameters use absolute distance units and are not relative to the particle radius.
104+
///
105+
/// Parameters
106+
/// ----------
107+
/// particles : numpy.ndarray
108+
/// A two-dimensional numpy array of shape (N, 3) containing the positions of the particles.
109+
/// particle_radius
110+
/// Particle radius.
111+
/// rest_density
112+
/// Rest density of the fluid.
113+
/// smoothing_length
114+
/// Smoothing length of the SPH kernel in absolute distance units (compact support radius of SPH kernel will be twice the smoothing length).
115+
/// cube_size
116+
/// Size of the cubes (voxels) used for the marching cubes grid in absolute distance units.
117+
/// iso_surface_threshold
118+
/// Threshold of the SPH interpolation of the "color field" where the iso surface should be extracted.
119+
/// aabb_min
120+
/// Lower corner of the AABB of particles to consider in the reconstruction.
121+
/// aabb_max
122+
/// Upper corner of the AABB of particles to consider in the reconstruction.
123+
/// multi_threading
124+
/// Flag to enable multi-threading for the reconstruction and post-processing steps.
125+
/// subdomain_grid
126+
/// Flag to enable spatial decomposition by dividing the domain into subdomains with dense marching cube grids for efficient multi-threading.
127+
/// subdomain_grid_auto_disable
128+
/// Flag to automatically disable the subdomain grid if the global domain is too small.
129+
/// subdomain_num_cubes_per_dim
130+
/// Number of marching cubes voxels along each coordinate axis in each subdomain if the subdomain grid is enabled.
104131
#[gen_stub_pyfunction]
105132
#[pyfunction]
106133
#[pyo3(name = "reconstruct_surface")]
107134
#[pyo3(signature = (particles, *,
108135
particle_radius, rest_density = 1000.0, smoothing_length, cube_size, iso_surface_threshold = 0.6,
136+
aabb_min = None, aabb_max = None,
109137
multi_threading = true, global_neighborhood_list = false,
110-
subdomain_grid = true, subdomain_grid_auto_disable = true, subdomain_num_cubes_per_dim = 64,
111-
aabb_min = None, aabb_max = None
138+
subdomain_grid = true, subdomain_grid_auto_disable = true, subdomain_num_cubes_per_dim = 64
112139
))]
113140
pub fn reconstruct_surface<'py>(
114141
particles: &Bound<'py, PyUntypedArray>,
@@ -117,13 +144,13 @@ pub fn reconstruct_surface<'py>(
117144
smoothing_length: f64,
118145
cube_size: f64,
119146
iso_surface_threshold: f64,
147+
aabb_min: Option<[f64; 3]>,
148+
aabb_max: Option<[f64; 3]>,
120149
multi_threading: bool,
121150
global_neighborhood_list: bool,
122151
subdomain_grid: bool,
123152
subdomain_grid_auto_disable: bool,
124153
subdomain_num_cubes_per_dim: u32,
125-
aabb_min: Option<[f64; 3]>,
126-
aabb_max: Option<[f64; 3]>,
127154
) -> PyResult<PySurfaceReconstruction> {
128155
let py = particles.py();
129156

pysplashsurf/src/sph_interpolation.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ impl PySphInterpolator {
160160
#[pymethods]
161161
impl PySphInterpolator {
162162
/// Constructs an SPH interpolator (with cubic kernels) for the given particles
163+
///
164+
/// Parameters
165+
/// ----------
166+
/// particle_positions : numpy.ndarray
167+
/// A two-dimensional numpy array of shape (N, 3) containing the positions of the particles that are used for interpolation.
168+
/// particle_densities : numpy.ndarray
169+
/// A one-dimensional numpy array of shape (N,) containing the densities of the particles.
170+
/// particle_rest_mass
171+
/// The rest mass of each particle (assumed to be the same for all particles).
172+
/// compact_support_radius
173+
/// The compact support radius of the cubic spline kernel used for interpolation.
163174
#[new]
164175
fn py_new<'py>(
165176
particle_positions: &Bound<'py, PyUntypedArray>,

0 commit comments

Comments
 (0)