@@ -33,9 +33,11 @@ class WarpPointsInputSpec(BaseInterfaceInputSpec):
3333 output_name = 'out_points' , keep_extension = True ,
3434 desc = 'the warped point set' )
3535
36+
3637class WarpPointsOutputSpec (TraitedSpec ):
3738 out_points = File (desc = 'the warped point set' )
3839
40+
3941class WarpPoints (BaseInterface ):
4042 """
4143 Applies a displacement field to a point set in vtk
@@ -69,6 +71,8 @@ def _gen_fname(self, in_file, suffix='generated', ext=None):
6971 return op .abspath ('%s_%s.%s' % (fname , suffix , ext ))
7072
7173 def _run_interface (self , runtime ):
74+ from traits .etsconfig .api import ETSConfig # This is necessary to
75+ ETSConfig .toolkit = 'null' # avoid 'unable to connect display' errors
7276 from tvtk .api import tvtk
7377 import nibabel as nb
7478 import numpy as np
@@ -82,26 +86,26 @@ def _run_interface(self, runtime):
8286
8387 affine = warp_dims [0 ].get_affine ()
8488 voxsize = warp_dims [0 ].get_header ().get_zooms ()
85- vox2ras = affine [0 :3 ,0 :3 ]
89+ vox2ras = affine [0 :3 , 0 :3 ]
8690 ras2vox = np .linalg .inv (vox2ras )
87- origin = affine [0 :3 ,3 ]
91+ origin = affine [0 :3 , 3 ]
8892 voxpoints = np .array ([np .dot (ras2vox ,
8993 (p - origin )) for p in points ])
9094
9195 warps = []
9296 for axis in warp_dims :
9397 wdata = axis .get_data ()
94- if np .any (wdata != 0 ):
98+ if np .any (wdata != 0 ):
9599
96100 warp = ndimage .map_coordinates (wdata ,
97- voxpoints .transpose ())
101+ voxpoints .transpose ())
98102 else :
99103 warp = np .zeros ((points .shape [0 ],))
100104
101105 warps .append (warp )
102106
103107 disps = np .squeeze (np .dstack (warps ))
104- newpoints = [p + d for p ,d in zip (points , disps )]
108+ newpoints = [p + d for p , d in zip (points , disps )]
105109 mesh .points = newpoints
106110 w = tvtk .PolyDataWriter (input = mesh )
107111 w .file_name = self ._gen_fname (self .inputs .points ,
@@ -117,6 +121,7 @@ def _list_outputs(self):
117121 ext = '.vtk' )
118122 return outputs
119123
124+
120125class P2PDistanceInputSpec (BaseInterfaceInputSpec ):
121126 surface1 = File (exists = True , mandatory = True ,
122127 desc = ("Reference surface (vtk format) to which compute "
@@ -126,8 +131,8 @@ class P2PDistanceInputSpec(BaseInterfaceInputSpec):
126131 "distance." ))
127132 weighting = traits .Enum ("none" , "surface" , usedefault = True ,
128133 desc = ('"none": no weighting is performed, '
129- '"surface": edge distance is weighted by the '
130- 'corresponding surface area' ))
134+ '"surface": edge distance is weighted by the'
135+ ' corresponding surface area' ))
131136
132137class P2PDistanceOutputSpec (TraitedSpec ):
133138 distance = traits .Float (desc = "computed distance" )
0 commit comments