Beispiel #1
0
  def createNeedleModelNode(self, name):

    locatorModel = self.scene.CreateNodeByClass('vtkMRMLModelNode')
    
    # Cylinder represents the locator stick
    cylinder = vtk.vtkCylinderSource()
    cylinder.SetRadius(1.5)
    cylinder.SetHeight(100)
    cylinder.SetCenter(0, 0, 0)
    cylinder.Update()

    # Rotate cylinder
    tfilter = vtk.vtkTransformPolyDataFilter()
    trans =   vtk.vtkTransform()
    trans.RotateX(90.0)
    trans.Translate(0.0, -50.0, 0.0)
    trans.Update()
    if vtk.VTK_MAJOR_VERSION <= 5:
      tfilter.SetInput(cylinder.GetOutput())
    else:
      tfilter.SetInputConnection(cylinder.GetOutputPort())
    tfilter.SetTransform(trans)
    tfilter.Update()

    # Sphere represents the locator tip
    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(3.0)
    sphere.SetCenter(0, 0, 0)
    sphere.Update()

    apd = vtk.vtkAppendPolyData()

    if vtk.VTK_MAJOR_VERSION <= 5:
      apd.AddInput(sphere.GetOutput())
      apd.AddInput(tfilter.GetOutput())
    else:
      apd.AddInputConnection(sphere.GetOutputPort())
      apd.AddInputConnection(tfilter.GetOutputPort())
    apd.Update()
    
    locatorModel.SetAndObservePolyData(apd.GetOutput());

    self.scene.AddNode(locatorModel)
    locatorModel.SetScene(self.scene);
    locatorModel.SetName(name)
    
    locatorDisp = locatorModel.GetDisplayNodeID()
    if locatorDisp == None:
      locatorDisp = self.scene.CreateNodeByClass('vtkMRMLModelDisplayNode')
      self.scene.AddNode(locatorDisp)
      locatorDisp.SetScene(self.scene)
      locatorModel.SetAndObserveDisplayNodeID(locatorDisp.GetID());
      
    color = [0, 0, 0]
    color[0] = 0.5
    color[1] = 0.5
    color[2] = 1.0
    locatorDisp.SetColor(color)
    
    return locatorModel.GetID()
Beispiel #2
0
  def test_FiducialsToModelRegistration1(self):
    """
    Test FiducialsToModelRegistrationLogic.

    This test scenario:
    - Creates and adds a cylinder model to the scene
    - Creates 3 markup fiducials (points)
    - Runs module processing logic to register points against the cylinder
    """
    # Create and add cylinder to the scene.
    s = vtk.vtkCylinderSource()
    s.SetHeight(100)
    s.SetRadius(50)
    s.SetResolution(50)
    s.Update()
    inputModel = slicer.modules.models.logic().AddModel(s.GetOutput())

    # Create and add markup fiducials to the scene.
    slicer.modules.markups.logic().AddFiducial(40, -20, 33)
    slicer.modules.markups.logic().AddFiducial(40, -25, 37)
    slicer.modules.markups.logic().AddFiducial(52, -28, 42)

    # Create output transform node
    transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode")

    # Run module logic with default settings
    logic = slicer.modules.fiducialstomodelregistration.widgetRepresentation().self().logic

    inputFiducials = slicer.util.getNode("F")
    success = logic.run(inputFiducials, inputModel, transformNode)

    self.assertEqual(success, True)

    slicer.util.delayDisplay('Test passed')
  def updateModel(self):

    if self.AutomaticUpdate == False:
      return

    if not self.ModelNode:
      return

    if self.ModelNode.GetDisplayNodeID() == None:
      modelDisplayNode = slicer.vtkMRMLModelDisplayNode()
      modelDisplayNode.SetColor(self.ModelColor)
      slicer.mrmlScene.AddNode(modelDisplayNode)
      self.ModelNode.SetAndObserveDisplayNodeID(modelDisplayNode.GetID())
        
    displayNodeID = self.ModelNode.GetDisplayNodeID()
    modelDisplayNode = slicer.mrmlScene.GetNodeByID(displayNodeID)

    if modelDisplayNode:
      if self.SliceIntersection == True:
        modelDisplayNode.SliceIntersectionVisibilityOn()
      else:
        modelDisplayNode.SliceIntersectionVisibilityOff()

      modelDisplayNode.SetOpacity(0.5)
      
    if self.CylinderSource == None:  
      self.CylinderSource = vtk.vtkCylinderSource()
      self.CylinderSource.SetResolution(60)

    self.CylinderSource.SetRadius(self.Diameter/2.0)
    self.CylinderSource.SetHeight(self.Length)
    self.CylinderSource.SetCenter(self.Offset)
    self.CylinderSource.Update()

    ## Scale sphere to make ellipsoid
    #scale = vtk.vtkTransform()
    #scale.Scale(self.MinorAxis, self.MinorAxis, self.MajorAxis)
    #scaleFilter = vtk.vtkTransformPolyDataFilter()
    #scaleFilter.SetInputConnection(self.CylinderSource.GetOutputPort())
    #scaleFilter.SetTransform(scale)
    #scaleFilter.Update();
    
    # Transform
    #transform = vtk.vtkTransform()
    #self.computeTransform(pTip, pTail, self.TipOffset, transform)
    #transformFilter = vtk.vtkTransformPolyDataFilter()
    #transformFilter.SetInputConnection(scaleFilter.GetOutputPort())
    #transformFilter.SetInputConnection(self.CylinderSource.GetOutputPort())
    #transformFilter.SetTransform(transform)
    #transformFilter.Update();
    
    #self.ModelNode.SetAndObservePolyData(transformFilter.GetOutput())
    self.ModelNode.SetAndObservePolyData(self.CylinderSource.GetOutput())
    self.ModelNode.Modified()
    
    if self.ModelNode.GetScene() == None:
      slicer.mrmlScene.AddNode(self.ModelNode)
