Generate surface file from 'nii' or 'mgz' volume files
Source: R/utils_generate_subcortical_surf.R
volume_to_surf.RdGenerate surface file from 'nii' or 'mgz' volume files
Usage
volume_to_surf(
volume,
save_to = NA,
lambda = 0.2,
degree = 2,
threshold_lb = 0.5,
threshold_ub = NA,
format = "auto",
smooth_method = c("implicit", "explicit", "none"),
smooth_iterations = 10L,
max_vertices = 5e+05
)Arguments
- volume
path to the volume file, or object from
read_volume.- save_to
where to save the surface file; default is
NA(no save).- lambda
'Laplacian'smooth, the higher the smoother- degree
'Laplacian'degree; default is2- threshold_lb
lower threshold of the volume (to create mask); default is
0.5- threshold_ub
upper threshold of the volume; default is
NA(no upper bound). Voxels strictly between the two thresholds form the mask; voxels that areNA,NaN, or infinite are invalid and never part of it- format
The format of the file if
save_tois a valid path, choices include'auto'Default, supports
'FreeSurfer'binary format and'ASCII'text format, based on file name suffix'bin''FreeSurfer'binary format'asc''ASCII'text format'ply''Stanford'
'PLY'format'off'Object file format
'obj''Wavefront'object format'gii''GIfTI'format. Please avoid using'gii.gz'as the file suffix'mz3''Surf-Ice'format'byu''BYU'mesh format'vtk'Legacy
'VTK'format
'gii', otherwise'FreeSurfer'format. Please do not use'gii.gz'suffix.- smooth_method
"implicit"(default) smooths withvcg_smooth_implicitusinglambdaanddegree;"explicit"smooths withmris_smoothinstead, repeated neighbor averaging whose memory grows only linearly with the surface (with a ravetools version that does not havemris_smooth, the"laplace"type ofvcg_smooth_explicitis used);"none"returns the surface without smoothing- smooth_iterations
number of averaging rounds when
smooth_methodis"explicit"; default is10- max_vertices
used only when
smooth_methodis"implicit", whose memory grows quickly with the surface size: surfaces with more vertices than this are reduced to about this many withravetools::vcg_decimate()before smoothing, which removes vertices from flat regions first and keeps the shape; default is500000. Because the smoothing works in mesh steps, the samelambdaanddegreesmooth a reduced surface more; use a larger value orInfto smooth at full resolution. With a ravetools version that does not havevcg_decimate, surfaces with more than20000vertices are not smoothed, since the implicit smoothing of those versions can crash on large surfaces
Value
Triangle 'rgl' mesh (vertex positions in native 'RAS'). If save_to is a valid path, then the mesh will be saved to this location.
When no valid voxel lies within the thresholds, a warning is issued and
the mesh has a single vertex at the origin and no face; it is still saved
to save_to.
Examples
library(threeBrain)
N27_path <- file.path(default_template_directory(), "N27")
if(dir.exists(N27_path)) {
aseg <- file.path(N27_path, "mri", "aparc+aseg.mgz")
# generate surface for left-hemisphere insula
mesh <- volume_to_surf(aseg, threshold_lb = 1034,
threshold_ub = 1036)
if (interactive()) {
ravetools::rgl_view({
ravetools::rgl_call("shade3d", mesh, color = "yellow")
})
}
}