1
1
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
2
# vi: set ft=python sts=4 ts=4 sw=4 et:
3
- '''
3
+ """
4
4
Miscellaneous algorithms for 2D contours and 3D triangularized meshes handling
5
5
6
- Change directory to provide relative paths for doctests
7
- >>> import os
8
- >>> filepath = os.path.dirname(os.path.realpath( __file__ ))
9
- >>> datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
10
- >>> os.chdir(datadir)
6
+ .. testsetup::
7
+ # Change directory to provide relative paths for doctests
8
+ import os
9
+ filepath = os.path.dirname(os.path.realpath( __file__ ))
10
+ datadir = os.path.realpath(os.path.join(filepath, '../testing/data'))
11
+ os.chdir(datadir)
11
12
12
- '''
13
+ """
13
14
from __future__ import division
14
15
from builtins import zip
15
16
44
45
45
46
46
47
class TVTKBaseInterface (BaseInterface ):
48
+
47
49
""" A base class for interfaces using VTK """
48
50
49
51
_redirect_x = True
@@ -66,9 +68,9 @@ def __init__(self, **inputs):
66
68
67
69
class WarpPointsInputSpec (BaseInterfaceInputSpec ):
68
70
points = File (exists = True , mandatory = True ,
69
- desc = ( 'file containing the point set' ) )
71
+ desc = 'file containing the point set' )
70
72
warp = File (exists = True , mandatory = True ,
71
- desc = ( 'dense deformation field to be applied' ) )
73
+ desc = 'dense deformation field to be applied' )
72
74
interp = traits .Enum ('cubic' , 'nearest' , 'linear' , usedefault = True ,
73
75
mandatory = True , desc = 'interpolation' )
74
76
out_points = File (name_source = 'points' , name_template = '%s_warped' ,
@@ -92,11 +94,19 @@ class WarpPoints(TVTKBaseInterface):
92
94
Example
93
95
-------
94
96
97
+ >>> from nipype.algorithms.mesh import have_tvtk
95
98
>>> from nipype.algorithms.mesh import WarpPoints
96
- >>> wp = WarpPoints()
97
- >>> wp.inputs.points = 'surf1.vtk'
98
- >>> wp.inputs.warp = 'warpfield.nii'
99
- >>> res = wp.run() # doctest: +SKIP
99
+ >>> if not have_tvtk:
100
+ ... wp = WarpPoints()
101
+ Traceback (most recent call last):
102
+ ...
103
+ ImportError: This interface requires tvtk to run.
104
+ >>> else:
105
+ ... wp = WarpPoints()
106
+ ... wp.inputs.points = 'surf1.vtk'
107
+ ... wp.inputs.warp = 'warpfield.nii'
108
+ ... res = wp.run() # doctest: +SKIP
109
+
100
110
"""
101
111
input_spec = WarpPointsInputSpec
102
112
output_spec = WarpPointsOutputSpec
@@ -179,7 +189,7 @@ class ComputeMeshWarpInputSpec(BaseInterfaceInputSpec):
179
189
desc = ('Test surface (vtk format) from which compute '
180
190
'distance.' ))
181
191
metric = traits .Enum ('euclidean' , 'sqeuclidean' , usedefault = True ,
182
- desc = ( 'norm used to report distance' ) )
192
+ desc = 'norm used to report distance' )
183
193
weighting = traits .Enum (
184
194
'none' , 'area' , usedefault = True ,
185
195
desc = ('"none": no weighting is performed, surface": edge distance is '
@@ -256,9 +266,9 @@ def _run_interface(self, runtime):
256
266
errvector = np .apply_along_axis (nla .norm , 1 , diff )
257
267
258
268
if self .inputs .metric == 'sqeuclidean' :
259
- errvector = errvector ** 2
269
+ errvector **= 2
260
270
261
- if ( self .inputs .weighting == 'area' ) :
271
+ if self .inputs .weighting == 'area' :
262
272
faces = vtk1 .polys .to_array ().reshape (- 1 , 4 ).astype (int )[:, 1 :]
263
273
264
274
for i , p1 in enumerate (points2 ):
@@ -285,9 +295,9 @@ def _run_interface(self, runtime):
285
295
file_name = op .abspath (self .inputs .out_warp ))
286
296
287
297
if self ._vtk_major <= 5 :
288
- writer .input = mesh
298
+ writer .input = out_mesh
289
299
else :
290
- writer .set_input_data_object (mesh )
300
+ writer .set_input_data_object (out_mesh )
291
301
292
302
writer .write ()
293
303
@@ -311,10 +321,10 @@ class MeshWarpMathsInputSpec(BaseInterfaceInputSpec):
311
321
312
322
operator = traits .Either (
313
323
float_trait , File (exists = True ), default = 1.0 , mandatory = True ,
314
- desc = ( 'image, float or tuple of floats to act as operator' ) )
324
+ desc = 'image, float or tuple of floats to act as operator' )
315
325
316
326
operation = traits .Enum ('sum' , 'sub' , 'mul' , 'div' , usedefault = True ,
317
- desc = ( 'operation to be performed' ) )
327
+ desc = 'operation to be performed' )
318
328
319
329
out_warp = File ('warp_maths.vtk' , usedefault = True ,
320
330
desc = 'vtk file based on in_surf and warpings mapping it '
@@ -364,7 +374,7 @@ def _run_interface(self, runtime):
364
374
points1 = np .array (vtk1 .points )
365
375
366
376
if vtk1 .point_data .vectors is None :
367
- raise RuntimeError (( 'No warping field was found in in_surf' ) )
377
+ raise RuntimeError ('No warping field was found in in_surf' )
368
378
369
379
operator = self .inputs .operator
370
380
opfield = np .ones_like (points1 )
0 commit comments