stentfit.core.sampling
Functions
|
Estimate the stent length and diameter from the raw mesh vertices. |
|
Sample the mesh, align it, and extract the stent point cloud and features. |
|
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
trimeshobject.- Returns:
Dict with the stent
length,diameter, and theirsize_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
trimeshobject.n_samples – Number of points to sample.
Noneuses one sample per face, scaled bysamples_per_face.samples_per_face – Samples per mesh face when
n_samplesisNone.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.
Nonedraws a fresh cloud each call; an int makes it reproducible.out_dir – Folder to write
thickness_diagnostics.htmlinto.Noneskips the diagnostic plot.
- Returns:
Dict with the point cloud (
stent_df), thestent_features(length, diameter, radius, strut_thickness, z-bounds, inner/outer/mid radii, center_cylinder_radius, num_points), and thestent_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_pointsis not given, it first picks a sample count from the stent size (small or short stents get fewer points). It then callspreprocess_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 assampling_points.csvand drawn tosampling_points.html, and the strut thickness is drawn tothickness_diagnostics.html.- Parameters:
mesh – The stent surface mesh, already loaded as a
trimeshobject.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.
Nonepicks 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 extractedstent_features, and thestent_centerline_directionunit vector.