Beispiel #4
0
 def generateCylinderPolyData(self, x, y):
     cylinderHeightMm = 80
     cylinderRadiusMm = 1
     cylinderSource = vtk.vtkCylinderSource()
     cylinderSource.SetHeight(cylinderHeightMm)
     cylinderSource.SetRadius(cylinderRadiusMm)
     renderDepthMm = -cylinderHeightMm  # negative because in graphics, negative is depth, positive goes toward the user
     transform = vtk.vtkTransform()
     transform.Translate(x, y, renderDepthMm)
     transform.RotateX(90)  # rotate so that the cylinder follows the z axis
     transformFilter = vtk.vtkTransformFilter()
     transformFilter.SetTransform(transform)
     transformFilter.SetInputConnection(cylinderSource.GetOutputPort(0))
     transformFilter.Update()
     polyData = transformFilter.GetOutput()
     return polyData
 def generateCylinderPolyData(self,x,y):
   cylinderHeightMm = 80
   cylinderRadiusMm = 1
   cylinderSource = vtk.vtkCylinderSource()
   cylinderSource.SetHeight(cylinderHeightMm)
   cylinderSource.SetRadius(cylinderRadiusMm)
   renderDepthMm = -cylinderHeightMm # negative because in graphics, negative is depth, positive goes toward the user
   transform = vtk.vtkTransform()
   transform.Translate(x,y,renderDepthMm)
   transform.RotateX(90) # rotate so that the cylinder follows the z axis
   transformFilter = vtk.vtkTransformFilter()
   transformFilter.SetTransform(transform)
   transformFilter.SetInputConnection(cylinderSource.GetOutputPort(0))
   transformFilter.Update()
   polyData = transformFilter.GetOutput()
   return polyData
