コード例 #1
0
 def renderLabelMap(self):
   # Initializes a vtkMRMLScalarVolumeNode for the SegmentCAD Output and copies ijkToRAS matrix and Image data from nodeLabel
   ijkToRASMatrix = vtk.vtkMatrix4x4()
   self.volumePre.GetIJKToRASMatrix(ijkToRASMatrix)
   self.SegmentCADLabelMap.SetIJKToRASMatrix(ijkToRASMatrix)
   SegmentCADLabelMapImageData = vtk.vtkImageData()
   SegmentCADLabelMapImageData.DeepCopy(self.volumePre.GetImageData())
   SegmentCADLabelMapPointData = SegmentCADLabelMapImageData.GetPointData()
   # Numpy array is converted from signed int16 to signed vtkShortArray
   scalarArray = vtk.vtkShortArray()
   dims1D = SegmentCADLabelMapPointData.GetScalars().GetSize()
   self.nodeArraySegmentCADLabel = self.nodeArraySegmentCADLabel.reshape(dims1D, order='C')
   scalarArray = vtk.util.numpy_support.numpy_to_vtk(self.nodeArraySegmentCADLabel)
   # PointData() of SegmentCAD label output pointed to new vtkShortArray for scalar values
   SegmentCADLabelMapImageData.SetScalarTypeToShort()
   SegmentCADLabelMapPointData.SetScalars(scalarArray)
   SegmentCADLabelMapPointData.Update()
   SegmentCADLabelMapImageData.Update()
   self.SegmentCADLabelMap.SetAndObserveImageData(SegmentCADLabelMapImageData)
   # Corresponding display node and color table nodes created for SegmentCAD label Output
   self.SegmentCADLabelMapDisplay = slicer.vtkMRMLLabelMapVolumeDisplayNode()
   self.SegmentCADLabelMapDisplay.SetScene(slicer.mrmlScene)
   self.SegmentCADLabelMapDisplay.SetAndObserveColorNodeID('vtkMRMLColorTableNodeFileGenericColors.txt')
   self.SegmentCADLabelMapDisplay.SetInputImageData(SegmentCADLabelMapImageData)
   self.SegmentCADLabelMapDisplay.UpdateImageDataPipeline()
   
   slicer.mrmlScene.AddNode(self.SegmentCADLabelMapDisplay)
   self.SegmentCADLabelMap.SetAndObserveDisplayNodeID(self.SegmentCADLabelMapDisplay.GetID())
   self.SegmentCADLabelMapDisplay.UpdateScene(slicer.mrmlScene)
コード例 #2
0
def renderArray(self, labelNodeArray, labelNode, imageNode, shape=(512,512,88), spacing=(1,1,1), origin=(0,0,0)):
  ras2ijk = vtk.vtkMatrix4x4()
  ijk2ras = vtk.vtkMatrix4x4()
  imageNode.GetRASToIJKMatrix(ras2ijk)
  imageNode.GetIJKToRASMatrix(ijk2ras)
  labelNode.SetRASToIJKMatrix(ras2ijk)
  labelNode.SetIJKToRASMatrix(ijk2ras)
  
  labelNodeImageData = vtk.vtkImageData()
  labelNodeImageData.DeepCopy(imageNode.GetImageData())
  #labelNodeImageData.AllocateScalars(4,1)
  #labelNodeImageData.SetDimensions(shape)
  labelNodePointData = labelNodeImageData.GetPointData()

  """
  # Numpy array is converted from signed int16 to signed vtkShortArray
  scalarArray = vtk.vtkShortArray()
  dims1D = labelNodeArray.size #labelNodePointData.GetScalars().GetSize()
  flatArray = labelNodeArray.reshape(dims1D, order='C')
  scalarArray = vtk.util.numpy_support.numpy_to_vtk(flatArray)
  """
  scalarArray = vtk.vtkShortArray()
  dims1D = labelNodePointData.GetScalars().GetSize() #labelNodePointData.GetScalars().GetSize()
  flatArray = labelNodeArray.reshape(dims1D, order='F')
  scalarArray = vtk.util.numpy_support.numpy_to_vtk(flatArray) # VTK Unsigned Char Array =3, short =4, uint = 7
     
  labelNodePointData.SetScalars(scalarArray)
  labelNodeImageData.Modified()
  
  slicer.mrmlScene.AddNode(labelNode)
  labelNode.SetAndObserveImageData(labelNodeImageData)
  labelNode.SetSpacing(spacing)
  labelNode.SetOrigin(origin)
     
  return labelNode
