def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkExtractGrid(), 'Processing.', ('vtkStructuredGrid',), ('vtkStructuredGrid',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkExtractGrid(), 'Processing.', ('vtkStructuredGrid', ), ('vtkStructuredGrid', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def make_models(self): """ make models """ # Read some structured data. pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() pl3d_output = pl3d.GetOutput().GetBlock(0) # Here we subsample the grid. The SetVOI method requires six values # specifying (imin,imax, jmin,jmax, kmin,kmax) extents. In this # example we extracting a plane. Note that the VOI is clamped to zero # (min) and the maximum i-j-k value; that way we can use the # -1000,1000 specification and be sure the values are clamped. The # SampleRate specifies that we take every point in the i-direction; # every other point in the j-direction; and every third point in the # k-direction. IncludeBoundaryOn makes sure that we get the boundary # points even if the SampleRate does not coincident with the boundary. extract = vtk.vtkExtractGrid() extract.SetInputData(pl3d_output) extract.SetVOI(self.slice_factor, self.slice_factor, -1000, 1000, -1000, 1000) extract.SetSampleRate(1, 2, 3) extract.IncludeBoundaryOn() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(extract.GetOutputPort()) mapper.SetScalarRange(.18, .7) self.surface_actor = vtk.vtkActor() self.surface_actor.SetMapper(mapper) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3d_output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) self.outline_actor = vtk.vtkActor() self.outline_actor.SetMapper(outlineMapper) self.outline_actor.GetProperty().SetColor(0, 0, 0) self.extract_model = extract
def _set_input (self): """ This function tries its best to use an appropriate filter for the given input data.""" debug ("In ExtractGrid::_set_input ()") out = self.prev_fil.GetOutput () dim = out.GetDimensions () self.dim = [dim[0] -1, dim[1] -1, dim[2] -1] if out.IsA ('vtkStructuredGrid'): f = vtk.vtkExtractGrid() elif out.IsA ('vtkRectilinearGrid'): f = vtk.vtkExtractRectilinearGrid() elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'): f = vtk.vtkExtractVOI() else: msg = "This module does not support the given "\ "output - %s "%(out.GetClassName ()) raise Base.Objects.ModuleException, msg if f.GetClassName() != self.fil.GetClassName(): self.fil = f self.fil.SetInput (out)
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() pl3d_output = pl3d.GetOutput().GetBlock(0) # Here we subsample the grid. The SetVOI method requires six values # specifying (imin,imax, jmin,jmax, kmin,kmax) extents. In this # example we extracting a plane. Note that the VOI is clamped to zero # (min) and the maximum i-j-k value; that way we can use the # -1000,1000 specification and be sure the values are clamped. The # SampleRate specifies that we take every point in the i-direction; # every other point in the j-direction; and every third point in the # k-direction. IncludeBoundaryOn makes sure that we get the boundary # points even if the SampleRate does not coincident with the boundary. extract = vtk.vtkExtractGrid() extract.SetInputData(pl3d_output) extract.SetVOI(30, 30, -1000, 1000, -1000, 1000) extract.SetSampleRate(1, 2, 3) extract.IncludeBoundaryOn() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(extract.GetOutputPort()) mapper.SetScalarRange(.18, .7) actor = vtk.vtkActor() actor.SetMapper(mapper) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3d_output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor()
Mapper5.SetScalarModeToDefault() Actor5 = vtk.vtkActor() Actor5.SetMapper(Mapper5) Actor5.GetProperty().SetRepresentationToSurface() Actor5.GetProperty().SetInterpolationToGouraud() Actor5.GetProperty().SetAmbient(0.15) Actor5.GetProperty().SetDiffuse(0.85) Actor5.GetProperty().SetSpecular(0.1) Actor5.GetProperty().SetSpecularPower(100) Actor5.GetProperty().SetSpecularColor(1, 1, 1) Actor5.GetProperty().SetColor(1, 1, 1) Ren1.AddActor(Actor5) ExtractGrid0 = vtk.vtkExtractGrid() ExtractGrid0.SetInputData(output) ExtractGrid0.SetVOI(0, 14, 0, 32, 0, 24) ExtractGrid0.SetSampleRate(1, 1, 1) ExtractGrid0.SetIncludeBoundary(0) ExtractGrid1 = vtk.vtkExtractGrid() ExtractGrid1.SetInputData(output) ExtractGrid1.SetVOI(14, 29, 0, 32, 0, 24) ExtractGrid1.SetSampleRate(1, 1, 1) ExtractGrid1.SetIncludeBoundary(0) ExtractGrid2 = vtk.vtkExtractGrid() ExtractGrid2.SetInputData(output) ExtractGrid2.SetVOI(29, 56, 0, 32, 0, 24) ExtractGrid2.SetSampleRate(1, 1, 1)
renWin = vtk.vtkRenderWindow() renWin.AddRenderer( ren ) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # create pipeline # pl3d = vtk.vtkPLOT3DReader() pl3d.SetXYZFileName( vtkGetDataRoot() + '/Data/combxyz.bin' ) pl3d.SetQFileName( vtkGetDataRoot() + '/Data/combq.bin' ) pl3d.SetScalarFunctionNumber( 100 ) pl3d.SetVectorFunctionNumber( 202 ) pl3d.Update() eg = vtk.vtkExtractGrid() eg.SetInputConnection(pl3d.GetOutputPort()) eg.SetSampleRate(4,4,4) gs = vtk.vtkGlyphSource2D() gs.SetGlyphTypeToThickArrow() gs.SetScale( 1 ) gs.FilledOff() gs.CrossOff() glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(eg.GetOutputPort()) glyph.SetSource(gs.GetOutput()) glyph.SetScaleFactor( 0.75 ) mapper = vtk.vtkPolyDataMapper()
# techniques demonstrated: one uses an image to perform the blanking; # the other uses scalar values to do the same thing. Both images should # be identical. # # create pipeline - start by extracting a single plane from the grid # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) plane = vtk.vtkExtractGrid() plane.SetInputData(output) plane.SetVOI(0, 57, 0, 33, 0, 0) plane.Update() # Create some data to use for the (image) blanking # blankImage = vtk.vtkImageData() # vtkType.h has definitions for vtk datatypes VTK_INT, VTK_FLOAT, etc. that # don't get wrapped in Python. VTK_UNSIGNED_CHAR = 3 blankImage.SetDimensions(57, 33, 1) blankImage.AllocateScalars(VTK_UNSIGNED_CHAR, 1) blankImage.GetPointData().GetScalars().SetName("blankScalars")
# techniques demonstrated: one uses an image to perform the blanking; # the other uses scalar values to do the same thing. Both images should # be identical. # # create pipeline - start by extracting a single plane from the grid # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) plane = vtk.vtkExtractGrid() plane.SetInputData(output) plane.SetVOI(0, 57, 0, 33, 0, 0) plane.Update() # Create some data to use for the (image) blanking # blankImage = vtk.vtkImageData() # vtkType.h has definitions for vtk datatypes VTK_INT, VTK_FLOAT, etc. that # don't get wrapped in Tcl. VTK_UNSIGNED_CHAR = 3 blankImage.SetDimensions(57, 33, 1) blankImage.AllocateScalars(VTK_UNSIGNED_CHAR, 1) blankImage.GetPointData().GetScalars().SetName("blankScalars")
def main(): xyzFile, qFile = get_program_parameters() colors = vtk.vtkNamedColors() # Create pipeline. Read structured grid data. # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(xyzFile) pl3d.SetQFileName(qFile) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() pl3dOutput = pl3d.GetOutput().GetBlock(0) # A convenience, use this filter to limit data for experimentation. extract = vtk.vtkExtractGrid() extract.SetVOI(1, 55, -1000, 1000, -1000, 1000) extract.SetInputData(pl3dOutput) # The (implicit) plane is used to do the cutting plane = vtk.vtkPlane() plane.SetOrigin(0, 4, 2) plane.SetNormal(0, 1, 0) # The cutter is set up to process each contour value over all cells # (SetSortByToSortByCell). This results in an ordered output of polygons # which is key to the compositing. cutter = vtk.vtkCutter() cutter.SetInputConnection(extract.GetOutputPort()) cutter.SetCutFunction(plane) cutter.GenerateCutScalarsOff() cutter.SetSortByToSortByCell() clut = vtk.vtkLookupTable() clut.SetHueRange(0, 0.67) clut.Build() cutterMapper = vtk.vtkPolyDataMapper() cutterMapper.SetInputConnection(cutter.GetOutputPort()) cutterMapper.SetScalarRange(0.18, 0.7) cutterMapper.SetLookupTable(clut) cut = vtk.vtkActor() cut.SetMapper(cutterMapper) # Add in some surface geometry for interest. iso = vtk.vtkContourFilter() iso.SetInputData(pl3dOutput) iso.SetValue(0, .22) normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(iso.GetOutputPort()) normals.SetFeatureAngle(60) isoMapper = vtk.vtkPolyDataMapper() isoMapper.SetInputConnection(normals.GetOutputPort()) isoMapper.ScalarVisibilityOff() isoActor = vtk.vtkActor() isoActor.SetMapper(isoMapper) isoActor.GetProperty().SetDiffuseColor(colors.GetColor3d('Tomato')) isoActor.GetProperty().SetSpecularColor(colors.GetColor3d('White')) isoActor.GetProperty().SetDiffuse(0.8) isoActor.GetProperty().SetSpecular(0.5) isoActor.GetProperty().SetSpecularPower(30) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3dOutput) outlineStrip = vtk.vtkStripper() outlineStrip.SetInputConnection(outline.GetOutputPort()) outlineTubes = vtk.vtkTubeFilter() outlineTubes.SetInputConnection(outline.GetOutputPort()) outlineTubes.SetInputConnection(outlineStrip.GetOutputPort()) outlineTubes.SetRadius(0.1) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outlineTubes.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # Create the RenderWindow, Renderer and Interactor. # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and size. # ren1.AddActor(outlineActor) outlineActor.GetProperty().SetColor(colors.GetColor3d('Banana')) ren1.AddActor(isoActor) isoActor.VisibilityOn() ren1.AddActor(cut) n = 20 opacity = 1.0 / float(n) * 5.0 cut.GetProperty().SetOpacity(1) ren1.SetBackground(colors.GetColor3d('SlateGray')) renWin.SetSize(640, 480) renWin.SetWindowName('PseudoVolumeRendering') ren1.GetActiveCamera().SetClippingRange(3.95297, 50) ren1.GetActiveCamera().SetFocalPoint(9.71821, 0.458166, 29.3999) ren1.GetActiveCamera().SetPosition(2.7439, -37.3196, 38.7167) ren1.GetActiveCamera().ComputeViewPlaneNormal() ren1.GetActiveCamera().SetViewUp(-0.16123, 0.264271, 0.950876) # Cut: generates n cut planes normal to camera's view plane. # plane.SetNormal(ren1.GetActiveCamera().GetViewPlaneNormal()) plane.SetOrigin(ren1.GetActiveCamera().GetFocalPoint()) cutter.GenerateValues(n, -5, 5) clut.SetAlphaRange(opacity, opacity) renWin.Render() iren.Start()
VTK_DATA_ROOT = vtkGetDataRoot() # This test checks netCDF CF reader for reading 2D bounds information. renWin = vtk.vtkRenderWindow() renWin.SetSize(400, 200) ############################################################################# # Case 1: Spherical coordinates off. # Open the file. reader_cartesian = vtk.vtkNetCDFCFReader() reader_cartesian.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sampleCurveGrid4.nc") # Set the arrays we want to load. reader_cartesian.UpdateMetaData() reader_cartesian.SetVariableArrayStatus("sample", 1) reader_cartesian.SphericalCoordinatesOff() # Extract a region that is non-overlapping. voi_cartesian = vtk.vtkExtractGrid() voi_cartesian.SetInputConnection(reader_cartesian.GetOutputPort()) voi_cartesian.SetVOI(20, 47, 0, 31, 0, 0) # Assign the field to scalars. aa_cartesian = vtk.vtkAssignAttribute() aa_cartesian.SetInputConnection(voi_cartesian.GetOutputPort()) aa_cartesian.Assign("sample", "SCALARS", "CELL_DATA") # Extract a surface that we can render. surface_cartesian = vtk.vtkDataSetSurfaceFilter() surface_cartesian.SetInputConnection(aa_cartesian.GetOutputPort()) mapper_cartesian = vtk.vtkPolyDataMapper() mapper_cartesian.SetInputConnection(surface_cartesian.GetOutputPort()) mapper_cartesian.SetScalarRange(0, 1535) actor_cartesian = vtk.vtkActor() actor_cartesian.SetMapper(mapper_cartesian) ren_cartesian = vtk.vtkRenderer()
import vtk lut = vtk.vtkLookupTable() lut.SetNumberOfColors(256) lut.SetHueRange(0.0, 0.667) lut.Build() #read the data reader = vtk.vtkStructuredGridReader() reader.SetFileName("density.vtk") reader.Update() minx, maxx, miny, maxy, minz, maxz = reader.GetOutput().GetExtent() #For lab 6 create a vtkExtractGrid here, then set the VOI extents and sample rate. grid = vtk.vtkExtractGrid() grid.SetInputConnection(reader.GetOutputPort()) grid.SetSampleRate(2, 8, 2) # 1/2, 1/8, 1/2 sample rate grid.SetVOI(minx, maxx, miny, maxy/2, minz, maxz/2) # Set Volume of Interest #create an arrow to use as a glyph source (must be an object inherited from vtkPolyData) arrow = vtk.vtkArrowSource() arrow.SetTipResolution(6) arrow.SetTipRadius(0.1) arrow.SetTipLength(0.35) arrow.SetShaftResolution(6) arrow.SetShaftRadius(0.03) #create glyph object glyph = vtk.vtkGlyph3D()
VTK_DATA_ROOT = vtkGetDataRoot() # This test checks netCDF CF reader for reading 2D bounds information. renWin = vtk.vtkRenderWindow() renWin.SetSize(400,200) ############################################################################# # Case 1: Spherical coordinates off. # Open the file. reader_cartesian = vtk.vtkNetCDFCFReader() reader_cartesian.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/sampleCurveGrid4.nc") # Set the arrays we want to load. reader_cartesian.UpdateMetaData() reader_cartesian.SetVariableArrayStatus("sample",1) reader_cartesian.SphericalCoordinatesOff() # Extract a region that is non-overlapping. voi_cartesian = vtk.vtkExtractGrid() voi_cartesian.SetInputConnection(reader_cartesian.GetOutputPort()) voi_cartesian.SetVOI(20,47,0,31,0,0) # Assign the field to scalars. aa_cartesian = vtk.vtkAssignAttribute() aa_cartesian.SetInputConnection(voi_cartesian.GetOutputPort()) aa_cartesian.Assign("sample","SCALARS","CELL_DATA") # Extract a surface that we can render. surface_cartesian = vtk.vtkDataSetSurfaceFilter() surface_cartesian.SetInputConnection(aa_cartesian.GetOutputPort()) mapper_cartesian = vtk.vtkPolyDataMapper() mapper_cartesian.SetInputConnection(surface_cartesian.GetOutputPort()) mapper_cartesian.SetScalarRange(0,1535) actor_cartesian = vtk.vtkActor() actor_cartesian.SetMapper(mapper_cartesian) ren_cartesian = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # create pipeline # pl3d = vtk.vtkPLOT3DReader() pl3d.SetXYZFileName(vtkGetDataRoot() + '/Data/combxyz.bin') pl3d.SetQFileName(vtkGetDataRoot() + '/Data/combq.bin') pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() eg = vtk.vtkExtractGrid() eg.SetInputConnection(pl3d.GetOutputPort()) eg.SetSampleRate(4, 4, 4) gs = vtk.vtkGlyphSource2D() gs.SetGlyphTypeToThickArrow() gs.SetScale(1) gs.FilledOff() gs.CrossOff() glyph = vtk.vtkGlyph3D() glyph.SetInputConnection(eg.GetOutputPort()) glyph.SetSource(gs.GetOutput()) glyph.SetScaleFactor(0.75) mapper = vtk.vtkPolyDataMapper()