Beispiel #6
0
        def __init__(self, markupID, radius, length, position):
            # We use the markupID to check whether this tool's markup has
            # been removed in the onMarkupRemoved event
            self.markupID = markupID

            # Create a vtkCylinderSource for rendering the tool
            self.toolSrc = vtk.vtkCylinderSource()
            self.toolSrc.SetRadius(radius)
            self.toolSrc.SetHeight(length)

            # Create tool model using cylinder source
            self.modelNode = slicer.vtkMRMLModelNode()
            self.modelNode.HideFromEditorsOn()
            self.modelNode.SetName(slicer.mrmlScene.GenerateUniqueName("Tool"))
            polyData = self.toolSrc.GetOutput()
            self.modelNode.SetAndObservePolyData(polyData)
            slicer.mrmlScene.AddNode(self.modelNode)

            # Create a DisplayNode for this node (so that it can control its
            # own visibility) and have modelNode observe it
            self.modelDisplay = slicer.vtkMRMLModelDisplayNode()
            self.modelDisplay.SetColor(0, 1, 1)  # cyan
            slicer.mrmlScene.AddNode(self.modelDisplay)
            self.modelNode.SetAndObserveDisplayNodeID(
                self.modelDisplay.GetID())

            # Create a transform for our tool model that will scale it to
            # the proper radius, length, and position. Leave the orientation
            # at the default.
            self.transformNode = slicer.vtkMRMLLinearTransformNode()
            self.transformNode.HideFromEditorsOn()
            self.transformNode.SetName(
                slicer.mrmlScene.GenerateUniqueName("Transform"))
            self.updatePosition(position)
            slicer.mrmlScene.AddNode(self.transformNode)

            # apply the new transform to our tool
            self.modelNode.SetAndObserveTransformNodeID(
                self.transformNode.GetID())

            # Set tool to be visible
            self.visible = True
  def GenerateCylinderLabelMap(self,needleTransform, image, outputMask, radius, length, offset, refineRate = 3):

    # Get needle matrix
    needleMatrix = needleTransform.GetMatrixTransformToParent()
    
    # Create cylinder
    cylinderSource = vtk.vtkCylinderSource()
    cylinderSource.SetCenter(0.0, 0.0, 0.0)
    cylinderSource.SetRadius(radius)
    cylinderSource.SetHeight(length)
    cylinderSource.SetResolution(240)
    cylinderSource.Update()

    # Move cylinder to needleTransform
    transformCylinder = vtk.vtkTransform()
    transformCylinder.RotateX(90)
    transformCylinder.Translate(0.0, -length/2, 0.0)
    transformCylinder.PostMultiply()
    transformCylinder.Concatenate(needleMatrix)
    transformCylinder.Update()

    transformPolyData = vtk.vtkTransformPolyDataFilter()
    transformPolyData.SetInputConnection(cylinderSource.GetOutputPort())
    transformPolyData.SetTransform(transformCylinder)
    transformPolyData.Update()
    
    # Add nodes to the scene
    modelDisplayNode = slicer.mrmlScene.CreateNodeByClass("vtkMRMLModelDisplayNode")
    modelDisplayNode.SetColor(1.0,0.0,0.0)
    slicer.mrmlScene.AddNode(modelDisplayNode)

    modelNode = slicer.mrmlScene.CreateNodeByClass("vtkMRMLModelNode")
    modelNode.SetName("CylinderModel")
    modelNode.SetAndObservePolyData(transformPolyData.GetOutput())
    modelNode.SetAndObserveDisplayNodeID(modelDisplayNode.GetID())
    modelNode.Modified()
    slicer.mrmlScene.AddNode(modelNode)

    # Call ModelToLabelMap module
    cliNode = self.runModelToLabelMap(image, modelNode, outputMask, refineRate)
Beispiel #8
0
    def __init__(self, markupID, radius, length, position):
      # We use the markupID to check whether this tool's markup has
      # been removed in the onMarkupRemoved event
      self.markupID = markupID

      # Create a vtkCylinderSource for rendering the tool
      self.toolSrc = vtk.vtkCylinderSource()
      self.toolSrc.SetRadius(radius)
      self.toolSrc.SetHeight(length)

      # Create tool model using cylinder source
      self.modelNode = slicer.vtkMRMLModelNode()
      self.modelNode.HideFromEditorsOn()
      self.modelNode.SetName(slicer.mrmlScene.GenerateUniqueName("Tool"))
      polyData = self.toolSrc.GetOutput()
      self.modelNode.SetAndObservePolyData(polyData)
      slicer.mrmlScene.AddNode(self.modelNode)

      # Create a DisplayNode for this node (so that it can control its
      # own visibility) and have modelNode observe it
      self.modelDisplay = slicer.vtkMRMLModelDisplayNode()
      self.modelDisplay.SetColor(0,1,1) # cyan
      slicer.mrmlScene.AddNode(self.modelDisplay)
      self.modelNode.SetAndObserveDisplayNodeID(self.modelDisplay.GetID())

      # Create a transform for our tool model that will scale it to
      # the proper radius, length, and position. Leave the orientation
      # at the default.
      self.transformNode = slicer.vtkMRMLLinearTransformNode()
      self.transformNode.HideFromEditorsOn()
      self.transformNode.SetName(slicer.mrmlScene.GenerateUniqueName("Transform"))
      self.updatePosition(position)
      slicer.mrmlScene.AddNode(self.transformNode)

      # apply the new transform to our tool
      self.modelNode.SetAndObserveTransformNodeID(self.transformNode.GetID())

      # Set tool to be visible
      self.visible = True
  def AddApplicatorTrajectoryModel(self,scene,LineLandmarkTransform ):
      # check if already implemented
      if ( self.ApplicatorTrajectoryModel != None ):
        print "removing", self.ApplicatorTrajectoryModel.GetName()
        scene.RemoveNode(self.ApplicatorTrajectoryModel)

      # Define applicator tip
      vtkCylinder = vtk.vtkCylinderSource()
      vtkCylinder.SetHeight(10.*self.DiffusingTipLength); 
      vtkCylinder.SetRadius(0.1*self.DiffusingTipRadius);
      vtkCylinder.SetCenter(0.0,  10.*self.DiffusingTipLength/2.0, 0.0);
      vtkCylinder.SetResolution(16);

      # transform
      slicertransformFilter = vtk.vtkTransformFilter()
      slicertransformFilter.SetInput(vtkCylinder.GetOutput() ) 
      slicertransformFilter.SetTransform( LineLandmarkTransform ) 
      slicertransformFilter.Update()
      apppolyData=slicertransformFilter.GetOutput();

      # add to scene
      self.ApplicatorTrajectoryModel = slicer.vtkMRMLModelNode()
      self.ApplicatorTrajectoryModel.SetScene(scene)
      #self.ApplicatorTrajectoryModel.SetName(scene.GenerateUniqueName("Applicator-%s" % fiducialsNode.GetName()))
      self.ApplicatorTrajectoryModel.SetName("ApplicatorTrajectory" )
      self.ApplicatorTrajectoryModel.SetAndObservePolyData(apppolyData)

      # Create display node
      modelDisplay = slicer.vtkMRMLModelDisplayNode()
      modelDisplay.SetColor(1,0.5,0) # red
      modelDisplay.SetScene(scene)
      scene.AddNode(modelDisplay)
      self.ApplicatorTrajectoryModel.SetAndObserveDisplayNodeID(modelDisplay.GetID())

      # Add to scene
      modelDisplay.SetInputPolyData(self.ApplicatorTrajectoryModel.GetPolyData())
      scene.AddNode(self.ApplicatorTrajectoryModel)
