Exemple #1
0
  def ComputeMeanDistance(self, inputSourceModel, inputTargetModel, transform ):
    sourcePolyData = inputSourceModel.GetPolyData()
    targetPolyData = inputTargetModel.GetPolyData()

    cellId = vtk.mutable(0)
    subId = vtk.mutable(0)
    dist2 = vtk.mutable(0.0)
    locator = vtk.vtkCellLocator()
    locator.SetDataSet( targetPolyData )
    locator.SetNumberOfCellsPerBucket( 1 )
    locator.BuildLocator()

    totalDistance = 0.0

    sourcePoints = sourcePolyData.GetPoints()
    n = sourcePoints.GetNumberOfPoints()
    m = vtk.vtkMath()
    for sourcePointIndex in range(n):
      sourcePointPos = [0, 0, 0]
      sourcePoints.GetPoint( sourcePointIndex, sourcePointPos )
      transformedSourcePointPos = [0, 0, 0, 1]
      #transform.GetTransformToParent().TransformVector( sourcePointPos, transformedSourcePointPos )
      sourcePointPos.append(1)
      transform.GetTransformToParent().MultiplyPoint( sourcePointPos, transformedSourcePointPos )
      #transformedPoints.InsertNextPoint( transformedSourcePointPos )
      surfacePoint = [0, 0, 0]
      transformedSourcePointPos.pop()
      locator.FindClosestPoint( transformedSourcePointPos, surfacePoint, cellId, subId, dist2 )
      totalDistance = totalDistance + math.sqrt(dist2)

    return ( totalDistance / n )
