def __init__(self): self.lookupTable = vtk.vtkLookupTable() self.lookupTable.SetRampToLinear() self.lookupTable.SetNumberOfTableValues(2) self.lookupTable.SetTableRange(0, 1) self.lookupTable.SetTableValue(0, 0, 0, 0, 0) self.colorMapper = vtk.vtkImageMapToRGBA() self.colorMapper.SetOutputFormatToRGBA() self.colorMapper.SetLookupTable(self.lookupTable) self.thresholdFilter = vtk.vtkImageThreshold() self.thresholdFilter.SetInValue(1) self.thresholdFilter.SetOutValue(0) self.thresholdFilter.SetOutputScalarTypeToUnsignedChar() # Feedback actor self.mapper = vtk.vtkImageMapper() self.dummyImage = vtk.vtkImageData() self.dummyImage.AllocateScalars(vtk.VTK_UNSIGNED_INT, 1) self.mapper.SetInputData(self.dummyImage) self.actor = vtk.vtkActor2D() self.actor.VisibilityOff() self.actor.SetMapper(self.mapper) self.mapper.SetColorWindow(255) self.mapper.SetColorLevel(128) # Setup pipeline self.colorMapper.SetInputConnection( self.thresholdFilter.GetOutputPort()) self.mapper.SetInputConnection(self.colorMapper.GetOutputPort())
def __init__(self): self.lookupTable = vtk.vtkLookupTable() self.lookupTable.SetRampToLinear() self.lookupTable.SetNumberOfTableValues(2) self.lookupTable.SetTableRange(0, 1) self.lookupTable.SetTableValue(0, 0, 0, 0, 0) self.colorMapper = vtk.vtkImageMapToRGBA() self.colorMapper.SetOutputFormatToRGBA() self.colorMapper.SetLookupTable(self.lookupTable) self.thresholdFilter = vtk.vtkImageThreshold() self.thresholdFilter.SetInValue(1) self.thresholdFilter.SetOutValue(0) self.thresholdFilter.SetOutputScalarTypeToUnsignedChar() # Feedback actor self.mapper = vtk.vtkImageMapper() self.dummyImage = vtk.vtkImageData() self.dummyImage.AllocateScalars(vtk.VTK_UNSIGNED_INT, 1) self.mapper.SetInputData(self.dummyImage) self.actor = vtk.vtkActor2D() self.actor.VisibilityOff() self.actor.SetMapper(self.mapper) self.mapper.SetColorWindow(255) self.mapper.SetColorLevel(128) # Setup pipeline self.colorMapper.SetInputConnection(self.thresholdFilter.GetOutputPort()) self.mapper.SetInputConnection(self.colorMapper.GetOutputPort())
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkImageMapToRGBA(), 'Processing.', ('vtkImageData',), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkImageMapToRGBA(), 'Processing.', ('vtkImageData', ), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
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( 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()
#!/usr/bin/env python import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Make an image larger by repeating the data. Tile. # Image pipeline reader = vtk.vtkPNMReader() reader.ReleaseDataFlagOff() reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/earth.ppm") pad = vtk.vtkImageMirrorPad() pad.SetInputConnection(reader.GetOutputPort()) pad.SetOutputWholeExtent(-120, 320, -120, 320, 0, 0) quant = vtk.vtkImageQuantizeRGBToIndex() quant.SetInputConnection(pad.GetOutputPort()) quant.SetNumberOfColors(16) quant.Update() map = vtk.vtkImageMapToRGBA() map.SetInputConnection(quant.GetOutputPort()) map.SetLookupTable(quant.GetLookupTable()) viewer = vtk.vtkImageViewer() viewer.SetInputConnection(map.GetOutputPort()) viewer.SetColorWindow(256) viewer.SetColorLevel(127) viewer.GetActor2D().SetDisplayPosition(110, 110) viewer.Render() # --- end of script --
#!/usr/bin/env python import vtk from vtk.test import Testing from vtk.util.misc import vtkGetDataRoot VTK_DATA_ROOT = vtkGetDataRoot() # Make an image larger by repeating the data. Tile. # Image pipeline reader = vtk.vtkPNMReader() reader.ReleaseDataFlagOff() reader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/earth.ppm") pad = vtk.vtkImageMirrorPad() pad.SetInputConnection(reader.GetOutputPort()) pad.SetOutputWholeExtent(-120,320,-120,320,0,0) quant = vtk.vtkImageQuantizeRGBToIndex() quant.SetInputConnection(pad.GetOutputPort()) quant.SetNumberOfColors(16) quant.Update() map = vtk.vtkImageMapToRGBA() map.SetInputConnection(quant.GetOutputPort()) map.SetLookupTable(quant.GetLookupTable()) viewer = vtk.vtkImageViewer() viewer.SetInputConnection(map.GetOutputPort()) viewer.SetColorWindow(256) viewer.SetColorLevel(127) viewer.GetActor2D().SetDisplayPosition(110,110) viewer.Render() # --- end of script --