@@ -33,9 +33,11 @@ class WarpPointsInputSpec(BaseInterfaceInputSpec):
33
33
output_name = 'out_points' , keep_extension = True ,
34
34
desc = 'the warped point set' )
35
35
36
+
36
37
class WarpPointsOutputSpec (TraitedSpec ):
37
38
out_points = File (desc = 'the warped point set' )
38
39
40
+
39
41
class WarpPoints (BaseInterface ):
40
42
"""
41
43
Applies a displacement field to a point set in vtk
@@ -69,6 +71,8 @@ def _gen_fname(self, in_file, suffix='generated', ext=None):
69
71
return op .abspath ('%s_%s.%s' % (fname , suffix , ext ))
70
72
71
73
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
72
76
from tvtk .api import tvtk
73
77
import nibabel as nb
74
78
import numpy as np
@@ -82,26 +86,26 @@ def _run_interface(self, runtime):
82
86
83
87
affine = warp_dims [0 ].get_affine ()
84
88
voxsize = warp_dims [0 ].get_header ().get_zooms ()
85
- vox2ras = affine [0 :3 ,0 :3 ]
89
+ vox2ras = affine [0 :3 , 0 :3 ]
86
90
ras2vox = np .linalg .inv (vox2ras )
87
- origin = affine [0 :3 ,3 ]
91
+ origin = affine [0 :3 , 3 ]
88
92
voxpoints = np .array ([np .dot (ras2vox ,
89
93
(p - origin )) for p in points ])
90
94
91
95
warps = []
92
96
for axis in warp_dims :
93
97
wdata = axis .get_data ()
94
- if np .any (wdata != 0 ):
98
+ if np .any (wdata != 0 ):
95
99
96
100
warp = ndimage .map_coordinates (wdata ,
97
- voxpoints .transpose ())
101
+ voxpoints .transpose ())
98
102
else :
99
103
warp = np .zeros ((points .shape [0 ],))
100
104
101
105
warps .append (warp )
102
106
103
107
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 )]
105
109
mesh .points = newpoints
106
110
w = tvtk .PolyDataWriter (input = mesh )
107
111
w .file_name = self ._gen_fname (self .inputs .points ,
@@ -117,6 +121,7 @@ def _list_outputs(self):
117
121
ext = '.vtk' )
118
122
return outputs
119
123
124
+
120
125
class P2PDistanceInputSpec (BaseInterfaceInputSpec ):
121
126
surface1 = File (exists = True , mandatory = True ,
122
127
desc = ("Reference surface (vtk format) to which compute "
@@ -126,8 +131,8 @@ class P2PDistanceInputSpec(BaseInterfaceInputSpec):
126
131
"distance." ))
127
132
weighting = traits .Enum ("none" , "surface" , usedefault = True ,
128
133
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' ))
131
136
132
137
class P2PDistanceOutputSpec (TraitedSpec ):
133
138
distance = traits .Float (desc = "computed distance" )
0 commit comments