-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRotationTotal.py
51 lines (36 loc) · 1.3 KB
/
RotationTotal.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 RotationTotal( PerkEvaluatorMetric ):
# Static methods
@staticmethod
def GetMetricName():
return "Rotation Total"
@staticmethod
def GetMetricUnit():
return "deg"
# Instance methods
def __init__( self ):
PerkEvaluatorMetric.__init__( self )
self.rotationTotal = 0
self.matrixPrev = None
def AddTimestamp( self, time, matrix, point, role ):
if ( self.matrixPrev == None or self.matrixPrev == None ):
self.matrixPrev = vtk.vtkMatrix4x4()
self.matrixPrev.DeepCopy( matrix )
return
invertPrev = vtk.vtkMatrix4x4()
invertPrev.DeepCopy( self.matrixPrev )
invertPrev.Invert()
currChangeMatrix = vtk.vtkMatrix4x4()
vtk.vtkMatrix4x4().Multiply4x4( matrix, invertPrev, currChangeMatrix )
currChangeTransform = vtk.vtkTransform()
currChangeTransform.SetMatrix( currChangeMatrix )
angleChange = [ 0, 0, 0, 0 ]
currChangeTransform.GetOrientationWXYZ( angleChange )
currAngleChange = min( angleChange[ 0 ], 360 - angleChange[ 0 ] )
self.rotationTotal += currAngleChange
self.matrixPrev = vtk.vtkMatrix4x4()
self.matrixPrev.DeepCopy( matrix )
def GetMetric( self ):
return self.rotationTotal