Beispiel #1
0
def registerCustomVrPresets(usPresetsScenePath):
    """
  Set volume rendering presets from Resources/VrPresets/US-VrPresets.mrml
  """
    import os

    if not os.path.isfile(usPresetsScenePath):
        logging.warning('Volume rendering presets are not found at {0}'.format(
            usPresetsScenePath))
        return

    # Read scene
    usPresetsScene = slicer.vtkMRMLScene()
    vrPropNode = slicer.vtkMRMLVolumePropertyNode()
    usPresetsScene.RegisterNodeClass(vrPropNode)
    usPresetsScene.SetURL(usPresetsScenePath)
    usPresetsScene.Connect()

    # Add presets to volume rendering logic
    vrLogic = slicer.modules.volumerendering.logic()
    presetsScene = vrLogic.GetPresetsScene()
    vrNodes = usPresetsScene.GetNodesByClass("vtkMRMLVolumePropertyNode")
    vrNodes.UnRegister(None)
    for itemNum in range(vrNodes.GetNumberOfItems()):
        node = vrNodes.GetItemAsObject(itemNum)
        vrLogic.AddPreset(node)
Beispiel #2
0
  def InitVRDisplayNode(vrDisplayNode, volumeID, roiID):
    vrLogic = slicer.modules.volumerendering.logic()

    print('ChangeTracker VR: will observe ID '+volumeID)
    propNode = vrDisplayNode.GetVolumePropertyNode()

    if propNode == None:
      propNode = slicer.vtkMRMLVolumePropertyNode()
      slicer.mrmlScene.AddNode(propNode)
    else:
      print('Property node: '+propNode.GetID())

    vrDisplayNode.SetAndObserveVolumePropertyNodeID(propNode.GetID())

    vrDisplayNode.SetAndObserveROINodeID(roiID)

    vrDisplayNode.SetAndObserveVolumeNodeID(volumeID)

    vrLogic.CopyDisplayToVolumeRenderingDisplayNode(vrDisplayNode)
Beispiel #3
0
    def InitVRDisplayNode(vrDisplayNode, volumeID, roiID):
        vrLogic = slicer.modules.volumerendering.logic()

        logging.debug('PedicleScrewSimulator VR: will observe ID ' + volumeID)
        propNode = vrDisplayNode.GetVolumePropertyNode()

        if propNode == None:
            propNode = slicer.vtkMRMLVolumePropertyNode()
            slicer.mrmlScene.AddNode(propNode)
        else:
            logging.debug('Property node: ' + propNode.GetID())

        vrDisplayNode.SetAndObserveVolumePropertyNodeID(propNode.GetID())

        vrDisplayNode.SetAndObserveROINodeID(roiID)

        vrDisplayNode.SetAndObserveVolumeNodeID(volumeID)

        vrLogic.CopyDisplayToVolumeRenderingDisplayNode(vrDisplayNode)
Beispiel #4
0
    def InitVRDisplayNode(vrDisplayNode, volumeID, roiID):

        # Takes most of the steps necessary to create a 3D Visualization of an image.

        vrLogic = slicer.modules.volumerendering.logic()

        propNode = vrDisplayNode.GetVolumePropertyNode()

        if propNode == None:
            propNode = slicer.vtkMRMLVolumePropertyNode()
            slicer.mrmlScene.AddNode(propNode)

        vrDisplayNode.SetAndObserveVolumePropertyNodeID(propNode.GetID())

        if roiID != '':
            vrDisplayNode.SetAndObserveROINodeID(roiID)

        vrDisplayNode.SetAndObserveVolumeNodeID(volumeID)

        vrLogic.CopyDisplayToVolumeRenderingDisplayNode(vrDisplayNode)
	def InitVRDisplayNode(vrDisplayNode, volumeID, roiID):

		# Takes most of the steps necessary to create a 3D Visualization of an image.

		vrLogic = slicer.modules.volumerendering.logic()

		propNode = vrDisplayNode.GetVolumePropertyNode()

		if propNode == None:
			propNode = slicer.vtkMRMLVolumePropertyNode()
			slicer.mrmlScene.AddNode(propNode)

		vrDisplayNode.SetAndObserveVolumePropertyNodeID(propNode.GetID())

		if roiID != '':
			vrDisplayNode.SetAndObserveROINodeID(roiID)

		vrDisplayNode.SetAndObserveVolumeNodeID(volumeID)

		vrLogic.CopyDisplayToVolumeRenderingDisplayNode(vrDisplayNode)
