stentfit.core.sampling

Functions

compute_pre_stent_size_ratio(→ dict)

Estimate the stent length and diameter from the raw mesh vertices.

preprocess_stent(→ dict)

Sample the mesh, align it, and extract the stent point cloud and features.

sample_stent_points(→ dict)

Turn the stent mesh into a cleaned, aligned point cloud.

Module Contents

stentfit.core.sampling.compute_pre_stent_size_ratio(mesh: trimesh.Trimesh) dict[source]

Estimate the stent length and diameter from the raw mesh vertices.

This is a quick, cheap pre-check run before any sampling. It fits a PCA axis to the mesh vertices, measures the length along that axis and the diameter across it, and returns their ratio. sample_stent_points() uses this ratio to pick how many points to sample.

Parameters:

mesh – The stent surface mesh, already loaded as a trimesh object.

Returns:

Dict with the stent length, diameter, and their size_ratio (length / diameter).

stentfit.core.sampling.preprocess_stent(mesh: trimesh.Trimesh, n_samples: int, samples_per_face: int, n_thickness_slices: int, slice_cutoff: int, remove_supports: bool, random_seed: int | None = None, out_dir: pathlib.Path | None = None) dict[source]

Sample the mesh, align it, and extract the stent point cloud and features.

This does the main sampling work behind sample_stent_points(). It samples points on the mesh surface, fits a PCA axis and rotates it onto [0, 0, 1], then builds a cylindrical-coordinate point cloud. Along the axis it measures the length, diameter, and strut thickness. Thickness is read per axial slice and averaged over the middle of the stent. Support points can be trimmed first.

Parameters:
  • mesh – The stent surface mesh, already loaded as a trimesh object.

  • n_samples – Number of points to sample. None uses one sample per face, scaled by samples_per_face.

  • samples_per_face – Samples per mesh face when n_samples is None.

  • n_thickness_slices – Number of axial slices used to measure thickness.

  • slice_cutoff – Slices dropped from each axial end before averaging, so the closed stent ends do not skew the thickness.

  • remove_supports – Trim print-support points before extracting features.

  • random_seed – Seed for the surface sampling. None draws a fresh cloud each call; an int makes it reproducible.

  • out_dir – Folder to write thickness_diagnostics.html into. None skips the diagnostic plot.

Returns:

Dict with the point cloud (stent_df), the stent_features (length, diameter, radius, strut_thickness, z-bounds, inner/outer/mid radii, center_cylinder_radius, num_points), and the stent_centerline_direction (the PCA axis before rotation).

stentfit.core.sampling.sample_stent_points(mesh: trimesh.Trimesh, stent_name: str, output_dir: pathlib.Path, n_points: int = None, samples_per_face: int = 1, max_display: int = 500000, remove_supports: bool = False, random_seed: int = 0) dict[source]

Turn the stent mesh into a cleaned, aligned point cloud.

This is the first step of the pipeline. When n_points is not given, it first picks a sample count from the stent size (small or short stents get fewer points). It then calls preprocess_stent() to align the PCA axis to [0, 0, 1], extract the stent features, and build a cylindrical-coordinate point cloud. The cloud is saved as sampling_points.csv and drawn to sampling_points.html, and the strut thickness is drawn to thickness_diagnostics.html.

Parameters:
  • mesh – The stent surface mesh, already loaded as a trimesh object.

  • stent_name – Name used to label outputs and plots.

  • output_dir – Folder where the CSV and HTML view are written.

  • n_points – Number of points to sample. None picks the count automatically from the stent size.

  • samples_per_face – Number of samples taken per mesh face.

  • max_display – Maximum number of points drawn in the HTML view.

  • remove_supports – Drop print-support points during sampling.

  • random_seed – Seed for the sampling, for repeatable runs.

Returns:

Dict with the point cloud (stent_df), the extracted stent_features, and the stent_centerline_direction unit vector.