-
Notifications
You must be signed in to change notification settings - Fork 1
/
DepthPerception.py
51 lines (37 loc) · 1.47 KB
/
DepthPerception.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
import math
import vtk
from PythonMetricsCalculator import PerkEvaluatorMetric
class DepthPerception( PerkEvaluatorMetric ):
# Static methods
@staticmethod
def GetMetricName():
return "Depth Perception"
@staticmethod
def GetMetricUnit():
return "mm"
@staticmethod
def GetTransformRoles():
return [ "Needle" ]
# Instance methods
def __init__( self ):
PerkEvaluatorMetric.__init__( self )
self.depthPerception = 0
self.pointPrev = None
def AddTimestamp( self, time, matrix, point, role ):
if ( self.pointPrev == None ):
self.pointPrev = point[:]
# Find the prev to current vector
prevToCurrentVector = [ 0, 0, 0 ]
vtk.vtkMath().Subtract( point[0:3], self.pointPrev[0:3], prevToCurrentVector )
prevToCurrentVector = [ prevToCurrentVector[ 0 ], prevToCurrentVector[ 1 ], prevToCurrentVector[ 2 ] ]
# Compute the direction vector of the needle in RAS, using the needle orientation protocol
needleOrientation = self.NeedleOrientation[:]
needleOrientation.append( 0 )
needleVector_RAS = [ 0, 0, 0, 0 ]
matrix.MultiplyPoint( needleOrientation, needleVector_RAS )
# Find the movement in the needle direction
needleAxisMovement = vtk.vtkMath().Dot( prevToCurrentVector, needleVector_RAS[ 0:3 ] )
self.depthPerception += math.fabs( needleAxisMovement )
self.pointPrev = point[:]
def GetMetric( self ):
return self.depthPerception