Beispiel #6
0
    def InitVRDisplayNode(vrDisplayNode, volumeID, roiID):

        # Uses the volume rendering module to initiate 3D visualizations.
        # NOTE: This code seems to be duplicated several times within individual
        # steps. It would be best to consolidate them in this code if possible..

        vrLogic = slicer.modules.volumerendering.logic()

        propNode = vrDisplayNode.GetVolumePropertyNode()

        if propNode == None:
            propNode = slicer.vtkMRMLVolumePropertyNode()
            slicer.mrmlScene.AddNode(propNode)

        vrDisplayNode.SetAndObserveVolumePropertyNodeID(propNode.GetID())

        if roiID != '':
            vrDisplayNode.SetAndObserveROINodeID(roiID)

        vrDisplayNode.SetAndObserveVolumeNodeID(volumeID)

        vrLogic.CopyDisplayToVolumeRenderingDisplayNode(vrDisplayNode)
Beispiel #7
0
 def addDefaultVolumeProperty(self):
   # create a volume property node in the scene if needed.  This is used
   # for the color transfer function and can be manipulated in the
   # Slicer Volume Rendering module widget
   volumePropertyNode = slicer.util.getNode('ShaderVolumeProperty')
   if not volumePropertyNode:
     volumePropertyNode = slicer.vtkMRMLVolumePropertyNode()
     volumePropertyNode.SetName('ShaderVolumeProperty')
     scalarOpacity = vtk.vtkPiecewiseFunction()
     points = ( (-1024., 0.), (20., 0.), (300., 1.), (3532., 1.) )
     for point in points:
       scalarOpacity.AddPoint(*point)
     volumePropertyNode.SetScalarOpacity(scalarOpacity)
     colorTransfer = vtk.vtkColorTransferFunction()
     colors = ( (-1024., (0., 0., 0.)), (3., (0., 0., 0.)), (131., (1., 1., 0.)) )
     colors = ( (-1024., (0., 0., 0.)), (-984., (0., 0., 0.)), (469., (1., 1., 1.)) )
     for intensity,rgb in colors:
       colorTransfer.AddRGBPoint(intensity, *rgb)
     volumePropertyNode.SetScalarOpacity(scalarOpacity)
     volumePropertyNode.SetColor(colorTransfer, 0)
     slicer.mrmlScene.AddNode(volumePropertyNode)
   self.volumePropertyNode = volumePropertyNode
Beispiel #8
0
 def addDefaultVolumeProperty(self):
     # create a volume property node in the scene if needed.  This is used
     # for the color transfer function and can be manipulated in the
     # Slicer Volume Rendering module widget
     volumePropertyNode = slicer.util.getNode('ShaderVolumeProperty')
     if not volumePropertyNode:
         volumePropertyNode = slicer.vtkMRMLVolumePropertyNode()
         volumePropertyNode.SetName('ShaderVolumeProperty')
         scalarOpacity = vtk.vtkPiecewiseFunction()
         points = ((-1024., 0.), (20., 0.), (300., 1.), (3532., 1.))
         for point in points:
             scalarOpacity.AddPoint(*point)
         volumePropertyNode.SetScalarOpacity(scalarOpacity)
         colorTransfer = vtk.vtkColorTransferFunction()
         colors = ((-1024., (0., 0., 0.)), (3., (0., 0., 0.)),
                   (131., (1., 1., 0.)))
         colors = ((-1024., (0., 0., 0.)), (-984., (0., 0., 0.)),
                   (469., (1., 1., 1.)))
         for intensity, rgb in colors:
             colorTransfer.AddRGBPoint(intensity, *rgb)
         volumePropertyNode.SetScalarOpacity(scalarOpacity)
         volumePropertyNode.SetColor(colorTransfer, 0)
         slicer.mrmlScene.AddNode(volumePropertyNode)
     self.volumePropertyNode = volumePropertyNode
