def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkImageShrink3D(), 'Processing.', ('vtkImageData',), ('vtkImageData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkImageShrink3D(), 'Processing.', ('vtkImageData', ), ('vtkImageData', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def decimateImage( self, image, decx, decy ): image.Update() dims = image.GetDimensions() image_size = dims[0] * dims[1] result = image if image_size > MAX_IMAGE_SIZE: resample = vtk.vtkImageShrink3D() resample.SetInput( image ) resample.SetShrinkFactors( decx, decy, 1 ) result = resample.GetOutput() result.Update() return result
def decimateImage(self, image, decx, decy): image.Update() dims = image.GetDimensions() image_size = dims[0] * dims[1] result = image if image_size > MAX_IMAGE_SIZE: resample = vtk.vtkImageShrink3D() resample.SetInput(image) resample.SetShrinkFactors(decx, decy, 1) result = resample.GetOutput() result.Update() return result
def createMesh(self, polyData, spacing): dv = 1.75 rf = 1 data_matrix = polyData data_matrix = np.rot90(data_matrix, 1) data_matrix = data_matrix.astype(np.uint8) xSize, ySize, zSize = data_matrix.shape #================================BoneExtrctor================================== dataImporter = vtk.vtkImageImport() data_string = data_matrix.tostring() dataImporter.CopyImportVoidPointer(data_string, len(data_string)) dataImporter.SetDataScalarTypeToUnsignedChar() dataImporter.SetNumberOfScalarComponents(1) dataImporter.SetDataExtent(0, xSize - 1, 0, ySize - 1, 0, zSize - 1) dataImporter.SetWholeExtent(0, xSize - 1, 0, ySize - 1, 0, zSize - 1) dataImporter.SetDataExtentToWholeExtent() #============================= Smoothed pipeline ============================== smooth = vtk.vtkImageGaussianSmooth() smooth.SetDimensionality(3) smooth.SetInputConnection(dataImporter.GetOutputPort()) smooth.SetStandardDeviations(dv, dv, dv) smooth.SetRadiusFactor(rf) subsampleSmoothed = vtk.vtkImageShrink3D() subsampleSmoothed.SetInputConnection(smooth.GetOutputPort()) subsampleSmoothed.SetShrinkFactors(4, 4, 1) isoSmoothed = vtk.vtkImageMarchingCubes() isoSmoothed.SetInputConnection(smooth.GetOutputPort()) isoSmoothed.SetValue(0, 10) isoSmoothedMapper = vtk.vtkPolyDataMapper() isoSmoothedMapper.SetInputConnection(isoSmoothed.GetOutputPort()) isoSmoothedMapper.ScalarVisibilityOff() tmpTransfor = vtk.vtkTransform() tmpTransfor.Scale(spacing) meshActor = vtk.vtkActor() meshActor.SetMapper(isoSmoothedMapper) meshActor.SetUserTransform(tmpTransfor) return meshActor
def __init__(self): ActorFactory.ActorFactory.__init__(self) # whether to display the volume self._ShowVolume = 1 self._StatusChange = 0 # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # for if we clip in with OrthoPlanes self._OrthoPlanes = None self._ShowOrthoPlanes = 1 self._OrthoPlanesLookupTables = {} self._OrthoPickThreshold = 0.0025 # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume self._ClippingPlanes = [ vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection() ] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) self._Input = None # generate the pipeline self._ImagePrefilter = vtk.vtkImageShrink3D() self._ImageReslice = vtk.vtkImageReslice() self._ImageReslice.SetInterpolationModeToLinear() self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() self._ImageClipsXY = [] self._PlanesXY = [] self._ActorsXY = [] self._PropertyXY = vtk.vtkProperty() self._PropertyXY.SetDiffuse(0) self._PropertyXY.SetAmbient(1) self._ImageClipsYZ = [] self._PlanesYZ = [] self._ActorsYZ = [] self._PropertyYZ = vtk.vtkProperty() self._PropertyYZ.SetDiffuse(0) self._PropertyYZ.SetAmbient(1) self._ImageClipsZX = [] self._PlanesZX = [] self._ActorsZX = [] self._PropertyZX = vtk.vtkProperty() self._PropertyZX.SetDiffuse(0) self._PropertyZX.SetAmbient(1) # a list of the renderer info self._RendererCurrentIndex = {} self._RendererActorList = {} self._RendererObserverList = {} # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the alpha pick threshold for the volume self._PickThreshold = 0.25 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the extent of the texture maps self._VolumeResolution = (64, 64, 64) # the bounds of the volume self._VolumeBounds = None
lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) demModel = vtk.vtkDEMReader() demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demModel.Update() print demModel lo = Scale * demModel.GetElevationBounds()[0] hi = Scale * demModel.GetElevationBounds()[1] demActor = vtk.vtkLODActor() # create a pipeline for each lod mapper shrink16 = vtk.vtkImageShrink3D() shrink16.SetShrinkFactors(16, 16, 1) shrink16.SetInputConnection(demModel.GetOutputPort()) shrink16.AveragingOn() geom16 = vtk.vtkImageDataGeometryFilter() geom16.SetInputConnection(shrink16.GetOutputPort()) geom16.ReleaseDataFlagOn() warp16 = vtk.vtkWarpScalar() warp16.SetInputConnection(geom16.GetOutputPort()) warp16.SetNormal(0, 0, 1) warp16.UseNormalOn() warp16.SetScaleFactor(Scale) warp16.ReleaseDataFlagOn()
def testAllShrinks(self): prefix = VTK_DATA_ROOT + "/Data/headsq/quarter" renWin = vtk.vtkRenderWindow() # Image pipeline reader = vtk.vtkImageReader() reader.SetDataExtent(0, 63, 0, 63, 1, 93) reader.SetFilePrefix(prefix) reader.SetDataByteOrderToLittleEndian() reader.SetDataMask(0x7fff) factor = 4 magFactor = 8 ops = ["Minimum", "Maximum", "Mean", "Median", "NoOp"] shrink = dict() mag = dict() mapper = dict() actor = dict() imager = dict() for operator in ops: shrink.update({operator:vtk.vtkImageShrink3D()}) shrink[operator].SetMean(0) if operator != "NoOp": eval('shrink[operator].' + operator + 'On()') shrink[operator].SetShrinkFactors(factor, factor, factor) shrink[operator].SetInputConnection(reader.GetOutputPort()) mag.update({operator:vtk.vtkImageMagnify()}) mag[operator].SetMagnificationFactors(magFactor, magFactor, magFactor) mag[operator].InterpolateOff() mag[operator].SetInputConnection(shrink[operator].GetOutputPort()) mapper.update({operator:vtk.vtkImageMapper()}) mapper[operator].SetInputConnection(mag[operator].GetOutputPort()) mapper[operator].SetColorWindow(2000) mapper[operator].SetColorLevel(1000) mapper[operator].SetZSlice(45) actor.update({operator:vtk.vtkActor2D()}) actor[operator].SetMapper(mapper[operator]) imager.update({operator:vtk.vtkRenderer()}) imager[operator].AddActor2D(actor[operator]) renWin.AddRenderer(imager[operator]) shrink["Minimum"].Update shrink["Maximum"].Update shrink["Mean"].Update shrink["Median"].Update imager["Minimum"].SetViewport(0, 0, .5, .33) imager["Maximum"].SetViewport(0, .33, .5, .667) imager["Mean"].SetViewport(.5, 0, 1, .33) imager["Median"].SetViewport(.5, .33, 1, .667) imager["NoOp"].SetViewport(0, .667, 1, 1) renWin.SetSize(256, 384) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "TestAllShrinks.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image # orientation accordingly. To overwrite this orientation with a vtk # convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke # SetOrientationType method with parameter value of 4. image1.SetOrientationType(4) image2 = vtk.vtkBMPReader() image2.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") # shrink the images to a reasonable size color = vtk.vtkImageShrink3D() color.SetInputConnection(image1.GetOutputPort()) color.SetShrinkFactors(2, 2, 1) backgroundColor = vtk.vtkImageShrink3D() backgroundColor.SetInputConnection(image2.GetOutputPort()) backgroundColor.SetShrinkFactors(2, 2, 1) # create a greyscale version luminance = vtk.vtkImageLuminance() luminance.SetInputConnection(color.GetOutputPort()) backgroundLuminance = vtk.vtkImageLuminance() backgroundLuminance.SetInputConnection(backgroundColor.GetOutputPort())
def __init__(self): ActorFactory.ActorFactory.__init__(self) self._LookupTable = None # lookup table is currently not used self._ColorTransferFunction = None self._OpacityTransferFunction = None self._RendererObserverList = {} # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume # (these are currently unused) self._ClippingPlanes = [vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection()] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) # generate the pipeline pieces self._Input = None # transform the full-resolution volume self._RayCastReslice = vtk.vtkImageReslice() self._RayCastReslice.SetInterpolationModeToLinear() # subsample the volume for low-res rendering self._ImagePrefilter1 = vtk.vtkImageShrink3D() self._ImagePrefilter2 = vtk.vtkImageShrink3D() # transform the subsampled volume self._ImageReslice1 = vtk.vtkImageReslice() self._ImageReslice1.SetInterpolationModeToLinear() self._ImageReslice2 = vtk.vtkImageReslice() self._ImageReslice2.SetInterpolationModeToLinear() # convert to RGBA for rendering (unused) self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() # strictly for VTK 3.2 compatibility self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the opacity pick threshold for the volume self._PickThreshold = 0.99 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the texture dimensions (later this will be set automatically # to provide the desired interactive rendering time) self._TextureSize = 128 # the bounds of the volume self._VolumeBounds = None # vtkVolume specific stuff self._VolumeProperty = vtk.vtkVolumeProperty() self._VolumeProperty.SetInterpolationTypeToLinear() rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction() self._VolumeRayCastMapper = vtk.vtkVolumeRayCastMapper() self._VolumeRayCastMapper.SetVolumeRayCastFunction(rayCastFunction) self._VolumeRayCastMapper.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: self._VolumeRayCastMapper.AutoAdjustSampleDistancesOff() except: pass self._VolumeTextureMapper1 = vtk.vtkVolumeTextureMapper2D() self._VolumeTextureMapper1.SetTargetTextureSize(old_div(self._TextureSize, 4), old_div(self._TextureSize, 4)) self._VolumeTextureMapper1.SetMaximumNumberOfPlanes( old_div(self._TextureSize, 2)) self._VolumeTextureMapper1.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: # set to the amount of available texture memory (24MB is a good # start) self._VolumeTextureMapper1.SetMaximumStorageSize(24 * 1024 * 1024) except: pass self._VolumeTextureMapper2 = vtk.vtkVolumeTextureMapper2D() self._VolumeTextureMapper2.SetTargetTextureSize(self._TextureSize, self._TextureSize) self._VolumeTextureMapper2.SetMaximumNumberOfPlanes(self._TextureSize) self._VolumeTextureMapper2.SetClippingPlanes( self._ClippingCube.GetClippingPlanes()) try: # vtk 3.2 does not contain this function call: # set to the amount of available texture memory (24MB is a good # start) self._VolumeTextureMapper2.SetMaximumStorageSize(24 * 1024 * 1024) except: pass # set two levels of detail: texture and ray-casting self._Volume = vtk.vtkLODProp3D() self._Volume.PickableOff() idT1 = self._Volume.AddLOD(self._VolumeTextureMapper1, self._VolumeProperty, 0.02) idT2 = self._Volume.AddLOD(self._VolumeTextureMapper2, self._VolumeProperty, 0.1) # remember these LOD id numbers self._lod = [idT1, idT2] # idRC = self._Volume.AddLOD(self._VolumeRayCastMapper, # self._VolumeProperty, # 2.0) self._Volume.SetLODLevel(idT1, 2.0) self._Volume.SetLODLevel(idT2, 1.0)
# Start by loading some data. dem = vtk.vtkDEMReader() dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") dem.Update() Scale = 2 lut = vtk.vtkLookupTable() lut.SetHueRange(0.6, 0) lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) lo = Scale * dem.GetElevationBounds()[0] hi = Scale * dem.GetElevationBounds()[1] shrink = vtk.vtkImageShrink3D() shrink.SetShrinkFactors(4, 4, 1) shrink.SetInputConnection(dem.GetOutputPort()) shrink.AveragingOn() geom = vtk.vtkImageDataGeometryFilter() geom.SetInputConnection(shrink.GetOutputPort()) geom.ReleaseDataFlagOn() warp = vtk.vtkWarpScalar() warp.SetInputConnection(geom.GetOutputPort()) warp.SetNormal(0, 0, 1) warp.UseNormalOn() warp.SetScaleFactor(Scale) warp.ReleaseDataFlagOn()
lutLand.SetNumberOfColors(10) lutLand.SetHueRange(0.1, 0.1) lutLand.SetSaturationRange(0.4, 0.1) lutLand.SetValueRange(0.55, 0.9) lutLand.Build() # The DEM reader reads data and creates an output image. demModel = vtk.vtkDEMReader() demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demModel.Update() # We shrink the terrain data down a bit to yield better performance for # this example. shrinkFactor = 4 shrink = vtk.vtkImageShrink3D() shrink.SetShrinkFactors(shrinkFactor, shrinkFactor, 1) shrink.SetInputConnection(demModel.GetOutputPort()) shrink.AveragingOn() # Convert the image into polygons. geom = vtk.vtkImageDataGeometryFilter() geom.SetInputConnection(shrink.GetOutputPort()) # Warp the polygons based on elevation. warp = vtk.vtkWarpScalar() warp.SetInputConnection(geom.GetOutputPort()) warp.SetNormal(0, 0, 1) warp.UseNormalOn() warp.SetScaleFactor(Scale)
def __init__(self): ActorFactory.ActorFactory.__init__(self) # whether to display the volume self._ShowVolume = 1 self._StatusChange = 0 # create a clipping cube to go with the volume self._ClippingCube = ClippingCubeFactory.ClippingCubeFactory() self.AddChild(self._ClippingCube) self._CubeClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CubeClippingPlanes.AddItem(vtk.vtkPlane()) # for if we clip in with OrthoPlanes self._OrthoPlanes = None self._ShowOrthoPlanes = 1 self._OrthoPlanesLookupTables = {} self._OrthoPickThreshold = 0.0025 # corner clipping planes, in pairs with opposite normals self._CornerClippingPlanes = vtk.vtkPlaneCollection() for i in range(6): self._CornerClippingPlanes.AddItem(vtk.vtkPlane()) # clipping planes for the volume, sorted for the # three chunks that will make up the final volume self._ClippingPlanes = [vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection(), vtk.vtkPlaneCollection()] for i in range(3): planes = self._ClippingPlanes[i] cplanes = self._CornerClippingPlanes bplanes = self._CubeClippingPlanes if i == 0: planes.AddItem(cplanes.GetItemAsObject(0)) planes.AddItem(bplanes.GetItemAsObject(1)) planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(0)) planes.AddItem(cplanes.GetItemAsObject(1)) if i == 1: planes.AddItem(cplanes.GetItemAsObject(2)) planes.AddItem(bplanes.GetItemAsObject(3)) planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(2)) planes.AddItem(cplanes.GetItemAsObject(3)) if i == 2: planes.AddItem(cplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) else: planes.AddItem(bplanes.GetItemAsObject(4)) planes.AddItem(bplanes.GetItemAsObject(5)) self._Input = None # generate the pipeline self._ImagePrefilter = vtk.vtkImageShrink3D() self._ImageReslice = vtk.vtkImageReslice() self._ImageReslice.SetInterpolationModeToLinear() self._ImageMapToColors = vtk.vtkImageMapToColors() self._ImageMapToColors.SetOutputFormatToRGBA() self._ImageToStructuredPoints = vtk.vtkImageToStructuredPoints() self._ImageClipsXY = [] self._PlanesXY = [] self._ActorsXY = [] self._PropertyXY = vtk.vtkProperty() self._PropertyXY.SetDiffuse(0) self._PropertyXY.SetAmbient(1) self._ImageClipsYZ = [] self._PlanesYZ = [] self._ActorsYZ = [] self._PropertyYZ = vtk.vtkProperty() self._PropertyYZ.SetDiffuse(0) self._PropertyYZ.SetAmbient(1) self._ImageClipsZX = [] self._PlanesZX = [] self._ActorsZX = [] self._PropertyZX = vtk.vtkProperty() self._PropertyZX.SetDiffuse(0) self._PropertyZX.SetAmbient(1) # a list of the renderer info self._RendererCurrentIndex = {} self._RendererActorList = {} self._RendererObserverList = {} # a transform to apply to the image self._ImageTransform = None self._TransformToGrid = vtk.vtkTransformToGrid() # the alpha pick threshold for the volume self._PickThreshold = 0.25 # the implicit volume for finding the gradient self._ImplicitVolume = vtk.vtkImplicitVolume() # the extent of the texture maps self._VolumeResolution = (64, 64, 64) # the bounds of the volume self._VolumeBounds = None
def main(): colors = vtk.vtkNamedColors() colors.SetColor("ActorColor", [235, 235, 235, 255]) fileName = get_program_parameters() # Read the image. readerFactory = vtk.vtkImageReader2Factory() reader = readerFactory.CreateImageReader2(fileName) reader.SetFileName(fileName) reader.Update() # Smoothed pipeline. smooth = vtk.vtkImageGaussianSmooth() smooth.SetDimensionality(3) smooth.SetInputConnection(reader.GetOutputPort()) smooth.SetStandardDeviations(1.75, 1.75, 0.0) smooth.SetRadiusFactor(2) subsampleSmoothed = vtk.vtkImageShrink3D() subsampleSmoothed.SetInputConnection(smooth.GetOutputPort()) subsampleSmoothed.SetShrinkFactors(4, 4, 1) isoSmoothed = vtk.vtkImageMarchingCubes() isoSmoothed.SetInputConnection(smooth.GetOutputPort()) isoSmoothed.SetValue(0, 1150) isoSmoothedMapper = vtk.vtkPolyDataMapper() isoSmoothedMapper.SetInputConnection(isoSmoothed.GetOutputPort()) isoSmoothedMapper.ScalarVisibilityOff() isoSmoothedActor = vtk.vtkActor() isoSmoothedActor.SetMapper(isoSmoothedMapper) isoSmoothedActor.GetProperty().SetColor(colors.GetColor3d("ActorColor")) # Unsmoothed pipeline. # Sub sample the data. subsample = vtk.vtkImageShrink3D() subsample.SetInputConnection(reader.GetOutputPort()) subsample.SetShrinkFactors(4, 4, 1) iso = vtk.vtkImageMarchingCubes() iso.SetInputConnection(subsample.GetOutputPort()) iso.SetValue(0, 1150) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(iso.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetColor(colors.GetColor3d("ActorColor")) # The rendering Pipeline. # Setup the render window, renderer, and interactor. leftViewport = [0.0, 0.0, 0.5, 1.0] rightViewport = [0.5, 0.0, 1.0, 1.0] rendererLeft = vtk.vtkRenderer() rendererLeft.SetViewport(leftViewport) rendererRight = vtk.vtkRenderer() rendererRight.SetViewport(rightViewport) renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(rendererLeft) renderWindow.AddRenderer(rendererRight) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) rendererLeft.AddActor(isoActor) rendererRight.AddActor(isoSmoothedActor) rendererLeft.GetActiveCamera().SetFocalPoint(0.0, 0.0, 0.0) rendererLeft.GetActiveCamera().SetPosition(0.0, -1.0, 0.0) rendererLeft.GetActiveCamera().SetViewUp(0.0, 0.0, -1.0) rendererLeft.ResetCamera() rendererLeft.GetActiveCamera().Azimuth(-20.0) rendererLeft.GetActiveCamera().Elevation(20.0) rendererLeft.ResetCameraClippingRange() rendererLeft.SetBackground(colors.GetColor3d("SlateGray")) rendererRight.SetBackground(colors.GetColor3d("LightSlateGray")) rendererRight.SetActiveCamera(rendererLeft.GetActiveCamera()) renderWindow.SetSize(640, 480) renderWindow.Render() renderWindowInteractor.Start()
def testAllMaskBits(self): # This script calculates the luminance of an image renWin = vtk.vtkRenderWindow() # Image pipeline image1 = vtk.vtkTIFFReader() image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image # orientation accordingly. To overwrite this orientation with a vtk # convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke # SetOrientationType method with parameter value of 4. image1.SetOrientationType(4) shrink = vtk.vtkImageShrink3D() shrink.SetInputConnection(image1.GetOutputPort()) shrink.SetShrinkFactors(2, 2, 1) operators = ["ByPass", "And", "Nand", "Xor", "Or", "Nor"] operator = dict() mapper = dict() actor = dict() imager = dict() for idx, op in enumerate(operators): if op != "ByPass": operator.update({idx: vtk.vtkImageMaskBits()}) operator[idx].SetInputConnection(shrink.GetOutputPort()) eval('operator[' + str(idx) + '].SetOperationTo' + op + '()') operator[idx].SetMasks(255, 255, 0) mapper.update({idx: vtk.vtkImageMapper()}) if op != "ByPass": mapper[idx].SetInputConnection(operator[idx].GetOutputPort()) else: mapper[idx].SetInputConnection(shrink.GetOutputPort()) mapper[idx].SetColorWindow(255) mapper[idx].SetColorLevel(127.5) actor.update({idx: vtk.vtkActor2D()}) actor[idx].SetMapper(mapper[idx]) imager.update({idx: vtk.vtkRenderer()}) imager[idx].AddActor2D(actor[idx]) renWin.AddRenderer(imager[idx]) column = 0 row = 0 deltaX = 1.0 / 3.0 deltaY = 1.0 / 2.0 for idx in range(len(operators)): imager[idx].SetViewport(column * deltaX, row * deltaY, (column + 1) * deltaX, (row + 1) * deltaY) column += 1 if column > 2: column = 0 row += 1 renWin.SetSize(384, 256) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "TestAllMaskBits.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def testAllShrinks(self): prefix = VTK_DATA_ROOT + "/Data/headsq/quarter" renWin = vtk.vtkRenderWindow() # Image pipeline reader = vtk.vtkImageReader() reader.SetDataExtent(0, 63, 0, 63, 1, 93) reader.SetFilePrefix(prefix) reader.SetDataByteOrderToLittleEndian() reader.SetDataMask(0x7fff) factor = 4 magFactor = 8 ops = ["Minimum", "Maximum", "Mean", "Median", "NoOp"] shrink = dict() mag = dict() mapper = dict() actor = dict() imager = dict() for operator in ops: shrink.update({operator: vtk.vtkImageShrink3D()}) shrink[operator].SetMean(0) if operator != "NoOp": eval('shrink[operator].' + operator + 'On()') shrink[operator].SetShrinkFactors(factor, factor, factor) shrink[operator].SetInputConnection(reader.GetOutputPort()) mag.update({operator: vtk.vtkImageMagnify()}) mag[operator].SetMagnificationFactors(magFactor, magFactor, magFactor) mag[operator].InterpolateOff() mag[operator].SetInputConnection(shrink[operator].GetOutputPort()) mapper.update({operator: vtk.vtkImageMapper()}) mapper[operator].SetInputConnection(mag[operator].GetOutputPort()) mapper[operator].SetColorWindow(2000) mapper[operator].SetColorLevel(1000) mapper[operator].SetZSlice(45) actor.update({operator: vtk.vtkActor2D()}) actor[operator].SetMapper(mapper[operator]) imager.update({operator: vtk.vtkRenderer()}) imager[operator].AddActor2D(actor[operator]) renWin.AddRenderer(imager[operator]) shrink["Minimum"].Update shrink["Maximum"].Update shrink["Mean"].Update shrink["Median"].Update imager["Minimum"].SetViewport(0, 0, .5, .33) imager["Maximum"].SetViewport(0, .33, .5, .667) imager["Mean"].SetViewport(.5, 0, 1, .33) imager["Median"].SetViewport(.5, .33, 1, .667) imager["NoOp"].SetViewport(0, .667, 1, 1) renWin.SetSize(256, 384) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) renWin.Render() img_file = "TestAllShrinks.png" vtk.test.Testing.compareImage( iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
Scale = 5 lut = vtk.vtkLookupTable() lut.SetHueRange(0.6,0) lut.SetSaturationRange(1.0,0) lut.SetValueRange(0.5,1.0) demModel = vtk.vtkDEMReader() demModel.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") demModel.Update() catch.catch(globals(),"""#demModel.Print()""") lo = expr.expr(globals(), locals(),["Scale","*","lindex(demModel.GetElevationBounds(),0)"]) hi = expr.expr(globals(), locals(),["Scale","*","lindex(demModel.GetElevationBounds(),1)"]) demActor = vtk.vtkLODActor() # create a pipeline for each lod mapper lods = "4 8 16" for lod in lods.split(): locals()[get_variable_name("shrink", lod, "")] = vtk.vtkImageShrink3D() locals()[get_variable_name("shrink", lod, "")].SetShrinkFactors(expr.expr(globals(), locals(),["int","(","lod",")"]),expr.expr(globals(), locals(),["int","(","lod",")"]),1) locals()[get_variable_name("shrink", lod, "")].SetInputConnection(demModel.GetOutputPort()) locals()[get_variable_name("shrink", lod, "")].AveragingOn() locals()[get_variable_name("geom", lod, "")] = vtk.vtkImageDataGeometryFilter() locals()[get_variable_name("geom", lod, "")].SetInputConnection(locals()[get_variable_name("shrink", lod, "")].GetOutputPort()) locals()[get_variable_name("geom", lod, "")].ReleaseDataFlagOn() locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar() locals()[get_variable_name("warp", lod, "")].SetInputConnection(locals()[get_variable_name("geom", lod, "")].GetOutputPort()) locals()[get_variable_name("warp", lod, "")].SetNormal(0,0,1) locals()[get_variable_name("warp", lod, "")].UseNormalOn() locals()[get_variable_name("warp", lod, "")].SetScaleFactor(Scale) locals()[get_variable_name("warp", lod, "")].ReleaseDataFlagOn() locals()[get_variable_name("elevation", lod, "")] = vtk.vtkElevationFilter() locals()[get_variable_name("elevation", lod, "")].SetInputConnection(locals()[get_variable_name("warp", lod, "")].GetOutputPort()) locals()[get_variable_name("elevation", lod, "")].SetLowPoint(0,0,lo)
def create_frog_actor(frog_fn, frog_tissue_fn, tissue, flying_edges, decimate, lut): # Get the tissue parameters pixel_size = tissue['PIXEL_SIZE'] columns = tissue['COLUMNS'] rows = tissue['ROWS'] voi = tissue['VOI'] spacing = float(tissue['SPACING']) start_slice = float(tissue['START_SLICE']) data_spacing = [pixel_size, pixel_size, spacing] data_origin = [-(columns / 2.0) * pixel_size, -(rows / 2.0) * pixel_size, start_slice * spacing] # # adjust y bounds for PNM coordinate system # tmp = voi[2] voi[2] = rows - voi[3] - 1 voi[3] = rows - tmp - 1 if tissue['NAME'] == 'skin': fn = frog_fn else: fn = frog_tissue_fn reader = vtk.vtkMetaImageReader() reader.SetFileName(str(fn)) reader.SetDataSpacing(data_spacing) reader.SetDataOrigin(data_origin) reader.SetDataExtent(voi) reader.Update() last_connection = reader if not tissue['NAME'] == 'skin': if tissue['ISLAND_REPLACE'] >= 0: island_remover = vtk.vtkImageIslandRemoval2D() island_remover.SetAreaThreshold(tissue['ISLAND_AREA']) island_remover.SetIslandValue(tissue['ISLAND_REPLACE']) island_remover.SetReplaceValue(tissue['TISSUE']) island_remover.SetInput(last_connection.GetOutput()) island_remover.Update() last_connection = island_remover select_tissue = vtk.vtkImageThreshold() select_tissue.ThresholdBetween(tissue['TISSUE'], tissue['TISSUE']) select_tissue.SetInValue(255) select_tissue.SetOutValue(0) select_tissue.SetInputConnection(last_connection.GetOutputPort()) last_connection = select_tissue shrinker = vtk.vtkImageShrink3D() shrinker.SetInputConnection(last_connection.GetOutputPort()) shrinker.SetShrinkFactors(tissue['SAMPLE_RATE']) shrinker.AveragingOn() last_connection = shrinker if not all(v == 0 for v in tissue['GAUSSIAN_STANDARD_DEVIATION']): gaussian = vtk.vtkImageGaussianSmooth() gaussian.SetStandardDeviation(*tissue['GAUSSIAN_STANDARD_DEVIATION']) gaussian.SetRadiusFactors(*tissue['GAUSSIAN_RADIUS_FACTORS']) gaussian.SetInputConnection(shrinker.GetOutputPort()) last_connection = gaussian # Time the isocontouring. ict = collections.defaultdict() iso_value = tissue['VALUE'] if flying_edges: iso_surface = vtk.vtkFlyingEdges3D() iso_surface.SetInputConnection(last_connection.GetOutputPort()) iso_surface.ComputeScalarsOff() iso_surface.ComputeGradientsOff() iso_surface.ComputeNormalsOff() iso_surface.SetValue(0, iso_value) timer = vtk.vtkExecutionTimer() timer.SetFilter(iso_surface) iso_surface.Update() ict['Flying Edges'] = timer.GetElapsedWallClockTime() else: iso_surface = vtk.vtkMarchingCubes() iso_surface.SetInputConnection(last_connection.GetOutputPort()) iso_surface.ComputeScalarsOff() iso_surface.ComputeGradientsOff() iso_surface.ComputeNormalsOff() iso_surface.SetValue(0, iso_value) timer = vtk.vtkExecutionTimer() timer.SetFilter(iso_surface) iso_surface.Update() ict['Marching Cubes'] = timer.GetElapsedWallClockTime() so = SliceOrder() # transform = so.get(tissue['SLICE_ORDER']) # Match Frog.py transform = so.get('hfap') transform.Scale(1, -1, 1) tf = vtk.vtkTransformPolyDataFilter() tf.SetTransform(transform) tf.SetInputConnection(iso_surface.GetOutputPort()) last_connection = tf if decimate: decimator = vtk.vtkDecimatePro() decimator.SetInputConnection(last_connection.GetOutputPort()) decimator.SetFeatureAngle(tissue['DECIMATE_ANGLE']) decimator.MaximumIterations = tissue['DECIMATE_ITERATIONS'] decimator.PreserveTopologyOn() decimator.SetErrorIsAbsolute(1) decimator.SetAbsoluteError(tissue['DECIMATE_ERROR']) decimator.SetTargetReduction(tissue['DECIMATE_REDUCTION']) last_connection = decimator smoother = vtk.vtkWindowedSincPolyDataFilter() smoother.SetInputConnection(last_connection.GetOutputPort()) smoother.SetNumberOfIterations(tissue['SMOOTH_ITERATIONS']) smoother.BoundarySmoothingOff() smoother.FeatureEdgeSmoothingOff() smoother.SetFeatureAngle(tissue['SMOOTH_ANGLE']) smoother.SetPassBand(tissue['SMOOTH_FACTOR']) smoother.NonManifoldSmoothingOn() smoother.NormalizeCoordinatesOff() smoother.Update() normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(smoother.GetOutputPort()) normals.SetFeatureAngle(tissue['FEATURE_ANGLE']) stripper = vtk.vtkStripper() stripper.SetInputConnection(normals.GetOutputPort()) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(stripper.GetOutputPort()) # Create iso-surface contour = vtk.vtkContourFilter() contour.SetInputConnection(reader.GetOutputPort()) contour.SetValue(0, iso_value) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetOpacity(tissue['OPACITY']) actor.GetProperty().SetDiffuseColor(lut.GetTableValue(tissue['TISSUE'])[:3]) actor.GetProperty().SetSpecular(0.5) actor.GetProperty().SetSpecularPower(10) return ict, actor
lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) demModel = vtk.vtkDEMReader() demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") demModel.Update() print(demModel) lo = Scale * demModel.GetElevationBounds()[0] hi = Scale * demModel.GetElevationBounds()[1] demActor = vtk.vtkLODActor() # create a pipeline for each lod mapper shrink16 = vtk.vtkImageShrink3D() shrink16.SetShrinkFactors(16, 16, 1) shrink16.SetInputConnection(demModel.GetOutputPort()) shrink16.AveragingOn() geom16 = vtk.vtkImageDataGeometryFilter() geom16.SetInputConnection(shrink16.GetOutputPort()) geom16.ReleaseDataFlagOn() warp16 = vtk.vtkWarpScalar() warp16.SetInputConnection(geom16.GetOutputPort()) warp16.SetNormal(0, 0, 1) warp16.UseNormalOn() warp16.SetScaleFactor(Scale) warp16.ReleaseDataFlagOn()
def testAllBlends(self): # This script calculates the luminance of an image renWin = vtk.vtkRenderWindow() renWin.SetSize(512, 256) # Image pipeline image1 = vtk.vtkTIFFReader() image1.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image # orientation accordingly. To overwrite this orientation with a vtk # convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke # SetOrientationType method with parameter value of 4. image1.SetOrientationType(4) image2 = vtk.vtkBMPReader() image2.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") # shrink the images to a reasonable size color = vtk.vtkImageShrink3D() color.SetInputConnection(image1.GetOutputPort()) color.SetShrinkFactors(2, 2, 1) backgroundColor = vtk.vtkImageShrink3D() backgroundColor.SetInputConnection(image2.GetOutputPort()) backgroundColor.SetShrinkFactors(2, 2, 1) # create a greyscale version luminance = vtk.vtkImageLuminance() luminance.SetInputConnection(color.GetOutputPort()) backgroundLuminance = vtk.vtkImageLuminance() backgroundLuminance.SetInputConnection(backgroundColor.GetOutputPort()) # create an alpha mask table = vtk.vtkLookupTable() table.SetTableRange(220, 255) table.SetValueRange(1, 0) table.SetSaturationRange(0, 0) table.Build() alpha = vtk.vtkImageMapToColors() alpha.SetInputConnection(luminance.GetOutputPort()) alpha.SetLookupTable(table) alpha.SetOutputFormatToLuminance() # make luminanceAlpha and colorAlpha versions luminanceAlpha = vtk.vtkImageAppendComponents() luminanceAlpha.AddInputConnection(luminance.GetOutputPort()) luminanceAlpha.AddInputConnection(alpha.GetOutputPort()) colorAlpha = vtk.vtkImageAppendComponents() colorAlpha.AddInputConnection(color.GetOutputPort()) colorAlpha.AddInputConnection(alpha.GetOutputPort()) foregrounds = ["luminance", "luminanceAlpha", "color", "colorAlpha"] backgrounds = ["backgroundColor", "backgroundLuminance"] deltaX = 1.0 / 4.0 deltaY = 1.0 / 2.0 blend = dict() mapper = dict() actor = dict() imager = dict() for row, bg in enumerate(backgrounds): for column, fg in enumerate(foregrounds): blend.update({bg:{fg:vtk.vtkImageBlend()}}) blend[bg][fg].AddInputConnection(eval(bg + '.GetOutputPort()')) if bg == "backgroundColor" or fg == "luminance" or fg == "luminanceAlpha": blend[bg][fg].AddInputConnection(eval(fg + '.GetOutputPort()')) blend[bg][fg].SetOpacity(1, 0.8) mapper.update({bg:{fg:vtk.vtkImageMapper()}}) mapper[bg][fg].SetInputConnection(blend[bg][fg].GetOutputPort()) mapper[bg][fg].SetColorWindow(255) mapper[bg][fg].SetColorLevel(127.5) actor.update({bg:{fg:vtk.vtkActor2D()}}) actor[bg][fg].SetMapper(mapper[bg][fg]) imager.update({bg:{fg:vtk.vtkRenderer()}}) imager[bg][fg].AddActor2D(actor[bg][fg]) imager[bg][fg].SetViewport(column * deltaX, row * deltaY, (column + 1) * deltaX, (row + 1) * deltaY) renWin.AddRenderer(imager[bg][fg]) column += 1 # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "TestAllBlends.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def testAllBlendsFloat(self): # This script blends images that consist of float data renWin = vtk.vtkRenderWindow() renWin.SetSize(512, 256) # Image pipeline inputImage = vtk.vtkTIFFReader() inputImage.SetFileName(VTK_DATA_ROOT + "/Data/beach.tif") # "beach.tif" image contains ORIENTATION tag which is # ORIENTATION_TOPLEFT (row 0 top, col 0 lhs) type. The TIFF # reader parses this tag and sets the internal TIFF image # orientation accordingly. To overwrite this orientation with a vtk # convention of ORIENTATION_BOTLEFT (row 0 bottom, col 0 lhs ), invoke # SetOrientationType method with parameter value of 4. inputImage.SetOrientationType(4) inputImage2 = vtk.vtkBMPReader() inputImage2.SetFileName(VTK_DATA_ROOT + "/Data/masonry.bmp") # shrink the images to a reasonable size shrink1 = vtk.vtkImageShrink3D() shrink1.SetInputConnection(inputImage.GetOutputPort()) shrink1.SetShrinkFactors(2, 2, 1) shrink2 = vtk.vtkImageShrink3D() shrink2.SetInputConnection(inputImage2.GetOutputPort()) shrink2.SetShrinkFactors(2, 2, 1) color = vtk.vtkImageShiftScale() color.SetOutputScalarTypeToFloat() color.SetShift(0) color.SetScale(1.0 / 255) color.SetInputConnection(shrink1.GetOutputPort()) backgroundColor = vtk.vtkImageShiftScale() backgroundColor.SetOutputScalarTypeToFloat() backgroundColor.SetShift(0) backgroundColor.SetScale(1.0 / 255) backgroundColor.SetInputConnection(shrink2.GetOutputPort()) # create a greyscale version luminance = vtk.vtkImageLuminance() luminance.SetInputConnection(color.GetOutputPort()) backgroundLuminance = vtk.vtkImageLuminance() backgroundLuminance.SetInputConnection(backgroundColor.GetOutputPort()) # create an alpha mask alpha = vtk.vtkImageThreshold() alpha.SetInputConnection(luminance.GetOutputPort()) alpha.ThresholdByLower(0.9) alpha.SetInValue(1.0) alpha.SetOutValue(0.0) # make luminanceAlpha and colorAlpha versions luminanceAlpha = vtk.vtkImageAppendComponents() luminanceAlpha.AddInputConnection(luminance.GetOutputPort()) luminanceAlpha.AddInputConnection(alpha.GetOutputPort()) colorAlpha = vtk.vtkImageAppendComponents() colorAlpha.AddInputConnection(color.GetOutputPort()) colorAlpha.AddInputConnection(alpha.GetOutputPort()) foregrounds = ["luminance", "luminanceAlpha", "color", "colorAlpha"] backgrounds = ["backgroundColor", "backgroundLuminance"] deltaX = 1.0 / 4.0 deltaY = 1.0 / 2.0 blend = dict() mapper = dict() actor = dict() imager = dict() for row, bg in enumerate(backgrounds): for column, fg in enumerate(foregrounds): blend.update({bg:{fg:vtk.vtkImageBlend()}}) blend[bg][fg].AddInputConnection(eval(bg + '.GetOutputPort()')) if bg == "backgroundColor" or fg == "luminance" or fg == "luminanceAlpha": blend[bg][fg].AddInputConnection(eval(fg + '.GetOutputPort()')) blend[bg][fg].SetOpacity(1, 0.8) mapper.update({bg:{fg:vtk.vtkImageMapper()}}) mapper[bg][fg].SetInputConnection(blend[bg][fg].GetOutputPort()) mapper[bg][fg].SetColorWindow(1.0) mapper[bg][fg].SetColorLevel(0.5) actor.update({bg:{fg:vtk.vtkActor2D()}}) actor[bg][fg].SetMapper(mapper[bg][fg]) imager.update({bg:{fg:vtk.vtkRenderer()}}) imager[bg][fg].AddActor2D(actor[bg][fg]) imager[bg][fg].SetViewport(column * deltaX, row * deltaY, (column + 1) * deltaX, (row + 1) * deltaY) renWin.AddRenderer(imager[bg][fg]) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "TestAllBlendsFloat.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
def testSphereWidget(self): # This example demonstrates how to use the vtkSphereWidget to control the # position of a light. # These are the pre-recorded events Recording = \ "# StreamVersion 1\n\ CharEvent 23 266 0 0 105 1 i\n\ KeyReleaseEvent 23 266 0 0 105 1 i\n\ EnterEvent 69 294 0 0 0 0 i\n\ MouseMoveEvent 69 294 0 0 0 0 i\n\ MouseMoveEvent 68 293 0 0 0 0 i\n\ MouseMoveEvent 67 292 0 0 0 0 i\n\ MouseMoveEvent 66 289 0 0 0 0 i\n\ MouseMoveEvent 66 282 0 0 0 0 i\n\ MouseMoveEvent 66 271 0 0 0 0 i\n\ MouseMoveEvent 69 253 0 0 0 0 i\n\ MouseMoveEvent 71 236 0 0 0 0 i\n\ MouseMoveEvent 74 219 0 0 0 0 i\n\ MouseMoveEvent 76 208 0 0 0 0 i\n\ MouseMoveEvent 78 190 0 0 0 0 i\n\ MouseMoveEvent 78 173 0 0 0 0 i\n\ MouseMoveEvent 77 162 0 0 0 0 i\n\ MouseMoveEvent 77 151 0 0 0 0 i\n\ MouseMoveEvent 77 139 0 0 0 0 i\n\ MouseMoveEvent 76 125 0 0 0 0 i\n\ MouseMoveEvent 73 114 0 0 0 0 i\n\ MouseMoveEvent 73 106 0 0 0 0 i\n\ MouseMoveEvent 73 101 0 0 0 0 i\n\ MouseMoveEvent 72 95 0 0 0 0 i\n\ MouseMoveEvent 72 92 0 0 0 0 i\n\ MouseMoveEvent 70 89 0 0 0 0 i\n\ MouseMoveEvent 69 86 0 0 0 0 i\n\ MouseMoveEvent 67 84 0 0 0 0 i\n\ MouseMoveEvent 65 81 0 0 0 0 i\n\ MouseMoveEvent 60 79 0 0 0 0 i\n\ MouseMoveEvent 59 79 0 0 0 0 i\n\ MouseMoveEvent 58 79 0 0 0 0 i\n\ MouseMoveEvent 57 78 0 0 0 0 i\n\ MouseMoveEvent 55 78 0 0 0 0 i\n\ MouseMoveEvent 54 77 0 0 0 0 i\n\ LeftButtonPressEvent 54 77 0 0 0 0 i\n\ MouseMoveEvent 61 79 0 0 0 0 i\n\ MouseMoveEvent 67 83 0 0 0 0 i\n\ MouseMoveEvent 72 88 0 0 0 0 i\n\ MouseMoveEvent 77 90 0 0 0 0 i\n\ MouseMoveEvent 78 91 0 0 0 0 i\n\ MouseMoveEvent 80 92 0 0 0 0 i\n\ MouseMoveEvent 84 93 0 0 0 0 i\n\ MouseMoveEvent 85 94 0 0 0 0 i\n\ MouseMoveEvent 88 97 0 0 0 0 i\n\ MouseMoveEvent 90 100 0 0 0 0 i\n\ MouseMoveEvent 92 102 0 0 0 0 i\n\ MouseMoveEvent 94 103 0 0 0 0 i\n\ MouseMoveEvent 97 105 0 0 0 0 i\n\ MouseMoveEvent 101 107 0 0 0 0 i\n\ MouseMoveEvent 102 109 0 0 0 0 i\n\ MouseMoveEvent 104 111 0 0 0 0 i\n\ MouseMoveEvent 108 113 0 0 0 0 i\n\ MouseMoveEvent 112 115 0 0 0 0 i\n\ MouseMoveEvent 118 119 0 0 0 0 i\n\ MouseMoveEvent 118 120 0 0 0 0 i\n\ MouseMoveEvent 118 123 0 0 0 0 i\n\ MouseMoveEvent 120 125 0 0 0 0 i\n\ MouseMoveEvent 122 128 0 0 0 0 i\n\ MouseMoveEvent 123 129 0 0 0 0 i\n\ MouseMoveEvent 125 132 0 0 0 0 i\n\ MouseMoveEvent 125 134 0 0 0 0 i\n\ MouseMoveEvent 127 138 0 0 0 0 i\n\ MouseMoveEvent 127 142 0 0 0 0 i\n\ MouseMoveEvent 127 147 0 0 0 0 i\n\ MouseMoveEvent 126 152 0 0 0 0 i\n\ MouseMoveEvent 126 155 0 0 0 0 i\n\ MouseMoveEvent 125 160 0 0 0 0 i\n\ MouseMoveEvent 125 167 0 0 0 0 i\n\ MouseMoveEvent 125 169 0 0 0 0 i\n\ MouseMoveEvent 125 174 0 0 0 0 i\n\ MouseMoveEvent 122 179 0 0 0 0 i\n\ MouseMoveEvent 120 183 0 0 0 0 i\n\ MouseMoveEvent 116 187 0 0 0 0 i\n\ MouseMoveEvent 113 192 0 0 0 0 i\n\ MouseMoveEvent 113 193 0 0 0 0 i\n\ MouseMoveEvent 111 195 0 0 0 0 i\n\ MouseMoveEvent 108 198 0 0 0 0 i\n\ MouseMoveEvent 106 200 0 0 0 0 i\n\ MouseMoveEvent 104 202 0 0 0 0 i\n\ MouseMoveEvent 103 203 0 0 0 0 i\n\ MouseMoveEvent 99 205 0 0 0 0 i\n\ MouseMoveEvent 97 207 0 0 0 0 i\n\ MouseMoveEvent 94 208 0 0 0 0 i\n\ MouseMoveEvent 91 210 0 0 0 0 i\n\ MouseMoveEvent 89 211 0 0 0 0 i\n\ MouseMoveEvent 86 211 0 0 0 0 i\n\ MouseMoveEvent 84 211 0 0 0 0 i\n\ MouseMoveEvent 80 211 0 0 0 0 i\n\ MouseMoveEvent 77 211 0 0 0 0 i\n\ MouseMoveEvent 75 211 0 0 0 0 i\n\ MouseMoveEvent 71 211 0 0 0 0 i\n\ MouseMoveEvent 68 211 0 0 0 0 i\n\ MouseMoveEvent 66 210 0 0 0 0 i\n\ MouseMoveEvent 62 210 0 0 0 0 i\n\ MouseMoveEvent 58 209 0 0 0 0 i\n\ MouseMoveEvent 54 207 0 0 0 0 i\n\ MouseMoveEvent 52 204 0 0 0 0 i\n\ MouseMoveEvent 51 203 0 0 0 0 i\n\ MouseMoveEvent 51 200 0 0 0 0 i\n\ MouseMoveEvent 48 196 0 0 0 0 i\n\ MouseMoveEvent 45 187 0 0 0 0 i\n\ MouseMoveEvent 45 181 0 0 0 0 i\n\ MouseMoveEvent 44 168 0 0 0 0 i\n\ MouseMoveEvent 40 161 0 0 0 0 i\n\ MouseMoveEvent 39 154 0 0 0 0 i\n\ MouseMoveEvent 38 146 0 0 0 0 i\n\ MouseMoveEvent 35 131 0 0 0 0 i\n\ MouseMoveEvent 34 121 0 0 0 0 i\n\ MouseMoveEvent 34 110 0 0 0 0 i\n\ MouseMoveEvent 34 103 0 0 0 0 i\n\ MouseMoveEvent 34 91 0 0 0 0 i\n\ MouseMoveEvent 34 86 0 0 0 0 i\n\ MouseMoveEvent 34 73 0 0 0 0 i\n\ MouseMoveEvent 35 66 0 0 0 0 i\n\ MouseMoveEvent 37 60 0 0 0 0 i\n\ MouseMoveEvent 37 53 0 0 0 0 i\n\ MouseMoveEvent 38 50 0 0 0 0 i\n\ MouseMoveEvent 38 48 0 0 0 0 i\n\ MouseMoveEvent 41 45 0 0 0 0 i\n\ MouseMoveEvent 43 45 0 0 0 0 i\n\ MouseMoveEvent 44 45 0 0 0 0 i\n\ MouseMoveEvent 47 43 0 0 0 0 i\n\ MouseMoveEvent 51 44 0 0 0 0 i\n\ MouseMoveEvent 54 44 0 0 0 0 i\n\ MouseMoveEvent 55 44 0 0 0 0 i\n\ MouseMoveEvent 59 44 0 0 0 0 i\n\ MouseMoveEvent 64 44 0 0 0 0 i\n\ MouseMoveEvent 67 44 0 0 0 0 i\n\ MouseMoveEvent 68 44 0 0 0 0 i\n\ MouseMoveEvent 71 44 0 0 0 0 i\n\ MouseMoveEvent 74 44 0 0 0 0 i\n\ MouseMoveEvent 77 44 0 0 0 0 i\n\ MouseMoveEvent 80 45 0 0 0 0 i\n\ MouseMoveEvent 81 45 0 0 0 0 i\n\ MouseMoveEvent 85 49 0 0 0 0 i\n\ MouseMoveEvent 89 50 0 0 0 0 i\n\ MouseMoveEvent 94 52 0 0 0 0 i\n\ MouseMoveEvent 99 56 0 0 0 0 i\n\ MouseMoveEvent 104 58 0 0 0 0 i\n\ MouseMoveEvent 107 61 0 0 0 0 i\n\ MouseMoveEvent 109 63 0 0 0 0 i\n\ MouseMoveEvent 109 67 0 0 0 0 i\n\ MouseMoveEvent 111 83 0 0 0 0 i\n\ MouseMoveEvent 113 86 0 0 0 0 i\n\ MouseMoveEvent 113 87 0 0 0 0 i\n\ MouseMoveEvent 113 89 0 0 0 0 i\n\ MouseMoveEvent 112 93 0 0 0 0 i\n\ MouseMoveEvent 112 97 0 0 0 0 i\n\ MouseMoveEvent 111 104 0 0 0 0 i\n\ MouseMoveEvent 112 108 0 0 0 0 i\n\ MouseMoveEvent 116 115 0 0 0 0 i\n\ MouseMoveEvent 116 123 0 0 0 0 i\n\ MouseMoveEvent 116 129 0 0 0 0 i\n\ MouseMoveEvent 119 138 0 0 0 0 i\n\ MouseMoveEvent 122 141 0 0 0 0 i\n\ MouseMoveEvent 127 148 0 0 0 0 i\n\ MouseMoveEvent 128 161 0 0 0 0 i\n\ MouseMoveEvent 131 166 0 0 0 0 i\n\ MouseMoveEvent 134 168 0 0 0 0 i\n\ MouseMoveEvent 135 171 0 0 0 0 i\n\ MouseMoveEvent 134 174 0 0 0 0 i\n\ MouseMoveEvent 132 176 0 0 0 0 i\n\ MouseMoveEvent 132 178 0 0 0 0 i\n\ MouseMoveEvent 129 180 0 0 0 0 i\n\ MouseMoveEvent 127 182 0 0 0 0 i\n\ MouseMoveEvent 124 185 0 0 0 0 i\n\ MouseMoveEvent 122 186 0 0 0 0 i\n\ MouseMoveEvent 118 189 0 0 0 0 i\n\ MouseMoveEvent 114 191 0 0 0 0 i\n\ MouseMoveEvent 114 193 0 0 0 0 i\n\ MouseMoveEvent 112 193 0 0 0 0 i\n\ MouseMoveEvent 111 194 0 0 0 0 i\n\ MouseMoveEvent 110 197 0 0 0 0 i\n\ MouseMoveEvent 110 198 0 0 0 0 i\n\ MouseMoveEvent 109 199 0 0 0 0 i\n\ MouseMoveEvent 108 200 0 0 0 0 i\n\ MouseMoveEvent 108 201 0 0 0 0 i\n\ MouseMoveEvent 108 202 0 0 0 0 i\n\ MouseMoveEvent 108 203 0 0 0 0 i\n\ MouseMoveEvent 104 206 0 0 0 0 i\n\ LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\ MouseMoveEvent 104 205 0 0 0 0 i\n\ MouseMoveEvent 104 204 0 0 0 0 i\n\ MouseMoveEvent 105 205 0 0 0 0 i\n\ MouseMoveEvent 105 206 0 0 0 0 i\n\ " # Start by loading some data. # dem = vtk.vtkDEMReader() dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") dem.Update() Scale = 2 lut = vtk.vtkLookupTable() lut.SetHueRange(0.6, 0) lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) lo = Scale * dem.GetElevationBounds()[0] hi = Scale * dem.GetElevationBounds()[1] shrink = vtk.vtkImageShrink3D() shrink.SetShrinkFactors(4, 4, 1) shrink.SetInputConnection(dem.GetOutputPort()) shrink.AveragingOn() geom = vtk.vtkImageDataGeometryFilter() geom.SetInputConnection(shrink.GetOutputPort()) geom.ReleaseDataFlagOn() warp = vtk.vtkWarpScalar() warp.SetInputConnection(geom.GetOutputPort()) warp.SetNormal(0, 0, 1) warp.UseNormalOn() warp.SetScaleFactor(Scale) warp.ReleaseDataFlagOn() elevation = vtk.vtkElevationFilter() elevation.SetInputConnection(warp.GetOutputPort()) elevation.SetLowPoint(0, 0, lo) elevation.SetHighPoint(0, 0, hi) elevation.SetScalarRange(lo, hi) elevation.ReleaseDataFlagOn() normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(elevation.GetOutputPort()) normals.SetFeatureAngle(60) normals.ConsistencyOff() normals.SplittingOff() normals.ReleaseDataFlagOn() normals.Update() demMapper = vtk.vtkPolyDataMapper() demMapper.SetInputConnection(normals.GetOutputPort()) demMapper.SetScalarRange(lo, hi) demMapper.SetLookupTable(lut) demActor = vtk.vtkActor() demActor.SetMapper(demMapper) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) iRen.LightFollowCameraOff() # iRen.SetInteractorStyle("") # The callback takes two arguments. # The first being the object that generates the event and # the second argument the event name (which is a string). def MoveLight(widget, event_string): light.SetPosition(rep.GetHandlePosition()) # Associate the line widget with the interactor rep = vtk.vtkSphereRepresentation() rep.SetPlaceFactor(4) rep.PlaceWidget(normals.GetOutput().GetBounds()) rep.HandleVisibilityOn() rep.SetRepresentationToWireframe() # rep HandleVisibilityOff # rep HandleTextOff sphereWidget = vtk.vtkSphereWidget2() sphereWidget.SetInteractor(iRen) sphereWidget.SetRepresentation(rep) # sphereWidget.TranslationEnabledOff() # sphereWidget.ScalingEnabledOff() sphereWidget.AddObserver("InteractionEvent", MoveLight) recorder = vtk.vtkInteractorEventRecorder() recorder.SetInteractor(iRen) # recorder.SetFileName("c:/record.log") # recorder.Record() recorder.ReadFromInputStringOn() recorder.SetInputString(Recording) # Add the actors to the renderer, set the background and size # ren.AddActor(demActor) ren.SetBackground(1, 1, 1) renWin.SetSize(300, 300) ren.SetBackground(0.1, 0.2, 0.4) cam1 = ren.GetActiveCamera() cam1.SetViewUp(0, 0, 1) cam1.SetFocalPoint(dem.GetOutput().GetCenter()) cam1.SetPosition(1, 0, 0) ren.ResetCamera() cam1.Elevation(25) cam1.Azimuth(125) cam1.Zoom(1.25) light = vtk.vtkLight() light.SetFocalPoint(rep.GetCenter()) light.SetPosition(rep.GetHandlePosition()) ren.AddLight(light) iRen.Initialize() renWin.Render() # render the image renWin.Render() # Actually probe the data recorder.Play() img_file = "TestSphereWidget.png" vtk.test.Testing.compareImage( iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
lut.SetHueRange(0.6, 0) lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) demModel = vtk.vtkDEMReader() demModel.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/SainteHelens.dem") demModel.Update() catch.catch(globals(), """#demModel.Print()""") lo = expr.expr(globals(), locals(), ["Scale", "*", "lindex(demModel.GetElevationBounds(),0)"]) hi = expr.expr(globals(), locals(), ["Scale", "*", "lindex(demModel.GetElevationBounds(),1)"]) demActor = vtk.vtkLODActor() # create a pipeline for each lod mapper lods = "4 8 16" for lod in lods.split(): locals()[get_variable_name("shrink", lod, "")] = vtk.vtkImageShrink3D() locals()[get_variable_name("shrink", lod, "")].SetShrinkFactors( expr.expr(globals(), locals(), ["int", "(", "lod", ")"]), expr.expr(globals(), locals(), ["int", "(", "lod", ")"]), 1) locals()[get_variable_name("shrink", lod, "")].SetInputConnection( demModel.GetOutputPort()) locals()[get_variable_name("shrink", lod, "")].AveragingOn() locals()[get_variable_name("geom", lod, "")] = vtk.vtkImageDataGeometryFilter() locals()[get_variable_name("geom", lod, "")].SetInputConnection( locals()[get_variable_name("shrink", lod, "")].GetOutputPort()) locals()[get_variable_name("geom", lod, "")].ReleaseDataFlagOn() locals()[get_variable_name("warp", lod, "")] = vtk.vtkWarpScalar() locals()[get_variable_name("warp", lod, "")].SetInputConnection( locals()[get_variable_name("geom", lod, "")].GetOutputPort()) locals()[get_variable_name("warp", lod, "")].SetNormal(0, 0, 1)
def testSphereWidget(self): # This example demonstrates how to use the vtkSphereWidget to control the # position of a light. # These are the pre-recorded events Recording = \ "# StreamVersion 1\n\ CharEvent 23 266 0 0 105 1 i\n\ KeyReleaseEvent 23 266 0 0 105 1 i\n\ EnterEvent 69 294 0 0 0 0 i\n\ MouseMoveEvent 69 294 0 0 0 0 i\n\ MouseMoveEvent 68 293 0 0 0 0 i\n\ MouseMoveEvent 67 292 0 0 0 0 i\n\ MouseMoveEvent 66 289 0 0 0 0 i\n\ MouseMoveEvent 66 282 0 0 0 0 i\n\ MouseMoveEvent 66 271 0 0 0 0 i\n\ MouseMoveEvent 69 253 0 0 0 0 i\n\ MouseMoveEvent 71 236 0 0 0 0 i\n\ MouseMoveEvent 74 219 0 0 0 0 i\n\ MouseMoveEvent 76 208 0 0 0 0 i\n\ MouseMoveEvent 78 190 0 0 0 0 i\n\ MouseMoveEvent 78 173 0 0 0 0 i\n\ MouseMoveEvent 77 162 0 0 0 0 i\n\ MouseMoveEvent 77 151 0 0 0 0 i\n\ MouseMoveEvent 77 139 0 0 0 0 i\n\ MouseMoveEvent 76 125 0 0 0 0 i\n\ MouseMoveEvent 73 114 0 0 0 0 i\n\ MouseMoveEvent 73 106 0 0 0 0 i\n\ MouseMoveEvent 73 101 0 0 0 0 i\n\ MouseMoveEvent 72 95 0 0 0 0 i\n\ MouseMoveEvent 72 92 0 0 0 0 i\n\ MouseMoveEvent 70 89 0 0 0 0 i\n\ MouseMoveEvent 69 86 0 0 0 0 i\n\ MouseMoveEvent 67 84 0 0 0 0 i\n\ MouseMoveEvent 65 81 0 0 0 0 i\n\ MouseMoveEvent 60 79 0 0 0 0 i\n\ MouseMoveEvent 59 79 0 0 0 0 i\n\ MouseMoveEvent 58 79 0 0 0 0 i\n\ MouseMoveEvent 57 78 0 0 0 0 i\n\ MouseMoveEvent 55 78 0 0 0 0 i\n\ MouseMoveEvent 54 77 0 0 0 0 i\n\ LeftButtonPressEvent 54 77 0 0 0 0 i\n\ MouseMoveEvent 61 79 0 0 0 0 i\n\ MouseMoveEvent 67 83 0 0 0 0 i\n\ MouseMoveEvent 72 88 0 0 0 0 i\n\ MouseMoveEvent 77 90 0 0 0 0 i\n\ MouseMoveEvent 78 91 0 0 0 0 i\n\ MouseMoveEvent 80 92 0 0 0 0 i\n\ MouseMoveEvent 84 93 0 0 0 0 i\n\ MouseMoveEvent 85 94 0 0 0 0 i\n\ MouseMoveEvent 88 97 0 0 0 0 i\n\ MouseMoveEvent 90 100 0 0 0 0 i\n\ MouseMoveEvent 92 102 0 0 0 0 i\n\ MouseMoveEvent 94 103 0 0 0 0 i\n\ MouseMoveEvent 97 105 0 0 0 0 i\n\ MouseMoveEvent 101 107 0 0 0 0 i\n\ MouseMoveEvent 102 109 0 0 0 0 i\n\ MouseMoveEvent 104 111 0 0 0 0 i\n\ MouseMoveEvent 108 113 0 0 0 0 i\n\ MouseMoveEvent 112 115 0 0 0 0 i\n\ MouseMoveEvent 118 119 0 0 0 0 i\n\ MouseMoveEvent 118 120 0 0 0 0 i\n\ MouseMoveEvent 118 123 0 0 0 0 i\n\ MouseMoveEvent 120 125 0 0 0 0 i\n\ MouseMoveEvent 122 128 0 0 0 0 i\n\ MouseMoveEvent 123 129 0 0 0 0 i\n\ MouseMoveEvent 125 132 0 0 0 0 i\n\ MouseMoveEvent 125 134 0 0 0 0 i\n\ MouseMoveEvent 127 138 0 0 0 0 i\n\ MouseMoveEvent 127 142 0 0 0 0 i\n\ MouseMoveEvent 127 147 0 0 0 0 i\n\ MouseMoveEvent 126 152 0 0 0 0 i\n\ MouseMoveEvent 126 155 0 0 0 0 i\n\ MouseMoveEvent 125 160 0 0 0 0 i\n\ MouseMoveEvent 125 167 0 0 0 0 i\n\ MouseMoveEvent 125 169 0 0 0 0 i\n\ MouseMoveEvent 125 174 0 0 0 0 i\n\ MouseMoveEvent 122 179 0 0 0 0 i\n\ MouseMoveEvent 120 183 0 0 0 0 i\n\ MouseMoveEvent 116 187 0 0 0 0 i\n\ MouseMoveEvent 113 192 0 0 0 0 i\n\ MouseMoveEvent 113 193 0 0 0 0 i\n\ MouseMoveEvent 111 195 0 0 0 0 i\n\ MouseMoveEvent 108 198 0 0 0 0 i\n\ MouseMoveEvent 106 200 0 0 0 0 i\n\ MouseMoveEvent 104 202 0 0 0 0 i\n\ MouseMoveEvent 103 203 0 0 0 0 i\n\ MouseMoveEvent 99 205 0 0 0 0 i\n\ MouseMoveEvent 97 207 0 0 0 0 i\n\ MouseMoveEvent 94 208 0 0 0 0 i\n\ MouseMoveEvent 91 210 0 0 0 0 i\n\ MouseMoveEvent 89 211 0 0 0 0 i\n\ MouseMoveEvent 86 211 0 0 0 0 i\n\ MouseMoveEvent 84 211 0 0 0 0 i\n\ MouseMoveEvent 80 211 0 0 0 0 i\n\ MouseMoveEvent 77 211 0 0 0 0 i\n\ MouseMoveEvent 75 211 0 0 0 0 i\n\ MouseMoveEvent 71 211 0 0 0 0 i\n\ MouseMoveEvent 68 211 0 0 0 0 i\n\ MouseMoveEvent 66 210 0 0 0 0 i\n\ MouseMoveEvent 62 210 0 0 0 0 i\n\ MouseMoveEvent 58 209 0 0 0 0 i\n\ MouseMoveEvent 54 207 0 0 0 0 i\n\ MouseMoveEvent 52 204 0 0 0 0 i\n\ MouseMoveEvent 51 203 0 0 0 0 i\n\ MouseMoveEvent 51 200 0 0 0 0 i\n\ MouseMoveEvent 48 196 0 0 0 0 i\n\ MouseMoveEvent 45 187 0 0 0 0 i\n\ MouseMoveEvent 45 181 0 0 0 0 i\n\ MouseMoveEvent 44 168 0 0 0 0 i\n\ MouseMoveEvent 40 161 0 0 0 0 i\n\ MouseMoveEvent 39 154 0 0 0 0 i\n\ MouseMoveEvent 38 146 0 0 0 0 i\n\ MouseMoveEvent 35 131 0 0 0 0 i\n\ MouseMoveEvent 34 121 0 0 0 0 i\n\ MouseMoveEvent 34 110 0 0 0 0 i\n\ MouseMoveEvent 34 103 0 0 0 0 i\n\ MouseMoveEvent 34 91 0 0 0 0 i\n\ MouseMoveEvent 34 86 0 0 0 0 i\n\ MouseMoveEvent 34 73 0 0 0 0 i\n\ MouseMoveEvent 35 66 0 0 0 0 i\n\ MouseMoveEvent 37 60 0 0 0 0 i\n\ MouseMoveEvent 37 53 0 0 0 0 i\n\ MouseMoveEvent 38 50 0 0 0 0 i\n\ MouseMoveEvent 38 48 0 0 0 0 i\n\ MouseMoveEvent 41 45 0 0 0 0 i\n\ MouseMoveEvent 43 45 0 0 0 0 i\n\ MouseMoveEvent 44 45 0 0 0 0 i\n\ MouseMoveEvent 47 43 0 0 0 0 i\n\ MouseMoveEvent 51 44 0 0 0 0 i\n\ MouseMoveEvent 54 44 0 0 0 0 i\n\ MouseMoveEvent 55 44 0 0 0 0 i\n\ MouseMoveEvent 59 44 0 0 0 0 i\n\ MouseMoveEvent 64 44 0 0 0 0 i\n\ MouseMoveEvent 67 44 0 0 0 0 i\n\ MouseMoveEvent 68 44 0 0 0 0 i\n\ MouseMoveEvent 71 44 0 0 0 0 i\n\ MouseMoveEvent 74 44 0 0 0 0 i\n\ MouseMoveEvent 77 44 0 0 0 0 i\n\ MouseMoveEvent 80 45 0 0 0 0 i\n\ MouseMoveEvent 81 45 0 0 0 0 i\n\ MouseMoveEvent 85 49 0 0 0 0 i\n\ MouseMoveEvent 89 50 0 0 0 0 i\n\ MouseMoveEvent 94 52 0 0 0 0 i\n\ MouseMoveEvent 99 56 0 0 0 0 i\n\ MouseMoveEvent 104 58 0 0 0 0 i\n\ MouseMoveEvent 107 61 0 0 0 0 i\n\ MouseMoveEvent 109 63 0 0 0 0 i\n\ MouseMoveEvent 109 67 0 0 0 0 i\n\ MouseMoveEvent 111 83 0 0 0 0 i\n\ MouseMoveEvent 113 86 0 0 0 0 i\n\ MouseMoveEvent 113 87 0 0 0 0 i\n\ MouseMoveEvent 113 89 0 0 0 0 i\n\ MouseMoveEvent 112 93 0 0 0 0 i\n\ MouseMoveEvent 112 97 0 0 0 0 i\n\ MouseMoveEvent 111 104 0 0 0 0 i\n\ MouseMoveEvent 112 108 0 0 0 0 i\n\ MouseMoveEvent 116 115 0 0 0 0 i\n\ MouseMoveEvent 116 123 0 0 0 0 i\n\ MouseMoveEvent 116 129 0 0 0 0 i\n\ MouseMoveEvent 119 138 0 0 0 0 i\n\ MouseMoveEvent 122 141 0 0 0 0 i\n\ MouseMoveEvent 127 148 0 0 0 0 i\n\ MouseMoveEvent 128 161 0 0 0 0 i\n\ MouseMoveEvent 131 166 0 0 0 0 i\n\ MouseMoveEvent 134 168 0 0 0 0 i\n\ MouseMoveEvent 135 171 0 0 0 0 i\n\ MouseMoveEvent 134 174 0 0 0 0 i\n\ MouseMoveEvent 132 176 0 0 0 0 i\n\ MouseMoveEvent 132 178 0 0 0 0 i\n\ MouseMoveEvent 129 180 0 0 0 0 i\n\ MouseMoveEvent 127 182 0 0 0 0 i\n\ MouseMoveEvent 124 185 0 0 0 0 i\n\ MouseMoveEvent 122 186 0 0 0 0 i\n\ MouseMoveEvent 118 189 0 0 0 0 i\n\ MouseMoveEvent 114 191 0 0 0 0 i\n\ MouseMoveEvent 114 193 0 0 0 0 i\n\ MouseMoveEvent 112 193 0 0 0 0 i\n\ MouseMoveEvent 111 194 0 0 0 0 i\n\ MouseMoveEvent 110 197 0 0 0 0 i\n\ MouseMoveEvent 110 198 0 0 0 0 i\n\ MouseMoveEvent 109 199 0 0 0 0 i\n\ MouseMoveEvent 108 200 0 0 0 0 i\n\ MouseMoveEvent 108 201 0 0 0 0 i\n\ MouseMoveEvent 108 202 0 0 0 0 i\n\ MouseMoveEvent 108 203 0 0 0 0 i\n\ MouseMoveEvent 104 206 0 0 0 0 i\n\ LeftButtonReleaseEvent 104 206 0 0 0 0 i\n\ MouseMoveEvent 104 205 0 0 0 0 i\n\ MouseMoveEvent 104 204 0 0 0 0 i\n\ MouseMoveEvent 105 205 0 0 0 0 i\n\ MouseMoveEvent 105 206 0 0 0 0 i\n\ " # Start by loading some data. # dem = vtk.vtkDEMReader() dem.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem") dem.Update() Scale = 2 lut = vtk.vtkLookupTable() lut.SetHueRange(0.6, 0) lut.SetSaturationRange(1.0, 0) lut.SetValueRange(0.5, 1.0) lo = Scale * dem.GetElevationBounds()[0] hi = Scale * dem.GetElevationBounds()[1] shrink = vtk.vtkImageShrink3D() shrink.SetShrinkFactors(4, 4, 1) shrink.SetInputConnection(dem.GetOutputPort()) shrink.AveragingOn() geom = vtk.vtkImageDataGeometryFilter() geom.SetInputConnection(shrink.GetOutputPort()) geom.ReleaseDataFlagOn() warp = vtk.vtkWarpScalar() warp.SetInputConnection(geom.GetOutputPort()) warp.SetNormal(0, 0, 1) warp.UseNormalOn() warp.SetScaleFactor(Scale) warp.ReleaseDataFlagOn() elevation = vtk.vtkElevationFilter() elevation.SetInputConnection(warp.GetOutputPort()) elevation.SetLowPoint(0, 0, lo) elevation.SetHighPoint(0, 0, hi) elevation.SetScalarRange(lo, hi) elevation.ReleaseDataFlagOn() normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(elevation.GetOutputPort()) normals.SetFeatureAngle(60) normals.ConsistencyOff() normals.SplittingOff() normals.ReleaseDataFlagOn() normals.Update() demMapper = vtk.vtkPolyDataMapper() demMapper.SetInputConnection(normals.GetOutputPort()) demMapper.SetScalarRange(lo, hi) demMapper.SetLookupTable(lut) demActor = vtk.vtkActor() demActor.SetMapper(demMapper) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.SetMultiSamples(0) renWin.AddRenderer(ren) iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin) iRen.LightFollowCameraOff() # iRen.SetInteractorStyle("") # The callback takes two arguments. # The first being the object that generates the event and # the second argument the event name (which is a string). def MoveLight(widget, event_string): light.SetPosition(rep.GetHandlePosition()) # Associate the line widget with the interactor rep = vtk.vtkSphereRepresentation() rep.SetPlaceFactor(4) rep.PlaceWidget(normals.GetOutput().GetBounds()) rep.HandleVisibilityOn() rep.SetRepresentationToWireframe() # rep HandleVisibilityOff # rep HandleTextOff sphereWidget = vtk.vtkSphereWidget2() sphereWidget.SetInteractor(iRen) sphereWidget.SetRepresentation(rep) # sphereWidget.TranslationEnabledOff() # sphereWidget.ScalingEnabledOff() sphereWidget.AddObserver("InteractionEvent", MoveLight) recorder = vtk.vtkInteractorEventRecorder() recorder.SetInteractor(iRen) # recorder.SetFileName("c:/record.log") # recorder.Record() recorder.ReadFromInputStringOn() recorder.SetInputString(Recording) # Add the actors to the renderer, set the background and size # ren.AddActor(demActor) ren.SetBackground(1, 1, 1) renWin.SetSize(300, 300) ren.SetBackground(0.1, 0.2, 0.4) cam1 = ren.GetActiveCamera() cam1.SetViewUp(0, 0, 1) cam1.SetFocalPoint(dem.GetOutput().GetCenter()) cam1.SetPosition(1, 0, 0) ren.ResetCamera() cam1.Elevation(25) cam1.Azimuth(125) cam1.Zoom(1.25) light = vtk.vtkLight() light.SetFocalPoint(rep.GetCenter()) light.SetPosition(rep.GetHandlePosition()) ren.AddLight(light) iRen.Initialize() renWin.Render() # render the image renWin.Render() # Actually probe the data recorder.Play() img_file = "TestSphereWidget.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()
dataImporter.SetDataScalarTypeToUnsignedChar() dataImporter.SetNumberOfScalarComponents(1) dataImporter.SetDataExtent(0, xSize - 1, 0, ySize - 1, 0, zSize - 1) dataImporter.SetWholeExtent(0, xSize - 1, 0, ySize - 1, 0, zSize - 1) dataImporter.SetDataExtentToWholeExtent() #============================================================================= # Smoothed pipeline. smooth = vtk.vtkImageGaussianSmooth() smooth.SetDimensionality(3) smooth.SetInputConnection(dataImporter.GetOutputPort()) smooth.SetStandardDeviations(dv, dv, dv) smooth.SetRadiusFactor(rf) subsampleSmoothed = vtk.vtkImageShrink3D() subsampleSmoothed.SetInputConnection(smooth.GetOutputPort()) subsampleSmoothed.SetShrinkFactors(4, 4, 1) isoSmoothed = vtk.vtkImageMarchingCubes() isoSmoothed.SetInputConnection(smooth.GetOutputPort()) isoSmoothed.SetValue(0, 10) isoSmoothedMapper = vtk.vtkPolyDataMapper() isoSmoothedMapper.SetInputConnection(isoSmoothed.GetOutputPort()) isoSmoothedMapper.ScalarVisibilityOff() colors = vtk.vtkNamedColors() colors.SetColor("ActorColor", [235, 235, 235, 255]) ''' threshold = vtk.vtkImageThreshold ()