Skip to content

Commit f2f96fe

Browse files
committed
Added PointsWarp interface to transformix
1 parent 183e354 commit f2f96fe

File tree

3 files changed

+86
-3
lines changed

3 files changed

+86
-3
lines changed

nipype/interfaces/elastix/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# @Author: oesteban - code@oscaresteban.es
77
# @Date: 2014-06-02 12:06:07
88
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-03 15:21:55
9+
# @Last Modified time: 2014-06-05 11:55:07
1010
"""Top-level namespace for elastix."""
1111

12-
from registration import Registration, ApplyWarp, AnalyzeWarp
12+
from registration import Registration, ApplyWarp, AnalyzeWarp, PointsWarp

nipype/interfaces/elastix/registration.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# @Author: oesteban - code@oscaresteban.es
77
# @Date: 2014-06-02 12:06:50
88
# @Last Modified by: oesteban
9-
# @Last Modified time: 2014-06-03 15:30:38
9+
# @Last Modified time: 2014-06-05 12:00:08
1010
"""The :py:mod:`nipype.interfaces.elastix` provides the interface to
1111
the elastix registration software.
1212
@@ -201,3 +201,42 @@ def _list_outputs(self):
201201
outputs['jacdet_map'] = op.join(out_dir,'spatialJacobian.nii.gz')
202202
outputs['jacmat_map'] = op.join(out_dir,'fullSpatialJacobian.nii.gz')
203203
return outputs
204+
205+
206+
class PointsWarpInputSpec(ElastixBaseInputSpec):
207+
transform_file = File(exists=True, mandatory=True, argstr='-tp %s',
208+
desc='transform-parameter file, only 1')
209+
points_file = File(exists=True, argstr='-def %s', mandatory=True,
210+
desc='input points (accepts .vtk triangular meshes).')
211+
212+
213+
214+
class PointsWarpOutputSpec(TraitedSpec):
215+
warped_file = File(desc='input points displaced in fixed image domain')
216+
217+
class PointsWarp(CommandLine):
218+
"""Use `transformix` to apply a transform on an input point set.
219+
The transform is specified in the transform-parameter file.
220+
221+
Example::
222+
223+
>>> from nipype.interfaces.elastix import PointsWarp
224+
>>> reg = PointsWarp()
225+
>>> reg.inputs.moving_image = 'surf.vtk'
226+
>>> reg.inputs.transform_file = 'TransformParameters.0.txt'
227+
>>> reg.cmdline
228+
'transformix -def surf.vtk -out ./ -tp TransformParameters.0.txt'
229+
"""
230+
231+
_cmd = 'transformix'
232+
input_spec = PointsWarpInputSpec
233+
output_spec = PointsWarpOutputSpec
234+
235+
def _list_outputs(self):
236+
outputs = self._outputs().get()
237+
out_dir = op.abspath(self.inputs.output_path)
238+
239+
fname, ext = op.splitext(op.basename(self.inputs.points_file))
240+
241+
outputs['warped_file'] = op.join(out_dir,'outputpoints%s' % ext)
242+
return outputs
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.elastix.registration import PointsWarp
4+
5+
def test_PointsWarp_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
environ=dict(nohash=True,
9+
usedefault=True,
10+
),
11+
ignore_exception=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
num_threads=dict(argstr='-threads %01d',
15+
),
16+
output_path=dict(argstr='-out %s',
17+
mandatory=True,
18+
usedefault=True,
19+
),
20+
points_file=dict(argstr='-def %s',
21+
mandatory=True,
22+
),
23+
terminal_output=dict(mandatory=True,
24+
nohash=True,
25+
),
26+
transform_file=dict(argstr='-tp %s',
27+
mandatory=True,
28+
),
29+
)
30+
inputs = PointsWarp.input_spec()
31+
32+
for key, metadata in input_map.items():
33+
for metakey, value in metadata.items():
34+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
35+
36+
def test_PointsWarp_outputs():
37+
output_map = dict(warped_file=dict(),
38+
)
39+
outputs = PointsWarp.output_spec()
40+
41+
for key, metadata in output_map.items():
42+
for metakey, value in metadata.items():
43+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
44+

0 commit comments

Comments
 (0)