|
4 | 4 |
|
5 | 5 | from nipype import Function, logging |
6 | 6 | from nipype.interfaces import utility as niu |
| 7 | +from nipype.interfaces.ants import ApplyTransformsToPoints |
7 | 8 | from nipype.pipeline import engine as pe |
8 | 9 | from niworkflows.engine.workflows import LiterateWorkflow as Workflow |
| 10 | +from niworkflows.interfaces.surf import CSVToGifti, GiftiToCSV |
9 | 11 |
|
10 | 12 | from xcp_d import config |
11 | 13 | from xcp_d.data import load as load_data |
@@ -102,12 +104,13 @@ def init_brainsprite_figures_wf( |
102 | 104 | if apply_transform: |
103 | 105 | for surface in ['lh_wm_surf', 'rh_wm_surf', 'lh_pial_surf', 'rh_pial_surf']: |
104 | 106 | # Warp the surfaces to the template space |
| 107 | + warp_to_template_wf = init_itk_warp_gifti_surface_wf(name=f'{surface}_warp_wf') |
105 | 108 | workflow.connect([ |
106 | 109 | (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'), |
109 | 112 | ]), |
110 | | - (warp_to_template_wf, surface_buffer, [('outputnode.out_file', surface)]), |
| 113 | + (warp_to_template_wf, surface_buffer, [('outputnode.warped_surf_gii', surface)]), |
111 | 114 | ]) # fmt:skip |
112 | 115 |
|
113 | 116 | else: |
@@ -296,6 +299,84 @@ def init_brainsprite_figures_wf( |
296 | 299 | return workflow |
297 | 300 |
|
298 | 301 |
|
| 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 | + |
299 | 380 | @fill_doc |
300 | 381 | def init_execsummary_anatomical_plots_wf( |
301 | 382 | t1w_available, |
|
0 commit comments