Beispiel #9
0
  def onVolumeAdded(self,volumeNode):  
    print("A volume was added!!")
    volumeNode.AddObserver("ModifiedEvent",self.onVolumeModified)      
    
    '''
    It is assumed that the volume was created with respect to the Reference
    The matrix associated with the volume must have the following structure
    sx 0  0  ox
    0  sy 0  oy
    0  0  sz oz
    with sx, sy, and sz >0
    This is checked and if it is not true is modified.
    By default Slicer add a volume with a ijkToRas matrix of the form:
    -1    0    0
    0    -1    0
    0     0    1
    In this case we want a ijkToRAS matrix equal to identity because we want to place the
    volume with respect to the Reference.
    ReferenceToRAS matrix is calculated during registration
    '''
    
    matrix=vtk.vtkMatrix4x4()
    volumeNode.GetIJKToRASMatrix(matrix) 
    print matrix
    sx = matrix.GetElement(0,0)
    if (sx<0):
        ox=matrix.GetElement(0,3)
        matrix.SetElement(0,0,-sx)
        matrix.SetElement(0,3,-ox)
    sy = matrix.GetElement(1,1)
    if (sy<0):
        oy=matrix.GetElement(1,3)
        matrix.SetElement(1,1,-sy)
        matrix.SetElement(1,3,-oy)    
    volumeNode.SetIJKToRASMatrix(matrix)
    print matrix
    
    # Volumes are placed under the Reference coordinate system
    referenceToRASNode=slicer.util.getNode("ReferenceToRAS")
    if referenceToRASNode==None:
        referenceToRASNode=slicer.vtkMRMLLinearTransformNode()
        slicer.mrmlScene.AddNode(referenceToRASNode)
        referenceToRASNode.SetName("ReferenceToRAS")
    
    volumeNode.SetAndObserveTransformNodeID(referenceToRASNode.GetID()) 
    volumeNode.SetDisplayVisibility(True)
    
    volumePropertyNode=slicer.vtkMRMLVolumePropertyNode()
    slicer.mrmlScene.RegisterNodeClass(volumePropertyNode);

    # the scalar opacity mapping function is configured
    # it is a ramp with opacity of 0 equal to zero and opacity of 1 equal to 1. 
    scalarOpacity = vtk.vtkPiecewiseFunction()
    scalarOpacity.AddPoint(self.scalarRange[0],0.)
    scalarOpacity.AddPoint(self.windowLevelMinMax[0],0.)
    scalarOpacity.AddPoint(self.windowLevelMinMax[1],1.)
    scalarOpacity.AddPoint(self.scalarRange[1],1.)

    volumePropertyNode.SetScalarOpacity(scalarOpacity);
    
    # the color function is configured
    # zero is associated to the scalar zero and 1 to the scalar 255
    colorTransfer = vtk.vtkColorTransferFunction()
    black=[0., 0., 0.]
    white=[1.,1.,1.]
    colorTransfer.AddRGBPoint(self.scalarRange[0],black[0],black[1],black[2])
    colorTransfer.AddRGBPoint(self.windowLevelMinMax[0], black[0], black[1], black[2])
    colorTransfer.AddRGBPoint(self.windowLevelMinMax[1], white[0], white[1], white[2]);
    colorTransfer.AddRGBPoint(self.scalarRange[1], white[0], white[1], white[2]);
    
    volumePropertyNode.SetColor(colorTransfer)
    
    
    vtkVolumeProperty=volumePropertyNode.GetVolumeProperty()
    
    vtkVolumeProperty.SetInterpolationTypeToNearest();
    vtkVolumeProperty.ShadeOn();
    vtkVolumeProperty.SetAmbient(0.30);
    vtkVolumeProperty.SetDiffuse(0.60);
    vtkVolumeProperty.SetSpecular(0.50);
    vtkVolumeProperty.SetSpecularPower(40);
    
    slicer.mrmlScene.AddNode(volumePropertyNode)
    
    # The volume rendering display node is created
    vrDisplayNode=slicer.vtkMRMLCPURayCastVolumeRenderingDisplayNode()
    vrDisplayNode.SetAndObserveVolumeNodeID(volumeNode.GetID())
    vrDisplayNode.SetAndObserveVolumePropertyNodeID(volumePropertyNode.GetID())
    slicer.mrmlScene.AddNode(vrDisplayNode)
    vrDisplayNode.SetVisibility(True)
    vrDisplayNode.AddObserver("ModifiedEvent",self.onVolumeRenderingModified)  
    
    vrDisplayNode.Modified()
    vrDisplayNode.UpdateScene(slicer.mrmlScene)