Ejemplo n.º 1
1
  def preview(self, color=None, checked = True):
    """previewsing the result of thresholding"""
    if not self.editUtil.getBackgroundImage() or not self.editUtil.getLabelImage():
      return

    if not checked:
      self.cursorActor.VisibilityOff()
      self.sliceView.scheduleRender()
      return

    #
    # make a lookup table where inside the threshold is opaque and colored
    # by the label color, while the background is transparent (black)
    # - apply the threshold operation to the currently visible background
    #   (output of the layer logic's vtkImageReslice instance)
    #

    if not color:
      color = self.getPaintColor

    if not self.lut:
      self.lut = vtk.vtkLookupTable()

    self.lut.SetRampToLinear()
    self.lut.SetNumberOfTableValues( 2 )
    self.lut.SetTableRange( 0, 1 )
    self.lut.SetTableValue( 0,  0, 0, 0,  0 )
    r,g,b,a = color
    self.lut.SetTableValue( 1,  r, g, b,  a )

    if not self.map:
      self.map = vtk.vtkImageMapToRGBA()
    self.map.SetOutputFormatToRGBA()
    self.map.SetLookupTable( self.lut )

    if not self.thresh:
      self.thresh = vtk.vtkImageThreshold()
    sliceLogic = self.sliceWidget.sliceLogic()
    backgroundLogic = sliceLogic.GetBackgroundLayer()
    if vtk.VTK_MAJOR_VERSION <= 5:
      self.thresh.SetInput( backgroundLogic.GetReslice().GetOutput() )
    else:
      self.thresh.SetInputConnection( backgroundLogic.GetReslice().GetOutputPort() )
    self.thresh.ThresholdBetween( self.min, self.max )
    self.thresh.SetInValue( 1 )
    self.thresh.SetOutValue( 0 )
    self.thresh.SetOutputScalarTypeToUnsignedChar()
    if vtk.VTK_MAJOR_VERSION <= 5:
      self.map.SetInput( self.thresh.GetOutput() )
      self.map.Update()
      self.cursorMapper.SetInput( self.map.GetOutput() )
    else:
      self.map.SetInputConnection( self.thresh.GetOutputPort() )
      self.cursorMapper.SetInputConnection( self.map.GetOutputPort() )

    self.cursorActor.VisibilityOn()

    self.sliceView.scheduleRender()
Ejemplo n.º 2
0
    def preview(self, color=None):

        if not self.editUtil.getBackgroundImage(
        ) or not self.editUtil.getLabelImage():
            return

        #
        # make a lookup table where inside the threshold is opaque and colored
        # by the label color, while the background is transparent (black)
        # - apply the threshold operation to the currently visible background
        #   (output of the layer logic's vtkImageReslice instance)
        #

        if not color:
            color = self.getPaintColor

        if not self.lut:
            self.lut = vtk.vtkLookupTable()

        self.lut.SetRampToLinear()
        self.lut.SetNumberOfTableValues(2)
        self.lut.SetTableRange(0, 1)
        self.lut.SetTableValue(0, 0, 0, 0, 0)
        r, g, b, a = color
        self.lut.SetTableValue(1, r, g, b, a)

        if not self.map:
            self.map = vtk.vtkImageMapToRGBA()
        self.map.SetOutputFormatToRGBA()
        self.map.SetLookupTable(self.lut)

        if not self.thresh:
            self.thresh = vtk.vtkImageThreshold()
        sliceLogic = self.sliceWidget.sliceLogic()
        backgroundLogic = sliceLogic.GetBackgroundLayer()
        if vtk.VTK_MAJOR_VERSION <= 5:
            self.thresh.SetInput(backgroundLogic.GetReslice().GetOutput())
        else:
            self.thresh.SetInputConnection(
                backgroundLogic.GetReslice().GetOutputPort())
        self.thresh.ThresholdBetween(self.min, self.max)
        self.thresh.SetInValue(1)
        self.thresh.SetOutValue(0)
        self.thresh.SetOutputScalarTypeToUnsignedChar()
        if vtk.VTK_MAJOR_VERSION <= 5:
            self.map.SetInput(self.thresh.GetOutput())
            self.map.Update()
            self.cursorMapper.SetInput(self.map.GetOutput())
        else:
            self.map.SetInputConnection(self.thresh.GetOutputPort())
            self.cursorMapper.SetInputConnection(self.map.GetOutputPort())

        self.cursorActor.VisibilityOn()

        self.sliceView.scheduleRender()
  def preview(self,color=None):

    if not self.editUtil.getBackgroundImage() or not self.editUtil.getLabelImage():
      return

    #
    # make a lookup table where inside the threshold is opaque and colored
    # by the label color, while the background is transparent (black)
    # - apply the threshold operation to the currently visible background
    #   (output of the layer logic's vtkImageReslice instance)
    #

    if not color:
      color = self.getPaintColor

    if not self.lut:
      self.lut = vtk.vtkLookupTable()

    self.lut.SetRampToLinear()
    self.lut.SetNumberOfTableValues( 3 )
    self.lut.SetTableRange( 0, 2 )
    self.lut.SetTableValue( 0,  0, 0, 0,  0 )
    r,g,b,a = color
    self.lut.SetTableValue( 1,  r, g, b,  a )
    #self.lut.SetTableValue( 2,  r, g, b,  a )

    if not self.map:
      self.map = vtk.vtkImageMapToRGBA()
    self.map.SetOutputFormatToRGBA()
    self.map.SetLookupTable( self.lut )

    if not self.thresh:
      self.thresh = vtk.vtkImageThreshold()
    sliceLogic = self.sliceWidget.sliceLogic()
    backgroundLogic = sliceLogic.GetBackgroundLayer()
#    backgroundNodeName = backgroundNode.GetName()
#    backgroundImage = sitk.ReadImage( sitkUtils.GetSlicerITKReadWriteAddress( backgroundNodeName ) )

    self.thresh.SetInput( backgroundLogic.GetReslice().GetOutput() )
    self.thresh.ThresholdBetween( self.min, self.max )
    self.thresh.SetInValue( 1 )
    self.thresh.SetOutValue( 0 )
    self.thresh.SetOutputScalarTypeToUnsignedChar()
    self.map.SetInput( self.thresh.GetOutput() )

    self.map.Update()

    self.cursorMapper.SetInput( self.map.GetOutput() )
    self.cursorActor.VisibilityOn()

    self.sliceView.scheduleRender()