Exemple #2
0
  def ComputeMeanDistance(self, inputFiducials, inputModel, transform):
    surfacePoints = vtk.vtkPoints()
    cellId = vtk.mutable(0)
    subId = vtk.mutable(0)
    dist2 = vtk.mutable(0.0)
    locator = vtk.vtkCellLocator()
    locator.SetDataSet(inputModel.GetPolyData())
    locator.SetNumberOfCellsPerBucket(1)
    locator.BuildLocator()
    totalDistance = 0.0

    n = inputFiducials.GetNumberOfFiducials()
    m = vtk.vtkMath()
    for fiducialIndex in range(0, n):
      originalPoint = [0, 0, 0]
      inputFiducials.GetNthFiducialPosition(fiducialIndex, originalPoint)
      transformedPoint = [0, 0, 0, 1]
      #transform.GetTransformToParent().TransformVector(originalPoint, transformedPoint)
      originalPoint.append(1)
      transform.GetTransformToParent().MultiplyPoint(originalPoint, transformedPoint)
      #transformedPoints.InsertNextPoint(transformedPoint)
      surfacePoint = [0, 0, 0]
      transformedPoint.pop()
      locator.FindClosestPoint(transformedPoint, surfacePoint, cellId, subId, dist2)
      totalDistance = totalDistance + math.sqrt(dist2)

    return (totalDistance / n)
  def ComputeMeanDistance(self, inputSourceModel, inputTargetModel, transform ):
    sourcePolyData = inputSourceModel.GetPolyData()
    targetPolyData = inputTargetModel.GetPolyData()

    cellId = vtk.mutable(0)
    subId = vtk.mutable(0)
    dist2 = vtk.mutable(0.0)
    locator = vtk.vtkCellLocator()
    locator.SetDataSet( targetPolyData )
    locator.SetNumberOfCellsPerBucket( 1 )
    locator.BuildLocator()
    
    totalDistance = 0.0

    sourcePoints = sourcePolyData.GetPoints()
    n = sourcePoints.GetNumberOfPoints()
    m = vtk.vtkMath()
    for sourcePointIndex in xrange(n):
      sourcePointPos = [0, 0, 0]
      sourcePoints.GetPoint( sourcePointIndex, sourcePointPos )
      transformedSourcePointPos = [0, 0, 0, 1]
      #transform.GetTransformToParent().TransformVector( sourcePointPos, transformedSourcePointPos )
      sourcePointPos.append(1)
      transform.GetTransformToParent().MultiplyPoint( sourcePointPos, transformedSourcePointPos )      
      #transformedPoints.InsertNextPoint( transformedSourcePointPos )
      surfacePoint = [0, 0, 0]
      transformedSourcePointPos.pop()
      locator.FindClosestPoint( transformedSourcePointPos, surfacePoint, cellId, subId, dist2 )
      totalDistance = totalDistance + math.sqrt(dist2)

    return ( totalDistance / n )
  def ComputeMeanDistance(self, inputFiducials, inputModel, transform ):
    surfacePoints = vtk.vtkPoints()
    cellId = vtk.mutable(0)
    subId = vtk.mutable(0)
    dist2 = vtk.mutable(0.0)
    locator = vtk.vtkCellLocator()
    locator.SetDataSet( inputModel.GetPolyData() )
    locator.SetNumberOfCellsPerBucket( 1 )
    locator.BuildLocator()
    totalDistance = 0.0

    n = inputFiducials.GetNumberOfFiducials()
    m = vtk.vtkMath()
    for fiducialIndex in range( 0, n ):
      originalPoint = [0, 0, 0]
      inputFiducials.GetNthFiducialPosition( fiducialIndex, originalPoint )
      transformedPoint = [0, 0, 0, 1]
      #transform.GetTransformToParent().TransformVector( originalPoint, transformedPoint )
      originalPoint.append(1)
      transform.GetTransformToParent().MultiplyPoint( originalPoint, transformedPoint )
      #transformedPoints.InsertNextPoint( transformedPoint )
      surfacePoint = [0, 0, 0]
      transformedPoint.pop()
      locator.FindClosestPoint( transformedPoint, surfacePoint, cellId, subId, dist2 )
      totalDistance = totalDistance + math.sqrt(dist2)

    return ( totalDistance / n )
 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 __init__(self, modelNode):
    self.modelNode = modelNode
    self.toolTipToTool = None
    self.toolToReference = None
    self.modelTransform = None
  
    self.transformedModel = slicer.util.getNode('Transformed Model')
    if not self.transformedModel:
      self.transformedModel = slicer.vtkMRMLModelNode()
      self.transformedModel.SetName('Transformed Model')
      self.transformedModel.SetAndObservePolyData(self.modelNode.GetPolyData())     
      modelDisplay = slicer.vtkMRMLModelDisplayNode()
      modelDisplay.SetSliceIntersectionVisibility(True)
      modelDisplay.SetColor(0,1,0)
      slicer.mrmlScene.AddNode(modelDisplay)      
      self.transformedModel.SetAndObserveDisplayNodeID(modelDisplay.GetID())      
      slicer.mrmlScene.AddNode(self.transformedModel)
      self.transformedModel.SetDisplayVisibility(False)     

    self.closestFiducial = slicer.util.getNode('CP')
    if not self.closestFiducial:
      self.closestFiducial = slicer.vtkMRMLMarkupsFiducialNode()  
      self.closestFiducial.SetName('CP')
      self.closestFiducial.AddFiducial(0, 0, 0)
      self.closestFiducial.SetNthFiducialLabel(0, '')
      slicer.mrmlScene.AddNode(self.closestFiducial)
      self.closestFiducial.SetDisplayVisibility(False)
      self.closestFiducial.GetDisplayNode().SetGlyphScale(3.0)
      self.closestFiducial.GetDisplayNode().SetGlyphType(4) # ThickCross2D
      self.closestFiducial.GetDisplayNode().SetSelectedColor(0,0,1)

    self.tipFiducial = slicer.util.getNode('Tip')
    if not self.tipFiducial:
      self.tipFiducial = slicer.vtkMRMLMarkupsFiducialNode()  
      self.tipFiducial.SetName('Tip')
      self.tipFiducial.AddFiducial(0, 0, 0)
      self.tipFiducial.SetNthFiducialLabel(0, '')
      slicer.mrmlScene.AddNode(self.tipFiducial)
      self.tipFiducial.SetDisplayVisibility(True)
      self.tipFiducial.GetDisplayNode().SetGlyphType(1) # Vertex2D
      self.tipFiducial.GetDisplayNode().SetTextScale(1.3)
      self.tipFiducial.GetDisplayNode().SetSelectedColor(1,1,1)
      
    self.line = slicer.util.getNode('Line')
    if not self.line:
      self.line = slicer.vtkMRMLModelNode()
      self.line.SetName('Line')
      linePolyData = vtk.vtkPolyData()
      self.line.SetAndObservePolyData(linePolyData)      
      modelDisplay = slicer.vtkMRMLModelDisplayNode()
      modelDisplay.SetSliceIntersectionVisibility(True)
      modelDisplay.SetColor(0,1,0)
      slicer.mrmlScene.AddNode(modelDisplay)      
      self.line.SetAndObserveDisplayNodeID(modelDisplay.GetID())      
      slicer.mrmlScene.AddNode(self.line)
      
    # VTK objects
    self.transformPolyDataFilter = vtk.vtkTransformPolyDataFilter()
    self.cellLocator = vtk.vtkCellLocator()
    
    # 3D View
    threeDWidget = slicer.app.layoutManager().threeDWidget(0)
    self.threeDView = threeDWidget.threeDView()
    
    self.callbackObserverTag = -1