コード例 #3
0
 def renderLabelMap(self):
   # Initializes a vtkMRMLScalarVolumeNode for the SegmentCAD Output and copies ijkToRAS matrix and Image data from nodeLabel
   ras2ijk = vtk.vtkMatrix4x4()
   ijk2ras = vtk.vtkMatrix4x4()
   self.nodePre.GetRASToIJKMatrix(ras2ijk)
   self.nodePre.GetIJKToRASMatrix(ijk2ras)
   self.SegmentCADLabelMap.SetRASToIJKMatrix(ras2ijk)
   self.SegmentCADLabelMap.SetIJKToRASMatrix(ijk2ras)
   SegmentCADLabelMapImageData = vtk.vtkImageData()
   SegmentCADLabelMapImageData.DeepCopy(self.nodePre.GetImageData())
   SegmentCADLabelMapPointData = SegmentCADLabelMapImageData.GetPointData()
   # Numpy array is converted from signed int16 to signed vtkShortArray
   scalarArray = vtk.vtkShortArray()
   dims1D = SegmentCADLabelMapPointData.GetScalars().GetSize()
   self.nodeArraySegmentCADLabel = self.nodeArraySegmentCADLabel.reshape(dims1D, order='C') #use a flattening function
   scalarArray = vtk.util.numpy_support.numpy_to_vtk(self.nodeArraySegmentCADLabel)
   # PointData() of SegmentCAD label output pointed to new vtkShortArray for scalar values
   
   if vtk.VTK_MAJOR_VERSION <= 5:
     #SegmentCADLabelMapImageData.SetScalarTypeToShort()
     SegmentCADLabelMapPointData.SetScalars(scalarArray)
     SegmentCADLabelMapPointData.Update()
   else:
     #SegmentCADLabelMapImageData.SetScalarType(4)
     SegmentCADLabelMapPointData.SetScalars(scalarArray)
     SegmentCADLabelMapImageData.Modified()
   
   self.SegmentCADLabelMap.SetAndObserveImageData(SegmentCADLabelMapImageData)
   # Corresponding display node and color table nodes created for SegmentCAD label Output
   self.SegmentCADLabelMapDisplay = slicer.vtkMRMLLabelMapVolumeDisplayNode()
   self.SegmentCADLabelMapDisplay.SetScene(slicer.mrmlScene)
   self.SegmentCADLabelMapDisplay.SetAndObserveColorNodeID('vtkMRMLColorTableNodeFileGenericColors.txt')
   
   if vtk.VTK_MAJOR_VERSION <= 5:
     self.SegmentCADLabelMapDisplay.SetInputImageData(self.SegmentCADLabelMap.GetImageData())
   else:
     self.SegmentCADLabelMapDisplay.SetInputImageDataConnection(self.SegmentCADLabelMap.GetImageDataConnection())
   self.SegmentCADLabelMapDisplay.UpdateImageDataPipeline()
   
   slicer.mrmlScene.AddNode(self.SegmentCADLabelMapDisplay)
   self.SegmentCADLabelMap.SetAndObserveDisplayNodeID(self.SegmentCADLabelMapDisplay.GetID())
   self.SegmentCADLabelMapDisplay.UpdateScene(slicer.mrmlScene)
   
   #red_logic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic()
   #red_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())  
   #yellow_logic = slicer.app.layoutManager().sliceWidget("Yellow").sliceLogic()
   #yellow_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())
   #green_logic = slicer.app.layoutManager().sliceWidget("Green").sliceLogic()
   #green_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())
   
   appLogic = slicer.app.applicationLogic()
   selectionNode = appLogic.GetSelectionNode()
   #selectionNode.SetReferenceActiveVolumeID(self.nodePre.GetID())
   selectionNode.SetReferenceActiveLabelVolumeID(self.SegmentCADLabelMap.GetID())  
   #selectionNode.SetReferenceSecondaryVolumeID(self.node1.GetID())
   appLogic.PropagateVolumeSelection()
