Esempio n. 1
0
 def calculateFiducialDistance(self, modelNode, fiducial):
   closestFiducial = slicer.util.getNode('CP')
   if not closestFiducial:
     closestFiducial = slicer.vtkMRMLMarkupsFiducialNode()  
     closestFiducial.SetName('CP')
     closestFiducial.AddFiducial(0, 0, 0)
     closestFiducial.SetNthFiducialLabel(0, 'CP')
     slicer.mrmlScene.AddNode(closestFiducial)
     closestFiducial.SetDisplayVisibility(False)
       
   line = slicer.util.getNode('Line')
   if not line:
     line = slicer.vtkMRMLModelNode()
     line.SetName('Line')
     linePolyData = vtk.vtkPolyData()
     line.SetAndObservePolyData(linePolyData)      
     modelDisplay = slicer.vtkMRMLModelDisplayNode()
     modelDisplay.SetSliceIntersectionVisibility(True)
     modelDisplay.SetColor(0,1,0)
     slicer.mrmlScene.AddNode(modelDisplay)      
     line.SetAndObserveDisplayNodeID(modelDisplay.GetID())      
     slicer.mrmlScene.AddNode(line)
     
   cellLocator = vtk.vtkCellLocator()
   cellLocator.SetDataSet(modelNode.GetPolyData())
   cellLocator.BuildLocator()
   
   if fiducial.GetNumberOfFiducials() > 0:          
     ras = [0.0, 0.0, 0.0]
     closestPoint = [0.0, 0.0, 0.0]
     
     fiducial.GetNthFiducialPosition(0, ras)
     distanceSquared = vtk.mutable(0.0) 
     subId = vtk.mutable(0) 
     cellId = vtk.mutable(0) 
     cell = vtk.vtkGenericCell()
     
     cellLocator.FindClosestPoint(ras, closestPoint, cell, cellId, subId, distanceSquared);
     distance = math.sqrt(distanceSquared)
           
     closestFiducial.SetNthFiducialPosition(0,  closestPoint[0], closestPoint[1], closestPoint[2])
     closestFiducial.SetDisplayVisibility(True)
     
     self.drawLineBetweenPoints(line, ras, closestPoint)
     
     self.set3dViewConernerAnnotation('Distance = ' + "%.2f" % distance + 'mm')
   else:
     logging.warning('No fiducials in list!')     
 def calculateDistance(self):
   point = [0.0,0.0,0.0]
   closestPoint = [0.0, 0.0, 0.0]
   
   m = vtk.vtkMatrix4x4()
   self.toolTipToTool.GetMatrixTransformToWorld(m)
   point[0] = m.GetElement(0, 3)
   point[1] = m.GetElement(1, 3)
   point[2] = m.GetElement(2, 3)        
   
   distanceSquared = vtk.mutable(0.0) 
   subId = vtk.mutable(0) 
   cellId = vtk.mutable(0) 
   cell = vtk.vtkGenericCell()
   
   self.cellLocator.FindClosestPoint(point, closestPoint, cell, cellId, subId, distanceSquared);
   distance = math.sqrt(distanceSquared)
         
   self.closestFiducial.SetNthFiducialPosition(0,  closestPoint[0], closestPoint[1], closestPoint[2])
   self.closestFiducial.SetDisplayVisibility(True)
   
   self.drawLineBetweenPoints(point, closestPoint)
   
   self.tipFiducial.SetNthFiducialLabel(0, '     %.0f' % distance + 'mm')