How to Generate a Mesh from MRI Data
Build a hex27 finite element mesh from an MRE acquisition, and write it in the NLI file format the solver reads.
You only need this if you are preparing a mesh as its own step. The .mat entry points (InversionProblem and the sentinel CLI) generate the mesh for you.
1. Read the displacement data
Pick the reader that matches your acquisition:
using Sentinel
# Siemens DICOM (phase images) — directory, frequency (Hz), phase scaling
mre_data = read_mre_siemens("dicom_dir/", 60.0, 1.0)
# WashU .mat format
mre_data = read_mre_washu("washu_data.mat")
# UIUC .mat format
mre_data = read_mre_uiuc("uiuc_data.mat")All three return an MREData holding the complex displacement arrays, anatomical volume, mask, and voxel spacing.
2. Configure the mesh
config = HexMeshConfig(
mesh_strategy = 2, # 1 = voxel, 2 = wavelength, 3 = target resolution
mu_estimate = 3000.0, # for the wavelength calculation [Pa]
rho_estimate = 1000.0, # density [kg/m^3]
nodes_per_wavelength = 8.0,
buffer_size = 2, # boundary padding elements
spline_bc_type = :natural
)Choose mesh_strategy by what you want to control:
| Strategy | Element size is set by | Use when |
|---|---|---|
1 | one node per voxel | you want to preserve the MRI resolution exactly |
2 | the shear wavelength | you want elements sized to resolve the wave (recommended) |
3 | a resolution you specify, in mm | you need a specific element size |
Strategy 2 needs mu_estimate and rho_estimate to compute the wavelength; a rough estimate is enough, since it only sets the element size.
See HexMeshConfig for every field.
3. Generate and write the mesh
result = generate_hex_mesh(mre_data, config)
# NLI-format files: .nod, .elm, .dsp, .bnd
write_hex_mesh_files(result, "output/mesh")The HexMeshResult carries the Ferrite grid, the full hex27 connectivity, the interpolated displacement data, the boundary nodes, and the metadata.
4. Check the mesh before you invert
Write a VTK file and open it in ParaView to confirm the mesh covers the anatomy and the displacement field looks sensible:
export_vtk("output/mesh_preview", result;
write_disp = true, write_anatomical = true, write_region = true)A mesh that is wrong here — wrong extent, holes in the mask, a displacement field that does not look like a wave — will not be rescued by the inversion.
Next
Reconstruct with it: Configuring Inverse Runfiles or the Command-Line Interface.
For fibre-based models, continue with How to Add DTI Fiber Directions.