Beispiel #10
0
    def createNeedleModelNode(self, name):

        locatorModel = self.scene.CreateNodeByClass('vtkMRMLModelNode')

        # Cylinder represents the locator stick
        cylinder = vtk.vtkCylinderSource()
        cylinder.SetRadius(1.5)
        cylinder.SetHeight(100)
        cylinder.SetCenter(0, 0, 0)
        cylinder.Update()

        # Rotate cylinder
        tfilter = vtk.vtkTransformPolyDataFilter()
        trans = vtk.vtkTransform()
        trans.RotateX(90.0)
        trans.Translate(0.0, -50.0, 0.0)
        trans.Update()
        if vtk.VTK_MAJOR_VERSION <= 5:
            tfilter.SetInput(cylinder.GetOutput())
        else:
            tfilter.SetInputConnection(cylinder.GetOutputPort())
        tfilter.SetTransform(trans)
        tfilter.Update()

        # Sphere represents the locator tip
        sphere = vtk.vtkSphereSource()
        sphere.SetRadius(3.0)
        sphere.SetCenter(0, 0, 0)
        sphere.Update()

        apd = vtk.vtkAppendPolyData()

        if vtk.VTK_MAJOR_VERSION <= 5:
            apd.AddInput(sphere.GetOutput())
            apd.AddInput(tfilter.GetOutput())
        else:
            apd.AddInputConnection(sphere.GetOutputPort())
            apd.AddInputConnection(tfilter.GetOutputPort())
        apd.Update()

        locatorModel.SetAndObservePolyData(apd.GetOutput())

        self.scene.AddNode(locatorModel)
        locatorModel.SetScene(self.scene)
        locatorModel.SetName(name)

        locatorDisp = locatorModel.GetDisplayNodeID()
        if locatorDisp == None:
            locatorDisp = self.scene.CreateNodeByClass(
                'vtkMRMLModelDisplayNode')
            self.scene.AddNode(locatorDisp)
            locatorDisp.SetScene(self.scene)
            locatorModel.SetAndObserveDisplayNodeID(locatorDisp.GetID())

        color = [0, 0, 0]
        color[0] = 0.5
        color[1] = 0.5
        color[2] = 1.0
        locatorDisp.SetColor(color)

        return locatorModel.GetID()
