mesh API
yabplot.mesh.load_bmesh(bmesh)
Transforms the bmesh parameter into a standardized dictionary of PyVista PolyData meshes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bmesh
|
None, str, dict, or pyvista.PolyData
|
|
required |
Returns:
| Type | Description |
|---|---|
dict
|
Standardized dictionary containing the loaded PyVista meshes. |
Notes
The standard meshes are group-average cortical surfaces from the Human Connectome Project (fs_LR 32k, 32492 vertices per hemisphere). They are in MNI152NLin6Asym space, the MNI152 template distributed with FSL, and cover the cortex only (no cerebellum or brainstem). Custom meshes are used as they are, in whatever space their coordinates are in.
Source code in yabplot/mesh.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
yabplot.mesh.make_cortical_mesh(verts, faces, scalars, scalar_name='Data')
Converts standard triangle face arrays into pyvista's specific padded format and injects per-vertex data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verts
|
ndarray
|
(N, 3) float array of spatial vertex coordinates (x, y, z). |
required |
faces
|
ndarray
|
(M, 3) int array of triangle face indices. |
required |
scalars
|
ndarray
|
(N,) float array of per-vertex scalar values. |
required |
scalar_name
|
str
|
the string key to store the data under. default is 'Data'. |
'Data'
|
Returns:
| Name | Type | Description |
|---|---|---|
mesh |
PolyData
|
the instantiated pyvista mesh with attached scalar data. |
Source code in yabplot/mesh.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
yabplot.mesh.load_nii_as_mesh(nii_path, threshold=0.5, blur_sigma=1.5, smooth_i=10, smooth_f=0.1)
Build a surface mesh from a 3D NIfTI volume using marching cubes, with optional Gaussian blurring and mesh smoothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nii_path
|
str
|
Absolute path to a NIfTI file representing a 3D volume. If 4D, only the first volume will be used. |
required |
threshold
|
float
|
Threshold applied after optional blur. Voxels |
0.5
|
blur_sigma
|
float
|
Gaussian blur (voxel units) before thresholding. |
1.5
|
smooth_i
|
int
|
Number of PyVista smoothing iterations after surface extraction. |
10
|
smooth_f
|
float
|
Relaxation factor for mesh smoothing. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
mesh |
PolyData
|
The extracted and smoothed surface mesh ready for plotting. |
Source code in yabplot/mesh.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
yabplot.mesh.load_vertexwise_mesh(lh_mesh_path, rh_mesh_path, lh_data, rh_data, scalar_name='Data')
Loads GIfTI geometry files (i.e. brain mesh), converts them to pyvista meshes, and injects the provided 1D data arrays into them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lh_mesh_path
|
str
|
absolute path to the left hemisphere geometry file (e.g., .surf.gii). |
required |
rh_mesh_path
|
str
|
absolute path to the right hemisphere geometry file (e.g., .surf.gii). |
required |
lh_data
|
ndarray
|
1D array of scalar values for the left hemisphere vertices. |
required |
rh_data
|
ndarray
|
1D array of scalar values for the right hemisphere vertices. |
required |
scalar_name
|
str
|
the string key to store the data under in the pyvista point data dictionary. default is 'Data'. |
'Data'
|
Returns:
| Type | Description |
|---|---|
lh_mesh, rh_mesh : tuple of pyvista.PolyData
|
left and right hemisphere meshes ready for |
Source code in yabplot/mesh.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |