-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeviationHausdorff.py
57 lines (41 loc) · 1.83 KB
/
DeviationHausdorff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import math
import vtk
from PythonMetricsCalculator import PerkEvaluatorMetric
class DeviationHausdorff( PerkEvaluatorMetric ):
# This metric computes the Hausdorff distance from the analyzed trajectory to a reference trajectory
# AddTimestamp works in O( n ) time, where n is the number of points in the reference trajectory (which is fixed)
# Static methods
@staticmethod
def GetMetricName():
return "Deviation from Trajectory - Hausdorff"
@staticmethod
def GetMetricUnit():
return "mm"
@staticmethod
def GetAnatomyRoles():
return { "Trajectory": "vtkMRMLSequenceNode" }
# Instance methods
def __init__( self ):
PerkEvaluatorMetric.__init__( self )
self.hausdorffDistance = 0
self.trajectory = None
def SetAnatomy( self, role, node ):
if ( role == "Trajectory" ):
self.trajectory = node
return True
return False
def AddTimestamp( self, time, matrix, point, role ):
if ( self.trajectory is None ):
return
# Check distance from each point on the reference trajectory
distances = [ 0 ] * self.trajectory.GetNumberOfDataNodes()
for j in range( self.trajectory.GetNumberOfDataNodes() ):
currTrajectoryNode = self.trajectory.GetNthDataNode( j )
currTrajectoryMatrix = vtk.vtkMatrix4x4()
currTrajectoryNode.GetMatrixTransformToWorld( currTrajectoryMatrix )
currTrajectoryPoint = [ currTrajectoryMatrix.GetElement( 0, 3 ), currTrajectoryMatrix.GetElement( 1, 3 ), currTrajectoryMatrix.GetElement( 2, 3 ) ]
distances[ j ] = vtk.vtkMath.Distance2BetweenPoints( point[ 0:3 ], currTrajectoryPoint )
minDistance = math.sqrt( min( distances ) )
self.hausdorffDistance = max( self.hausdorffDistance, minDistance )
def GetMetric( self ):
return self.hausdorffDistance