def download_kitchen(split=False): """Download structured grid of kitchen with velocity field. Use the ``split`` argument to extract all of the furniture in the kitchen. """ mesh = _download_and_read('kitchen.vtk') if not split: return mesh extents = { 'door' : (27, 27, 14, 18, 0, 11), 'window1' : (0, 0, 9, 18, 6, 12), 'window2' : (5, 12, 23, 23, 6, 12), 'klower1' : (17, 17, 0, 11, 0, 6), 'klower2' : (19, 19, 0, 11, 0, 6), 'klower3' : (17, 19, 0, 0, 0, 6), 'klower4' : (17, 19, 11, 11, 0, 6), 'klower5' : (17, 19, 0, 11, 0, 0), 'klower6' : (17, 19, 0, 7, 6, 6), 'klower7' : (17, 19, 9, 11, 6, 6), 'hood1' : (17, 17, 0, 11, 11, 16), 'hood2' : (19, 19, 0, 11, 11, 16), 'hood3' : (17, 19, 0, 0, 11, 16), 'hood4' : (17, 19, 11, 11, 11, 16), 'hood5' : (17, 19, 0, 11, 16, 16), 'cookingPlate' : (17, 19, 7, 9, 6, 6), 'furniture' : (17, 19, 7, 9, 11, 11), } kitchen = pyvista.MultiBlock() for key, extent in extents.items(): alg = vtk.vtkStructuredGridGeometryFilter() alg.SetInputDataObject(mesh) alg.SetExtent(extent) alg.Update() result = pyvista.filters._get_output(alg) kitchen[key] = result return kitchen
def buildBasePipeline(self): self.pointArray = vtk.vtkDoubleArray() self.points = vtk.vtkPoints() self.sgrid = vtk.vtkStructuredGrid() self.c2p = vtk.vtkCellDataToPointData() self.sgridGeomFilter = vtk.vtkStructuredGridGeometryFilter() self.contour = vtk.vtkContourFilter() self.mapper = vtk.vtkPolyDataMapper() self.actor = vtk.vtkActor() self.pointArray.SetNumberOfComponents(3) self.pointArray.SetName('coordinates') self.pointArray.SetVoidArray(self.xyz, self.numPoints * 3, 1) # connect self.points.SetData(self.pointArray) self.sgrid.SetDimensions(self.nx1, self.ny1, 1) self.sgrid.SetPoints(self.points) self.c2p.PassCellDataOn() self.c2p.SetInputData(self.sgrid) self.sgridGeomFilter.SetInputData(self.c2p.GetOutput()) self.contour.SetInputConnection( self.sgridGeomFilter.GetOutputPort() ) # Connection(self.sgridGeomFilter.GetOutputPort()) #Connection(self.cell2Points.GetOutputPort()) self.mapper.SetInputConnection(self.contour.GetOutputPort()) self.mapper.UseLookupTableScalarRangeOn() self.actor.SetMapper(self.mapper)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkStructuredGridGeometryFilter(), 'Processing.', ('vtkStructuredGrid',), ('vtkPolyData',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def main(): filename = get_program_parameters() # Read the file reader = vtk.vtkStructuredGridReader() reader.SetFileName(filename) reader.Update() geometry_filter = vtk.vtkStructuredGridGeometryFilter() geometry_filter.SetInputConnection(reader.GetOutputPort()) geometry_filter.Update() # Visualize mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(geometry_filter.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) renderer = vtk.vtkRenderer() render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window_interactor = vtk.vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) renderer.AddActor(actor) named_colors = vtk.vtkNamedColors() renderer.SetBackground(named_colors.GetColor3d("Green")) render_window.Render() render_window_interactor.Start()
def __init__ (self, mod_m): debug ("In CustomGridPlane::__init__ ()") Common.state.busy () Base.Objects.Module.__init__ (self, mod_m) self.act = None out = self.mod_m.GetOutput () if out.IsA('vtkStructuredGrid'): self.plane = vtk.vtkStructuredGridGeometryFilter () elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'): if hasattr (vtk, 'vtkImageDataGeometryFilter'): self.plane = vtk.vtkImageDataGeometryFilter () else: self.plane = vtk.vtkStructuredPointsGeometryFilter () elif out.IsA ('vtkRectilinearGrid'): self.plane = vtk.vtkRectilinearGridGeometryFilter () else: msg = "This module does not support the %s dataset."%(out.GetClassName()) raise Base.Objects.ModuleException, msg self.cont_fil = vtk.vtkContourFilter () self.mapper = self.map = vtk.vtkPolyDataMapper () self.actor = self.act = vtk.vtkActor () self._initialize () self._gui_init () self.renwin.Render () Common.state.idle ()
def _set_input (self): """ This function tries its best to generate an appropriate input for the Normals. If one has an input StructuredGrid or StructuredPoints or even a RectilinearGrid the PolyDataNormals will not work. In order for it to work an appropriate intermediate filter is used to create the correct output.""" debug ("In PolyDataNormals::_set_input ()") out = self.prev_fil.GetOutput () f = None if out.IsA ('vtkStructuredGrid'): f = vtk.vtkStructuredGridGeometryFilter () elif out.IsA ('vtkRectilinearGrid'): f = vtk.vtkRectilinearGridGeometryFilter () elif out.IsA ('vtkStructuredPoints') or out.IsA('vtkImageData'): if hasattr (vtk, 'vtkImageDataGeometryFilter'): f = vtk.vtkImageDataGeometryFilter () else: f = vtk.vtkStructuredPointsGeometryFilter () elif out.IsA('vtkUnstructuredGrid'): f = vtk.vtkGeometryFilter() elif out.IsA('vtkPolyData'): f = None else: msg = "This module does not support the given "\ "output - %s "%(out.GetClassName ()) raise Base.Objects.ModuleException, msg if f: f.SetInput (out) self.fil.SetInput (f.GetOutput ()) else: self.fil.SetInput(out)
def main(): xyz_filename, g_filename = get_program_parameters() colors = vtk.vtkNamedColors() reader = vtk.vtkMultiBlockPLOT3DReader() reader.SetXYZFileName(xyz_filename) reader.SetQFileName(g_filename) reader.SetScalarFunctionNumber(100) reader.SetVectorFunctionNumber(202) reader.Update() geometry_filter = vtk.vtkStructuredGridGeometryFilter() geometry_filter.SetInputData(reader.GetOutput().GetBlock(0)) geometry_filter.Update() # Visualize mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(geometry_filter.GetOutputPort()) mapper.ScalarVisibilityOff() actor = vtk.vtkActor() actor.SetMapper(mapper) renderer = vtk.vtkRenderer() render_window = vtk.vtkRenderWindow() render_window.AddRenderer(renderer) render_window_interactor = vtk.vtkRenderWindowInteractor() render_window_interactor.SetRenderWindow(render_window) renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d("LimeGreen")) render_window.Render() render_window_interactor.Start()
def loadStructuredGrid(filename): # not tested '''Load a vtkStructuredGrid object from file and return a vtkActor.''' reader = vtk.vtkStructuredGridReader() reader.SetFileName(filename) reader.Update() gf = vtk.vtkStructuredGridGeometryFilter() gf.SetInputConnection(reader.GetOutputPort()) gf.Update() return Actor(gf.GetOutput())
def loadPolyData(filename): '''Load a file and return a vtkPolyData object (not a vtkActor).''' if not os.path.exists(filename): colors.printc('Error in loadPolyData: Cannot find', filename, c=1) return None fl = filename.lower() if fl.endswith('.vtk') or fl.endswith('.vtp'): reader = vtk.vtkPolyDataReader() elif fl.endswith('.ply'): reader = vtk.vtkPLYReader() elif fl.endswith('.obj'): reader = vtk.vtkOBJReader() elif fl.endswith('.stl'): reader = vtk.vtkSTLReader() elif fl.endswith('.byu') or fl.endswith('.g'): reader = vtk.vtkBYUReader() elif fl.endswith('.vtp'): reader = vtk.vtkXMLPolyDataReader() elif fl.endswith('.vts'): reader = vtk.vtkXMLStructuredGridReader() elif fl.endswith('.vtu'): reader = vtk.vtkXMLUnstructuredGridReader() elif fl.endswith('.txt'): reader = vtk.vtkParticleReader() # (x y z scalar) elif fl.endswith('.xyz'): reader = vtk.vtkParticleReader() else: reader = vtk.vtkDataReader() reader.SetFileName(filename) if fl.endswith('.vts'): # structured grid reader.Update() gf = vtk.vtkStructuredGridGeometryFilter() gf.SetInputConnection(reader.GetOutputPort()) gf.Update() poly = gf.GetOutput() elif fl.endswith('.vtu'): # unstructured grid reader.Update() gf = vtk.vtkGeometryFilter() gf.SetInputConnection(reader.GetOutputPort()) gf.Update() poly = gf.GetOutput() else: try: reader.Update() poly = reader.GetOutput() except: poly = None if not poly: return None cleanpd = vtk.vtkCleanPolyData() cleanpd.SetInputData(poly) cleanpd.Update() return cleanpd.GetOutput()
def mesh(x,y,z, rgb=None, color='g', normals=True, renderer=None): np1,np2 = x.shape npts = np1*np2 allPoints = vtk.vtkPoints() allPoints.SetNumberOfPoints(npts) for i,xi in enumerate([x,y,z]): flt = xi.ravel() ci = numpy_support.numpy_to_vtk(flt, deep=False) allPoints.GetData().CopyComponent(i,ci,0) # grid = vtk.vtkStructuredGrid() grid.SetDimensions(1,np2,np1) grid.SetPoints(allPoints) if rgb is not None: cols = vtk.vtkUnsignedCharArray() cols.SetNumberOfComponents(3) cols.SetName("Colors") cols.SetNumberOfTuples(npts) for i,cc in enumerate(rgb): cj = (cc.ravel()*255).astype(np.uint8) ci = numpy_support.numpy_to_vtk(cj, deep=True) cols.CopyComponent(i,ci,0) # grid.GetPointData().SetScalars(cols) # if normals: conv = vtk.vtkStructuredGridGeometryFilter() vtkConnectDataInput(grid, conv) normals = vtk.vtkPolyDataNormals() vtkConnectOutputInput(conv, normals) mapped = vtk.vtkPolyDataMapper() vtkConnectOutputInput(normals, mapped) else: mapped = vtk.vtkDataSetMapper() vtkConnectDataInput(grid, mapped) # grac = vtk.vtkActor() grac.SetMapper(mapped) if rgb is None: color = colors.to_rgb(color) grac.GetProperty().SetColor(*color) # if renderer is not None: renderer.AddActor2D(grac) # return grac
def do_contour (self, event=None): debug ("In BandedSurfaceMap::do_contour ()") Common.state.busy () if self.contour_on.get (): if not self.mod_m.get_scalar_data_name (): self.contour_on.set (0) msg = "Warning: No scalar data present to contour!" Common.print_err (msg) Common.state.idle () return out = self.mod_m.GetOutput () if out.IsA('vtkPolyData'): f = None elif out.IsA ('vtkStructuredGrid'): f = vtk.vtkStructuredGridGeometryFilter () elif out.IsA ('vtkRectilinearGrid'): f = vtk.vtkRectilinearGridGeometryFilter () elif out.IsA ('vtkStructuredPoints') or \ out.IsA('vtkImageData'): if hasattr (vtk, 'vtkImageDataGeometryFilter'): f = vtk.vtkImageDataGeometryFilter () else: f = vtk.vtkStructuredPointsGeometryFilter () elif out.IsA('vtkUnstructuredGrid'): f = vtk.vtkGeometryFilter() else: msg = "This module does not support the given "\ "output - %s "%(out.GetClassName ()) raise Base.Objects.ModuleException, msg if f: f.SetInput (out) self.cont_fil.SetInput (f.GetOutput()) else: self.cont_fil.SetInput (out) self.map.SetInput (self.cont_fil.GetOutput ()) self.map.SetScalarModeToUseCellData() else: self.map.SetInput (self.mod_m.GetOutput ()) self.map.SetScalarModeToDefault() self.change_contour () Common.state.idle ()
def MakeActors(xyz): npts = xyz.size / xyz.shape[0] floats = vtk.vtkFloatArray() floats.SetNumberOfComponents(3) floats.SetNumberOfTuples(npts) data = xyz.reshape((3, npts), order="F").transpose() for i, p in enumerate(data): floats.SetTuple3(i, p[0], p[1], p[2]) points = vtk.vtkPoints() points.SetData(floats) grid = vtk.vtkStructuredGrid() grid.SetDimensions(xyz.shape[1], xyz.shape[2], xyz.shape[3]) grid.SetPoints(points) polydataSurface = vtk.vtkStructuredGridGeometryFilter() #polydataSurface.SetInputData(grid) polydataSurface.SetInputData(grid) mapperSurface = vtk.vtkPolyDataMapper() #mapperSurface.SetInputData(polydataSurface.GetOutput()) mapperSurface.SetInputConnection(polydataSurface.GetOutputPort()) actorSurface = vtk.vtkActor() actorSurface.SetMapper(mapperSurface) actorSurface.GetProperty().SetOpacity(0.3) polydataOutline = vtk.vtkStructuredGridOutlineFilter() #polydataOutline.SetInputData(grid) polydataOutline.SetInputData(grid) mapperOutline = vtk.vtkPolyDataMapper() #mapperOutline.SetInputData(polydataOutline.GetOutput()) mapperOutline.SetInputConnection(polydataOutline.GetOutputPort()) actorOutline = vtk.vtkActor() actorOutline.SetMapper(mapperOutline) actorOutline.GetProperty().SetColor(0.0, 0.0, 0.0) return actorSurface, actorOutline
def Grid(full_length, cell_length): num_cols = int(math.ceil(float(full_length) / cell_length)) if (num_cols % 2) == 1: # even number of cols/rows num_cols += 1 full_length = num_cols * cell_length gridPoints = vtk.vtkPoints() for i in xrange(num_cols + 1): p0 = [-full_length / 2.0, -full_length / 2.0 + i * cell_length, 0.0] p1 = [full_length / 2.0, -full_length / 2.0 + i * cell_length, 0.0] if (i % 2) == 1: gridPoints.InsertNextPoint(p0) gridPoints.InsertNextPoint(p1) else: gridPoints.InsertNextPoint(p1) gridPoints.InsertNextPoint(p0) for i in xrange(num_cols + 1): p0 = [-full_length / 2.0 + i * cell_length, -full_length / 2.0, 0.0] p1 = [-full_length / 2.0 + i * cell_length, full_length / 2.0, 0.0] if (i % 2) == 1: gridPoints.InsertNextPoint(p0) gridPoints.InsertNextPoint(p1) else: gridPoints.InsertNextPoint(p1) gridPoints.InsertNextPoint(p0) baseGrid = vtk.vtkStructuredGrid() baseGrid.SetDimensions(4 * (num_cols + 1), 1, 1) baseGrid.SetPoints(gridPoints) outlineFilter = vtk.vtkStructuredGridGeometryFilter() outlineFilter.SetInputConnection(baseGrid.GetProducerPort()) outlineFilter.Update() mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(outlineFilter.GetOutputPort()) actor = vtk.vtkActor() actor.SetMapper(mapper) return actor
def loadPoly(filename): '''Return a vtkPolyData object, NOT a vtkActor''' if not os.path.exists(filename): vc.printc(('Error in loadPoly: Cannot find', filename), c=1) return None fl = filename.lower() if '.vtk' in fl: reader = vtk.vtkPolyDataReader() elif '.ply' in fl: reader = vtk.vtkPLYReader() elif '.obj' in fl: reader = vtk.vtkOBJReader() elif '.stl' in fl: reader = vtk.vtkSTLReader() elif '.byu' in fl or '.g' in fl: reader = vtk.vtkBYUReader() elif '.vtp' in fl: reader = vtk.vtkXMLPolyDataReader() elif '.vts' in fl: reader = vtk.vtkXMLStructuredGridReader() elif '.vtu' in fl: reader = vtk.vtkXMLUnstructuredGridReader() elif '.txt' in fl: reader = vtk.vtkParticleReader() # (x y z scalar) elif '.xyz' in fl: reader = vtk.vtkParticleReader() else: reader = vtk.vtkDataReader() reader.SetFileName(filename) reader.Update() if '.vts' in fl: # structured grid gf = vtk.vtkStructuredGridGeometryFilter() gf.SetInputConnection(reader.GetOutputPort()) gf.Update() poly = gf.GetOutput() elif '.vtu' in fl: # unstructured grid gf = vtk.vtkGeometryFilter() gf.SetInputConnection(reader.GetOutputPort()) gf.Update() poly = gf.GetOutput() else: poly = reader.GetOutput() if not poly: vc.printc(('Unable to load', filename), c=1) return False cleanpd = vtk.vtkCleanPolyData() vu.setInput(cleanpd, poly) cleanpd.Update() return cleanpd.GetOutput()
i += 1 # Manually blank out areas corresponding to dilution holes blanking.SetComponent(318, 0, 0) blanking.SetComponent(945, 0, 0) blanking.SetComponent(1572, 0, 0) blanking.SetComponent(641, 0, 0) blanking.SetComponent(1553, 0, 0) # The first blanking technique uses the image to set the blanking values # blankIt = vtk.vtkBlankStructuredGridWithImage() blankIt.SetInputConnection(plane.GetOutputPort()) blankIt.SetBlankingInputData(blankImage) blankedPlane = vtk.vtkStructuredGridGeometryFilter() blankedPlane.SetInputConnection(blankIt.GetOutputPort()) blankedPlane.SetExtent(0, 100, 0, 100, 0, 0) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(blankedPlane.GetOutputPort()) planeMapper.SetScalarRange(0.197813, 0.710419) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) # The second blanking technique uses grid data values to create the blanking. # Here we borrow the image data and threshold on that. # anotherGrid = vtk.vtkStructuredGrid() anotherGrid.CopyStructure(plane.GetOutput())
def main(): colors = vtk.vtkNamedColors() xyxFile, qFile = get_program_parameters() # Read the data. # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.AutoDetectFormatOn() pl3d.SetXYZFileName(xyxFile) pl3d.SetQFileName(qFile) pl3d.SetScalarFunctionNumber(153) pl3d.SetVectorFunctionNumber(200) pl3d.Update() sg = pl3d.GetOutput().GetBlock(0) # blue to red lut # lut = vtk.vtkLookupTable() lut.SetHueRange(0.667, 0.0) # Computational planes. floorComp = vtk.vtkStructuredGridGeometryFilter() floorComp.SetExtent(0, 37, 0, 75, 0, 0) floorComp.SetInputData(sg) floorComp.Update() floorMapper = vtk.vtkPolyDataMapper() floorMapper.SetInputConnection(floorComp.GetOutputPort()) floorMapper.ScalarVisibilityOff() floorMapper.SetLookupTable(lut) floorActor = vtk.vtkActor() floorActor.SetMapper(floorMapper) floorActor.GetProperty().SetRepresentationToWireframe() floorActor.GetProperty().SetColor(colors.GetColor3d("Beige")) floorActor.GetProperty().SetLineWidth(2) subFloorComp = vtk.vtkStructuredGridGeometryFilter() subFloorComp.SetExtent(0, 37, 0, 15, 22, 22) subFloorComp.SetInputData(sg) subFloorMapper = vtk.vtkPolyDataMapper() subFloorMapper.SetInputConnection(subFloorComp.GetOutputPort()) subFloorMapper.SetLookupTable(lut) subFloorMapper.SetScalarRange(sg.GetScalarRange()) subFloorActor = vtk.vtkActor() subFloorActor.SetMapper(subFloorMapper) subFloor2Comp = vtk.vtkStructuredGridGeometryFilter() subFloor2Comp.SetExtent(0, 37, 60, 75, 22, 22) subFloor2Comp.SetInputData(sg) subFloor2Mapper = vtk.vtkPolyDataMapper() subFloor2Mapper.SetInputConnection(subFloor2Comp.GetOutputPort()) subFloor2Mapper.SetLookupTable(lut) subFloor2Mapper.SetScalarRange(sg.GetScalarRange()) subFloor2Actor = vtk.vtkActor() subFloor2Actor.SetMapper(subFloor2Mapper) postComp = vtk.vtkStructuredGridGeometryFilter() postComp.SetExtent(10, 10, 0, 75, 0, 37) postComp.SetInputData(sg) postMapper = vtk.vtkPolyDataMapper() postMapper.SetInputConnection(postComp.GetOutputPort()) postMapper.SetLookupTable(lut) postMapper.SetScalarRange(sg.GetScalarRange()) postActor = vtk.vtkActor() postActor.SetMapper(postMapper) postActor.GetProperty().SetColor(colors.GetColor3d("Beige")) fanComp = vtk.vtkStructuredGridGeometryFilter() fanComp.SetExtent(0, 37, 38, 38, 0, 37) fanComp.SetInputData(sg) fanMapper = vtk.vtkPolyDataMapper() fanMapper.SetInputConnection(fanComp.GetOutputPort()) fanMapper.SetLookupTable(lut) fanMapper.SetScalarRange(sg.GetScalarRange()) fanActor = vtk.vtkActor() fanActor.SetMapper(fanMapper) fanActor.GetProperty().SetColor(colors.GetColor3d("Beige")) # streamers # # spherical seed points rake = vtk.vtkPointSource() rake.SetCenter(-0.74, 0, 0.3) rake.SetNumberOfPoints(10) # a line of seed points seedsComp = vtk.vtkStructuredGridGeometryFilter() seedsComp.SetExtent(10, 10, 37, 39, 1, 35) seedsComp.SetInputData(sg) streamers = vtk.vtkStreamTracer() streamers.SetInputConnection(pl3d.GetOutputPort()) # streamers SetSource [rake GetOutput] streamers.SetSourceConnection(seedsComp.GetOutputPort()) streamers.SetMaximumPropagation(250) streamers.SetInitialIntegrationStep(.2) streamers.SetMinimumIntegrationStep(.01) streamers.SetIntegratorType(2) streamers.Update() tubes = vtk.vtkTubeFilter() tubes.SetInputConnection(streamers.GetOutputPort()) tubes.SetNumberOfSides(8) tubes.SetRadius(.08) tubes.SetVaryRadius(0) mapTubes = vtk.vtkPolyDataMapper() mapTubes.SetInputConnection(tubes.GetOutputPort()) mapTubes.SetScalarRange(sg.GetScalarRange()) tubesActor = vtk.vtkActor() tubesActor.SetMapper(mapTubes) # outline outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(sg) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d("Beige")) # Create graphics stuff. 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) ren1.AddActor(floorActor) ren1.AddActor(subFloorActor) ren1.AddActor(subFloor2Actor) ren1.AddActor(postActor) ren1.AddActor(fanActor) ren1.AddActor(tubesActor) aCam = vtk.vtkCamera() aCam.SetFocalPoint(0.00657892, 0, 2.41026) aCam.SetPosition(-1.94838, -47.1275, 39.4607) aCam.SetViewUp(0.00653193, 0.617865, 0.786257) ren1.ResetCamera() aCam.Dolly(1.) aCam.SetClippingRange(1, 100) ren1.SetBackground(colors.GetColor3d("SlateGray")) ren1.SetActiveCamera(aCam) renWin.SetSize(640, 480) renWin.Render() iren.Start()
def main(): xyzFile, qFile = get_program_parameters() colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # The cut data. pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(xyzFile) pl3d.SetQFileName(qFile) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() sg = pl3d.GetOutput().GetBlock(0) plane = vtk.vtkPlane() plane.SetOrigin(sg.GetCenter()) plane.SetNormal(-0.287, 0, 0.9579) planeCut = vtk.vtkCutter() planeCut.SetInputData(pl3d.GetOutput().GetBlock(0)) planeCut.SetCutFunction(plane) cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) cutMapper.SetScalarRange(sg.GetPointData().GetScalars().GetRange()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) # Extract the plane. compPlane = vtk.vtkStructuredGridGeometryFilter() compPlane.SetInputData(sg) compPlane.SetExtent(0, 100, 0, 100, 9, 9) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(compPlane.GetOutputPort()) planeMapper.ScalarVisibilityOff() planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.GetProperty().SetRepresentationToWireframe() planeActor.GetProperty().SetColor(colors.GetColor3d('Wheat')) # Outline. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3d.GetOutput().GetBlock(0)) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d('Wheat')) # Add the actors to the renderer, set the background and size. # ren1.AddActor(outlineActor) ren1.AddActor(planeActor) ren1.AddActor(cutActor) ren1.SetBackground(colors.GetColor3d('SlateGray')) renWin.SetSize(640, 480) renWin.SetWindowName('CutStructuredGrid') camera = ren1.GetActiveCamera() camera.SetPosition(5.02611, -23.535, 50.3979) camera.SetFocalPoint(9.33614, 0.0414149, 30.112) camera.SetViewUp(-0.0676794, 0.657814, 0.750134) camera.SetDistance(31.3997) camera.SetClippingRange(12.1468, 55.8147) # Render the image. # renWin.Render() iren.Start()
renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) cell = vtk.vtkGenericCell() ptIds = vtk.vtkIdList() # 0D ZeroDPts = vtk.vtkPoints() ZeroDPts.SetNumberOfPoints(1) ZeroDPts.SetPoint(0,0,0,0) ZeroDGrid = vtk.vtkStructuredGrid() ZeroDGrid.SetDimensions(1,1,1) ZeroDGrid.SetPoints(ZeroDPts) ZeroDGrid.GetCell(0) ZeroDGrid.GetCell(0,cell) ZeroDGrid.GetCellPoints(0,ptIds) ZeroDGeom = vtk.vtkStructuredGridGeometryFilter() ZeroDGeom.SetInputData(ZeroDGrid) ZeroDGeom.SetExtent(0,2,0,2,0,2) ZeroDMapper = vtk.vtkPolyDataMapper() ZeroDMapper.SetInputConnection(ZeroDGeom.GetOutputPort()) ZeroDActor = vtk.vtkActor() ZeroDActor.SetMapper(ZeroDMapper) ZeroDActor.SetPosition(0,0,0) ren1.AddActor(ZeroDActor) # 1D - X XPts = vtk.vtkPoints() XPts.SetNumberOfPoints(2) XPts.SetPoint(0,0,0,0) XPts.SetPoint(1,1,0,0) XGrid = vtk.vtkStructuredGrid() XGrid.SetDimensions(2,1,1)
for i in xrange(int(2*(n**3)/3.), int(n**3)): scalars.SetTuple1(i,.9) # Wrap as a structured grid even though the data is not. sg = vtk.vtkStructuredGrid() sg.GetPointData().SetScalars(scalars) sg.SetPoints(pts) sg.SetDimensions(n,n,n) w = vtk.vtkDataSetWriter() w.SetFileTypeToASCII() w.SetFileName('tmp-sgrid.vtk') w.SetInput(sg) w.Write() w.Update() geom = vtk.vtkStructuredGridGeometryFilter() geom.SetInput(sg) geom.Update() m = vtk.vtkPolyDataMapper() m.SetInput(geom.GetOutput()) a = vtk.vtkActor() a.SetMapper(m) a.GetProperty().SetRepresentationToPoints() a.GetProperty().SetPointSize(15) import time ren.AddActor(a)
# whose radius is proportional to mass flux (in incompressible flow). streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetRadius(0.02) streamTube.SetNumberOfSides(12) streamTube.SetVaryRadiusToVaryRadiusByVector() mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) mapStreamTube.SetScalarRange(reader.GetOutput().GetPointData().GetScalars().GetRange()) streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() # From here on we generate a whole bunch of planes which correspond to # the geometry in the analysis; tables, bookshelves and so on. table1 = vtk.vtkStructuredGridGeometryFilter() table1.SetInputConnection(reader.GetOutputPort()) table1.SetExtent(11, 15, 7, 9, 8, 8) mapTable1 = vtk.vtkPolyDataMapper() mapTable1.SetInputConnection(table1.GetOutputPort()) mapTable1.ScalarVisibilityOff() table1Actor = vtk.vtkActor() table1Actor.SetMapper(mapTable1) table1Actor.GetProperty().SetColor(.59, .427, .392) table2 = vtk.vtkStructuredGridGeometryFilter() table2.SetInputConnection(reader.GetOutputPort()) table2.SetExtent(11, 15, 10, 12, 8, 8) mapTable2 = vtk.vtkPolyDataMapper() mapTable2.SetInputConnection(table2.GetOutputPort()) mapTable2.ScalarVisibilityOff()
renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # read data # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) # wall # wall = vtk.vtkStructuredGridGeometryFilter() wall.SetInputData(output) wall.SetExtent(0,100,0,0,0,100) wallMap = vtk.vtkPolyDataMapper() wallMap.SetInputConnection(wall.GetOutputPort()) wallMap.ScalarVisibilityOff() wallActor = vtk.vtkActor() wallActor.SetMapper(wallMap) wallActor.GetProperty().SetColor(0.8,0.8,0.8) # fin # fin = vtk.vtkStructuredGridGeometryFilter() fin.SetInputData(output) fin.SetExtent(0,100,0,100,0,0) finMap = vtk.vtkPolyDataMapper() finMap.SetInputConnection(fin.GetOutputPort())
def main(): fileName1, fileName2 = get_program_parameters() colors = vtk.vtkNamedColors() # Set the background color. colors.SetColor('BkgColor', [65, 99, 149, 255]) # Read a vtk file # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(fileName1) pl3d.SetQFileName(fileName2) pl3d.SetScalarFunctionNumber(100) # Density pl3d.SetVectorFunctionNumber(202) # Momentum pl3d.Update() pl3dOutput = pl3d.GetOutput().GetBlock(0) # What do we know about the data? # Get the extent of the data: imin,imax, jmin,jmax, kmin,kmax extent = pl3dOutput.GetExtent() scalarRange = pl3dOutput.GetScalarRange() # Planes are specified using a imin,imax, jmin,jmax, kmin,kmax coordinate # specification. Min and max i,j,k values are clamped to 0 and maximum value. # See the variable named extent for the values. # plane = vtk.vtkStructuredGridGeometryFilter() plane.SetInputData(pl3dOutput) plane.SetExtent(10, 10, 1, extent[3], 1, extent[5]) plane2 = vtk.vtkStructuredGridGeometryFilter() plane2.SetInputData(pl3dOutput) plane2.SetExtent(30, 30, 1, extent[3], 1, extent[5]) plane3 = vtk.vtkStructuredGridGeometryFilter() plane3.SetInputData(pl3dOutput) plane3.SetExtent(45, 45, 1, extent[3], 1, extent[5]) # We use an append filter because that way we can do the warping, etc. just # using a single pipeline and actor. # appendF = vtk.vtkAppendPolyData() appendF.AddInputConnection(plane.GetOutputPort()) appendF.AddInputConnection(plane2.GetOutputPort()) appendF.AddInputConnection(plane3.GetOutputPort()) # Warp warp = vtk.vtkWarpVector() warp.SetInputConnection(appendF.GetOutputPort()) warp.SetScaleFactor(0.005) warp.Update() normals = vtk.vtkPolyDataNormals() normals.SetInputData(warp.GetPolyDataOutput()) normals.SetFeatureAngle(45) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(normals.GetOutputPort()) planeMapper.SetScalarRange(scalarRange) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) # The outline provides context for the data and the planes. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3dOutput) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d('Black')) # Create the RenderWindow, Renderer and both Actors # ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the actors to the renderer, set the background and size # ren.AddActor(planeActor) ren.AddActor(outlineActor) ren.SetBackground(colors.GetColor3d('BkgColor')) renWin.SetSize(512, 512) renWin.SetWindowName('VelocityProfile') iren.Initialize() renWin.Render() ren.GetActiveCamera().SetPosition(19.8562, -31.8912, 47.0755) ren.GetActiveCamera().SetFocalPoint(8.255, 0.147815, 29.7631) ren.GetActiveCamera().SetViewUp(-0.0333325, 0.465756, 0.884285) ren.GetActiveCamera().SetClippingRange(17.3078, 64.6375) renWin.Render() iren.Start()
ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # read data # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) # planes to connect plane1 = vtk.vtkStructuredGridGeometryFilter() plane1.SetInputData(output) plane1.SetExtent(20,20,0,100,0,100) conn = vtk.vtkPolyDataConnectivityFilter() conn.SetInputConnection(plane1.GetOutputPort()) conn.ScalarConnectivityOn() conn.SetScalarRange(0.19,0.25) conn.Update() #conn.Print() plane1Map = vtk.vtkPolyDataMapper() plane1Map.SetInputConnection(conn.GetOutputPort()) plane1Map.SetScalarRange(output.GetScalarRange()) plane1Actor = vtk.vtkActor() plane1Actor.SetMapper(plane1Map) plane1Actor.GetProperty().SetOpacity(0.999) # outline
def main(): fileName = get_program_parameters() colors = vtk.vtkNamedColors() # Set the furniture colors, matching those in the VTKTextBook. tableTopColor = [0.59, 0.427, 0.392] filingCabinetColor = [0.8, 0.8, 0.6] bookShelfColor = [0.8, 0.8, 0.6] windowColor = [0.3, 0.3, 0.5] colors.SetColor('TableTop', *tableTopColor) colors.SetColor('FilingCabinet', *filingCabinetColor) colors.SetColor('BookShelf', *bookShelfColor) colors.SetColor('WindowColor', *windowColor) # We read a data file that represents a CFD analysis of airflow in an office # (with ventilation and a burning cigarette). We force an update so that we # can query the output for its length, i.e., the length of the diagonal # of the bounding box. This is useful for normalizing the data. reader = vtk.vtkDataSetReader() reader.SetFileName(fileName) reader.Update() # Now we will generate a single streamline in the data. We select the # integration order to use (RungeKutta order 4) and associate it with # the streamer. The start position is the position in world space where # we want to begin streamline integration; and we integrate in both # directions. The step length is the length of the line segments that # make up the streamline (i.e., related to display). The # IntegrationStepLength specifies the integration step length as a # fraction of the cell size that the streamline is in. integ = vtk.vtkRungeKutta4() streamer = vtk.vtkStreamTracer() streamer.SetInputConnection(reader.GetOutputPort()) streamer.SetStartPosition(0.1, 2.1, 0.5) streamer.SetMaximumPropagation(500) streamer.SetInitialIntegrationStep(0.05) streamer.SetIntegrationDirectionToBoth() streamer.SetIntegrator(integ) # The tube is wrapped around the generated streamline. By varying the radius # by the inverse of vector magnitude, we are creating a tube whose radius is # proportional to mass flux (in incompressible flow). streamTube = vtk.vtkTubeFilter() streamTube.SetInputConnection(streamer.GetOutputPort()) streamTube.SetInputArrayToProcess(1, 0, 0, vtkDataObject.FIELD_ASSOCIATION_POINTS, 'vectors') streamTube.SetRadius(0.02) streamTube.SetNumberOfSides(12) streamTube.SetVaryRadiusToVaryRadiusByVector() mapStreamTube = vtk.vtkPolyDataMapper() mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) mapStreamTube.SetScalarRange( reader.GetOutput().GetPointData().GetScalars().GetRange()) streamTubeActor = vtk.vtkActor() streamTubeActor.SetMapper(mapStreamTube) streamTubeActor.GetProperty().BackfaceCullingOn() # Create the scene. # We generate a whole bunch of planes which correspond to # the geometry in the analysis; tables, bookshelves and so on. table1 = vtk.vtkStructuredGridGeometryFilter() table1.SetInputData(reader.GetStructuredGridOutput()) table1.SetExtent(11, 15, 7, 9, 8, 8) mapTable1 = vtk.vtkPolyDataMapper() mapTable1.SetInputConnection(table1.GetOutputPort()) mapTable1.ScalarVisibilityOff() table1Actor = vtk.vtkActor() table1Actor.SetMapper(mapTable1) table1Actor.GetProperty().SetColor(colors.GetColor3d('TableTop')) table2 = vtk.vtkStructuredGridGeometryFilter() table2.SetInputData(reader.GetStructuredGridOutput()) table2.SetExtent(11, 15, 10, 12, 8, 8) mapTable2 = vtk.vtkPolyDataMapper() mapTable2.SetInputConnection(table2.GetOutputPort()) mapTable2.ScalarVisibilityOff() table2Actor = vtk.vtkActor() table2Actor.SetMapper(mapTable2) table2Actor.GetProperty().SetColor(colors.GetColor3d('TableTop')) FilingCabinet1 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet1.SetInputData(reader.GetStructuredGridOutput()) FilingCabinet1.SetExtent(15, 15, 7, 9, 0, 8) mapFilingCabinet1 = vtk.vtkPolyDataMapper() mapFilingCabinet1.SetInputConnection(FilingCabinet1.GetOutputPort()) mapFilingCabinet1.ScalarVisibilityOff() FilingCabinet1Actor = vtk.vtkActor() FilingCabinet1Actor.SetMapper(mapFilingCabinet1) FilingCabinet1Actor.GetProperty().SetColor( colors.GetColor3d('FilingCabinet')) FilingCabinet2 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet2.SetInputData(reader.GetStructuredGridOutput()) FilingCabinet2.SetExtent(15, 15, 10, 12, 0, 8) mapFilingCabinet2 = vtk.vtkPolyDataMapper() mapFilingCabinet2.SetInputConnection(FilingCabinet2.GetOutputPort()) mapFilingCabinet2.ScalarVisibilityOff() FilingCabinet2Actor = vtk.vtkActor() FilingCabinet2Actor.SetMapper(mapFilingCabinet2) FilingCabinet2Actor.GetProperty().SetColor( colors.GetColor3d('FilingCabinet')) bookshelf1Top = vtk.vtkStructuredGridGeometryFilter() bookshelf1Top.SetInputData(reader.GetStructuredGridOutput()) bookshelf1Top.SetExtent(13, 13, 0, 4, 0, 11) mapBookshelf1Top = vtk.vtkPolyDataMapper() mapBookshelf1Top.SetInputConnection(bookshelf1Top.GetOutputPort()) mapBookshelf1Top.ScalarVisibilityOff() bookshelf1TopActor = vtk.vtkActor() bookshelf1TopActor.SetMapper(mapBookshelf1Top) bookshelf1TopActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf1Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf1Bottom.SetInputData(reader.GetStructuredGridOutput()) bookshelf1Bottom.SetExtent(20, 20, 0, 4, 0, 11) mapBookshelf1Bottom = vtk.vtkPolyDataMapper() mapBookshelf1Bottom.SetInputConnection(bookshelf1Bottom.GetOutputPort()) mapBookshelf1Bottom.ScalarVisibilityOff() bookshelf1BottomActor = vtk.vtkActor() bookshelf1BottomActor.SetMapper(mapBookshelf1Bottom) bookshelf1BottomActor.GetProperty().SetColor( colors.GetColor3d('BookShelf')) bookshelf1Front = vtk.vtkStructuredGridGeometryFilter() bookshelf1Front.SetInputData(reader.GetStructuredGridOutput()) bookshelf1Front.SetExtent(13, 20, 0, 0, 0, 11) mapBookshelf1Front = vtk.vtkPolyDataMapper() mapBookshelf1Front.SetInputConnection(bookshelf1Front.GetOutputPort()) mapBookshelf1Front.ScalarVisibilityOff() bookshelf1FrontActor = vtk.vtkActor() bookshelf1FrontActor.SetMapper(mapBookshelf1Front) bookshelf1FrontActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf1Back = vtk.vtkStructuredGridGeometryFilter() bookshelf1Back.SetInputData(reader.GetStructuredGridOutput()) bookshelf1Back.SetExtent(13, 20, 4, 4, 0, 11) mapBookshelf1Back = vtk.vtkPolyDataMapper() mapBookshelf1Back.SetInputConnection(bookshelf1Back.GetOutputPort()) mapBookshelf1Back.ScalarVisibilityOff() bookshelf1BackActor = vtk.vtkActor() bookshelf1BackActor.SetMapper(mapBookshelf1Back) bookshelf1BackActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf1LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1LHS.SetInputData(reader.GetStructuredGridOutput()) bookshelf1LHS.SetExtent(13, 20, 0, 4, 0, 0) mapBookshelf1LHS = vtk.vtkPolyDataMapper() mapBookshelf1LHS.SetInputConnection(bookshelf1LHS.GetOutputPort()) mapBookshelf1LHS.ScalarVisibilityOff() bookshelf1LHSActor = vtk.vtkActor() bookshelf1LHSActor.SetMapper(mapBookshelf1LHS) bookshelf1LHSActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf1RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1RHS.SetInputData(reader.GetStructuredGridOutput()) bookshelf1RHS.SetExtent(13, 20, 0, 4, 11, 11) mapBookshelf1RHS = vtk.vtkPolyDataMapper() mapBookshelf1RHS.SetInputConnection(bookshelf1RHS.GetOutputPort()) mapBookshelf1RHS.ScalarVisibilityOff() bookshelf1RHSActor = vtk.vtkActor() bookshelf1RHSActor.SetMapper(mapBookshelf1RHS) bookshelf1RHSActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf2Top = vtk.vtkStructuredGridGeometryFilter() bookshelf2Top.SetInputData(reader.GetStructuredGridOutput()) bookshelf2Top.SetExtent(13, 13, 15, 19, 0, 11) mapBookshelf2Top = vtk.vtkPolyDataMapper() mapBookshelf2Top.SetInputConnection(bookshelf2Top.GetOutputPort()) mapBookshelf2Top.ScalarVisibilityOff() bookshelf2TopActor = vtk.vtkActor() bookshelf2TopActor.SetMapper(mapBookshelf2Top) bookshelf2TopActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf2Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf2Bottom.SetInputData(reader.GetStructuredGridOutput()) bookshelf2Bottom.SetExtent(20, 20, 15, 19, 0, 11) mapBookshelf2Bottom = vtk.vtkPolyDataMapper() mapBookshelf2Bottom.SetInputConnection(bookshelf2Bottom.GetOutputPort()) mapBookshelf2Bottom.ScalarVisibilityOff() bookshelf2BottomActor = vtk.vtkActor() bookshelf2BottomActor.SetMapper(mapBookshelf2Bottom) bookshelf2BottomActor.GetProperty().SetColor( colors.GetColor3d('BookShelf')) bookshelf2Front = vtk.vtkStructuredGridGeometryFilter() bookshelf2Front.SetInputData(reader.GetStructuredGridOutput()) bookshelf2Front.SetExtent(13, 20, 15, 15, 0, 11) mapBookshelf2Front = vtk.vtkPolyDataMapper() mapBookshelf2Front.SetInputConnection(bookshelf2Front.GetOutputPort()) mapBookshelf2Front.ScalarVisibilityOff() bookshelf2FrontActor = vtk.vtkActor() bookshelf2FrontActor.SetMapper(mapBookshelf2Front) bookshelf2FrontActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf2Back = vtk.vtkStructuredGridGeometryFilter() bookshelf2Back.SetInputData(reader.GetStructuredGridOutput()) bookshelf2Back.SetExtent(13, 20, 19, 19, 0, 11) mapBookshelf2Back = vtk.vtkPolyDataMapper() mapBookshelf2Back.SetInputConnection(bookshelf2Back.GetOutputPort()) mapBookshelf2Back.ScalarVisibilityOff() bookshelf2BackActor = vtk.vtkActor() bookshelf2BackActor.SetMapper(mapBookshelf2Back) bookshelf2BackActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf2LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2LHS.SetInputData(reader.GetStructuredGridOutput()) bookshelf2LHS.SetExtent(13, 20, 15, 19, 0, 0) mapBookshelf2LHS = vtk.vtkPolyDataMapper() mapBookshelf2LHS.SetInputConnection(bookshelf2LHS.GetOutputPort()) mapBookshelf2LHS.ScalarVisibilityOff() bookshelf2LHSActor = vtk.vtkActor() bookshelf2LHSActor.SetMapper(mapBookshelf2LHS) bookshelf2LHSActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) bookshelf2RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2RHS.SetInputData(reader.GetStructuredGridOutput()) bookshelf2RHS.SetExtent(13, 20, 15, 19, 11, 11) mapBookshelf2RHS = vtk.vtkPolyDataMapper() mapBookshelf2RHS.SetInputConnection(bookshelf2RHS.GetOutputPort()) mapBookshelf2RHS.ScalarVisibilityOff() bookshelf2RHSActor = vtk.vtkActor() bookshelf2RHSActor.SetMapper(mapBookshelf2RHS) bookshelf2RHSActor.GetProperty().SetColor(colors.GetColor3d('BookShelf')) window = vtk.vtkStructuredGridGeometryFilter() window.SetInputData(reader.GetStructuredGridOutput()) window.SetExtent(20, 20, 6, 13, 10, 13) mapWindow = vtk.vtkPolyDataMapper() mapWindow.SetInputConnection(window.GetOutputPort()) mapWindow.ScalarVisibilityOff() windowActor = vtk.vtkActor() windowActor.SetMapper(mapWindow) windowActor.GetProperty().SetColor(colors.GetColor3d('WindowColor')) outlet = vtk.vtkStructuredGridGeometryFilter() outlet.SetInputData(reader.GetStructuredGridOutput()) outlet.SetExtent(0, 0, 9, 10, 14, 16) mapOutlet = vtk.vtkPolyDataMapper() mapOutlet.SetInputConnection(outlet.GetOutputPort()) mapOutlet.ScalarVisibilityOff() outletActor = vtk.vtkActor() outletActor.SetMapper(mapOutlet) outletActor.GetProperty().SetColor(colors.GetColor3d('lamp_black')) inlet = vtk.vtkStructuredGridGeometryFilter() inlet.SetInputData(reader.GetStructuredGridOutput()) inlet.SetExtent(0, 0, 9, 10, 0, 6) mapInlet = vtk.vtkPolyDataMapper() mapInlet.SetInputConnection(inlet.GetOutputPort()) mapInlet.ScalarVisibilityOff() inletActor = vtk.vtkActor() inletActor.SetMapper(mapInlet) inletActor.GetProperty().SetColor(colors.GetColor3d('lamp_black')) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(reader.GetStructuredGridOutput()) mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) outlineActor.GetProperty().SetColor(colors.GetColor3d('Black')) # Create the rendering window, renderer, and interactive renderer. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Add the remaining actors to the renderer, set the background and size. ren.AddActor(table1Actor) ren.AddActor(table2Actor) ren.AddActor(FilingCabinet1Actor) ren.AddActor(FilingCabinet2Actor) ren.AddActor(bookshelf1TopActor) ren.AddActor(bookshelf1BottomActor) ren.AddActor(bookshelf1FrontActor) ren.AddActor(bookshelf1BackActor) ren.AddActor(bookshelf1LHSActor) ren.AddActor(bookshelf1RHSActor) ren.AddActor(bookshelf2TopActor) ren.AddActor(bookshelf2BottomActor) ren.AddActor(bookshelf2FrontActor) ren.AddActor(bookshelf2BackActor) ren.AddActor(bookshelf2LHSActor) ren.AddActor(bookshelf2RHSActor) ren.AddActor(windowActor) ren.AddActor(outletActor) ren.AddActor(inletActor) ren.AddActor(outlineActor) ren.AddActor(streamTubeActor) ren.SetBackground(colors.GetColor3d('SlateGray')) aCamera = vtk.vtkCamera() aCamera.SetClippingRange(0.726079, 36.3039) aCamera.SetFocalPoint(2.43584, 2.15046, 1.11104) aCamera.SetPosition(-4.76183, -10.4426, 3.17203) aCamera.ComputeViewPlaneNormal() aCamera.SetViewUp(0.0511273, 0.132773, 0.989827) aCamera.SetViewAngle(18.604) aCamera.Zoom(1.2) ren.SetActiveCamera(aCamera) renWin.SetSize(640, 400) renWin.SetWindowName('OfficeTube') iren.Initialize() iren.Start()
"")] = vtk.vtkMultiBlockPLOT3DReader() locals()[get_variable_name("pl3d", scalarFunction, "")].SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") locals()[get_variable_name("pl3d", scalarFunction, "")].SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") locals()[get_variable_name( "pl3d", scalarFunction, "")].SetScalarFunctionNumber( expr.expr(globals(), locals(), ["int", "(", "scalarFunction", ")"])) locals()[get_variable_name("pl3d", scalarFunction, "")].Update() output = locals()[get_variable_name("pl3d", scalarFunction, "")].GetOutput().GetBlock(0) locals()[get_variable_name("plane", scalarFunction, "")] = vtk.vtkStructuredGridGeometryFilter() locals()[get_variable_name("plane", scalarFunction, "")].SetInputData(output) locals()[get_variable_name("plane", scalarFunction, "")].SetExtent(25, 25, 0, 100, 0, 100) locals()[get_variable_name("mapper", scalarFunction, "")] = vtk.vtkPolyDataMapper() locals()[get_variable_name( "mapper", scalarFunction, "")].SetInputConnection(locals()[get_variable_name( "plane", scalarFunction, "")].GetOutputPort()) locals()[get_variable_name("mapper", scalarFunction, "")].SetScalarRange( output.GetPointData().GetScalars().GetRange()) locals()[get_variable_name("actor", scalarFunction, "")] = vtk.vtkActor() locals()[get_variable_name("actor", scalarFunction, "")].SetMapper(locals()[get_variable_name(
def main(): dataFn1, dataFn2, textureFn = get_program_parameters() colors = vtk.vtkNamedColors() # Read the data. pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(dataFn1) pl3d.SetQFileName(dataFn2) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) # Make the wall (floor). wall = vtk.vtkStructuredGridGeometryFilter() wall.SetInputData(output) wall.SetExtent(0, 100, 0, 0, 0, 100) wallMap = vtk.vtkPolyDataMapper() wallMap.SetInputConnection(wall.GetOutputPort()) wallMap.ScalarVisibilityOff() wallActor = vtk.vtkActor() wallActor.SetMapper(wallMap) wallActor.GetProperty().SetColor(colors.GetColor3d('PeachPuff')) # Make the fin (rear wall) fin = vtk.vtkStructuredGridGeometryFilter() fin.SetInputData(output) fin.SetExtent(0, 100, 0, 100, 0, 0) finMap = vtk.vtkPolyDataMapper() finMap.SetInputConnection(fin.GetOutputPort()) finMap.ScalarVisibilityOff() finActor = vtk.vtkActor() finActor.SetMapper(finMap) finActor.GetProperty().SetColor(colors.GetColor3d('DarkSlateGray')) # Get the texture. tmap = vtk.vtkStructuredPointsReader() tmap.SetFileName(textureFn) texture = vtk.vtkTexture() texture.SetInputConnection(tmap.GetOutputPort()) texture.InterpolateOff() texture.RepeatOff() # Create the rendering window, renderer, and interactive renderer. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Make the planes to threshold and texture. plane = list() thresh = list() planeMap = list() planeActor = list() # Define the extents of planes that we will use. planeExtents = [[10, 10, 0, 100, 0, 100], [30, 30, 0, 100, 0, 100], [35, 35, 0, 100, 0, 100]] # Now set up the pipeline. for i in range(0, len(planeExtents)): plane.append(vtk.vtkStructuredGridGeometryFilter()) plane[i].SetInputData(output) plane[i].SetExtent(*planeExtents[i]) thresh.append(vtk.vtkThresholdTextureCoords()) thresh[i].SetInputConnection(plane[i].GetOutputPort()) thresh[i].SetInputConnection(plane[i].GetOutputPort()) # If you want an image similar to Fig 9-43(a) in the VTK textbook, # set thresh[i].ThresholdByUpper(1.5) for all planes. if i == 1: thresh[i].ThresholdByLower(1.5) elif i == 2: thresh[i].ThresholdBetween(1.5, 1.8) else: thresh[i].ThresholdByUpper(1.5) planeMap.append(vtk.vtkDataSetMapper()) planeMap[i].SetInputConnection(thresh[i].GetOutputPort()) planeMap[i].SetScalarRange(output.GetScalarRange()) planeActor.append(vtk.vtkActor()) planeActor[i].SetMapper(planeMap[i]) planeActor[i].SetTexture(texture) # The slight transparency gives a nice effect. planeActor[i].GetProperty().SetOpacity(0.999) ren.AddActor(planeActor[i]) # Get an outline of the data set for context. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineProp = outlineActor.GetProperty() outlineProp.SetColor(colors.GetColor3d('Black')) # Add the remaining actors to the renderer, set the background and size. ren.AddActor(outlineActor) ren.AddActor(wallActor) ren.AddActor(finActor) ren.SetBackground(colors.GetColor3d('MistyRose')) renWin.SetSize(512, 512) renWin.SetWindowName('TextureThreshold') cam = vtk.vtkCamera() cam.SetClippingRange(1.51176, 75.5879) cam.SetFocalPoint(2.33749, 2.96739, 3.61023) cam.SetPosition(10.8787, 5.27346, 15.8687) cam.SetViewAngle(30) cam.SetViewUp(-0.0610856, 0.987798, -0.143262) ren.SetActiveCamera(cam) iren.Initialize() iren.Start()
# Then we assign the plane to the cutter. plane = vtk.vtkPlane() plane.SetOrigin(pl3d_output.GetCenter()) plane.SetNormal(-0.287, 0, 0.9579) planeCut = vtk.vtkCutter() planeCut.SetInputData(pl3d_output) planeCut.SetCutFunction(plane) cutMapper = vtk.vtkPolyDataMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) cutMapper.SetScalarRange(pl3d_output.GetPointData().GetScalars().GetRange()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) # Here we extract a computational plane from the structured grid. # We render it as wireframe. compPlane = vtk.vtkStructuredGridGeometryFilter() compPlane.SetInputData(pl3d_output) compPlane.SetExtent(0, 100, 0, 100, 9, 9) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(compPlane.GetOutputPort()) planeMapper.ScalarVisibilityOff() planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.GetProperty().SetRepresentationToWireframe() planeActor.GetProperty().SetColor(0, 0, 0) # The outline of the data puts the data in context. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3d_output) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort())
camera = vtk.vtkCamera() light = vtk.vtkLight() # All text actors will share the same text prop textProp = vtk.vtkTextProperty() textProp.SetFontSize(10) textProp.SetFontFamilyToArial() textProp.SetColor(.3,1,1) i = 0 for vectorFunction in vectorFunctions.split(): locals()[get_variable_name("pl3d", vectorFunction, "")] = vtk.vtkMultiBlockPLOT3DReader() locals()[get_variable_name("pl3d", vectorFunction, "")].SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") locals()[get_variable_name("pl3d", vectorFunction, "")].SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") locals()[get_variable_name("pl3d", vectorFunction, "")].SetVectorFunctionNumber(expr.expr(globals(), locals(),["int","(","vectorFunction",")"])) locals()[get_variable_name("pl3d", vectorFunction, "")].Update() output = locals()[get_variable_name("pl3d", vectorFunction, "")].GetOutput().GetBlock(0) locals()[get_variable_name("plane", vectorFunction, "")] = vtk.vtkStructuredGridGeometryFilter() locals()[get_variable_name("plane", vectorFunction, "")].SetInputData(output) locals()[get_variable_name("plane", vectorFunction, "")].SetExtent(25,25,0,100,0,100) locals()[get_variable_name("hog", vectorFunction, "")] = vtk.vtkHedgeHog() locals()[get_variable_name("hog", vectorFunction, "")].SetInputConnection(locals()[get_variable_name("plane", vectorFunction, "")].GetOutputPort()) maxnorm = output.GetPointData().GetVectors().GetMaxNorm() locals()[get_variable_name("hog", vectorFunction, "")].SetScaleFactor(expr.expr(globals(), locals(),["1.0","/","maxnorm"])) locals()[get_variable_name("mapper", vectorFunction, "")] = vtk.vtkPolyDataMapper() locals()[get_variable_name("mapper", vectorFunction, "")].SetInputConnection(locals()[get_variable_name("hog", vectorFunction, "")].GetOutputPort()) locals()[get_variable_name("actor", vectorFunction, "")] = vtk.vtkActor() locals()[get_variable_name("actor", vectorFunction, "")].SetMapper(locals()[get_variable_name("mapper", vectorFunction, "")]) locals()[get_variable_name("ren", vectorFunction, "")] = vtk.vtkRenderer() locals()[get_variable_name("ren", vectorFunction, "")].SetBackground(0.5,.5,.5) locals()[get_variable_name("ren", vectorFunction, "")].SetActiveCamera(camera) locals()[get_variable_name("ren", vectorFunction, "")].AddLight(light) renWin.AddRenderer(locals()[get_variable_name("ren", vectorFunction, "")])
def main(): xyzFn, qFn = get_program_parameters() colors = vtk.vtkNamedColors() pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(xyzFn) pl3d.SetQFileName(qFn) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() pl3dOutput = pl3d.GetOutput().GetBlock(0) plane = vtk.vtkStructuredGridGeometryFilter() plane.SetInputData(pl3dOutput) plane.SetExtent(1, 100, 1, 100, 7, 7) lut = vtk.vtkLookupTable() planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetLookupTable(lut) planeMapper.SetInputConnection(plane.GetOutputPort()) planeMapper.SetScalarRange(pl3dOutput.GetScalarRange()) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) # This creates an outline around the data. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3dOutput) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) # Much of the following is commented out. To try different lookup tables, # uncomment the appropriate portions. # # This creates a black to white lut. # lut.SetHueRange(0, 0) # lut.SetSaturationRange(0, 0) # lut.SetValueRange(0.2, 1.0) # This creates a red to blue lut. # lut.SetHueRange(0.0, 0.667) # This creates a blue to red lut. # lut.SetHueRange(0.667, 0.0) # This creates a weird effect. The Build() method causes the lookup table # to allocate memory and create a table based on the correct hue, saturation, # value, and alpha (transparency) range. Here we then manually overwrite the # values generated by the Build() method. lut.SetNumberOfColors(256) lut.SetHueRange(0.0, 0.667) lut.Build() # Create the RenderWindow, Renderer and both Actors. # 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) ren1.AddActor(planeActor) ren1.SetBackground(colors.GetColor3d('SlateGray')) ren1.TwoSidedLightingOff() renWin.SetSize(512, 512) renWin.SetWindowName('Rainbow') iren.Initialize() cam1 = ren1.GetActiveCamera() cam1.SetClippingRange(3.95297, 50) cam1.SetFocalPoint(8.88908, 0.595038, 29.3342) cam1.SetPosition(-12.3332, 31.7479, 41.2387) cam1.SetViewUp(0.060772, -0.319905, 0.945498) iren.Start()
# read data # reader = vtk.vtkStructuredGridReader() reader.SetFileName(VTK_DATA_ROOT + "/Data/office.binary.vtk") reader.Update() # force a read to occur # to add coverage for vtkOnePieceExtentTranslator translator = vtk.vtkOnePieceExtentTranslator() reader.GetExecutive().SetExtentTranslator(0, translator) length = reader.GetOutput().GetLength() maxVelocity = reader.GetOutput().GetPointData().GetVectors().GetMaxNorm() maxTime = 35.0 * length / maxVelocity table1 = vtk.vtkStructuredGridGeometryFilter() table1.SetInputConnection(reader.GetOutputPort()) table1.SetExtent(11, 15, 7, 9, 8, 8) mapTable1 = vtk.vtkPolyDataMapper() mapTable1.SetInputConnection(table1.GetOutputPort()) mapTable1.ScalarVisibilityOff() table1Actor = vtk.vtkActor() table1Actor.SetMapper(mapTable1) table1Actor.GetProperty().SetColor(.59, .427, .392) table2 = vtk.vtkStructuredGridGeometryFilter() table2.SetInputConnection(reader.GetOutputPort()) table2.SetExtent(11, 15, 10, 12, 8, 8) mapTable2 = vtk.vtkPolyDataMapper() mapTable2.SetInputConnection(table2.GetOutputPort()) mapTable2.ScalarVisibilityOff()
# Here we read data from a annular combustor. A combustor burns fuel # and air in a gas turbine (e.g., a jet engine) and the hot gas # eventually makes its way to the turbine section. 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) # Planes are specified using a imin,imax, jmin,jmax, kmin,kmax # coordinate specification. Min and max i,j,k values are clamped to 0 # and maximum value. plane = vtk.vtkStructuredGridGeometryFilter() plane.SetInputData(pl3d_output) plane.SetExtent(10, 10, 1, 100, 1, 100) plane2 = vtk.vtkStructuredGridGeometryFilter() plane2.SetInputData(pl3d_output) plane2.SetExtent(30, 30, 1, 100, 1, 100) plane3 = vtk.vtkStructuredGridGeometryFilter() plane3.SetInputData(pl3d_output) plane3.SetExtent(45, 45, 1, 100, 1, 100) # We use an append filter because that way we can do the warping, # etc. just using a single pipeline and actor. appendF = vtk.vtkAppendPolyData() appendF.AddInputConnection(plane.GetOutputPort()) appendF.AddInputConnection(plane2.GetOutputPort()) appendF.AddInputConnection(plane3.GetOutputPort())
def render(self, **args): """ main function to render all required objects """ gridData = args.get('gridData', True) drawSurface = args.get('drawSurface', True) drawAxes = args.get('drawAxes', True) drawColorBar = args.get('drawColorBar', True) drawLegend = args.get('drawLegend', True) wireSurface = args.get('wireSurface', False) drawBox = args.get('drawBox', True) scaleFactor = args.get('scaleFactor', (1, 1, 1)) autoscale = args.get('autoScale', True) colorMap = args.get('colorMap', 'rainbow') reverseMap = args.get('reverseMap', False) drawGrid = args.get('drawGrid', False) resolution = args.get('gridResolution', 10) xtics = args.get('xtics', 0) ytics = args.get('ytics', 0) ztics = args.get('ztics', 0) planeGrid = args.get('planeGrid', True) xCutterOn = args.get('XCutterOn', True) yCutterOn = args.get('YCutterOn', True) zCutterOn = args.get('ZCutterOn', True) xCutterPos = args.get('XCutterPos', None) yCutterPos = args.get('YCutterPos', None) zCutterPos = args.get('ZCutterPos', None) self.parseRenderArgs(**args) if gridData: geometry = vtk.vtkStructuredGridGeometryFilter() else: geometry = vtk.vtkRectilinearGridGeometryFilter() geometry.SetInputData(self.gridfunc) geometry.SetExtent(self.gridfunc.GetExtent()) if gridData: wzscale = self.computeScale(self.gridfunc) self.out = geometry.GetOutput() else: geometry.SetExtent(self.gridfunc.GetExtent()) geometry.GetOutput().SetPoints(self.Points) geometry.GetOutput().GetPointData().SetScalars(self.Colors) geometry.GetOutput().Update() self.out = geometry.GetOutput() self.out.SetPoints(self.Points) self.out.GetPointData().SetScalars(self.Colors) self.out.Update() wzscale = self.computeScale(self.out) x = self.XScale if autoscale else self.XScale * scaleFactor[0] y = self.YScale if autoscale else self.YScale * scaleFactor[1] z = 0.5 * self.ZScale if autoscale else self.ZScale * scaleFactor[2] transform = vtk.vtkTransform() transform.Scale(x, y, z) trans = vtk.vtkTransformPolyDataFilter() trans.SetInputConnection(geometry.GetOutputPort()) trans.SetTransform(transform) localScale = wzscale if wzscale < 1 else 1 / wzscale self.warp = vtk.vtkWarpScalar() self.warp.XYPlaneOn() self.warp.SetInputConnection(trans.GetOutputPort()) self.warp.SetNormal(0, 0, 1) self.warp.UseNormalOn() self.warp.SetScaleFactor(localScale) tmp = self.gridfunc.GetScalarRange() # map gridfunction self.mapper = vtk.vtkPolyDataMapper() self.mapper.SetInputConnection(self.warp.GetOutputPort()) # calculate ranges if self.customZRange: self.mapper.SetScalarRange(*self.customZRange) elif self.autoZRange: mx = max(abs(tmp[0]), abs(tmp[1])) self.mapper.SetScalarRange(-mx, mx) else: self.mapper.SetScalarRange(tmp[0], tmp[1]) wireActor = None bounds = self.mapper.GetBounds() # wire mapper if planeGrid: if not gridData: self.plane = vtk.vtkRectilinearGridGeometryFilter() self.plane.SetInput(self.gridfunc) self.plane.SetExtent(self.gridfunc.GetExtent()) x_, y_ = x, y else: self.plane = vtk.vtkPlaneSource() self.plane.SetXResolution(resolution) self.plane.SetYResolution(resolution) x_, y_ = bounds[1] - bounds[0], bounds[3] - bounds[2] pltr = vtk.vtkTransform() pltr.Translate((bounds[1] - bounds[0]) / 2. - (0 - bounds[0]), (bounds[3] - bounds[2]) / 2. - (0 - bounds[2]), bounds[4]) pltr.Scale(x_, y_, 1) pltran = vtk.vtkTransformPolyDataFilter() pltran.SetInputConnection(self.plane.GetOutputPort()) pltran.SetTransform(pltr) cmap = self.buildColormap('black-white', True) rgridMapper = vtk.vtkPolyDataMapper() rgridMapper.SetInputConnection(pltran.GetOutputPort()) rgridMapper.SetLookupTable(cmap) wireActor = vtk.vtkActor() wireActor.SetMapper(rgridMapper) wireActor.GetProperty().SetRepresentationToWireframe() wireActor.GetProperty().SetColor(self.fgColor) # xcutter actor xactor = None if xCutterOn: xactor = self.makeXCutter(bounds, scaleFactor, xCutterPos) # ycutter actor yactor = None if yCutterOn: yactor = self.makeYCutter(bounds, scaleFactor, yCutterPos) # zcutter actor zactor = None if zCutterOn: zactor = self.makeZCutter(bounds, scaleFactor, zCutterPos) # create plot surface actor surfplot = vtk.vtkActor() surfplot.SetMapper(self.mapper) if wireSurface: surfplot.GetProperty().SetRepresentationToWireframe() # color map clut = self.buildColormap(colorMap, reverseMap) self.mapper.SetLookupTable(clut) # create outline outlinefilter = vtk.vtkOutlineFilter() outlinefilter.SetInputConnection(self.warp.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outlinefilter.GetOutputPort()) outline = vtk.vtkActor() outline.SetMapper(outlineMapper) outline.GetProperty().SetColor(self.fgColor) # make axes zax, axes = self.makeAxes(outline, outlinefilter) # setup axes xaxis = axes.GetXAxisActor2D() yaxis = axes.GetYAxisActor2D() zaxis = axes.GetZAxisActor2D() xaxis.SetLabelFormat(self.config.XLabelsFormat()) xaxis.SetAdjustLabels(1) xaxis.SetNumberOfMinorTicks(xtics) yaxis.SetLabelFormat(self.config.YLabelsFormat()) yaxis.SetNumberOfMinorTicks(ytics) yaxis.SetAdjustLabels(1) zaxis.SetLabelFormat(self.config.ZLabelsFormat()) zaxis.SetNumberOfMinorTicks(ztics) zaxis.SetAdjustLabels(1) # create colorbar colorbar = self.makeColorbar() # renderer if drawSurface: self.renderer.AddActor(surfplot) self.actors.append(surfplot) if drawGrid: self.renderer.AddViewProp(zax) self.actors.append(zax) if planeGrid: self.renderer.AddActor(wireActor) self.actors.append(wireActor) if drawBox: self.renderer.AddActor(outline) self.actors.append(outline) if drawAxes: self.renderer.AddViewProp(axes) self.actors.append(axes) if drawColorBar or drawLegend: self.renderer.AddActor(colorbar) self.actors.append(colorbar) self.colorbar = colorbar self._addPlaneCutters(xactor, yactor, zactor, xCutterOn, yCutterOn, zCutterOn)
def main(): xyzFilename, qFilename = get_program_parameters() colors = vtk.vtkNamedColors() aren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(aren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) scalarRange = [0.0] * 2 c = [0.0] * 3 maxTime = 0.0 reader = vtk.vtkMultiBlockPLOT3DReader() reader.SetXYZFileName(xyzFilename) reader.SetQFileName(qFilename) reader.Update() # Force a read to occur. pd = reader.GetOutput().GetBlock(0) pd.GetCenter(c) if pd.GetPointData().GetScalars(): pd.GetPointData().GetScalars().GetRange(scalarRange) if pd.GetPointData().GetVectors(): maxVelocity = pd.GetPointData().GetVectors().GetMaxNorm() maxTime = 20.0 * pd.GetLength() / maxVelocity outlineF = vtk.vtkStructuredGridOutlineFilter() outlineF.SetInputData(pd) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outlineF.GetOutputPort()) outline = vtk.vtkActor() outline.SetMapper(outlineMapper) outline.GetProperty().SetColor(colors.GetColor3d('Moccasin')) outline.GetProperty().SetLineWidth(2.0) # # Some geometry for context # wall = vtk.vtkStructuredGridGeometryFilter() wall.SetInputData(pd) wall.SetExtent(0, 100, 0, 100, 0, 0) wallMap = vtk.vtkPolyDataMapper() wallMap.SetInputConnection(wall.GetOutputPort()) wallMap.ScalarVisibilityOff() wallActor = vtk.vtkActor() wallActor.SetMapper(wallMap) wallActor.GetProperty().SetColor(colors.GetColor3d('Silver')) fin = vtk.vtkStructuredGridGeometryFilter() fin.SetInputData(pd) fin.SetExtent(0, 100, 0, 0, 0, 100) finMap = vtk.vtkPolyDataMapper() finMap.SetInputConnection(fin.GetOutputPort()) finMap.ScalarVisibilityOff() finActor = vtk.vtkActor() finActor.SetMapper(finMap) finActor.GetProperty().SetColor(colors.GetColor3d('Silver')) # # regular streamlines # line1 = vtk.vtkLineSource() line1.SetResolution(25) line1.SetPoint1(-6.36, 0.25, 0.06) line1.SetPoint2(-6.36, 0.25, 5.37) rakeMapper = vtk.vtkPolyDataMapper() rakeMapper.SetInputConnection(line1.GetOutputPort()) rake1 = vtk.vtkActor() rake1.SetMapper(rakeMapper) rake1.GetProperty().SetColor(colors.GetColor3d('Black')) rake1.GetProperty().SetLineWidth(5) streamers = vtk.vtkStreamTracer() # streamers.DebugOn() streamers.SetInputConnection(reader.GetOutputPort()) streamers.SetSourceConnection(line1.GetOutputPort()) streamers.SetMaximumPropagation(maxTime) streamers.SetInitialIntegrationStep(0.2) streamers.SetMinimumIntegrationStep(0.01) streamers.SetIntegratorType(2) streamers.Update() streamersMapper = vtk.vtkPolyDataMapper() streamersMapper.SetInputConnection(streamers.GetOutputPort()) streamersMapper.SetScalarRange(scalarRange) lines = vtk.vtkActor() lines.SetMapper(streamersMapper) aren.AddActor(outline) aren.AddActor(wallActor) aren.AddActor(finActor) aren.AddActor(rake1) aren.AddActor(lines) aren.SetBackground(colors.GetColor3d('Gray')) aren.ResetCamera() aren.GetActiveCamera().Elevation(30.0) aren.GetActiveCamera().Azimuth(30.0) aren.GetActiveCamera().Dolly(1.2) aren.ResetCameraClippingRange() renWin.SetSize(640, 480) renWin.SetWindowName('BluntStreamlines') renWin.Render() # Interact with the data. iren.Start()
planeCut.SetInputData(output) planeCut.SetCutFunction(plane) probe = vtk.vtkProbeFilter() probe.SetInputConnection(planeCut.GetOutputPort()) probe.SetSourceData(output) cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(probe.GetOutputPort()) cutMapper.SetScalarRange(output.GetPointData().GetScalars().GetRange()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) #extract plane compPlane = vtk.vtkStructuredGridGeometryFilter() compPlane.SetInputData(output) compPlane.SetExtent(0, 100, 0, 100, 9, 9) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(compPlane.GetOutputPort()) planeMapper.ScalarVisibilityOff() planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.GetProperty().SetRepresentationToWireframe() planeActor.GetProperty().SetColor(0, 0, 0) #outline outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(output)
def furniture(): # generate a whole bunch of planes which correspond to # the geometry in the analysis; tables, bookshelves and so on. from vedo import datadir reader = vtk.vtkStructuredGridReader() reader.SetFileName(datadir + "office.binary.vtk") reader.Update() sgrid = reader.GetOutput() table1 = vtk.vtkStructuredGridGeometryFilter() table1.SetInputData(sgrid) table1.SetExtent(11, 15, 7, 9, 8, 8) mapTable1 = vtk.vtkPolyDataMapper() mapTable1.SetInputConnection(table1.GetOutputPort()) mapTable1.ScalarVisibilityOff() table1Actor = vtk.vtkActor() table1Actor.SetMapper(mapTable1) table1Actor.GetProperty().SetColor(.59, .427, .392) table2 = vtk.vtkStructuredGridGeometryFilter() table2.SetInputData(sgrid) table2.SetExtent(11, 15, 10, 12, 8, 8) mapTable2 = vtk.vtkPolyDataMapper() mapTable2.SetInputConnection(table2.GetOutputPort()) mapTable2.ScalarVisibilityOff() table2Actor = vtk.vtkActor() table2Actor.SetMapper(mapTable2) table2Actor.GetProperty().SetColor(.59, .427, .392) FilingCabinet1 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet1.SetInputData(sgrid) FilingCabinet1.SetExtent(15, 15, 7, 9, 0, 8) mapFilingCabinet1 = vtk.vtkPolyDataMapper() mapFilingCabinet1.SetInputConnection(FilingCabinet1.GetOutputPort()) mapFilingCabinet1.ScalarVisibilityOff() FilingCabinet1Actor = vtk.vtkActor() FilingCabinet1Actor.SetMapper(mapFilingCabinet1) FilingCabinet1Actor.GetProperty().SetColor(.8, .8, .6) FilingCabinet2 = vtk.vtkStructuredGridGeometryFilter() FilingCabinet2.SetInputData(sgrid) FilingCabinet2.SetExtent(15, 15, 10, 12, 0, 8) mapFilingCabinet2 = vtk.vtkPolyDataMapper() mapFilingCabinet2.SetInputConnection(FilingCabinet2.GetOutputPort()) mapFilingCabinet2.ScalarVisibilityOff() FilingCabinet2Actor = vtk.vtkActor() FilingCabinet2Actor.SetMapper(mapFilingCabinet2) FilingCabinet2Actor.GetProperty().SetColor(.8, .8, .6) bookshelf1Top = vtk.vtkStructuredGridGeometryFilter() bookshelf1Top.SetInputData(sgrid) bookshelf1Top.SetExtent(13, 13, 0, 4, 0, 11) mapBookshelf1Top = vtk.vtkPolyDataMapper() mapBookshelf1Top.SetInputConnection(bookshelf1Top.GetOutputPort()) mapBookshelf1Top.ScalarVisibilityOff() bookshelf1TopActor = vtk.vtkActor() bookshelf1TopActor.SetMapper(mapBookshelf1Top) bookshelf1TopActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf1Bottom.SetInputData(sgrid) bookshelf1Bottom.SetExtent(20, 20, 0, 4, 0, 11) mapBookshelf1Bottom = vtk.vtkPolyDataMapper() mapBookshelf1Bottom.SetInputConnection(bookshelf1Bottom.GetOutputPort()) mapBookshelf1Bottom.ScalarVisibilityOff() bookshelf1BottomActor = vtk.vtkActor() bookshelf1BottomActor.SetMapper(mapBookshelf1Bottom) bookshelf1BottomActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Front = vtk.vtkStructuredGridGeometryFilter() bookshelf1Front.SetInputData(sgrid) bookshelf1Front.SetExtent(13, 20, 0, 0, 0, 11) mapBookshelf1Front = vtk.vtkPolyDataMapper() mapBookshelf1Front.SetInputConnection(bookshelf1Front.GetOutputPort()) mapBookshelf1Front.ScalarVisibilityOff() bookshelf1FrontActor = vtk.vtkActor() bookshelf1FrontActor.SetMapper(mapBookshelf1Front) bookshelf1FrontActor.GetProperty().SetColor(.8, .8, .6) bookshelf1Back = vtk.vtkStructuredGridGeometryFilter() bookshelf1Back.SetInputData(sgrid) bookshelf1Back.SetExtent(13, 20, 4, 4, 0, 11) mapBookshelf1Back = vtk.vtkPolyDataMapper() mapBookshelf1Back.SetInputConnection(bookshelf1Back.GetOutputPort()) mapBookshelf1Back.ScalarVisibilityOff() bookshelf1BackActor = vtk.vtkActor() bookshelf1BackActor.SetMapper(mapBookshelf1Back) bookshelf1BackActor.GetProperty().SetColor(.8, .8, .6) bookshelf1LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1LHS.SetInputData(sgrid) bookshelf1LHS.SetExtent(13, 20, 0, 4, 0, 0) mapBookshelf1LHS = vtk.vtkPolyDataMapper() mapBookshelf1LHS.SetInputConnection(bookshelf1LHS.GetOutputPort()) mapBookshelf1LHS.ScalarVisibilityOff() bookshelf1LHSActor = vtk.vtkActor() bookshelf1LHSActor.SetMapper(mapBookshelf1LHS) bookshelf1LHSActor.GetProperty().SetColor(.8, .8, .6) bookshelf1RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf1RHS.SetInputData(sgrid) bookshelf1RHS.SetExtent(13, 20, 0, 4, 11, 11) mapBookshelf1RHS = vtk.vtkPolyDataMapper() mapBookshelf1RHS.SetInputConnection(bookshelf1RHS.GetOutputPort()) mapBookshelf1RHS.ScalarVisibilityOff() bookshelf1RHSActor = vtk.vtkActor() bookshelf1RHSActor.SetMapper(mapBookshelf1RHS) bookshelf1RHSActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Top = vtk.vtkStructuredGridGeometryFilter() bookshelf2Top.SetInputData(sgrid) bookshelf2Top.SetExtent(13, 13, 15, 19, 0, 11) mapBookshelf2Top = vtk.vtkPolyDataMapper() mapBookshelf2Top.SetInputConnection(bookshelf2Top.GetOutputPort()) mapBookshelf2Top.ScalarVisibilityOff() bookshelf2TopActor = vtk.vtkActor() bookshelf2TopActor.SetMapper(mapBookshelf2Top) bookshelf2TopActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Bottom = vtk.vtkStructuredGridGeometryFilter() bookshelf2Bottom.SetInputData(sgrid) bookshelf2Bottom.SetExtent(20, 20, 15, 19, 0, 11) mapBookshelf2Bottom = vtk.vtkPolyDataMapper() mapBookshelf2Bottom.SetInputConnection(bookshelf2Bottom.GetOutputPort()) mapBookshelf2Bottom.ScalarVisibilityOff() bookshelf2BottomActor = vtk.vtkActor() bookshelf2BottomActor.SetMapper(mapBookshelf2Bottom) bookshelf2BottomActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Front = vtk.vtkStructuredGridGeometryFilter() bookshelf2Front.SetInputData(sgrid) bookshelf2Front.SetExtent(13, 20, 15, 15, 0, 11) mapBookshelf2Front = vtk.vtkPolyDataMapper() mapBookshelf2Front.SetInputConnection(bookshelf2Front.GetOutputPort()) mapBookshelf2Front.ScalarVisibilityOff() bookshelf2FrontActor = vtk.vtkActor() bookshelf2FrontActor.SetMapper(mapBookshelf2Front) bookshelf2FrontActor.GetProperty().SetColor(.8, .8, .6) bookshelf2Back = vtk.vtkStructuredGridGeometryFilter() bookshelf2Back.SetInputData(sgrid) bookshelf2Back.SetExtent(13, 20, 19, 19, 0, 11) mapBookshelf2Back = vtk.vtkPolyDataMapper() mapBookshelf2Back.SetInputConnection(bookshelf2Back.GetOutputPort()) mapBookshelf2Back.ScalarVisibilityOff() bookshelf2BackActor = vtk.vtkActor() bookshelf2BackActor.SetMapper(mapBookshelf2Back) bookshelf2BackActor.GetProperty().SetColor(.8, .8, .6) bookshelf2LHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2LHS.SetInputData(sgrid) bookshelf2LHS.SetExtent(13, 20, 15, 19, 0, 0) mapBookshelf2LHS = vtk.vtkPolyDataMapper() mapBookshelf2LHS.SetInputConnection(bookshelf2LHS.GetOutputPort()) mapBookshelf2LHS.ScalarVisibilityOff() bookshelf2LHSActor = vtk.vtkActor() bookshelf2LHSActor.SetMapper(mapBookshelf2LHS) bookshelf2LHSActor.GetProperty().SetColor(.8, .8, .6) bookshelf2RHS = vtk.vtkStructuredGridGeometryFilter() bookshelf2RHS.SetInputData(sgrid) bookshelf2RHS.SetExtent(13, 20, 15, 19, 11, 11) mapBookshelf2RHS = vtk.vtkPolyDataMapper() mapBookshelf2RHS.SetInputConnection(bookshelf2RHS.GetOutputPort()) mapBookshelf2RHS.ScalarVisibilityOff() bookshelf2RHSActor = vtk.vtkActor() bookshelf2RHSActor.SetMapper(mapBookshelf2RHS) bookshelf2RHSActor.GetProperty().SetColor(.8, .8, .6) window = vtk.vtkStructuredGridGeometryFilter() window.SetInputData(sgrid) window.SetExtent(20, 20, 6, 13, 10, 13) mapWindow = vtk.vtkPolyDataMapper() mapWindow.SetInputConnection(window.GetOutputPort()) mapWindow.ScalarVisibilityOff() windowActor = vtk.vtkActor() windowActor.SetMapper(mapWindow) windowActor.GetProperty().SetColor(.3, .3, .5) outlet = vtk.vtkStructuredGridGeometryFilter() outlet.SetInputData(sgrid) outlet.SetExtent(0, 0, 9, 10, 14, 16) mapOutlet = vtk.vtkPolyDataMapper() mapOutlet.SetInputConnection(outlet.GetOutputPort()) mapOutlet.ScalarVisibilityOff() outletActor = vtk.vtkActor() outletActor.SetMapper(mapOutlet) outletActor.GetProperty().SetColor(1, 1, 1) inlet = vtk.vtkStructuredGridGeometryFilter() inlet.SetInputData(sgrid) inlet.SetExtent(0, 0, 9, 10, 0, 6) mapInlet = vtk.vtkPolyDataMapper() mapInlet.SetInputConnection(inlet.GetOutputPort()) mapInlet.ScalarVisibilityOff() inletActor = vtk.vtkActor() inletActor.SetMapper(mapInlet) inletActor.GetProperty().SetColor(1, 1, 1) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(sgrid) mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) outlineActor.GetProperty().SetColor(1, 1, 1) acts = [] acts.append(table1Actor) acts.append(table2Actor) acts.append(FilingCabinet1Actor) acts.append(FilingCabinet2Actor) acts.append(bookshelf1TopActor) acts.append(bookshelf1BottomActor) acts.append(bookshelf1FrontActor) acts.append(bookshelf1BackActor) acts.append(bookshelf1LHSActor) acts.append(bookshelf1RHSActor) acts.append(bookshelf2TopActor) acts.append(bookshelf2BottomActor) acts.append(bookshelf2FrontActor) acts.append(bookshelf2BackActor) acts.append(bookshelf2LHSActor) acts.append(bookshelf2RHSActor) acts.append(windowActor) acts.append(outletActor) acts.append(inletActor) acts.append(outlineActor) return acts
def main(): xyzFile, qFile = get_program_parameters() colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # The cut data. pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(xyzFile) pl3d.SetQFileName(qFile) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() sg = pl3d.GetOutput().GetBlock(0) plane = vtk.vtkPlane() plane.SetOrigin(sg.GetCenter()) plane.SetNormal(-0.287, 0, 0.9579) planeCut = vtk.vtkCutter() planeCut.SetInputData(pl3d.GetOutput().GetBlock(0)) planeCut.SetCutFunction(plane) cutMapper = vtk.vtkDataSetMapper() cutMapper.SetInputConnection(planeCut.GetOutputPort()) cutMapper.SetScalarRange(sg.GetPointData().GetScalars().GetRange()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) # Extract the plane. compPlane = vtk.vtkStructuredGridGeometryFilter() compPlane.SetInputData(sg) compPlane.SetExtent(0, 100, 0, 100, 9, 9) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(compPlane.GetOutputPort()) planeMapper.ScalarVisibilityOff() planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.GetProperty().SetRepresentationToWireframe() planeActor.GetProperty().SetColor(colors.GetColor3d("Wheat")) # Outline. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3d.GetOutput().GetBlock(0)) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d("Wheat")) # Add the actors to the renderer, set the background and size. # ren1.AddActor(outlineActor) ren1.AddActor(planeActor) ren1.AddActor(cutActor) ren1.SetBackground(colors.GetColor3d("SlateGray")) renWin.SetSize(640, 480) 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().SetViewUp(-0.16123, 0.264271, 0.950876) ren1.ResetCamera() ren1.GetActiveCamera().Elevation(30) # Render the image. # renWin.Render() iren.Start()
def main(): colors = vtk.vtkNamedColors() fileName1, fileName2 = get_program_parameters() # Here we read data from a annular combustor. A combustor burns fuel and air # in a gas turbine (e.g., a jet engine) and the hot gas eventually makes its # way to the turbine section. # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName(fileName1) pl3d.SetQFileName(fileName2) pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() pl3dOutput = pl3d.GetOutput().GetBlock(0) # Planes are specified using a imin,imax, jmin,jmax, kmin,kmax coordinate # specification. Min and max i,j,k values are clamped to 0 and maximum value. # plane = vtk.vtkStructuredGridGeometryFilter() plane.SetInputData(pl3dOutput) plane.SetExtent(10, 10, 1, 100, 1, 100) plane2 = vtk.vtkStructuredGridGeometryFilter() plane2.SetInputData(pl3dOutput) plane2.SetExtent(30, 30, 1, 100, 1, 100) plane3 = vtk.vtkStructuredGridGeometryFilter() plane3.SetInputData(pl3dOutput) plane3.SetExtent(45, 45, 1, 100, 1, 100) # We use an append filter because that way we can do the warping, etc. just # using a single pipeline and actor. # appendF = vtk.vtkAppendPolyData() appendF.AddInputConnection(plane.GetOutputPort()) appendF.AddInputConnection(plane2.GetOutputPort()) appendF.AddInputConnection(plane3.GetOutputPort()) warp = vtk.vtkWarpScalar() warp.SetInputConnection(appendF.GetOutputPort()) warp.UseNormalOn() warp.SetNormal(1.0, 0.0, 0.0) warp.SetScaleFactor(2.5) normals = vtk.vtkPolyDataNormals() normals.SetInputConnection(warp.GetOutputPort()) normals.SetFeatureAngle(60) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(normals.GetOutputPort()) planeMapper.SetScalarRange(pl3dOutput.GetScalarRange()) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) # The outline provides context for the data and the planes. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputData(pl3dOutput) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d('Black')) # Create the usual graphics stuff. # ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren1.AddActor(outlineActor) ren1.AddActor(planeActor) ren1.SetBackground(colors.GetColor3d('Silver')) renWin.SetSize(640, 480) renWin.SetWindowName('WarpCombustor') # Create an initial view. ren1.GetActiveCamera().SetClippingRange(3.95297, 50) ren1.GetActiveCamera().SetFocalPoint(8.88908, 0.595038, 29.3342) ren1.GetActiveCamera().SetPosition(-12.3332, 31.7479, 41.2387) ren1.GetActiveCamera().SetViewUp(0.060772, -0.319905, 0.945498) iren.Initialize() # Render the image. # renWin.Render() iren.Start()
renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # read data # pl3d = vtk.vtkMultiBlockPLOT3DReader() pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinxyz.bin") pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/bluntfinq.bin") pl3d.SetScalarFunctionNumber(100) pl3d.SetVectorFunctionNumber(202) pl3d.Update() output = pl3d.GetOutput().GetBlock(0) # wall # wall = vtk.vtkStructuredGridGeometryFilter() wall.SetInputData(output) wall.SetExtent(0, 100, 0, 0, 0, 100) wallMap = vtk.vtkPolyDataMapper() wallMap.SetInputConnection(wall.GetOutputPort()) wallMap.ScalarVisibilityOff() wallActor = vtk.vtkActor() wallActor.SetMapper(wallMap) wallActor.GetProperty().SetColor(0.8, 0.8, 0.8) # fin # fin = vtk.vtkStructuredGridGeometryFilter() fin.SetInputData(output) fin.SetExtent(0, 100, 0, 100, 0, 0) finMap = vtk.vtkPolyDataMapper() finMap.SetInputConnection(fin.GetOutputPort())