Skip to content

Commit 1a5d5c7

Browse files
committed
added regression tests
1 parent fe7584d commit 1a5d5c7

File tree

2 files changed

+52
-8
lines changed

2 files changed

+52
-8
lines changed

nipype/algorithms/mesh.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from ..interfaces.base import (BaseInterface, traits, TraitedSpec, File,
2222
BaseInterfaceInputSpec)
23+
from warnings import warn
2324
iflogger = logging.getLogger('interface')
2425

2526

@@ -87,7 +88,7 @@ def _triangle_area(self, A, B, C):
8788
def _run_interface(self, runtime):
8889
from numpy import linalg as nla
8990
try:
90-
from tvtk.api import tvtk, write_data
91+
from tvtk.api import tvtk
9192
except ImportError:
9293
raise ImportError('Interface ComputeMeshWarp requires tvtk')
9394

@@ -173,6 +174,6 @@ class P2PDistance(ComputeMeshWarp):
173174

174175
def __init__(self, **inputs):
175176
super(P2PDistance, self).__init__(**inputs)
176-
warnings.warn(("This interface has been deprecated since 1.0,"
177-
" please use nipype.algorithms.metrics.Distance"),
178-
DeprecationWarning)
177+
warn(('This interface has been deprecated since 1.0, please use '
178+
'ComputeMeshWarp'),
179+
DeprecationWarning)

nipype/algorithms/tests/test_mesh_ops.py

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,63 @@
1515

1616
from nipype.algorithms import mesh as m
1717

18+
notvtk = True
19+
try:
20+
from tvtk.api import tvtk
21+
notvtk = False
22+
except ImportError:
23+
pass
1824

19-
def test_distances():
25+
26+
def test_ident_distances():
2027
tempdir = mkdtemp()
28+
curdir = os.getcwd()
29+
os.chdir(tempdir)
2130
in_surf = example_data('surf01.vtk')
2231

23-
dist_ident = m.P2PDistance()
32+
dist_ident = m.ComputeMeshWarp()
2433
dist_ident.inputs.surface1 = in_surf
2534
dist_ident.inputs.surface2 = in_surf
2635
dist_ident.inputs.out_file = os.path.join(tempdir, 'distance.npy')
2736
res = dist_ident.run()
28-
yield assert_equal, res.outputs.distance, 0.0
37+
yield assert_equal, res.outputs.distance == 0.0
38+
39+
dist_ident.inputs.weighting = 'area'
40+
res = dist_ident.run()
41+
yield assert_equal, res.outputs.distance == 0.0
42+
43+
os.chdir(curdir)
44+
rmtree(tempdir)
45+
46+
47+
@skipif(notvtk)
48+
def test_trans_distances():
49+
tempdir = mkdtemp()
50+
in_surf = example_data('surf01.vtk')
51+
warped_surf = os.path.join(tempdir, 'warped.vtk')
52+
53+
curdir = os.getcwd()
54+
os.chdir(tempdir)
55+
inc = np.array([0.7, 0.3, -0.2])
56+
57+
r1 = tvtk.PolyDataReader(file_name=in_surf)
58+
vtk1 = r1.output
59+
r1.update()
60+
vtk1.points = np.array(vtk1.points) + inc
61+
62+
writer = tvtk.PolyDataWriter(file_name=warped_surf)
63+
writer.set_input_data(vtk1)
64+
writer.write()
2965

66+
dist = m.ComputeMeshWarp()
67+
dist.inputs.surface1 = in_surf
68+
dist.inputs.surface2 = warped_surf
69+
dist.inputs.out_file = os.path.join(tempdir, 'distance.npy')
70+
res = dist.run()
71+
yield assert_equal, np.isclose(res.outputs.distance, np.norm(inc))
3072
dist_ident.inputs.weighting = 'area'
3173
res = dist_ident.run()
32-
yield assert_equal, res.outputs.distance, 0.0
74+
yield assert_equal, np.isclose(res.outputs.distance, np.norm(inc))
3375

76+
os.chdir(curdir)
3477
rmtree(tempdir)

0 commit comments

Comments
 (0)