-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTraceTrajectory.py
55 lines (42 loc) · 1.63 KB
/
TraceTrajectory.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
import math
import vtk
from PythonMetricsCalculator import PerkEvaluatorMetric
class TraceTrajectory( PerkEvaluatorMetric ):
# Static methods
@staticmethod
def GetMetricName():
return "Trace Trajectory"
@staticmethod
def GetMetricUnit():
return ""
@staticmethod
def GetAnatomyRoles():
return { "OutputModel": "vtkMRMLModelNode" }
# Instance methods
def __init__( self ):
PerkEvaluatorMetric.__init__( self )
self.curvePoints = vtk.vtkPoints()
self.curveLines = vtk.vtkCellArray()
self.curvePolyData = vtk.vtkPolyData()
self.counter = 0
self.curvePolyData.SetPoints( self.curvePoints )
self.curvePolyData.SetLines( self.curveLines )
def SetAnatomy( self, role, node ):
if ( role == "OutputModel" ):
node.SetAndObservePolyData( self.curvePolyData )
if ( node.GetModelDisplayNode() is None ):
node.CreateDefaultDisplayNodes()
modelDisplayNode = node.GetModelDisplayNode()
return True
return False
def AddTimestamp( self, time, matrix, point, role ):
# Some initialization for the first point
if ( self.curveLines.GetNumberOfCells() == 0 ):
self.curvePoints.InsertNextPoint( point[ 0 ], point[ 1 ], point[ 2 ] )
self.curveLines.InsertNextCell( 1 )
self.curveLines.InsertCellPoint( 0 )
self.curvePoints.InsertPoint( self.counter + 1, point[ 0 ], point[ 1 ], point[ 2 ] )
self.curveLines.InsertNextCell( 2 ) # Because there are two points in the cell
self.curveLines.InsertCellPoint( self.counter )
self.curveLines.InsertCellPoint( self.counter + 1 )
self.counter += 1