コード例 #4
0
    def renderLabelMap(self):
        # Initializes a vtkMRMLScalarVolumeNode for the SegmentCAD Output and copies ijkToRAS matrix and Image data from nodeLabel
        ras2ijk = vtk.vtkMatrix4x4()
        ijk2ras = vtk.vtkMatrix4x4()
        self.nodePre.GetRASToIJKMatrix(ras2ijk)
        self.nodePre.GetIJKToRASMatrix(ijk2ras)
        self.SegmentCADLabelMap.SetRASToIJKMatrix(ras2ijk)
        self.SegmentCADLabelMap.SetIJKToRASMatrix(ijk2ras)
        SegmentCADLabelMapImageData = vtk.vtkImageData()
        SegmentCADLabelMapImageData.DeepCopy(self.nodePre.GetImageData())
        SegmentCADLabelMapPointData = SegmentCADLabelMapImageData.GetPointData(
        )
        # Numpy array is converted from signed int16 to signed vtkShortArray
        scalarArray = vtk.vtkShortArray()
        dims1D = SegmentCADLabelMapPointData.GetScalars().GetSize()
        self.nodeArraySegmentCADLabel = self.nodeArraySegmentCADLabel.reshape(
            dims1D, order='C')  #use a flattening function
        scalarArray = vtk.util.numpy_support.numpy_to_vtk(
            self.nodeArraySegmentCADLabel)
        # PointData() of SegmentCAD label output pointed to new vtkShortArray for scalar values

        if vtk.VTK_MAJOR_VERSION <= 5:
            #SegmentCADLabelMapImageData.SetScalarTypeToShort()
            SegmentCADLabelMapPointData.SetScalars(scalarArray)
            SegmentCADLabelMapPointData.Update()
        else:
            #SegmentCADLabelMapImageData.SetScalarType(4)
            SegmentCADLabelMapPointData.SetScalars(scalarArray)
            SegmentCADLabelMapImageData.Modified()

        self.SegmentCADLabelMap.SetAndObserveImageData(
            SegmentCADLabelMapImageData)
        # Corresponding display node and color table nodes created for SegmentCAD label Output
        self.SegmentCADLabelMapDisplay = slicer.vtkMRMLLabelMapVolumeDisplayNode(
        )
        self.SegmentCADLabelMapDisplay.SetScene(slicer.mrmlScene)
        self.SegmentCADLabelMapDisplay.SetAndObserveColorNodeID(
            'vtkMRMLColorTableNodeFileGenericColors.txt')

        if vtk.VTK_MAJOR_VERSION <= 5:
            self.SegmentCADLabelMapDisplay.SetInputImageData(
                self.SegmentCADLabelMap.GetImageData())
        else:
            self.SegmentCADLabelMapDisplay.SetInputImageDataConnection(
                self.SegmentCADLabelMap.GetImageDataConnection())
        self.SegmentCADLabelMapDisplay.UpdateImageDataPipeline()

        slicer.mrmlScene.AddNode(self.SegmentCADLabelMapDisplay)
        self.SegmentCADLabelMap.SetAndObserveDisplayNodeID(
            self.SegmentCADLabelMapDisplay.GetID())
        self.SegmentCADLabelMapDisplay.UpdateScene(slicer.mrmlScene)

        #red_logic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic()
        #red_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())
        #yellow_logic = slicer.app.layoutManager().sliceWidget("Yellow").sliceLogic()
        #yellow_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())
        #green_logic = slicer.app.layoutManager().sliceWidget("Green").sliceLogic()
        #green_logic.GetSliceCompositeNode().SetLabelVolumeID(self.SegmentCADLabelMap.GetID())

        appLogic = slicer.app.applicationLogic()
        selectionNode = appLogic.GetSelectionNode()
        #selectionNode.SetReferenceActiveVolumeID(self.nodePre.GetID())
        selectionNode.SetReferenceActiveLabelVolumeID(
            self.SegmentCADLabelMap.GetID())
        #selectionNode.SetReferenceSecondaryVolumeID(self.node1.GetID())
        appLogic.PropagateVolumeSelection()