import vtk import ovtk # Read in an image and compute a luminance value. The image is # extracted as a set of polygons (vtkImageDataGeometryFilter). We then # will warp the plane using the scalar (luminance) values. reader = vtk.vtkBMPReader() reader.SetFileName(ovtk.findFile("vtk/data/masonry.bmp")) luminance = vtk.vtkImageLuminance() luminance.SetInputConnection(reader.GetOutputPort()) geometry = vtk.vtkImageDataGeometryFilter() geometry.SetInputConnection(luminance.GetOutputPort()) warp = vtk.vtkWarpScalar() warp.SetInputConnection(geometry.GetOutputPort()) warp.SetScaleFactor(-0.1) # Use vtkMergeFilter to combine the original image with the warped # geometry. merge = vtk.vtkMergeFilter() merge.SetGeometry(warp.GetOutput()) merge.SetScalars(reader.GetOutput()) mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(merge.GetOutputPort()) mapper.SetScalarRange(0, 255) mapper.ImmediateModeRenderingOff() actor = vtk.vtkActor() actor.SetMapper(mapper) # Add the actors to the renderer, set the background and size ovtk.addActor(actor)
mapInlet = vtk.vtkPolyDataMapper() mapInlet.SetInputConnection(inlet.GetOutputPort()) mapInlet.ScalarVisibilityOff() inletActor = vtk.vtkActor() inletActor.SetMapper(mapInlet) inletActor.GetProperty().SetColor(0, 0, 0) outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputConnection(reader.GetOutputPort()) mapOutline = vtk.vtkPolyDataMapper() mapOutline.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(mapOutline) outlineActor.GetProperty().SetColor(0, 0, 0) ovtk.addActor(table1Actor) ovtk.addActor(table2Actor) ovtk.addActor(FilingCabinet1Actor) ovtk.addActor(FilingCabinet2Actor) ovtk.addActor(bookshelf1TopActor) ovtk.addActor(bookshelf1BottomActor) ovtk.addActor(bookshelf1FrontActor) ovtk.addActor(bookshelf1BackActor) ovtk.addActor(bookshelf1LHSActor) ovtk.addActor(bookshelf1RHSActor) ovtk.addActor(bookshelf2TopActor) ovtk.addActor(bookshelf2BottomActor) ovtk.addActor(bookshelf2FrontActor) ovtk.addActor(bookshelf2BackActor) ovtk.addActor(bookshelf2LHSActor) ovtk.addActor(bookshelf2RHSActor)
cone = vtk.vtkConeSource() coneMapper = vtk.vtkPolyDataMapper() coneMapper.SetInputConnection(cone.GetOutputPort()) coneActor = vtk.vtkActor() coneActor.SetMapper(coneMapper) coneActor.SetPosition(0, 0, .25) coneActor.GetProperty().SetColor(0, 1, 0) # top part of the assembly cylinder = vtk.vtkCylinderSource() cylinderMapper = vtk.vtkPolyDataMapper() cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) cylinderMapper.SetResolveCoincidentTopologyToPolygonOffset() cylinderActor = vtk.vtkActor() cylinderActor.SetMapper(cylinderMapper) cylinderActor.GetProperty().SetColor(1, 0, 0) # Create the assembly and add the 4 parts to it. Also set the origin, # position and orientation in space. assembly = vtk.vtkAssembly() assembly.AddPart(cylinderActor) assembly.AddPart(sphereActor) assembly.AddPart(cubeActor) assembly.AddPart(coneActor) assembly.SetOrigin(5, 10, 15) assembly.AddPosition(5, 0, 0) assembly.RotateX(15) ovtk.addActor(assembly)
cutMapper.SetInput(cutPoly) cutMapper.SetInputConnection(cutTriangles.GetOutputPort()) cutActor = vtk.vtkActor() cutActor.SetMapper(cutMapper) cutActor.GetProperty().SetColor(peacock) # The clipped part of the cow is rendered wireframe. restMapper = vtk.vtkPolyDataMapper() restMapper.SetInput(clipper.GetClippedOutput()) restMapper.ScalarVisibilityOff() restActor = vtk.vtkActor() restActor.SetMapper(restMapper) restActor.GetProperty().SetRepresentationToWireframe() # Add the actors to the renderer, set the background and size ovtk.addActor(clipActor) ovtk.addActor(cutActor) ovtk.addActor(restActor) # Lets you move the cut plane back and forth by invoking the function # Cut with the appropriate plane value (essentially a distance from # the original plane). This is not used in this code but should give # you an idea of how to define a function to do this. def Cut(v): clipper.SetValue(v) cutEdges.SetValue(0, v) cutStrips.Update() cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) cutMapper.Update()
appendF = vtk.vtkAppendPolyData() appendF.AddInput(plane.GetOutput()) appendF.AddInput(plane2.GetOutput()) appendF.AddInput(plane3.GetOutput()) 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.SetInput(warp.GetPolyDataOutput()) normals.SetFeatureAngle(60) planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(normals.GetOutputPort()) planeMapper.SetScalarRange(pl3d.GetOutput().GetScalarRange()) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.GetProperty().SetLighting(0) # The outline provides context for the data and the planes. outline = vtk.vtkStructuredGridOutlineFilter() outline.SetInputConnection(pl3d.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(0, 0, 0) ovtk.addActor(outlineActor) ovtk.addActor(planeActor)
# This simple example shows how to do basic texture mapping. import vtk import ovtk # Load in the texture map. A texture is any unsigned char image. If it # is not of this type, you will have to map it through a lookup table # or by using vtkImageShiftScale. bmpReader = vtk.vtkBMPReader() bmpReader.SetFileName(ovtk.findFile("vtk/data/masonry.bmp")) atext = vtk.vtkTexture() atext.SetInputConnection(bmpReader.GetOutputPort()) atext.InterpolateOn() # Create a plane source and actor. The vtkPlanesSource generates # texture coordinates. plane = vtk.vtkPlaneSource() planeMapper = vtk.vtkPolyDataMapper() planeMapper.SetInputConnection(plane.GetOutputPort()) planeActor = vtk.vtkActor() planeActor.SetMapper(planeMapper) planeActor.SetTexture(atext) # Add the actors to the renderer, set the background and size ovtk.addActor(planeActor)