Skip to content

Commit e94c744

Browse files
committed
Add surface warping wf
1 parent 2555087 commit e94c744

File tree

1 file changed

+84
-3
lines changed

1 file changed

+84
-3
lines changed

xcp_d/workflows/anatomical/plotting.py

Lines changed: 84 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
from nipype import Function, logging
66
from nipype.interfaces import utility as niu
7+
from nipype.interfaces.ants import ApplyTransformsToPoints
78
from nipype.pipeline import engine as pe
89
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
10+
from niworkflows.interfaces.surf import CSVToGifti, GiftiToCSV
911

1012
from xcp_d import config
1113
from xcp_d.data import load as load_data
@@ -102,12 +104,13 @@ def init_brainsprite_figures_wf(
102104
if apply_transform:
103105
for surface in ['lh_wm_surf', 'rh_wm_surf', 'lh_pial_surf', 'rh_pial_surf']:
104106
# Warp the surfaces to the template space
107+
warp_to_template_wf = init_itk_warp_gifti_surface_wf(name=f'{surface}_warp_wf')
105108
workflow.connect([
106109
(inputnode, warp_to_template_wf, [
107-
(surface, 'inputnode.in_file'),
108-
('anat_to_template_xfm', 'transform'),
110+
(surface, 'inputnode.native_surf_gii'),
111+
('anat_to_template_xfm', 'inputnode.itk_warp_file'),
109112
]),
110-
(warp_to_template_wf, surface_buffer, [('outputnode.out_file', surface)]),
113+
(warp_to_template_wf, surface_buffer, [('outputnode.warped_surf_gii', surface)]),
111114
]) # fmt:skip
112115

113116
else:
@@ -296,6 +299,84 @@ def init_brainsprite_figures_wf(
296299
return workflow
297300

298301

302+
@fill_doc
303+
def init_itk_warp_gifti_surface_wf(name='itk_warp_gifti_surface_wf'):
304+
"""Apply an arbitrary ITK transform to a Gifti file.
305+
306+
Workflow Graph
307+
.. workflow::
308+
:graph2use: orig
309+
:simple_form: yes
310+
311+
from xcp_d.tests.tests import mock_config
312+
from xcp_d import config
313+
from xcp_d.workflows.anatomical.plotting import init_itk_warp_gifti_surface_wf
314+
315+
with mock_config():
316+
wf = init_itk_warp_gifti_surface_wf()
317+
Parameters
318+
----------
319+
%(name)s
320+
321+
Inputs
322+
------
323+
native_surf_gii
324+
T1w image, after warping to standard space.
325+
itk_warp_file
326+
T2w image, after warping to standard space.
327+
328+
Outputs
329+
-------
330+
warped_surf_gii
331+
Gifti file where the transform in ``itk_warp_file`` has been applied
332+
to the vertices in ``native_surf_gii``.
333+
334+
"""
335+
workflow = Workflow(name=name)
336+
337+
inputnode = pe.Node(
338+
niu.IdentityInterface(
339+
fields=[
340+
'native_surf_gii',
341+
'itk_warp_file',
342+
],
343+
),
344+
name='inputnode',
345+
)
346+
outputnode = pe.Node(
347+
niu.IdentityInterface(
348+
fields=[
349+
'warped_surf_gii',
350+
],
351+
),
352+
name='inputnode',
353+
)
354+
355+
convert_to_csv = pe.Node(
356+
GiftiToCSV(itk_lps=True), name='convert_to_csv'
357+
)
358+
359+
transform_vertices = pe.Node(
360+
ApplyTransformsToPoints(dimension=3),
361+
name='transform_vertices',
362+
)
363+
364+
csv_to_gifti = pe.Node(CSVToGifti(itk_lps=True), name='csv_to_gifti')
365+
366+
workflow.connect(
367+
[
368+
(inputnode, convert_to_csv, [('native_surf_gii', 'in_file')]),
369+
(inputnode, transform_vertices, [('itk_warp_file', 'transforms')]),
370+
(inputnode, csv_to_gifti, [('native_surf_gii', 'gii_file')]),
371+
(convert_to_csv, transform_vertices, [('out_file', 'input_file')]),
372+
(transform_vertices, csv_to_gifti, [('output_file', 'in_file')]),
373+
(csv_to_gifti, outputnode, [('out_file', 'warped_surf_gii')]),
374+
]
375+
)
376+
377+
return workflow
378+
379+
299380
@fill_doc
300381
def init_execsummary_anatomical_plots_wf(
301382
t1w_available,

0 commit comments

Comments
 (0)