|
15 | 15 |
|
16 | 16 | from nipype.algorithms import mesh as m
|
17 | 17 |
|
| 18 | +notvtk = True |
| 19 | +try: |
| 20 | + from tvtk.api import tvtk |
| 21 | + notvtk = False |
| 22 | +except ImportError: |
| 23 | + pass |
18 | 24 |
|
19 |
| -def test_distances(): |
| 25 | + |
| 26 | +def test_ident_distances(): |
20 | 27 | tempdir = mkdtemp()
|
| 28 | + curdir = os.getcwd() |
| 29 | + os.chdir(tempdir) |
21 | 30 | in_surf = example_data('surf01.vtk')
|
22 | 31 |
|
23 |
| - dist_ident = m.P2PDistance() |
| 32 | + dist_ident = m.ComputeMeshWarp() |
24 | 33 | dist_ident.inputs.surface1 = in_surf
|
25 | 34 | dist_ident.inputs.surface2 = in_surf
|
26 | 35 | dist_ident.inputs.out_file = os.path.join(tempdir, 'distance.npy')
|
27 | 36 | 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() |
29 | 65 |
|
| 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)) |
30 | 72 | dist_ident.inputs.weighting = 'area'
|
31 | 73 | 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)) |
33 | 75 |
|
| 76 | + os.chdir(curdir) |
34 | 77 | rmtree(tempdir)
|
0 commit comments