def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkImageQuantizeRGBToIndex(), 'Processing.', ('vtkImageData',), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkImageQuantizeRGBToIndex(), 'Processing.', ('vtkImageData', ), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Read the data. Note this creates a 3-component scalar. red = vtk.vtkPNGReader() red.SetFileName(VTK_DATA_ROOT + "/Data/RedCircle.png") red.Update() # Next filter can only handle RGB *(&&*@ extract = vtk.vtkImageExtractComponents() extract.SetInputConnection(red.GetOutputPort()) extract.SetComponents(0,1,2) # Quantize the image into an index quantize = vtk.vtkImageQuantizeRGBToIndex() quantize.SetInputConnection(extract.GetOutputPort()) quantize.SetNumberOfColors(3) # Create the pipeline discrete = vtk.vtkDiscreteFlyingEdges2D() discrete.SetInputConnection(quantize.GetOutputPort()) discrete.SetValue(0,0) # Create polgons polyLoops = vtk.vtkContourLoopExtraction() polyLoops.SetInputConnection(discrete.GetOutputPort()) # Triangle filter because concave polygons are not rendered correctly triF = vtk.vtkTriangleFilter() triF.SetInputConnection(polyLoops.GetOutputPort())
#!/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 --
image.Update() mapper = vtk.vtkFixedPointVolumeRayCastMapper() #mapper.SetInput(image) volproperty = vtk.vtkVolumeProperty() #volproperty.IndependentComponentsOff() #red = vtk.vtkColorTransferFunction() #red.Set volume = vtk.vtkVolume() volume.SetMapper(mapper) volume.SetProperty(volproperty) # we want an indexed image indexer = vtk.vtkImageQuantizeRGBToIndex() indexer.SetInput(image) #indexer.SetNumberOfColors(5) # causes errors! indexedImage = indexer.GetOutput() indexedImage.Update() lookuptable = indexer.GetLookupTable() # fix annoyance with indexed image for i in xrange(20): for j in xrange(20): for k in xrange(20): value = indexedImage.GetScalarComponentAsFloat(i,j,k,0) if value % 2 == 0: indexedImage.SetScalarComponentFromFloat(i,j,k,0,0) mapper.SetInput(indexedImage)
# for some reason on the mac, the tiff reader gives us a four # component image - doesn't unless we are using QuantizeRGBToIndex extract = vtk.vtkImageExtractComponents() extract.SetInput(image) extract.SetComponents(0, 1, 2) image = extract.GetOutput() image.Update() mapper = vtk.vtkFixedPointVolumeRayCastMapper() volproperty = vtk.vtkVolumeProperty() volume = vtk.vtkVolume() volume.SetMapper(mapper) volume.SetProperty(volproperty) # we want an indexed image indexer = vtk.vtkImageQuantizeRGBToIndex() indexer.SetInput(image) #indexer.SetNumberOfColors(5) # causes errors! indexedImage = indexer.GetOutput() indexedImage.Update() lookuptable = indexer.GetLookupTable() #print lookuptable x0 = 0 y0 = 0 z0 = 0 #clip image so we can reasonably look at it ## clipper = vtk.vtkImageClip() ## clipper.SetInput(indexedImage) ## newsize = 50