Mesh Kernels
GPU primitives shared by the surface and volumetric mesh tools: closest-point and inside/outside queries, tetrahedron quality, distance maps, blur and label-vote resampling.
Module Reference
GPU primitives behind the surface and volumetric mesh tools.
This module provides the ProcessMeshKernels class: closest-point and
inside/outside queries against a triangle surface, the tetrahedron scaled
Jacobian, exact Euclidean distance maps, a blur matching ITK’s recursive
Gaussian, and label-vote resampling. The warp kernels stay at module scope,
where warp builds them; the class methods prepare their inputs and launch
them.
- class monai_physio.process_mesh_kernels.ProcessMeshKernels(log_level=20)[source]
GPU primitives shared by
ProcessSurfaceMeshandProcessVolumetricMesh.Surface queries take a
warp.Meshbuilt once bybuild_surface_mesh()and reused across calls. Distance maps and blurs take and return torch tensors ondevice;vote_resample_labelmap()takes and returns ITK images.Example
>>> kernels = ProcessMeshKernels() >>> mesh = kernels.build_surface_mesh(surface) >>> closest = kernels.closest_points_on_surface(mesh, points)
- NO_FEATURE = 1e+30
Squared distance given to a voxel no feature can reach.
- NO_FEATURE_LIMIT = 1e+20
Squared distance at or above which a voxel had no feature in reach.
- VOTE_ALPHA = 3.0
ITK’s label-vote interpolator weighs a voxel by the Gaussian’s mass over it and ignores voxels farther than this many sigmas from the sample.
- EDGE_BAND = 0.002
A closest point whose barycentric weight on a triangle corner is below this counts as lying on the opposite edge (on a vertex, for two such weights); float32 positions at a patient’s coordinates blur the weights by about 1e-3.
- property device: str
The current CUDA device, e.g.
"cuda:0".Read at each use, so a process that selected another device (
torch.cuda.set_device, as torchrun workers do) computes there, and constructing this class initializes no GPU.
- build_surface_mesh(surface)[source]
Upload surface’s triangles to the GPU for closest-point queries.
- Return type:
Mesh
- closest_points_on_surface(mesh, queries)[source]
Return each row of queries’ closest point on the surface of mesh.
- Return type:
- points_inside_surface(mesh, points)[source]
Return which rows of points lie inside the closed, outward-wound mesh.
The side is the one
vtkImplicitPolyDataDistancereports: that of the normal of the closest face. Where the closest point lies on an edge or a vertex, VTK takes whichever of the faces meeting there its search finds first. If they all put the point on one side the GPU has the answer; on a thin, tubular surface they sometimes do not, and those few points go to VTK.- Return type:
- scaled_jacobian(points, connectivity)[source]
Return VTK’s tetrahedron scaled Jacobian (Verdict) for every cell.
- Return type:
- squared_distance_to_features(features, spacing)[source]
Return every voxel’s squared distance, in mm squared, to a feature voxel.
The distance is the exact Euclidean one, taken between voxel centers, with spacing the voxel pitch along each axis of features.
- Return type:
- gaussian_blur(field, spacing, sigma_mm)[source]
Blur field as ITK’s recursive Gaussian does, repeating its edge values.
- Return type:
- vote_resample_labelmap(labelmap_image, isotropic_spacing_mm, sigma_mm=None)[source]
Resample a labelmap onto an isotropic grid, label boundaries intact.
This reproduces ITK’s
LabelImageGaussianInterpolateImageFunctionon the GPU, so labels stay whole numbers and keep sharing their walls. Each output voxel takes the label with the largest Gaussian-weighted vote, where a voxel’s weight is the Gaussian’s mass over it. The weights separate along the axes, so every label’s votes come from three banded sums. Exact ties, which ITK settles by rounding noise, go to the smaller label.- Parameters:
- Return type:
image
- signed_distance_mm(labels, spacing, label_id, sigma_mm)[source]
Return the signed distance, in mm, to label_id, negative inside.
The map measures to voxel centers, so its zero level is faceted at the voxel pitch; sigma_mm of blur takes those facets out, at the cost of pulling the level set in by roughly
sigma_mm ** 2times the surface curvature.label_idof0measures to the background like any other label, so a label-to-background wall lies midway between the two sides’ edge voxels, as a wall between two labels does.Like ITK’s signed Maurer map, distances run to the voxels of the label that touch a voxel outside it, so a voxel on the label’s edge is at distance zero. labels sits on the GPU and spacing is its voxel pitch along each axis.
- Return type:
Navigation
Volumetric Mesh Tools | Utility Modules | 4D Image Conversion