Skip to content

Commit 79d6d27

Browse files
committed
Merge remote-tracking branch 'origin/enh/MeshAlgorithm' into enh/MeshAlgorithm
2 parents 139ffac + 95180e9 commit 79d6d27

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

nipype/algorithms/mesh.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class P2PDistance(BaseInterface):
6363
input_spec = P2PDistanceInputSpec
6464
output_spec = P2PDistanceOutputSpec
6565

66+
def _triangle_area(A, B, C):
67+
ABxAC = euclidean(A,B) * euclidean(A,C)
68+
prod = np.dot(np.array(B)-np.array(A),np.array(C)-np.array(A))
69+
angle = np.arccos( prod / ABxAC )
70+
area = 0.5 * ABxAC * np.sin( angle )
71+
return area
72+
6673
def _run_interface(self, runtime):
6774
r1 = tvtk.PolyDataReader( file_name=self.inputs.surface1 )
6875
r2 = tvtk.PolyDataReader( file_name=self.inputs.surface2 )
@@ -73,16 +80,27 @@ def _run_interface(self, runtime):
7380
assert( len(vtk1.points) == len(vtk2.points) )
7481
d = 0.0
7582
totalWeight = 0.0
76-
for p1,p2 in zip( vtk1.points, vtk2.points ):
83+
84+
points = vtk1.points
85+
faces = vtk1.polys.to_array().reshape(-1,4).astype(int)[:,1:]
86+
87+
for p1,p2 in zip( points, vtk2.points ):
7788
weight = 1.0
7889
if (self.inputs.weighting == 'surface'):
7990
#compute surfaces, set in weight
80-
print "Error, not implemented"
91+
weight = 0.0
92+
point_faces = faces[ (faces[:,:]==0).any(axis=1) ]
93+
94+
for idset in point_faces:
95+
p1 = points[ int(idset[0]) ]
96+
p2 = points[ int(idset[1]) ]
97+
p3 = points[ int(idset[2]) ]
98+
weight = weight + self._triangle_area(p1, p2, p3)
8199

82-
d+= euclidean( p1, p2 )
100+
d+= weight*euclidean( p1, p2 )
83101
totalWeight = totalWeight + weight
84102

85-
self._distance = d / weight
103+
self._distance = d / totalWeight
86104
return runtime
87105

88106
def _list_outputs(self):

0 commit comments

Comments
 (0)