@@ -40,15 +40,25 @@ def __init__(self, **inputs):
40
40
41
41
42
42
class WarpPointsInputSpec (BaseInterfaceInputSpec ):
43
- points = File (exists = True , mandatory = True ,
44
- desc = 'file containing the point set' )
45
- warp = File (exists = True , mandatory = True ,
46
- desc = 'dense deformation field to be applied' )
47
- interp = traits .Enum ('cubic' , 'nearest' , 'linear' , usedefault = True ,
48
- mandatory = True , desc = 'interpolation' )
49
- out_points = File (name_source = 'points' , name_template = '%s_warped' ,
50
- output_name = 'out_points' , keep_extension = True ,
51
- desc = 'the warped point set' )
43
+ points = File (
44
+ exists = True , mandatory = True , desc = 'file containing the point set' )
45
+ warp = File (
46
+ exists = True ,
47
+ mandatory = True ,
48
+ desc = 'dense deformation field to be applied' )
49
+ interp = traits .Enum (
50
+ 'cubic' ,
51
+ 'nearest' ,
52
+ 'linear' ,
53
+ usedefault = True ,
54
+ mandatory = True ,
55
+ desc = 'interpolation' )
56
+ out_points = File (
57
+ name_source = 'points' ,
58
+ name_template = '%s_warped' ,
59
+ output_name = 'out_points' ,
60
+ keep_extension = True ,
61
+ desc = 'the warped point set' )
52
62
53
63
54
64
class WarpPointsOutputSpec (TraitedSpec ):
@@ -111,10 +121,9 @@ def _run_interface(self, runtime):
111
121
wdata = axis .get_data ()
112
122
if np .any (wdata != 0 ):
113
123
114
- warp = ndimage .map_coordinates (wdata ,
115
- voxpoints .transpose ())
124
+ warp = ndimage .map_coordinates (wdata , voxpoints .transpose ())
116
125
else :
117
- warp = np .zeros ((points .shape [0 ],))
126
+ warp = np .zeros ((points .shape [0 ], ))
118
127
119
128
warps .append (warp )
120
129
@@ -130,39 +139,52 @@ def _run_interface(self, runtime):
130
139
131
140
def _list_outputs (self ):
132
141
outputs = self ._outputs ().get ()
133
- outputs ['out_points' ] = self ._gen_fname (self .inputs .points ,
134
- suffix = 'warped' ,
135
- ext = '.vtk' )
142
+ outputs ['out_points' ] = self ._gen_fname (
143
+ self .inputs .points , suffix = 'warped' , ext = '.vtk' )
136
144
return outputs
137
145
138
146
139
147
class ComputeMeshWarpInputSpec (BaseInterfaceInputSpec ):
140
- surface1 = File (exists = True , mandatory = True ,
141
- desc = ('Reference surface (vtk format) to which compute '
142
- 'distance.' ))
143
- surface2 = File (exists = True , mandatory = True ,
144
-
145
- desc = ('Test surface (vtk format) from which compute '
146
- 'distance.' ))
147
- metric = traits .Enum ('euclidean' , 'sqeuclidean' , usedefault = True ,
148
- desc = 'norm used to report distance' )
148
+ surface1 = File (
149
+ exists = True ,
150
+ mandatory = True ,
151
+ desc = ('Reference surface (vtk format) to which compute '
152
+ 'distance.' ))
153
+ surface2 = File (
154
+ exists = True ,
155
+ mandatory = True ,
156
+ desc = ('Test surface (vtk format) from which compute '
157
+ 'distance.' ))
158
+ metric = traits .Enum (
159
+ 'euclidean' ,
160
+ 'sqeuclidean' ,
161
+ usedefault = True ,
162
+ desc = 'norm used to report distance' )
149
163
weighting = traits .Enum (
150
- 'none' , 'area' , usedefault = True ,
164
+ 'none' ,
165
+ 'area' ,
166
+ usedefault = True ,
151
167
desc = ('"none": no weighting is performed, surface": edge distance is '
152
168
'weighted by the corresponding surface area' ))
153
- out_warp = File ('surfwarp.vtk' , usedefault = True ,
154
- desc = 'vtk file based on surface1 and warpings mapping it '
155
- 'to surface2' )
156
- out_file = File ('distance.npy' , usedefault = True ,
157
- desc = 'numpy file keeping computed distances and weights' )
169
+ out_warp = File (
170
+ 'surfwarp.vtk' ,
171
+ usedefault = True ,
172
+ desc = 'vtk file based on surface1 and warpings mapping it '
173
+ 'to surface2' )
174
+ out_file = File (
175
+ 'distance.npy' ,
176
+ usedefault = True ,
177
+ desc = 'numpy file keeping computed distances and weights' )
158
178
159
179
160
180
class ComputeMeshWarpOutputSpec (TraitedSpec ):
161
181
distance = traits .Float (desc = "computed distance" )
162
- out_warp = File (exists = True , desc = ('vtk file with the vertex-wise '
163
- 'mapping of surface1 to surface2' ))
164
- out_file = File (exists = True ,
165
- desc = 'numpy file keeping computed distances and weights' )
182
+ out_warp = File (
183
+ exists = True ,
184
+ desc = ('vtk file with the vertex-wise '
185
+ 'mapping of surface1 to surface2' ))
186
+ out_file = File (
187
+ exists = True , desc = 'numpy file keeping computed distances and weights' )
166
188
167
189
168
190
class ComputeMeshWarp (TVTKBaseInterface ):
@@ -206,7 +228,7 @@ def _run_interface(self, runtime):
206
228
vtk2 = VTKInfo .vtk_output (r2 )
207
229
r1 .update ()
208
230
r2 .update ()
209
- assert (len (vtk1 .points ) == len (vtk2 .points ))
231
+ assert (len (vtk1 .points ) == len (vtk2 .points ))
210
232
211
233
points1 = np .array (vtk1 .points )
212
234
points2 = np .array (vtk2 .points )
@@ -262,31 +284,45 @@ def _list_outputs(self):
262
284
263
285
264
286
class MeshWarpMathsInputSpec (BaseInterfaceInputSpec ):
265
- in_surf = File (exists = True , mandatory = True ,
266
- desc = ('Input surface in vtk format, with associated warp '
267
- 'field as point data (ie. from ComputeMeshWarp' ))
268
- float_trait = traits .Either (traits .Float (1.0 ), traits .Tuple (
269
- traits .Float (1.0 ), traits .Float (1.0 ), traits .Float (1.0 )))
287
+ in_surf = File (
288
+ exists = True ,
289
+ mandatory = True ,
290
+ desc = ('Input surface in vtk format, with associated warp '
291
+ 'field as point data (ie. from ComputeMeshWarp' ))
292
+ float_trait = traits .Either (
293
+ traits .Float (1.0 ),
294
+ traits .Tuple (traits .Float (1.0 ), traits .Float (1.0 ), traits .Float (1.0 )))
270
295
271
296
operator = traits .Either (
272
- float_trait , File (exists = True ), default = 1.0 , mandatory = True ,
297
+ float_trait ,
298
+ File (exists = True ),
299
+ default = 1.0 ,
300
+ mandatory = True ,
273
301
desc = 'image, float or tuple of floats to act as operator' )
274
302
275
- operation = traits .Enum ('sum' , 'sub' , 'mul' , 'div' , usedefault = True ,
276
- desc = 'operation to be performed' )
303
+ operation = traits .Enum (
304
+ 'sum' ,
305
+ 'sub' ,
306
+ 'mul' ,
307
+ 'div' ,
308
+ usedefault = True ,
309
+ desc = 'operation to be performed' )
277
310
278
- out_warp = File ('warp_maths.vtk' , usedefault = True ,
279
- desc = 'vtk file based on in_surf and warpings mapping it '
280
- 'to out_file' )
281
- out_file = File ('warped_surf.vtk' , usedefault = True ,
282
- desc = 'vtk with surface warped' )
311
+ out_warp = File (
312
+ 'warp_maths.vtk' ,
313
+ usedefault = True ,
314
+ desc = 'vtk file based on in_surf and warpings mapping it '
315
+ 'to out_file' )
316
+ out_file = File (
317
+ 'warped_surf.vtk' , usedefault = True , desc = 'vtk with surface warped' )
283
318
284
319
285
320
class MeshWarpMathsOutputSpec (TraitedSpec ):
286
- out_warp = File (exists = True , desc = ('vtk file with the vertex-wise '
287
- 'mapping of surface1 to surface2' ))
288
- out_file = File (exists = True ,
289
- desc = 'vtk with surface warped' )
321
+ out_warp = File (
322
+ exists = True ,
323
+ desc = ('vtk file with the vertex-wise '
324
+ 'mapping of surface1 to surface2' ))
325
+ out_file = File (exists = True , desc = 'vtk with surface warped' )
290
326
291
327
292
328
class MeshWarpMaths (TVTKBaseInterface ):
@@ -330,16 +366,15 @@ def _run_interface(self, runtime):
330
366
r2 = tvtk .PolyDataReader (file_name = self .inputs .surface2 )
331
367
vtk2 = VTKInfo .vtk_output (r2 )
332
368
r2 .update ()
333
- assert (len (points1 ) == len (vtk2 .points ))
369
+ assert (len (points1 ) == len (vtk2 .points ))
334
370
335
371
opfield = vtk2 .point_data .vectors
336
372
337
373
if opfield is None :
338
374
opfield = vtk2 .point_data .scalars
339
375
340
376
if opfield is None :
341
- raise RuntimeError (
342
- 'No operator values found in operator file' )
377
+ raise RuntimeError ('No operator values found in operator file' )
343
378
344
379
opfield = np .array (opfield )
345
380
0 commit comments