Skip to content

Commit

Permalink
Merge pull request #375 from mgxd/fix/modify-sphere
Browse files Browse the repository at this point in the history
FIX: Add surface-modify-sphere call to catch potential sphere elongation
  • Loading branch information
effigies authored Oct 11, 2023
2 parents bfcc1a8 + 15dadca commit 949a13f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
65 changes: 65 additions & 0 deletions smriprep/interfaces/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,71 @@ class SurfaceApplyWarpfield(WBCommand):
_cmd = "wb_command -surface-apply-warpfield"


class SurfaceModifySphereInputSpec(CommandLineInputSpec):
in_surface = File(
exists=True,
mandatory=True,
position=0,
argstr="%s",
desc="the sphere to modify",
)
radius = traits.Int(
mandatory=True,
position=1,
argstr="%d",
desc='the radius the output sphere should have'
)
out_surface = File(
name_template="%s_mod.surf.gii",
name_source="in_surface",
position=2,
argstr="%s",
desc="the modified sphere",
)
recenter = traits.Bool(
False,
position=3,
argstr="-recenter",
desc="recenter the sphere by means of the bounding box",
)


class SurfaceModifySphereOutputSpec(TraitedSpec):
out_surface = File(desc="the modified sphere")


class SurfaceModifySphere(WBCommand):
"""CHANGE RADIUS AND OPTIONALLY RECENTER A SPHERE
wb_command -surface-modify-sphere
<sphere-in> - the sphere to modify
<radius> - the radius the output sphere should have
<sphere-out> - output - the output sphere
[-recenter] - recenter the sphere by means of the bounding box
This command may be useful if you have used -surface-resample to resample
a sphere, which can suffer from problems generally not present in
-surface-sphere-project-unproject. If the sphere should already be
centered around the origin, using -recenter may still shift it slightly
before changing the radius, which is likely to be undesireable.
If <sphere-in> is not close to spherical, or not centered around the
origin and -recenter is not used, a warning is printed.
>>> sms = SurfaceModifySphere()
>>> sms.inputs.in_surface = 'sub-01_hemi-L_sphere.surf.gii'
>>> sms.inputs.radius = 100
>>> sms.cmdline # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
'wb_command -surface-modify-sphere \
sub-01_hemi-L_sphere.surf.gii 100 sub-01_hemi-L_sphere.surf_mod.surf.gii'
"""

input_spec = SurfaceModifySphereInputSpec
output_spec = SurfaceModifySphereOutputSpec
_cmd = 'wb_command -surface-modify-sphere'


class SurfaceSphereProjectUnprojectInputSpec(TraitedSpec):
"""COPY REGISTRATION DEFORMATIONS TO DIFFERENT SPHERE.
Expand Down
17 changes: 15 additions & 2 deletions smriprep/workflows/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,11 @@ def init_sphere_reg_wf(
def init_msm_sulc_wf(*, sloppy: bool = False, name: str = 'msm_sulc_wf'):
"""Run MSMSulc registration to fsLR surfaces, per hemisphere."""
from ..interfaces.msm import MSM
from ..interfaces.workbench import SurfaceAffineRegression, SurfaceApplyAffine
from ..interfaces.workbench import (
SurfaceAffineRegression,
SurfaceApplyAffine,
SurfaceModifySphere,
)

workflow = Workflow(name=name)
inputnode = pe.Node(
Expand Down Expand Up @@ -616,6 +620,14 @@ def init_msm_sulc_wf(*, sloppy: bool = False, name: str = 'msm_sulc_wf'):
iterfield=['in_surface', 'in_affine'],
name='apply_surface_affine',
)

# Fix for oblongated sphere
modify_sphere = pe.MapNode(
SurfaceModifySphere(radius=100),
iterfield=['in_surface'],
name='modify_sphere',
)

# 2) Run MSMSulc
# ./msm_centos_v3 --conf=MSMSulcStrainFinalconf \
# --inmesh=${SUB}.${HEMI}.sphere_rot.native.surf.gii
Expand Down Expand Up @@ -662,8 +674,9 @@ def init_msm_sulc_wf(*, sloppy: bool = False, name: str = 'msm_sulc_wf'):
('sphere_reg_fsLR', 'target_surface')]),
(inputnode, apply_surface_affine, [('sphere', 'in_surface')]),
(regress_affine, apply_surface_affine, [('out_affine', 'in_affine')]),
(apply_surface_affine, modify_sphere, [('out_surface', 'in_surface')]),
(inputnode, msmsulc, [('sulc', 'in_data')]),
(apply_surface_affine, msmsulc, [('out_surface', 'in_mesh')]),
(modify_sphere, msmsulc, [('out_surface', 'in_mesh')]),
(msmsulc, outputnode, [('warped_mesh', 'sphere_reg_fsLR')]),
])
# fmt:on
Expand Down

0 comments on commit 949a13f

Please sign in to comment.