@@ -34,10 +34,13 @@ class P2PDistanceInputSpec(BaseInterfaceInputSpec):
34
34
'"surface": edge distance is weighted by the '
35
35
'corresponding surface area' ))
36
36
37
+
37
38
class P2PDistanceOutputSpec (TraitedSpec ):
38
39
distance = traits .Float (desc = "computed distance" )
39
40
41
+
40
42
class P2PDistance (BaseInterface ):
43
+
41
44
"""Calculates a point-to-point (p2p) distance between two corresponding
42
45
VTK-readable meshes or contours.
43
46
@@ -57,10 +60,10 @@ class P2PDistance(BaseInterface):
57
60
output_spec = P2PDistanceOutputSpec
58
61
59
62
def _triangle_area (self , A , B , C ):
60
- ABxAC = euclidean (A ,B ) * euclidean (A ,C )
61
- prod = np .dot (np .array (B )- np .array (A ),np .array (C )- np .array (A ))
62
- angle = np .arccos ( prod / ABxAC )
63
- area = 0.5 * ABxAC * np .sin ( angle )
63
+ ABxAC = euclidean (A , B ) * euclidean (A , C )
64
+ prod = np .dot (np .array (B ) - np .array (A ), np .array (C ) - np .array (A ))
65
+ angle = np .arccos (prod / ABxAC )
66
+ area = 0.5 * ABxAC * np .sin (angle )
64
67
return area
65
68
66
69
def _run_interface (self , runtime ):
@@ -74,33 +77,33 @@ def _run_interface(self, runtime):
74
77
except ImportError :
75
78
raise ImportError ('Interface P2PDistance requires tvtk' )
76
79
77
- r1 = tvtk .PolyDataReader ( file_name = self .inputs .surface1 )
78
- r2 = tvtk .PolyDataReader ( file_name = self .inputs .surface2 )
80
+ r1 = tvtk .PolyDataReader (file_name = self .inputs .surface1 )
81
+ r2 = tvtk .PolyDataReader (file_name = self .inputs .surface2 )
79
82
vtk1 = r1 .output
80
83
vtk2 = r2 .output
81
84
r1 .update ()
82
85
r2 .update ()
83
- assert ( len (vtk1 .points ) == len (vtk2 .points ) )
86
+ assert (len (vtk1 .points ) == len (vtk2 .points ))
84
87
d = 0.0
85
88
totalWeight = 0.0
86
89
87
90
points = vtk1 .points
88
- faces = vtk1 .polys .to_array ().reshape (- 1 ,4 ).astype (int )[:,1 :]
91
+ faces = vtk1 .polys .to_array ().reshape (- 1 , 4 ).astype (int )[:, 1 :]
89
92
90
- for p1 ,p2 in zip ( points , vtk2 .points ):
93
+ for p1 , p2 in zip (points , vtk2 .points ):
91
94
weight = 1.0
92
95
if (self .inputs .weighting == 'surface' ):
93
- #compute surfaces, set in weight
96
+ # compute surfaces, set in weight
94
97
weight = 0.0
95
- point_faces = faces [ (faces [:,:] == 0 ).any (axis = 1 ) ]
98
+ point_faces = faces [(faces [:, :] == 0 ).any (axis = 1 )]
96
99
97
100
for idset in point_faces :
98
- p1 = points [ int (idset [0 ]) ]
99
- p2 = points [ int (idset [1 ]) ]
100
- p3 = points [ int (idset [2 ]) ]
101
+ p1 = points [int (idset [0 ])]
102
+ p2 = points [int (idset [1 ])]
103
+ p3 = points [int (idset [2 ])]
101
104
weight = weight + self ._triangle_area (p1 , p2 , p3 )
102
105
103
- d += weight * euclidean ( p1 , p2 )
106
+ d += weight * euclidean (p1 , p2 )
104
107
totalWeight = totalWeight + weight
105
108
106
109
self ._distance = d / totalWeight
@@ -110,4 +113,3 @@ def _list_outputs(self):
110
113
outputs = self ._outputs ().get ()
111
114
outputs ['distance' ] = self ._distance
112
115
return outputs
113
-
0 commit comments