def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkVolume16Reader(), 'Reading vtkVolume16.', (), ('vtkVolume16',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def vtkReadVolumAll(self, filename): """ Chargement des fichiers images dicom""" #----------------------------------------- # Creation de la donnee volumique #----------------------------------------- self.vtkVolumAll = vtk.vtkVolume16Reader() self.vtkVolumAll.SetDataDimensions(self.col, self.lig) self.vtkVolumAll.SetDataByteOrderToLittleEndian() self.vtkVolumAll.SetFilePrefix(filename) self.vtkVolumAll.SetImageRange(1, self.nb_coupe) self.vtkVolumAll.SetDataSpacing(self.pixel_spacing_x, self.pixel_spacing_y, self.slice_spacing) self.SizeOfVolum = np.array([self.lig*self.pixel_spacing_x,self.col*self.pixel_spacing_y,self.slice_spacing*self.nb_coupe]) self.NumpyData = np.zeros((self.lig,self.col,self.nb_coupe),int) for i in range(self.nb_coupe): self.NumpyData[:,:,i] = vtk_to_np(self.vtkVolumAll.GetImage(i+1).GetPointData().GetArray(0)).reshape(self.lig,self.col)
def vtk_rendering(): renWin = iren.GetRenderWindow() aRenderer = vtk.vtkRenderer() renWin.AddRenderer(aRenderer) # Read Dataset using vtkVolume16Reader v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(dataDir) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) # An isosurface, or contour value of 500 is known to correspond to the surfaceExtractor.SetInputConnection(v16.GetOutputPort()) surfaceExtractor.SetValue(0, 500) surfaceNormals = vtk.vtkPolyDataNormals() surfaceNormals.SetInputConnection(surfaceExtractor.GetOutputPort()) surfaceNormals.SetFeatureAngle(60.0) surfaceMapper = vtk.vtkPolyDataMapper() surfaceMapper.SetInputConnection(surfaceNormals.GetOutputPort()) surfaceMapper.ScalarVisibilityOff() surface = vtk.vtkActor() surface.SetMapper(surfaceMapper) aCamera = vtk.vtkCamera() aCamera.SetViewUp(0, 0, -1) aCamera.SetPosition(0, 1, 0) aCamera.SetFocalPoint(0, 0, 0) aCamera.ComputeViewPlaneNormal() aRenderer.AddActor(surface) aRenderer.SetActiveCamera(aCamera) aRenderer.ResetCamera() aRenderer.SetBackground(0, 0, 0) aRenderer.ResetCameraClippingRange() # Interact with the data. iren.Initialize() renWin.Render() iren.Start() iren.show()
def main(argv): if os.name == 'nt': VTK_DATA_ROOT = "c:/VTK82/build_Release/ExternalData/Testing/" else: VTK_DATA_ROOT = "/home/jmh/" if 1: v16 = vtk.vtkMetaImageReader() v16.SetFileName("/home/jmh/github/fis/data/Abdomen/CT-Abdomen.mhd") v16.Update() elif 0: fname = os.path.join(VTK_DATA_ROOT, "Data/headsq/quarter") v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.SetFilePrefix(fname) v16.ReleaseDataFlagOn() v16.SetDataMask(0x7fff) v16.Update() else: v16 = vtk.vtkMetaImageReader() v16.SetFileName("c:/github/fis/data/Abdomen/CT-Abdomen.mhd") v16.Update() rng = v16.GetOutput().GetScalarRange() shifter = vtk.vtkImageShiftScale() shifter.SetShift(-1.0*rng[0]) shifter.SetScale(255.0/(rng[1]-rng[0])) shifter.SetOutputScalarTypeToUnsignedChar() shifter.SetInputConnection(v16.GetOutputPort()) shifter.ReleaseDataFlagOff() shifter.Update() ImageViewer = vtk.vtkImageViewer2() ImageViewer.SetInputData(shifter.GetOutput()) ImageViewer.SetColorLevel(127) ImageViewer.SetColorWindow(255) iren = vtk.vtkRenderWindowInteractor() ImageViewer.SetupInteractor(iren) ImageViewer.Render() ImageViewer.GetRenderer().ResetCamera() ImageViewer.Render() dims = v16.GetOutput().GetDimensions() global minArea spacing = v16.GetOutput().GetSpacing() minArea = ( spacing[0] * spacing[1] ) / 0.1 # Slider screen representation SliderRepres = vtk.vtkSliderRepresentation2D() _min = ImageViewer.GetSliceMin() _max = ImageViewer.GetSliceMax() SliderRepres.SetMinimumValue(_min) SliderRepres.SetMaximumValue(_max) SliderRepres.SetValue(int((_min + _max) / 2)) SliderRepres.SetTitleText("Slice") SliderRepres.GetPoint1Coordinate().SetCoordinateSystemToNormalizedDisplay() SliderRepres.GetPoint1Coordinate().SetValue(0.3, 0.05) SliderRepres.GetPoint2Coordinate().SetCoordinateSystemToNormalizedDisplay() SliderRepres.GetPoint2Coordinate().SetValue(0.7, 0.05) SliderRepres.SetSliderLength(0.02) SliderRepres.SetSliderWidth(0.03) SliderRepres.SetEndCapLength(0.01) SliderRepres.SetEndCapWidth(0.03) SliderRepres.SetTubeWidth(0.005) SliderRepres.SetLabelFormat("%3.0lf") SliderRepres.SetTitleHeight(0.02) SliderRepres.SetLabelHeight(0.02) # Slider widget SliderWidget = vtk.vtkSliderWidget() SliderWidget.SetInteractor(iren) SliderWidget.SetRepresentation(SliderRepres) SliderWidget.KeyPressActivationOff() SliderWidget.SetAnimationModeToAnimate() SliderWidget.SetEnabled(True) SliderCb = vtkSliderCallback() SliderCb.SetImageViewer(ImageViewer) SliderWidget.AddObserver(vtk.vtkCommand.InteractionEvent, SliderCb.Execute) ImageViewer.SetSlice(int(SliderRepres.GetValue())) # Contour representation - responsible for placement of points, calculation of lines and contour manipulation global rep rep = vtk.vtkOrientedGlyphContourRepresentation() # vtkContourRepresentation has GetActiveNodeWorldPostion/Orientation rep.GetProperty().SetOpacity(0) #1 prop = rep.GetLinesProperty() from vtkUtils import renderLinesAsTubes from vtk.util.colors import red, green, pink, yellow renderLinesAsTubes(prop) prop.SetColor(yellow) propActive = rep.GetActiveProperty() #propActive.SetOpacity(0) # 2 renderLinesAsTubes(propActive) propActive.SetColor(green) shapeActive = rep.GetActiveCursorShape() warp = vtk.vtkWarpVector() warp.SetInputData(shapeActive) warp.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, vtk.vtkDataSetAttributes.NORMALS) scale = 0.4 warp.SetScaleFactor(scale) warp.Update() rep.SetActiveCursorShape(warp.GetOutput()) # Use vtkContourTriangulator to fill contours # Point placer imageActorPointPlacer = vtk.vtkImageActorPointPlacer() imageActorPointPlacer.SetImageActor(ImageViewer.GetImageActor()) rep.SetPointPlacer(imageActorPointPlacer) global ContourWidget # Contour widget - has a vtkWidgetEventTranslator which translate events to vtkContourWidget events ContourWidget = vtk.vtkContourWidget() ContourWidget.SetRepresentation(rep) ContourWidget.SetInteractor(iren) ContourWidget.SetEnabled(True) ContourWidget.ProcessEventsOn() ContourWidget.ContinuousDrawOn() # Can be Initialize() using polydata # Override methods that returns display position to get an overlay # (display postions) instead of computing it from world position and # the method BuildLines to interpolate using display positions # instead of world positions # Thinning of contour control points # AddFinalPointAction ContourWidget.AddObserver(vtk.vtkCommand.EndInteractionEvent, callback) if 0: # TODO: Make interior transparent contour = ContourWidget.GetContourRepresentation().GetContourRepresentationAsPolyData() tc = vtk.vtkContourTriangulator() tc.SetInputData(contour) tc.Update() # Extrusion towards camera extruder = vtk.vtkLinearExtrusionFilter() extruder.CappingOn() extruder.SetScalaFactor(1.0) extruder.SetInputData(tc.GetOutput()) extruder.SetVector(0,0,1.0) extruder.SetExtrusionTypeToNormalExtrusion() polyMapper = vtk.vtkPolyMapper() polyMapper.SetInputConnection(extruder.GetOutputPort()) polyMapper.ScalarVisibilityOn() polyMapper.Update() polyActor = vtk.vtkActor() polyActor.SetMapper(polyMapper) prop = polyActor.GetProperty() prop.SetColor(0,1,0) #prop.SetRepresentationToWireframe() renderer.AddActor(polyActor) renderer.GetRenderWindow().Render() iren.Start()
def testSkinOrder(self): # Create the RenderWindow, Renderer and Interactor # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) RESOLUTION = 64 START_SLICE = 50 END_SLICE = 60 PIXEL_SIZE = 3.2 centerX = RESOLUTION / 2 centerY = RESOLUTION / 2 centerZ = (END_SLICE - START_SLICE) / 2 endX = RESOLUTION - 1 endY = RESOLUTION - 1 endZ = END_SLICE - 1 origin = (RESOLUTION / 2.0) * PIXEL_SIZE * -1.0 math = vtk.vtkMath() orders = ["ap", "pa", "si", "iss", "lr", "rl"] sliceOrder = SliceOrder.SliceOrder() reader = list() iso = list() mapper = list() actor = list() skinColors = [ [0.875950, 0.598302, 0.656878], [0.641134, 0.536594, 0.537889], [0.804079, 0.650506, 0.558249], [0.992896, 0.603716, 0.660385], [0.589101, 0.513448, 0.523095], [0.650247, 0.700527, 0.752458], ] for idx, order in enumerate(orders): reader.append(vtk.vtkVolume16Reader()) reader[idx].SetDataDimensions(RESOLUTION, RESOLUTION) reader[idx].SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") reader[idx].SetDataSpacing(PIXEL_SIZE, PIXEL_SIZE, 1.5) reader[idx].SetDataOrigin(origin, origin, 1.5) reader[idx].SetImageRange(START_SLICE, END_SLICE) if order == "ap": reader[idx].SetTransform(sliceOrder.ap) elif order == "pa": reader[idx].SetTransform(sliceOrder.pa) elif order == "si": reader[idx].SetTransform(sliceOrder.si) elif order == "iss": reader[idx].SetTransform(sliceOrder.iss) elif order == "lr": reader[idx].SetTransform(sliceOrder.lr) elif order == "rl": reader[idx].SetTransform(sliceOrder.rl) else: s = "No such transform exists." raise Exception(s) reader[idx].SetHeaderSize(0) reader[idx].SetDataMask(0x7FFF) reader[idx].SetDataByteOrderToLittleEndian() reader[idx].GetExecutive().SetReleaseDataFlag(0, 1) iso.append(vtk.vtkContourFilter()) iso[idx].SetInputConnection(reader[idx].GetOutputPort()) iso[idx].SetValue(0, 550.5) iso[idx].ComputeScalarsOff() iso[idx].ReleaseDataFlagOn() mapper.append(vtk.vtkPolyDataMapper()) mapper[idx].SetInputConnection(iso[idx].GetOutputPort()) mapper[idx].ImmediateModeRenderingOn() actor.append(vtk.vtkActor()) actor[idx].SetMapper(mapper[idx]) # r = math.Random(.5, 1) # g = math.Random(.5, 1) # b = math.Random(.5, 1) # print r, g, b actor[idx].GetProperty().SetDiffuseColor( # math.Random(.5, 1), math.Random(.5, 1), math.Random(.5, 1)) # r, g, b) skinColors[idx] ) ren.AddActor(actor[idx]) renWin.SetSize(300, 300) ren.ResetCamera() ren.GetActiveCamera().Azimuth(210) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() ren.SetBackground(0.8, 0.8, 0.8) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) renWin.Render() img_file = "skinOrder.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def testSkinOrder(self): # Create the RenderWindow, Renderer and Interactor # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) RESOLUTION = 64 START_SLICE = 50 END_SLICE = 60 PIXEL_SIZE = 3.2 centerX = RESOLUTION / 2 centerY = RESOLUTION / 2 centerZ = (END_SLICE - START_SLICE) / 2 endX = RESOLUTION - 1 endY = RESOLUTION - 1 endZ = END_SLICE - 1 origin = (RESOLUTION / 2.0) * PIXEL_SIZE * -1.0 math = vtk.vtkMath() orders = ["ap", "pa", "si", "iss", "lr", "rl"] sliceOrder = SliceOrder.SliceOrder() reader = list() iso = list() mapper = list() actor = list() skinColors = [[0.875950, 0.598302, 0.656878], [0.641134, 0.536594, 0.537889], [0.804079, 0.650506, 0.558249], [0.992896, 0.603716, 0.660385], [0.589101, 0.513448, 0.523095], [0.650247, 0.700527, 0.752458]] for idx, order in enumerate(orders): reader.append(vtk.vtkVolume16Reader()) reader[idx].SetDataDimensions(RESOLUTION, RESOLUTION) reader[idx].SetFilePrefix(VTK_DATA_ROOT + '/Data/headsq/quarter') reader[idx].SetDataSpacing(PIXEL_SIZE, PIXEL_SIZE, 1.5) reader[idx].SetDataOrigin(origin, origin, 1.5) reader[idx].SetImageRange(START_SLICE, END_SLICE) if order == "ap": reader[idx].SetTransform(sliceOrder.ap) elif order == "pa": reader[idx].SetTransform(sliceOrder.pa) elif order == "si": reader[idx].SetTransform(sliceOrder.si) elif order == "iss": reader[idx].SetTransform(sliceOrder.iss) elif order == "lr": reader[idx].SetTransform(sliceOrder.lr) elif order == "rl": reader[idx].SetTransform(sliceOrder.rl) else: s = "No such transform exists." raise Exception(s) reader[idx].SetHeaderSize(0) reader[idx].SetDataMask(0x7fff) reader[idx].SetDataByteOrderToLittleEndian() reader[idx].GetExecutive().SetReleaseDataFlag(0, 1) iso.append(vtk.vtkContourFilter()) iso[idx].SetInputConnection(reader[idx].GetOutputPort()) iso[idx].SetValue(0, 550.5) iso[idx].ComputeScalarsOff() iso[idx].ReleaseDataFlagOn() mapper.append(vtk.vtkPolyDataMapper()) mapper[idx].SetInputConnection(iso[idx].GetOutputPort()) mapper[idx].ImmediateModeRenderingOn() actor.append(vtk.vtkActor()) actor[idx].SetMapper(mapper[idx]) # r = math.Random(.5, 1) # g = math.Random(.5, 1) # b = math.Random(.5, 1) # print r, g, b actor[idx].GetProperty().SetDiffuseColor( # math.Random(.5, 1), math.Random(.5, 1), math.Random(.5, 1)) # r, g, b) skinColors[idx]) ren.AddActor(actor[idx]) renWin.SetSize(300, 300) ren.ResetCamera() ren.GetActiveCamera().Azimuth(210) ren.GetActiveCamera().Elevation(30) ren.GetActiveCamera().Dolly(1.2) ren.ResetCameraClippingRange() ren.SetBackground(.8, .8, .8) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) renWin.Render() img_file = "skinOrder.png" vtk.test.Testing.compareImage( iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def testBug(self): # Uncomment the next line if you want to run this via # `gdb python`. #raw_input('Hit Ctrl-C') # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetOutput().GetWholeExtent() img_data = v16.GetOutput() # ************************************************** # Look here for wierdness. # Lets create this data using the data from the reader. my_img_data = vtk.vtkImageData() my_img_data.SetDimensions(img_data.GetDimensions()) my_img_data.SetWholeExtent(img_data.GetWholeExtent()) my_img_data.SetExtent(img_data.GetExtent()) my_img_data.SetUpdateExtent(img_data.GetUpdateExtent()) my_img_data.SetSpacing(img_data.GetSpacing()) my_img_data.SetOrigin(img_data.GetOrigin()) my_img_data.SetScalarType(img_data.GetScalarType()) my_img_data.GetPointData().SetScalars(img_data.GetPointData().GetScalars()) my_img_data.Update() # hang on to original image data. orig_img_data = img_data # hijack img_data with our own. If you comment this out everything is # fine. img_data = my_img_data # ************************************************** spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInput(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInput(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInput(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInput(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()
# Create the renderer, the render window, and the interactor. The renderer # draws into the render window, the interactor enables mouse- and # keyboard-based interaction with the scene. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # The following reader is used to read a series of 2D slices (images) # that compose the volume. The slice dimensions are set, and the # pixel spacing. The data Endianness must also be specified. The reader # usese the FilePrefix in combination with the slice number to construct # filenames using the format FilePrefix.%d. (In this case the FilePrefix # is the root name of the file: quarter.) v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetImageRange(1, 93) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") v16.SetDataSpacing(3.2, 3.2, 1.5) # The volume will be displayed by ray-cast alpha compositing. # A ray-cast mapper is needed to do the ray-casting, and a # compositing function is needed to do the compositing along the ray. rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction() volumeMapper = vtk.vtkVolumeRayCastMapper() volumeMapper.SetInputConnection(v16.GetOutputPort()) volumeMapper.SetVolumeRayCastFunction(rayCastFunction)
def __init__(self): # Create the renderer, the render window, and the interactor. The # renderer draws into the render window, the interactor enables mouse- # and keyboard-based interaction with the scene. self.ren = vtk.vtkRenderer() self.renwin = vtk.vtkRenderWindow() self.renwin.AddRenderer(self.ren) self.iren = vtk.vtkRenderWindowInteractor() self.iren.SetRenderWindow(self.renwin) # Create text mappers and 2d actors to display finger position. self.fingerMarker1 = Marker("(1)") self.fingerMarker2 = Marker("(2)") self.fingerMarker3 = Marker("(3)") # The following reader is used to read a series of 2D slices (images) # that compose the volume. The slice dimensions are set, and the # pixel spacing. The data Endianness must also be specified. The reader # usese the FilePrefix in combination with the slice number to construct # filenames using the format FilePrefix.%d. (In this case the FilePrefix # is the root name of the file: quarter.) self.v16 = vtk.vtkVolume16Reader() self.v16.SetDataDimensions(64, 64) self.v16.SetDataByteOrderToLittleEndian() self.v16.SetFilePrefix("/Users/eddie/Programming/Python/python-vtk-tuio/headsq/Data_headsq_quarter") self.v16.SetImageRange(1, 93) self.v16.SetDataSpacing(3.2, 3.2, 1.5) # An isosurface, or contour value of 500 is known to correspond to the # skin of the patient. Once generated, a vtkPolyDataNormals filter is # is used to create normals for smooth surface shading during rendering. # The triangle stripper is used to create triangle strips from the # isosurface these render much faster on may systems. self.skinExtractor = vtk.vtkContourFilter() self.skinExtractor.SetInputConnection(self.v16.GetOutputPort()) self.skinExtractor.SetValue(0, 500) self.skinNormals = vtk.vtkPolyDataNormals() self.skinNormals.SetInputConnection(self.skinExtractor.GetOutputPort()) self.skinNormals.SetFeatureAngle(60.0) self.skinStripper = vtk.vtkStripper() self.skinStripper.SetInputConnection(self.skinNormals.GetOutputPort()) self.skinMapper = vtk.vtkPolyDataMapper() self.skinMapper.SetInputConnection(self.skinStripper.GetOutputPort()) self.skinMapper.ScalarVisibilityOff() self.skin = vtk.vtkActor() self.skin.SetMapper(self.skinMapper) self.skin.GetProperty().SetDiffuseColor(1, .49, .25) self.skin.GetProperty().SetSpecular(.3) self.skin.GetProperty().SetSpecularPower(20) # An isosurface, or contour value of 1150 is known to correspond to the # skin of the patient. Once generated, a vtkPolyDataNormals filter is # is used to create normals for smooth surface shading during rendering. # The triangle stripper is used to create triangle strips from the # isosurface these render much faster on may systems. self.boneExtractor = vtk.vtkContourFilter() self.boneExtractor.SetInputConnection(self.v16.GetOutputPort()) self.boneExtractor.SetValue(0, 1150) self.boneNormals = vtk.vtkPolyDataNormals() self.boneNormals.SetInputConnection(self.boneExtractor.GetOutputPort()) self.boneNormals.SetFeatureAngle(60.0) self.boneStripper = vtk.vtkStripper() self.boneStripper.SetInputConnection(self.boneNormals.GetOutputPort()) self.boneMapper = vtk.vtkPolyDataMapper() self.boneMapper.SetInputConnection(self.boneStripper.GetOutputPort()) self.boneMapper.ScalarVisibilityOff() self.bone = vtk.vtkActor() self.bone.SetMapper(self.boneMapper) self.bone.GetProperty().SetDiffuseColor(1, 1, .9412) # An outline provides context around the data. self.outlineData = vtk.vtkOutlineFilter() self.outlineData.SetInputConnection(self.v16.GetOutputPort()) self.mapOutline = vtk.vtkPolyDataMapper() self.mapOutline.SetInputConnection(self.outlineData.GetOutputPort()) self.outline = vtk.vtkActor() self.outline.SetMapper(self.mapOutline) self.outline.GetProperty().SetColor(0, 0, 0) # Now we are creating three orthogonal planes passing through the # volume. Each plane uses a different texture map and therefore has # diferent coloration. # Start by creatin a black/white lookup table. self.bwLut = vtk.vtkLookupTable() self.bwLut.SetTableRange(0, 2000) self.bwLut.SetSaturationRange(0, 0) self.bwLut.SetHueRange(0, 0) self.bwLut.SetValueRange(0, 1) self.bwLut.Build() # Now create a lookup table that consists of the full hue circle (from # HSV). self.hueLut = vtk.vtkLookupTable() self.hueLut.SetTableRange(0, 2000) self.hueLut.SetHueRange(0, 1) self.hueLut.SetSaturationRange(1, 1) self.hueLut.SetValueRange(1, 1) self.hueLut.Build() # Finally, create a lookup table with a single hue but having a range # in the saturation of the hue. self.satLut = vtk.vtkLookupTable() self.satLut.SetTableRange(0, 2000) self.satLut.SetHueRange(.6, .6) self.satLut.SetSaturationRange(0, 1) self.satLut.SetValueRange(1, 1) self.satLut.Build() # Create the first of the three planes. The filter vtkImageMapToColors # maps the data through the corresponding lookup table created above. # The vtkImageActor is a type of vtkProp and conveniently displays an # image on a single quadrilateral plane. It does this using texture # mapping and as a result is quite fast. (Note: the input image has to # be unsigned char values, which the vtkImageMapToColors produces.) # Note also that by specifying the DisplayExtent, the pipeline # requests data of this extent and the vtkImageMapToColors only # processes a slice of data. self.sagittalColors = vtk.vtkImageMapToColors() self.sagittalColors.SetInputConnection(self.v16.GetOutputPort()) self.sagittalColors.SetLookupTable(self.bwLut) self.sagittal = vtk.vtkImageActor() self.sagittal.GetMapper().SetInputConnection(self.sagittalColors.GetOutputPort()) self.sagittal.SetDisplayExtent(32, 32, 0, 63, 0, 92) # Create the second (axial) plane of the three planes. We use the same # approach as before except that the extent differs. self.axialColors = vtk.vtkImageMapToColors() self.axialColors.SetInputConnection(self.v16.GetOutputPort()) self.axialColors.SetLookupTable(self.hueLut) self.axial = vtk.vtkImageActor() self.axial.GetMapper().SetInputConnection(self.axialColors.GetOutputPort()) self.axial.SetDisplayExtent(0, 63, 0, 63, 46, 46) # Create the third (coronal) plane of the three planes. We use the same # approach as before except that the extent differs. self.coronalColors = vtk.vtkImageMapToColors() self.coronalColors.SetInputConnection(self.v16.GetOutputPort()) self.coronalColors.SetLookupTable(self.satLut) self.coronal = vtk.vtkImageActor() self.coronal.GetMapper().SetInputConnection(self.coronalColors.GetOutputPort()) self.coronal.SetDisplayExtent(0, 63, 32, 32, 0, 92) # move camera to view sagital slice self.aCamera = vtk.vtkCamera() self.aCamera.SetPosition(1,0,0) # view from positive x axis self.aCamera.SetViewUp(0,0,1) # z axis self.aCamera.Roll(180) # rotate 180 degrees # Actors are added to the renderer. #self.ren.AddActor(self.outline) self.ren.AddActor(self.sagittal) #self.ren.AddActor(self.axial) #self.ren.AddActor(self.coronal) #self.ren.AddActor(self.skin) #self.ren.AddActor(self.bone) self.ren.AddActor2D(self.fingerMarker1.textActor) self.ren.AddActor2D(self.fingerMarker2.textActor) self.ren.AddActor2D(self.fingerMarker3.textActor) # Turn off bone for this example. self.bone.VisibilityOff() # Set skin to semi-transparent. self.skin.GetProperty().SetOpacity(0.5) # An initial camera view is created. The Dolly() method moves # the camera towards the FocalPoint, thereby enlarging the image. self.ren.SetActiveCamera(self.aCamera) self.ren.ResetCamera() self.aCamera.Dolly(1.5) # Set a background color for the renderer and set the size of the # render window (expressed in pixels). self.ren.SetBackground(1, 1, 1) self.renwin.SetSize(640, 480) #self.renwin.FullScreenOn() # Note that when camera movement occurs (as it does in the Dolly() # method), the clipping planes often need adjusting. Clipping planes # consist of two planes: near and far along the view direction. The # near plane clips out objects in front of the plane the far plane # clips out objects behind the plane. This way only what is drawn # between the planes is actually rendered. self.ren.ResetCameraClippingRange() ''' TUIO STUFF ''' self.tracking = tuio.Tracking('') self.tracker = CursorTracker(4) self.terminate = False
def testVolumePicker(self): # volume render a medical data set # renderer and interactor ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) # read the volume v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetImageRange(1, 93) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") v16.SetDataSpacing(3.2, 3.2, 1.5) #--------------------------------------------------------- # set up the volume rendering volumeMapper = vtk.vtkFixedPointVolumeRayCastMapper() volumeMapper.SetInputConnection(v16.GetOutputPort()) volumeColor = vtk.vtkColorTransferFunction() volumeColor.AddRGBPoint(0, 0.0, 0.0, 0.0) volumeColor.AddRGBPoint(180, 0.3, 0.1, 0.2) volumeColor.AddRGBPoint(1000, 1.0, 0.7, 0.6) volumeColor.AddRGBPoint(2000, 1.0, 1.0, 0.9) volumeScalarOpacity = vtk.vtkPiecewiseFunction() volumeScalarOpacity.AddPoint(0, 0.0) volumeScalarOpacity.AddPoint(180, 0.0) volumeScalarOpacity.AddPoint(1000, 0.2) volumeScalarOpacity.AddPoint(2000, 0.8) volumeGradientOpacity = vtk.vtkPiecewiseFunction() volumeGradientOpacity.AddPoint(0, 0.0) volumeGradientOpacity.AddPoint(90, 0.5) volumeGradientOpacity.AddPoint(100, 1.0) volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(volumeColor) volumeProperty.SetScalarOpacity(volumeScalarOpacity) volumeProperty.SetGradientOpacity(volumeGradientOpacity) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() volumeProperty.SetAmbient(0.6) volumeProperty.SetDiffuse(0.6) volumeProperty.SetSpecular(0.1) volume = vtk.vtkVolume() volume.SetMapper(volumeMapper) volume.SetProperty(volumeProperty) #--------------------------------------------------------- # Do the surface rendering boneExtractor = vtk.vtkMarchingCubes() boneExtractor.SetInputConnection(v16.GetOutputPort()) boneExtractor.SetValue(0, 1150) boneNormals = vtk.vtkPolyDataNormals() boneNormals.SetInputConnection(boneExtractor.GetOutputPort()) boneNormals.SetFeatureAngle(60.0) boneStripper = vtk.vtkStripper() boneStripper.SetInputConnection(boneNormals.GetOutputPort()) boneMapper = vtk.vtkPolyDataMapper() boneMapper.SetInputConnection(boneStripper.GetOutputPort()) boneMapper.ScalarVisibilityOff() boneProperty = vtk.vtkProperty() boneProperty.SetColor(1.0, 1.0, 0.9) bone = vtk.vtkActor() bone.SetMapper(boneMapper) bone.SetProperty(boneProperty) #--------------------------------------------------------- # Create an image actor table = vtk.vtkLookupTable() table.SetRange(0, 2000) table.SetRampToLinear() table.SetValueRange(0, 1) table.SetHueRange(0, 0) table.SetSaturationRange(0, 0) mapToColors = vtk.vtkImageMapToColors() mapToColors.SetInputConnection(v16.GetOutputPort()) mapToColors.SetLookupTable(table) imageActor = vtk.vtkImageActor() imageActor.GetMapper().SetInputConnection(mapToColors.GetOutputPort()) imageActor.SetDisplayExtent(32, 32, 0, 63, 0, 92) #--------------------------------------------------------- # make a transform and some clipping planes transform = vtk.vtkTransform() transform.RotateWXYZ(-20, 0.0, -0.7, 0.7) volume.SetUserTransform(transform) bone.SetUserTransform(transform) imageActor.SetUserTransform(transform) c = volume.GetCenter() volumeClip = vtk.vtkPlane() volumeClip.SetNormal(0, 1, 0) volumeClip.SetOrigin(c) boneClip = vtk.vtkPlane() boneClip.SetNormal(0, 0, 1) boneClip.SetOrigin(c) volumeMapper.AddClippingPlane(volumeClip) boneMapper.AddClippingPlane(boneClip) #--------------------------------------------------------- ren.AddViewProp(volume) ren.AddViewProp(bone) ren.AddViewProp(imageActor) camera = ren.GetActiveCamera() camera.SetFocalPoint(c) camera.SetPosition(c[0] + 500, c[1] - 100, c[2] - 100) camera.SetViewUp(0, 0, -1) ren.ResetCameraClippingRange() renWin.Render() #--------------------------------------------------------- # the cone should point along the Z axis coneSource = vtk.vtkConeSource() coneSource.CappingOn() coneSource.SetHeight(12) coneSource.SetRadius(5) coneSource.SetResolution(31) coneSource.SetCenter(6, 0, 0) coneSource.SetDirection(-1, 0, 0) #--------------------------------------------------------- picker = vtk.vtkVolumePicker() picker.SetTolerance(1.0e-6) picker.SetVolumeOpacityIsovalue(0.01) # This should usually be left alone, but is used here to increase coverage picker.UseVolumeGradientOpacityOn() # A function to point an actor along a vector def PointCone(actor, n): if n[0] < 0.0: actor.RotateWXYZ(180, 0, 1, 0) actor.RotateWXYZ(180, (n[0] - 1.0) * 0.5, n[1] * 0.5, n[2] * 0.5) else: actor.RotateWXYZ(180, (n[0] + 1.0) * 0.5, n[1] * 0.5, n[2] * 0.5) # Pick the actor picker.Pick(192, 103, 0, ren) #print picker p = picker.GetPickPosition() n = picker.GetPickNormal() coneActor1 = vtk.vtkActor() coneActor1.PickableOff() coneMapper1 = vtk.vtkDataSetMapper() coneMapper1.SetInputConnection(coneSource.GetOutputPort()) coneActor1.SetMapper(coneMapper1) coneActor1.GetProperty().SetColor(1, 0, 0) coneActor1.SetPosition(p) PointCone(coneActor1, n) ren.AddViewProp(coneActor1) # Pick the volume picker.Pick(90, 180, 0, ren) p = picker.GetPickPosition() n = picker.GetPickNormal() coneActor2 = vtk.vtkActor() coneActor2.PickableOff() coneMapper2 = vtk.vtkDataSetMapper() coneMapper2.SetInputConnection(coneSource.GetOutputPort()) coneActor2.SetMapper(coneMapper2) coneActor2.GetProperty().SetColor(1, 0, 0) coneActor2.SetPosition(p) PointCone(coneActor2, n) ren.AddViewProp(coneActor2) # Pick the image picker.Pick(200, 200, 0, ren) p = picker.GetPickPosition() n = picker.GetPickNormal() coneActor3 = vtk.vtkActor() coneActor3.PickableOff() coneMapper3 = vtk.vtkDataSetMapper() coneMapper3.SetInputConnection(coneSource.GetOutputPort()) coneActor3.SetMapper(coneMapper3) coneActor3.GetProperty().SetColor(1, 0, 0) coneActor3.SetPosition(p) PointCone(coneActor3, n) ren.AddViewProp(coneActor3) # Pick a clipping plane picker.PickClippingPlanesOn() picker.Pick(145, 160, 0, ren) p = picker.GetPickPosition() n = picker.GetPickNormal() coneActor4 = vtk.vtkActor() coneActor4.PickableOff() coneMapper4 = vtk.vtkDataSetMapper() coneMapper4.SetInputConnection(coneSource.GetOutputPort()) coneActor4.SetMapper(coneMapper4) coneActor4.GetProperty().SetColor(1, 0, 0) coneActor4.SetPosition(p) PointCone(coneActor4, n) ren.AddViewProp(coneActor4) ren.ResetCameraClippingRange() # render and interact with data renWin.Render() img_file = "VolumePicker.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
#!/usr/local/bin/python import os import vtk from WindowLevelInterface import WindowLevelInterface # Create reader - you have total flexibility to specify the file # naming pattern, the byte order, the size of the header and so on reader = vtk.vtkVolume16Reader() reader.SetDataDimensions(256,256) reader.GetOutput().SetOrigin(0.0,0.0,0.0) reader.SetFilePrefix('../data/images/r') reader.SetFilePattern( '%s%d.ima') reader.SetDataByteOrderToBigEndian() reader.SetImageRange(1001,1060) reader.SetDataSpacing(1.0,1.0,3.5) reader.Update() # VTK comes with a helper class to view slice data viewer = vtk.vtkImageViewer() viewer.SetInput(reader.GetOutput()) viewer.SetZSlice(30) viewer.SetColorWindow(600) viewer.SetColorLevel(270) viewer.Render() viewer.SetPosition(50,50) # A helper class to set the window level, etc WindowLevelInterface(viewer)
def get_actors(args): # The following reader is used to read a series of 2D slices (images) # that compose the volume. The slice dimensions are set, and the # pixel spacing. The data Endianness must also be specified. The reader # usese the FilePrefix in combination with the slice number to construct # filenames using the format FilePrefix.%d. (In this case the FilePrefix # is the root name of the file: quarter.) v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(args[0]) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) # An isosurface, or contour value of 500 is known to correspond to the # skin of the patient. Once generated, a vtkPolyDataNormals filter is # is used to create normals for smooth surface shading during rendering. # The triangle stripper is used to create triangle strips from the # isosurface these render much faster on may systems. skinExtractor = vtk.vtkContourFilter() skinExtractor.SetInputConnection(v16.GetOutputPort()) skinExtractor.SetValue(0, 500) skinNormals = vtk.vtkPolyDataNormals() skinNormals.SetInputConnection(skinExtractor.GetOutputPort()) skinNormals.SetFeatureAngle(60.0) skinStripper = vtk.vtkStripper() skinStripper.SetInputConnection(skinNormals.GetOutputPort()) skinMapper = vtk.vtkPolyDataMapper() skinMapper.SetInputConnection(skinStripper.GetOutputPort()) skinMapper.ScalarVisibilityOff() skin = vtk.vtkActor() skin.SetMapper(skinMapper) skin.GetProperty().SetDiffuseColor(1, .49, .25) skin.GetProperty().SetSpecular(.3) skin.GetProperty().SetSpecularPower(20) # An isosurface, or contour value of 1150 is known to correspond to the # skin of the patient. Once generated, a vtkPolyDataNormals filter is # is used to create normals for smooth surface shading during rendering. # The triangle stripper is used to create triangle strips from the # isosurface these render much faster on may systems. boneExtractor = vtk.vtkContourFilter() boneExtractor.SetInputConnection(v16.GetOutputPort()) boneExtractor.SetValue(0, 1150) boneNormals = vtk.vtkPolyDataNormals() boneNormals.SetInputConnection(boneExtractor.GetOutputPort()) boneNormals.SetFeatureAngle(60.0) boneStripper = vtk.vtkStripper() boneStripper.SetInputConnection(boneNormals.GetOutputPort()) boneMapper = vtk.vtkPolyDataMapper() boneMapper.SetInputConnection(boneStripper.GetOutputPort()) boneMapper.ScalarVisibilityOff() bone = vtk.vtkActor() bone.SetMapper(boneMapper) bone.GetProperty().SetDiffuseColor(1, 1, .9412) # An outline provides context around the data. outlineData = vtk.vtkOutlineFilter() outlineData.SetInputConnection(v16.GetOutputPort()) mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outlineData.GetOutputPort()) outline = vtk.vtkActor() outline.SetMapper(mapOutline) outline.GetProperty().SetColor(0, 0, 0) return (outline, skin, bone)
def generateDemoData( self ): VTK_DATA_ROOT = getVTKDataRoot() if not self.dataset in demoDatasets: print>>sys.stderr, "Unknown dataset: %s " % self.dataset self.dataset = demoDatasets[0] if self.dataset == 'head': self.reader = vtk.vtkVolume16Reader() self.reader.SetDataDimensions(64, 64) self.reader.SetDataByteOrderToLittleEndian() self.reader.SetFilePrefix( VTK_DATA_ROOT + "/Data/headsq/quarter" ) self.reader.SetImageRange(1, 93) self.reader.SetDataSpacing(3.2, 3.2, 1.5) # self.addMetadata( self.reader.GetOutput() ) self.reader.AddObserver( "EndEvent", self.addMetadataObserver ) self.set3DOutput( port=self.reader.GetOutputPort() ) if self.dataset == 'iron': self.reader = vtk.vtkStructuredPointsReader() self.reader.SetFileName( VTK_DATA_ROOT + "/Data/ironProt.vtk" ) # self.addMetadata( self.reader.GetOutput() ) self.reader.AddObserver( "EndEvent", self.addMetadataObserver ) self.set3DOutput( port=self.reader.GetOutputPort() ) # if dataset == 'dust': # filePath = os.path.normpath( "%s/../../data/DustCloud.nc" % packagePath ) # self.dataSet = Dataset( filePath, 'r' ) # self.variableList = self.dataSet.variables.keys() # print " --- input vars: " + str( self.variableList ) # outputImage = vtk.vtkImageData() # self.imageSource = vtk.vtkImageSource() # self.imageSource.SetOutput( outputImage ) # return self.imageSource.GetOutputPort() if self.dataset == 'wind': # dataFile = "yotc_UV_1.nc" # undefVal = -999000000.0 # invertZVal = False # self.NCDR = NetCDFDataWrapper( dataFile, invertZ=invertZVal, undef=undefVal) # outputImage = self.NCDR.GetFloatVectorImageData( [ "u", "v" ], 0, self.fieldData ) self.dataWrapper = GradsReader.GradsDataWrapper( glob='*e5ncep.*.ctl', TimeRange=[ 1, self.maxNTS ] ) self.timeSteps = self.dataWrapper.getTimeSteps() self.imageData = self.dataWrapper.GetImageVectorData( self.fieldData, var=[ 'uf', 'vf', None ] ) self.set3DOutput( output=self.imageData ) if self.dataset == 'putman': dataFile = "/Developer/Data/Putman/Fortuna-cubed-c2000_latlon.inst3_3d_asm1Np.20100208_0000z.nc" undefVal = 1.0e15 invertZVal = False self.NCDR = NetCDFDataWrapper( dataFile, invertZ=invertZVal, undef=undefVal) outputImage = self.NCDR.GetShortImageData( "T", 0, self.fieldData ) self.set3DOutput( output=self.imageData ) if self.dataset == 'e5ncep': self.dataWrapper = GradsReader.GradsDataWrapper( glob='*e5ncep.*.ctl', TimeRange=[ 1, self.maxNTS ] ) self.timeSteps = self.dataWrapper.getTimeSteps() self.dataWrapper.SetCurrentVariable( 'tf', self.timeSteps[self.timeIndex] ) self.dataWrapper.ImportTimeSeries() self.imageData = self.dataWrapper.GetImageData( self.fieldData ) # pointData = imageData.GetPointData() # array0 = pointData.GetArray(0) # printArgs( "GRADS IMAGE DATA", npts= imageData.GetNumberOfPoints(), ncells= imageData.GetNumberOfCells(), ncomp= imageData.GetNumberOfScalarComponents(), img_len= imageData.GetLength() ) # printArgs( "GRADS IMAGE EXT", extent= imageData.GetExtent(), spacing= imageData.GetSpacing(), origin= imageData.GetOrigin(), dim= imageData.GetDimensions() ) # printArgs( "GRADS POINT DATA", ntup= pointData.GetNumberOfTuples(), narrays= pointData.GetNumberOfArrays(), ncomp= pointData.GetNumberOfComponents()) # printArgs( "GRADS Array DATA", ntup= array0.GetNumberOfTuples(), size= array0.GetSize(), dsize= array0.GetDataSize(), range= array0.GetRange(), maxid= array0.GetMaxId(), ncomp= array0.GetNumberOfComponents() ) self.set3DOutput( output=self.imageData )
def testImagePlaneWidget(self): "A more rigorous test using the image plane widget." # This test is largely copied from # Widgets/Python/TestImagePlaneWidget.py # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0)) img_data = v16.GetOutput() spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInputData(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInputData(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInputData(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInputData(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Now create another actor with an opacity < 1 and with some # scalars. p = vtk.vtkPolyData() pts = vtk.vtkPoints() pts.InsertNextPoint((0,0,0)) sc = vtk.vtkFloatArray() sc.InsertNextValue(1.0) p.SetPoints(pts) p.GetPointData().SetScalars(sc) m = vtk.vtkPolyDataMapper() m.SetInputData(p) # Share the lookup table of the widgets. m.SetLookupTable(planeWidgetX.GetLookupTable()) m.UseLookupTableScalarRangeOn() dummyActor = vtk.vtkActor() dummyActor.SetMapper(m) dummyActor.GetProperty().SetOpacity(0.0) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) # Add the dummy actor. ren.AddActor(dummyActor) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()
import vtk from vtk.util.colors import tan ## Load in skull model reader = vtk.vtkVolume16Reader() reader.SetDataDimensions(64, 64) reader.SetImageRange(1, 93) reader.SetDataByteOrderToLittleEndian() reader.SetFilePrefix("./assets/headsq/quarter") reader.SetDataSpacing(3.2, 3.2, 1.5) ## Load in skin model skinFilePath = r"./assets/skin.vtk" skinReader = vtk.vtkPolyDataReader() skinReader.SetFileName(skinFilePath) skinReader.Update() ## Apply contourfilter to skull model contourFilter = vtk.vtkContourFilter() contourFilter.SetInputConnection(reader.GetOutputPort()) ### Setting this to 500, 1150 creates a strange ring around most of the skeleton contourFilter.SetValue(0, 1150) ## Use the information from the contourfilter for the skull mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(contourFilter.GetOutputPort()) mapper.ScalarVisibilityOff() ## Add skin model to mapper skinMapper = vtk.vtkDataSetMapper() skinMapper.SetInputConnection(skinReader.GetOutputPort())
def testImagePlaneWidget(self): "A more rigorous test using the image plane widget." # This test is largely copied from # Widgets/Python/TestImagePlaneWidget.py # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0)) img_data = v16.GetOutput() spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInputData(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInputData(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInputData(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInputData(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Now create another actor with an opacity < 1 and with some # scalars. p = vtk.vtkPolyData() pts = vtk.vtkPoints() pts.InsertNextPoint((0, 0, 0)) sc = vtk.vtkFloatArray() sc.InsertNextValue(1.0) p.SetPoints(pts) p.GetPointData().SetScalars(sc) m = vtk.vtkPolyDataMapper() m.SetInputData(p) # Share the lookup table of the widgets. m.SetLookupTable(planeWidgetX.GetLookupTable()) m.UseLookupTableScalarRangeOn() dummyActor = vtk.vtkActor() dummyActor.SetMapper(m) dummyActor.GetProperty().SetOpacity(0.0) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) # Add the dummy actor. ren.AddActor(dummyActor) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera() cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render()
def generateDemoData(self): VTK_DATA_ROOT = getVTKDataRoot() if not self.dataset in demoDatasets: print >> sys.stderr, "Unknown dataset: %s " % self.dataset self.dataset = demoDatasets[0] if self.dataset == 'head': self.reader = vtk.vtkVolume16Reader() self.reader.SetDataDimensions(64, 64) self.reader.SetDataByteOrderToLittleEndian() self.reader.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") self.reader.SetImageRange(1, 93) self.reader.SetDataSpacing(3.2, 3.2, 1.5) # self.addMetadata( self.reader.GetOutput() ) self.reader.AddObserver("EndEvent", self.addMetadataObserver) self.set3DOutput(port=self.reader.GetOutputPort()) if self.dataset == 'iron': self.reader = vtk.vtkStructuredPointsReader() self.reader.SetFileName(VTK_DATA_ROOT + "/Data/ironProt.vtk") # self.addMetadata( self.reader.GetOutput() ) self.reader.AddObserver("EndEvent", self.addMetadataObserver) self.set3DOutput(port=self.reader.GetOutputPort()) # if dataset == 'dust': # filePath = os.path.normpath( "%s/../../data/DustCloud.nc" % packagePath ) # self.dataSet = Dataset( filePath, 'r' ) # self.variableList = self.dataSet.variables.keys() # print " --- input vars: " + str( self.variableList ) # outputImage = vtk.vtkImageData() # self.imageSource = vtk.vtkImageSource() # self.imageSource.SetOutput( outputImage ) # return self.imageSource.GetOutputPort() if self.dataset == 'wind': # dataFile = "yotc_UV_1.nc" # undefVal = -999000000.0 # invertZVal = False # self.NCDR = NetCDFDataWrapper( dataFile, invertZ=invertZVal, undef=undefVal) # outputImage = self.NCDR.GetFloatVectorImageData( [ "u", "v" ], 0, self.fieldData ) self.dataWrapper = GradsReader.GradsDataWrapper( glob='*e5ncep.*.ctl', TimeRange=[1, self.maxNTS]) self.timeSteps = self.dataWrapper.getTimeSteps() self.imageData = self.dataWrapper.GetImageVectorData( self.fieldData, var=['uf', 'vf', None]) self.set3DOutput(output=self.imageData) if self.dataset == 'putman': dataFile = "/Developer/Data/Putman/Fortuna-cubed-c2000_latlon.inst3_3d_asm1Np.20100208_0000z.nc" undefVal = 1.0e15 invertZVal = False self.NCDR = NetCDFDataWrapper(dataFile, invertZ=invertZVal, undef=undefVal) outputImage = self.NCDR.GetShortImageData("T", 0, self.fieldData) self.set3DOutput(output=self.imageData) if self.dataset == 'e5ncep': self.dataWrapper = GradsReader.GradsDataWrapper( glob='*e5ncep.*.ctl', TimeRange=[1, self.maxNTS]) self.timeSteps = self.dataWrapper.getTimeSteps() self.dataWrapper.SetCurrentVariable('tf', self.timeSteps[self.timeIndex]) self.dataWrapper.ImportTimeSeries() self.imageData = self.dataWrapper.GetImageData(self.fieldData) # pointData = imageData.GetPointData() # array0 = pointData.GetArray(0) # printArgs( "GRADS IMAGE DATA", npts= imageData.GetNumberOfPoints(), ncells= imageData.GetNumberOfCells(), ncomp= imageData.GetNumberOfScalarComponents(), img_len= imageData.GetLength() ) # printArgs( "GRADS IMAGE EXT", extent= imageData.GetExtent(), spacing= imageData.GetSpacing(), origin= imageData.GetOrigin(), dim= imageData.GetDimensions() ) # printArgs( "GRADS POINT DATA", ntup= pointData.GetNumberOfTuples(), narrays= pointData.GetNumberOfArrays(), ncomp= pointData.GetNumberOfComponents()) # printArgs( "GRADS Array DATA", ntup= array0.GetNumberOfTuples(), size= array0.GetSize(), dsize= array0.GetDataSize(), range= array0.GetRange(), maxid= array0.GetMaxId(), ncomp= array0.GetNumberOfComponents() ) self.set3DOutput(output=self.imageData)
rgb = [0.0, 0.0, 0.0] # black vtk.vtkNamedColors().GetColorRGB(colorName, rgb) return rgb # Create the RenderWindow, Renderer and both Actors # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # create pipeline # v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.GetOutput().SetOrigin(0.0, 0.0, 0.0) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(VTK_DATA_ROOT + "/Data/headsq/quarter") v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() iso = vtk.vtkImageMarchingCubes() iso.SetInputConnection(v16.GetOutputPort()) iso.SetValue(0, 1150) iso.SetInputMemoryLimit(1000) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort())
def testBug(self): # Uncomment the next line if you want to run this via # `gdb python`. #raw_input('Hit Ctrl-C') # Load some data. v16 = vtk.vtkVolume16Reader() v16.SetDataDimensions(64, 64) v16.SetDataByteOrderToLittleEndian() v16.SetFilePrefix(os.path.join(Testing.VTK_DATA_ROOT, "Data", "headsq", "quarter")) v16.SetImageRange(1, 93) v16.SetDataSpacing(3.2, 3.2, 1.5) v16.Update() xMin, xMax, yMin, yMax, zMin, zMax = v16.GetExecutive().GetWholeExtent(v16.GetOutputInformation(0)) img_data = v16.GetOutput() # ************************************************** # Look here for wierdness. # Lets create this data using the data from the reader. my_img_data = vtk.vtkImageData() my_img_data.SetDimensions(img_data.GetDimensions()) # my_img_data.SetWholeExtent(img_data.GetWholeExtent()) my_img_data.SetExtent(img_data.GetExtent()) # my_img_data.SetUpdateExtent(img_data.GetUpdateExtent()) my_img_data.SetSpacing(img_data.GetSpacing()) my_img_data.SetOrigin(img_data.GetOrigin()) my_img_data.SetScalarType(img_data.GetScalarType(), my_img_data.GetInformation()) my_img_data.GetPointData().SetScalars(img_data.GetPointData().GetScalars()) # hang on to original image data. orig_img_data = img_data # hijack img_data with our own. If you comment this out everything is # fine. img_data = my_img_data # ************************************************** spacing = img_data.GetSpacing() sx, sy, sz = spacing origin = img_data.GetOrigin() ox, oy, oz = origin # An outline is shown for context. outline = vtk.vtkOutlineFilter() outline.SetInputData(img_data) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # The shared picker enables us to use 3 planes at one time # and gets the picking order right picker = vtk.vtkCellPicker() picker.SetTolerance(0.005) # The 3 image plane widgets are used to probe the dataset. planeWidgetX = vtk.vtkImagePlaneWidget() planeWidgetX.DisplayTextOn() planeWidgetX.SetInputData(img_data) planeWidgetX.SetPlaneOrientationToXAxes() planeWidgetX.SetSliceIndex(32) planeWidgetX.SetPicker(picker) planeWidgetX.SetKeyPressActivationValue("x") prop1 = planeWidgetX.GetPlaneProperty() prop1.SetColor(1, 0, 0) planeWidgetY = vtk.vtkImagePlaneWidget() planeWidgetY.DisplayTextOn() planeWidgetY.SetInputData(img_data) planeWidgetY.SetPlaneOrientationToYAxes() planeWidgetY.SetSliceIndex(32) planeWidgetY.SetPicker(picker) planeWidgetY.SetKeyPressActivationValue("y") prop2 = planeWidgetY.GetPlaneProperty() prop2.SetColor(1, 1, 0) planeWidgetY.SetLookupTable(planeWidgetX.GetLookupTable()) # for the z-slice, turn off texture interpolation: # interpolation is now nearest neighbour, to demonstrate # cross-hair cursor snapping to pixel centers planeWidgetZ = vtk.vtkImagePlaneWidget() planeWidgetZ.DisplayTextOn() planeWidgetZ.SetInputData(img_data) planeWidgetZ.SetPlaneOrientationToZAxes() planeWidgetZ.SetSliceIndex(46) planeWidgetZ.SetPicker(picker) planeWidgetZ.SetKeyPressActivationValue("z") prop3 = planeWidgetZ.GetPlaneProperty() prop3.SetColor(0, 0, 1) planeWidgetZ.SetLookupTable(planeWidgetX.GetLookupTable()) # Create the RenderWindow and Renderer ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) # Add the outline actor to the renderer, set the background # color and size ren.AddActor(outlineActor) renWin.SetSize(600, 600) ren.SetBackground(0.1, 0.1, 0.2) current_widget = planeWidgetZ mode_widget = planeWidgetZ # Set the interactor for the widgets iact = vtk.vtkRenderWindowInteractor() iact.SetRenderWindow(renWin) planeWidgetX.SetInteractor(iact) planeWidgetX.On() planeWidgetY.SetInteractor(iact) planeWidgetY.On() planeWidgetZ.SetInteractor(iact) planeWidgetZ.On() # Create an initial interesting view ren.ResetCamera(); cam1 = ren.GetActiveCamera() cam1.Elevation(110) cam1.SetViewUp(0, 0, -1) cam1.Azimuth(45) ren.ResetCameraClippingRange() iact.Initialize() renWin.Render() # Compare the images and test. img_file = "TestImagePlaneWidget.png" Testing.compareImage(renWin, Testing.getAbsImagePath(img_file)) # Interact if necessary. if Testing.isInteractive(): iact.Start()
def render3d(directory, mouse_queue, mouse_move_event): # Create the renderer, the render window, and the interactor. The renderer # draws into the render window, the interactor enables mouse- and # keyboard-based interaction with the scene. renderer = vtk.vtkRenderer() render_window = vtk.vtkRenderWindow() render_window.SetWindowName("Test") render_window.AddRenderer(renderer) interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(render_window) # The following reader is used to read a series of 2D slices (images) # that compose the volume. The slice dimensions are set, and the # pixel spacing. The data Endianness must also be specified. The reader # usese the FilePrefix in combination with the slice number to construct # filenames using the format FilePrefix.%d. (In this case the FilePrefix # is the root name of the file: quarter.) reader = vtk.vtkVolume16Reader() reader.SetDataDimensions(256, 256) reader.SetImageRange(1, 99) reader.SetDataByteOrderToLittleEndian() reader.SetFilePrefix(os.path.join(directory, 'image')) data_spacing = (1, 1, 2) reader.SetDataSpacing(data_spacing[0], data_spacing[1], data_spacing[2]) volume_mapper = vtk.vtkSmartVolumeMapper() volume_mapper.SetInputConnection(reader.GetOutputPort()) volume_mapper.SetBlendModeToComposite() # Cutting plane plane = vtk.vtkPlane() plane.SetOrigin(0, 0, 2) plane.SetNormal(0, 0, 1) # create cutter cutter = vtk.vtkCutter() cutter.SetCutFunction(plane) cutter.SetInputConnection(reader.GetOutputPort()) cutter.Update() cutterMapper = vtk.vtkPolyDataMapper() cutterMapper.SetInputConnection(cutter.GetOutputPort()) # create plane actor planeActor = vtk.vtkActor() planeActor.GetProperty().SetColor(1.0, 1, 0) planeActor.GetProperty().SetLineWidth(2) planeActor.SetMapper(cutterMapper) volume_color = vtk.vtkColorTransferFunction() volume_color.AddRGBPoint(0, 0.0, 0.0, 0.0) volume_color.AddRGBPoint(500, 1.0, 0.5, 0.3) volume_color.AddRGBPoint(1000, 1.0, 0.5, 0.3) volume_color.AddRGBPoint(1150, 1.0, 1.0, 0.9) # The opacity transfer function is used to control the opacity # of different tissue types. volume_scalar_opacity = vtk.vtkPiecewiseFunction() volume_scalar_opacity.AddPoint(0, 0.00) volume_scalar_opacity.AddPoint(500, 0.15) volume_scalar_opacity.AddPoint(1000, 0.15) volume_scalar_opacity.AddPoint(1150, 0.85) # The gradient opacity function is used to decrease the opacity # in the "flat" regions of the volume while maintaining the opacity # at the boundaries between tissue types. The gradient is measured # as the amount by which the intensity changes over unit distance. # For most medical data, the unit distance is 1mm. volume_gradient_opacity = vtk.vtkPiecewiseFunction() volume_gradient_opacity.AddPoint(0, 0.0) volume_gradient_opacity.AddPoint(90, 0.5) volume_gradient_opacity.AddPoint(100, 1.0) # The VolumeProperty attaches the color and opacity functions to the # volume, and sets other volume properties. The interpolation should # be set to linear to do a high-quality rendering. The ShadeOn option # turns on directional lighting, which will usually enhance the # appearance of the volume and make it look more "3D". However, # the quality of the shading depends on how accurately the gradient # of the volume can be calculated, and for noisy data the gradient # estimation will be very poor. The impact of the shading can be # decreased by increasing the Ambient coefficient while decreasing # the Diffuse and Specular coefficient. To increase the impact # of shading, decrease the Ambient and increase the Diffuse and Specular. volumeProperty = vtk.vtkVolumeProperty() volumeProperty.SetColor(volume_color) volumeProperty.SetScalarOpacity(volume_scalar_opacity) volumeProperty.SetGradientOpacity(volume_gradient_opacity) volumeProperty.SetInterpolationTypeToLinear() volumeProperty.ShadeOn() volumeProperty.SetAmbient(0.4) volumeProperty.SetDiffuse(0.6) volumeProperty.SetSpecular(0.2) # The vtkVolume is a vtkProp3D (like a vtkActor) and controls the position # and orientation of the volume in world coordinates. volume = vtk.vtkVolume() volume.SetMapper(volume_mapper) volume.SetProperty(volumeProperty) # Finally, add the volume to the renderer renderer.AddViewProp(volume) renderer.AddActor(planeActor) # Set up an initial view of the volume. The focal point will be the # center of the volume, and the camera position will be 400mm to the # patient's left (which is our right). camera = renderer.GetActiveCamera() c = volume.GetCenter() camera.SetFocalPoint(c[0], c[1], c[2]) camera.SetPosition(c[0] + 400, c[1], c[2]) camera.SetViewUp(0, 0, -1) # Increase the size of the render window render_window.SetSize(640, 480) # Interact with the data. interactor.Initialize() def test(arg1, arg2): slice_numbers = [] while not mouse_queue.empty(): slice_numbers += [mouse_queue.get()] if len(slice_numbers) > 0: slice = slice_numbers[-1] plane.SetOrigin(0, 0, data_spacing[2] * slice) render_window.Render() interactor.AddObserver(vtk.vtkCommand.TimerEvent, test) timerId = interactor.CreateRepeatingTimer(1) render_window.Render() interactor.Start()