Beispiel #11
0
  def createNeedleModelNode(self, name,index):
    
    locatorModel = self.scene.CreateNodeByClass('vtkMRMLModelNode')
    
    # Cylinder represents the locator stick
    cylinder = vtk.vtkCylinderSource()
    cylinder.SetRadius(1.5)
    cylinder.SetHeight(100)
    cylinder.SetCenter(0, 0, 0)
    cylinder.Update()
    
    # Rotate cylinder
    tfilter = vtk.vtkTransformPolyDataFilter()
    trans =   vtk.vtkTransform()
    trans.RotateX(90.0)
    trans.Translate(0.0, -50.0, 0.0)
    trans.Update()
    if vtk.VTK_MAJOR_VERSION <= 5:
      tfilter.SetInput(cylinder.GetOutput())
    else:
      tfilter.SetInputConnection(cylinder.GetOutputPort())
    tfilter.SetTransform(trans)
    tfilter.Update()
    
    # Sphere represents the locator tip
    sphere = vtk.vtkSphereSource()
    sphere.SetRadius(3.0)
    sphere.SetCenter(0, 0, 0)
    sphere.Update()
    
    apd = vtk.vtkAppendPolyData()
    
    if vtk.VTK_MAJOR_VERSION <= 5:
      apd.AddInput(sphere.GetOutput())
      apd.AddInput(tfilter.GetOutput())
    else:
      apd.AddInputConnection(sphere.GetOutputPort())
      apd.AddInputConnection(tfilter.GetOutputPort())
    apd.Update()
    
    locatorModel.SetAndObservePolyData(apd.GetOutput());
    
    self.scene.AddNode(locatorModel)
    locatorModel.SetScene(self.scene);
    needleName = "Needle_%s" % name
    locatorModel.SetName(needleName)
    
    locatorDisp = locatorModel.GetDisplayNodeID()
    if locatorDisp == None:
      locatorDisp = self.scene.CreateNodeByClass('vtkMRMLModelDisplayNode')
      self.scene.AddNode(locatorDisp)
      locatorDisp.SetScene(self.scene)
      locatorModel.SetAndObserveDisplayNodeID(locatorDisp.GetID());

    color = [0, 0, 0]
    color[0] = 0.5
    color[1] = 0.5
    color[2] = 1.0
    locatorDisp.SetColor(color)
    print name
    if self.colorMap.get(name):
      locatorDisp.SetColor(self.colorMap.get(name))
      color = self.colorMap.get(name)
      colorName = "background:rgb({},{},{})".format(255*color[0], 255*color[1], 255*color[2])
      print colorName
      self.widget.colorSelectors[index].setStyleSheet(colorName)
      #qss = qt.QString("background-color: %1").arg(col.name());

    return locatorModel.GetID()
	def p2pCyl(startPoint, endPoint, radius=10, modName="Cyl", plus=0, Seg=3,
			   color="red", Opacity=1, RotY=0, Tx=0):
		"""12 prisms of point-to-point"""
		cylinderSource = vtk.vtkCylinderSource()
		cylinderSource.SetRadius(radius)
		cylinderSource.SetResolution(Seg)

		rng = vtk.vtkMinimalStandardRandomSequence()
		rng.SetSeed(8775070)  # For testing 8775070

		# Compute a basis
		normalizedX = [0] * 3
		normalizedY = [0] * 3
		normalizedZ = [0] * 3

		# The X axis is a vector from start to end
		vtk.vtkMath.Subtract(endPoint, startPoint, normalizedX)
		length = vtk.vtkMath.Norm(normalizedX) + plus
		#     length = 20
		vtk.vtkMath.Normalize(normalizedX)

		# The Xn axis is an arbitrary vector cross X
		arbitrary = [0] * 3
		for i in range(0, 3):
			rng.Next()
			arbitrary[i] = rng.GetRangeValue(-10, 10)
		vtk.vtkMath.Cross(normalizedX, arbitrary, normalizedZ)
		vtk.vtkMath.Normalize(normalizedZ)

		# The Zn axis is Xn cross X
		vtk.vtkMath.Cross(normalizedZ, normalizedX, normalizedY)
		matrix = vtk.vtkMatrix4x4()
		# Create the direction cosine matrix
		matrix.Identity()
		for i in range(0, 3):
			matrix.SetElement(i, 0, normalizedX[i])
			matrix.SetElement(i, 1, normalizedY[i])
			matrix.SetElement(i, 2, normalizedZ[i])
		# Apply the transforms
		transform = vtk.vtkTransform()
		transform.Translate(startPoint)  # translate to starting point
		transform.Concatenate(matrix)  # apply direction cosines
		transform.RotateZ(-90.0)  # align cylinder to x axis
		transform.Scale(1.0, length, 1.0)  # scale along the height vector
		transform.Translate(0, .5, 0)  # translate to start of cylinder
		transform.RotateY(RotY)
		transform.Translate(Tx, 0, 0)

		# Transform the polydata
		transformPD = vtk.vtkTransformPolyDataFilter()
		transformPD.SetTransform(transform)
		transformPD.SetInputConnection(cylinderSource.GetOutputPort())

		stlMapper = vtk.vtkPolyDataMapper()
		stlMapper.SetInputConnection(transformPD.GetOutputPort())
		vtkNode = slicer.modules.models.logic().AddModel(transformPD.GetOutputPort())
		vtkNode.SetName(modName)
		modelDisplay = vtkNode.GetDisplayNode()
		modelDisplay.SetColor(Helper.myColor(color))
		modelDisplay.SetOpacity(Opacity)
		modelDisplay.SetBackfaceCulling(0)
		# modelDisplay.SetVisibility(1)
		modelDisplay.SetVisibility2D(True)
		# modelDisplay.SetSliceDisplayModeToProjection()
		# dn.SetVisibility2D(True)
		return
  def __init__(self, entryPointFiducialListNode, targetFiducialListNode, length, diameter, probeText, probeColor):
    
    entryPointFid = entryPointFiducialListNode
    targetFid = targetFiducialListNode
    scene = slicer.mrmlScene
    
    #Create an probe.
    probe = vtk.vtkCylinderSource()
    probe.SetHeight(length)
    probe.SetRadius(diameter / 2)
    
    pos = [0 for i in range(3)]
    
    # get coordinates from current entry point fiducial
    currentEntryPointFiducialCoordinatesRAS = [0, 0, 0]
    
    entryPointFid.GetFiducialCoordinates(currentEntryPointFiducialCoordinatesRAS)
    
    currentTargetFiducialCoordinatesRAS = [0, 0, 0]
    
    targetFid.GetFiducialCoordinates(currentTargetFiducialCoordinatesRAS)
    
    # pos is the vector that describes the distance between the target and the entry point
    for i in range(3):
      pos[i] = currentTargetFiducialCoordinatesRAS[i] - currentEntryPointFiducialCoordinatesRAS[i]
      
    pointsDistance = sqrt(pow(pos[0], 2) + pow(pos[1], 2) + pow(pos[2], 2))
    
    # len is the vector that describes the length of the probe
    len = [0 for i in range(3)]
    for i in range(3):
      len[i] = length / pointsDistance * pos[i]
      
    translationTarget = [currentTargetFiducialCoordinatesRAS[0] - len[0] / 2, currentTargetFiducialCoordinatesRAS[1] - len[1] / 2, currentTargetFiducialCoordinatesRAS[2] - len[2] / 2]

    # Generate a random start and end point
    random.seed(8775070)
    startPoint = [0 for i in range(3)]
    startPoint[0] = currentEntryPointFiducialCoordinatesRAS[0]
    startPoint[1] = currentEntryPointFiducialCoordinatesRAS[1]
    startPoint[2] = currentEntryPointFiducialCoordinatesRAS[2]
    endPoint = [0 for i in range(3)]
    endPoint[0] = currentTargetFiducialCoordinatesRAS[0]
    endPoint[1] = currentTargetFiducialCoordinatesRAS[1]
    endPoint[2] = currentTargetFiducialCoordinatesRAS[2]
     
    # Compute a basis
    normalizedX = [0 for i in range(3)]
    normalizedY = [0 for i in range(3)]
    normalizedZ = [0 for i in range(3)]
     
    # The X axis is a vector from start to end
    math = vtk.vtkMath()
    math.Subtract(endPoint, startPoint, normalizedX)
    # length = math.Norm(normalizedX)
    math.Normalize(normalizedX)
    
    # The Z axis is an arbitrary vector cross X
    arbitrary = [0 for i in range(3)]
    arbitrary[0] = random.uniform(-10,10)
    arbitrary[1] = random.uniform(-10,10)
    arbitrary[2] = random.uniform(-10,10)
    math.Cross(normalizedX, arbitrary, normalizedZ)
    math.Normalize(normalizedZ)
    
    # The Y axis is Z cross X
    math.Cross(normalizedZ, normalizedX, normalizedY)
    matrix = vtk.vtkMatrix4x4()
     
    # Create the direction cosine matrix
    matrix.Identity()
    for i in range(3):
      matrix.SetElement(i, 0, normalizedX[i])
      matrix.SetElement(i, 1, normalizedY[i])
      matrix.SetElement(i, 2, normalizedZ[i])
     
    # Apply the transforms
    transform = vtk.vtkTransform()
    transform.Translate(translationTarget)
    transform.Concatenate(matrix)
    transform.RotateZ(90)
    
    
    # Create model node
    probeModel = slicer.vtkMRMLModelNode()
    probeModel.SetScene(scene)
    probeModel.SetName(probeText + "-%s" % targetFid.GetName())
    probeModel.SetAndObservePolyData(probe.GetOutput())

    # Create display node
    probeModelDisplay = slicer.vtkMRMLModelDisplayNode()
    
    probeModelDisplay.SetColor(probeColor)
    
    probeModelDisplay.SetOpacity(1)
    probeModelDisplay.SliceIntersectionVisibilityOn()
    
    probeModelDisplay.SetScene(scene)
    scene.AddNode(probeModelDisplay)
    probeModel.SetAndObserveDisplayNodeID(probeModelDisplay.GetID())

    # Add to scene
    probeModelDisplay.SetPolyData(probe.GetOutput())
    
    scene.AddNode(probeModel)
    
    
    # Create probeTransform node
    probeTransform = slicer.vtkMRMLLinearTransformNode()
    probeTransform.SetName(probeText + 'Transform-%s' % entryPointFid.GetName())
    
    scene.AddNode(probeTransform)
    
    probeTransform.ApplyTransformMatrix(transform.GetMatrix())
    
    probeModel.SetAndObserveTransformNodeID(probeTransform.GetID())
  def __init__(self, entryPointFiducialListNode, targetFiducialListNode, shape, shapeRadius, shapeHeight, shapeVolume, ablationZoneColor):
    
    entryPointFid = entryPointFiducialListNode
    targetFid = targetFiducialListNode
    
    scene = slicer.mrmlScene
    
    
    if (shape == 'sphere'):
      source = vtk.vtkSphereSource()
      source.SetRadius(shapeRadius)
      source.Update()
    elif (shape == 'cylinder'):
      source = vtk.vtkCylinderSource()
      source.SetRadius(shapeRadius)
      source.SetHeight(shapeHeight)
      source.Update()
    elif (shape == 'ellipsoid'):
      source = vtk.vtkSphereSource()
      source.SetRadius(shapeRadius)
      source.Update()
    else:
      source = vtk.vtkSphereSource()
      source.SetRadius(shapeRadius)
      source.Update()
    
    
    # get coordinates from current entry point fiducial
    currentEntryPointFiducialCoordinatesRAS = [0, 0, 0]
    
    entryPointFid.GetFiducialCoordinates(currentEntryPointFiducialCoordinatesRAS)
    
    currentTargetFiducialCoordinatesRAS = [0, 0, 0]
    
    targetFid.GetFiducialCoordinates(currentTargetFiducialCoordinatesRAS)
    
    translationTarget = [currentTargetFiducialCoordinatesRAS[0], currentTargetFiducialCoordinatesRAS[1], currentTargetFiducialCoordinatesRAS[2]]

    # Generate a random start and end point
    random.seed(8775070)
    startPoint = [0 for i in range(3)]
    startPoint[0] = currentEntryPointFiducialCoordinatesRAS[0]
    startPoint[1] = currentEntryPointFiducialCoordinatesRAS[1]
    startPoint[2] = currentEntryPointFiducialCoordinatesRAS[2]
    endPoint = [0 for i in range(3)]
    endPoint[0] = currentTargetFiducialCoordinatesRAS[0]
    endPoint[1] = currentTargetFiducialCoordinatesRAS[1]
    endPoint[2] = currentTargetFiducialCoordinatesRAS[2]
     
    # Compute a basis
    normalizedX = [0 for i in range(3)]
    normalizedY = [0 for i in range(3)]
    normalizedZ = [0 for i in range(3)]
     
    # The X axis is a vector from start to end
    math = vtk.vtkMath()
    math.Subtract(endPoint, startPoint, normalizedX)
    # length = math.Norm(normalizedX)
    math.Normalize(normalizedX)
    
    # The Z axis is an arbitrary vector cross X
    arbitrary = [0 for i in range(3)]
    arbitrary[0] = random.uniform(-10,10)
    arbitrary[1] = random.uniform(-10,10)
    arbitrary[2] = random.uniform(-10,10)
    math.Cross(normalizedX, arbitrary, normalizedZ)
    math.Normalize(normalizedZ)
    
    # The Y axis is Z cross X
    math.Cross(normalizedZ, normalizedX, normalizedY)
    matrix = vtk.vtkMatrix4x4()
     
    # Create the direction cosine matrix
    matrix.Identity()
    for i in range(3):
      matrix.SetElement(i, 0, normalizedX[i])
      matrix.SetElement(i, 1, normalizedY[i])
      matrix.SetElement(i, 2, normalizedZ[i])
      matrix.SetElement(i, 3, currentTargetFiducialCoordinatesRAS[i])
      
    # Apply the transforms
    transform = vtk.vtkTransform()
    transform.Concatenate(matrix)
    transform.RotateZ(90)
    
    '''
    ps = vtk.vtkProgrammableSource()
    
    import math 
    numPts = 80
    polyLinePoints = vtk.vtkPoints() 
    polyLinePoints.SetNumberOfPoints(numPts) 
    R=1.0 
    for i in range(0,numPts):
      x = R*math.cos(i*2*math.pi/numPts) 
      y = R*math.sin(i*2*math.pi/numPts) 
      polyLinePoints.InsertPoint(i, x, y, 0)
    aPolyLine1 = vtk.vtkPolyLine() 
    aPolyLine1.GetPointIds().SetNumberOfIds(numPts+1) 
    for i in range(0,numPts):
      aPolyLine1.GetPointIds().SetId(i,i) 
    # add one more cell at the end to close the circle on itself 
    aPolyLine1.GetPointIds().SetId(numPts, 0)
    aPolyLineGrid = ps.GetOutput()
    aPolyLineGrid.Allocate(1,1)
    aPolyLineGrid.InsertNextCell(aPolyLine1.GetCellType(), aPolyLine1.GetPointIds())
    aPolyLineGrid.SetPoints(polyLinePoints)
    '''
    
    '''
    #This script generates a helix double.
    #This is intended as the script of a 'Programmable Source'
    import math
     
    ps = vtk.vtkSphereSource()
    
    
    numPts = 80 # Points along each Helix
    length = 8 # Length of each Helix
    rounds = 3 # Number of times around
    phase_shift = math.pi/1.5 # Phase shift between Helixes
     
    #Get a vtk.PolyData object for the output
    pdo = ps.GetOutput()
    print "before"
    print pdo
    
    #This will store the points for the Helix
    newPts = vtk.vtkPoints()
    for i in range(0, numPts):
       #Generate Points for first Helix
       x = i*length/numPts
       y = math.sin(i*rounds*2*math.pi/numPts)
       z = math.cos(i*rounds*2*math.pi/numPts)
       newPts.InsertPoint(i, x,y,z)
     
       #Generate Points for second Helix. Add a phase offset to y and z.
       y = math.sin(i*rounds*2*math.pi/numPts+phase_shift)
       z = math.cos(i*rounds*2*math.pi/numPts+phase_shift)
       #Offset Helix 2 pts by 'numPts' to keep separate from Helix 1 Pts
       newPts.InsertPoint(i+numPts, x,y,z)
     
    #Add the points to the vtkPolyData object
    pdo.SetPoints(newPts)
     
    #Make two vtkPolyLine objects to hold curve construction data
    aPolyLine1 = vtk.vtkPolyLine()
    aPolyLine2 = vtk.vtkPolyLine()
     
    #Indicate the number of points along the line
    aPolyLine1.GetPointIds().SetNumberOfIds(numPts)
    aPolyLine2.GetPointIds().SetNumberOfIds(numPts)
    for i in range(0,numPts):
       #First Helix - use the first set of points
       aPolyLine1.GetPointIds().SetId(i, i)
       #Second Helix - use the second set of points
       #(Offset the point reference by 'numPts').
       aPolyLine2.GetPointIds().SetId(i,i+numPts)
     
    #Allocate the number of 'cells' that will be added. 
    #Two 'cells' for the Helix curves, and one 'cell'
    #for every 3rd point along the Helixes.
    links = range(0,numPts,3)
    pdo.Allocate(2+len(links), 1)
     
    #Add the poly line 'cell' to the vtkPolyData object.
    pdo.InsertNextCell(aPolyLine1.GetCellType(), aPolyLine1.GetPointIds())
    pdo.InsertNextCell(aPolyLine2.GetCellType(), aPolyLine2.GetPointIds())
     
    for i in links:
       #Add a line connecting the two Helixes.
       aLine = vtk.vtkLine()
       aLine.GetPointIds().SetId(0, i)
       aLine.GetPointIds().SetId(1, i+numPts)
       pdo.InsertNextCell(aLine.GetCellType(), aLine.GetPointIds())
       
    print "after"
    print pdo
    '''    
    # Create model node
    lesionModel = slicer.vtkMRMLModelNode()
    lesionModel.SetScene(scene)
    lesionModel.SetName("Ablationzone-%s" % targetFid.GetName())
    lesionModel.SetAndObservePolyData(source.GetOutput())
    self.lesionModel = lesionModel
    # Create display node
    lesionModelDisplay = slicer.vtkMRMLModelDisplayNode()
    lesionModelDisplay.SetColor(ablationZoneColor)
    lesionModelDisplay.SetOpacity(0.4)
    lesionModelDisplay.SliceIntersectionVisibilityOn()
    
    lesionModelDisplay.SetScene(scene)
    scene.AddNode(lesionModelDisplay)
    lesionModel.SetAndObserveDisplayNodeID(lesionModelDisplay.GetID())

    
    # Add to scene
    lesionModelDisplay.SetPolyData(source.GetOutput())
    self.lesionModelDisplay = lesionModelDisplay
    self.lesionModel= lesionModel
    
    scene.AddNode(lesionModel)
    
    # Create ablationZoneTransform node
    ablationZoneTransform = slicer.vtkMRMLLinearTransformNode()
    ablationZoneTransform.SetName('AblationZoneTransform-%s' % targetFid.GetName())
    
    scene.AddNode(ablationZoneTransform)
    
    ablationZoneTransform.ApplyTransformMatrix(transform.GetMatrix())
    
    lesionModel.SetAndObserveTransformNodeID(ablationZoneTransform.GetID())
    
    self.ablationZoneTransform = ablationZoneTransform