Commit d6007900 authored by Prabhu Ramachandran's avatar Prabhu Ramachandran

NEW: Added several examples translated from Tcl.

parent 260fa89a
#!/usr/bin/env python
# In this example we show the use of the
# vtkBandedPolyDataContourFilter. This filter creates separate,
# constant colored bands for a range of scalar values. Each band is
# bounded by two scalar values, and the cell data lying within the
# value has the same cell scalar value.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# The lookup table is similar to that used by maps. Two hues are used:
# a brown for land, and a blue for water. The value of the hue is
# changed to give the effect of elevation.
Scale = 5
lutWater = vtk.vtkLookupTable()
lutWater.SetNumberOfColors(10)
lutWater.SetHueRange(0.58, 0.58)
lutWater.SetSaturationRange(0.5, 0.1)
lutWater.SetValueRange(0.5, 1.0)
lutWater.Build()
lutLand = vtk.vtkLookupTable()
lutLand.SetNumberOfColors(10)
lutLand.SetHueRange(0.1, 0.1)
lutLand.SetSaturationRange(0.4, 0.1)
lutLand.SetValueRange(0.55, 0.9)
lutLand.Build()
# The DEM reader reads data and creates an output image.
demModel = vtk.vtkDEMReader()
demModel.SetFileName(VTK_DATA_ROOT + "/Data/SainteHelens.dem")
demModel.Update()
# We shrink the terrain data down a bit to yield better performance for
# this example.
shrinkFactor = 4
shrink = vtk.vtkImageShrink3D()
shrink.SetShrinkFactors(shrinkFactor, shrinkFactor, 1)
shrink.SetInput(demModel.GetOutput())
shrink.AveragingOn()
# Convert the image into polygons.
geom = vtk.vtkImageDataGeometryFilter()
geom.SetInput(shrink.GetOutput())
# Warp the polygons based on elevation.
warp = vtk.vtkWarpScalar()
warp.SetInput(geom.GetOutput())
warp.SetNormal(0, 0, 1)
warp.UseNormalOn()
warp.SetScaleFactor(Scale)
# Create the contour bands.
bcf = vtk.vtkBandedPolyDataContourFilter()
bcf.SetInput(warp.GetPolyDataOutput())
bcf.GenerateValues(15, demModel.GetOutput().GetScalarRange())
bcf.SetScalarModeToIndex()
bcf.GenerateContourEdgesOn()
# Compute normals to give a better look.
normals = vtk.vtkPolyDataNormals()
normals.SetInput(bcf.GetOutput())
normals.SetFeatureAngle(60)
normals.ConsistencyOff()
normals.SplittingOff()
demMapper = vtk.vtkPolyDataMapper()
demMapper.SetInput(normals.GetOutput())
demMapper.SetScalarRange(0, 10)
demMapper.SetLookupTable(lutLand)
demMapper.SetScalarModeToUseCellData()
demActor = vtk.vtkLODActor()
demActor.SetMapper(demMapper)
## Create contour edges
edgeMapper = vtk.vtkPolyDataMapper()
edgeMapper.SetInput(bcf.GetContourEdgesOutput())
edgeMapper.SetResolveCoincidentTopologyToPolygonOffset()
edgeActor = vtk.vtkActor()
edgeActor.SetMapper(edgeMapper)
edgeActor.GetProperty().SetColor(0, 0, 0)
## Test clipping
# Create the contour bands.
bcf2 = vtk.vtkBandedPolyDataContourFilter()
bcf2.SetInput(warp.GetPolyDataOutput())
bcf2.ClippingOn()
bcf2.GenerateValues(10, 1000, 2000)
bcf2.SetScalarModeToValue()
# Compute normals to give a better look.
normals2 = vtk.vtkPolyDataNormals()
normals2.SetInput(bcf2.GetOutput())
normals2.SetFeatureAngle(60)
normals2.ConsistencyOff()
normals2.SplittingOff()
lut = vtk.vtkLookupTable()
lut.SetNumberOfColors(10)
demMapper2 = vtk.vtkPolyDataMapper()
demMapper2.SetInput(normals2.GetOutput())
demMapper2.SetScalarRange(demModel.GetOutput().GetScalarRange())
demMapper2.SetLookupTable(lut)
demMapper2.SetScalarModeToUseCellData()
demActor2 = vtk.vtkLODActor()
demActor2.SetMapper(demMapper2)
demActor2.AddPosition(0, 15000, 0)
# 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(demActor)
ren.AddActor(demActor2)
ren.AddActor(edgeActor)
ren.SetBackground(.4, .4, .4)
renWin.SetSize(375, 200)
cam = vtk.vtkCamera()
cam.SetPosition(-17438.8, 2410.62, 25470.8)
cam.SetFocalPoint(3985.35, 11930.6, 5922.14)
cam.SetViewUp(0, 0, 1)
ren.SetActiveCamera(cam)
ren.ResetCameraClippingRange()
iren.Initialize()
iren.SetDesiredUpdateRate(1)
def CheckAbort(obj, event):
foo = renWin.GetEventPending()
if foo != 0:
renWin.SetAbortRender(1)
renWin.AddObserver("AbortCheckEvent", CheckAbort)
renWin.Render()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# In this example vtkClipPolyData is used to cut a polygonal model
# of a cow in half. In addition, the open clip is closed by triangulating
# the resulting complex polygons.
import vtk
from vtk.util.misc import vtkGetDataRoot
from vtk.util.colors import peacock, tomato
VTK_DATA_ROOT = vtkGetDataRoot()
# First start by reading a cow model. We also generate surface normals for
# prettier rendering.
cow = vtk.vtkBYUReader()
cow.SetGeometryFileName(VTK_DATA_ROOT + "/Data/Viewpoint/cow.g")
cowNormals = vtk.vtkPolyDataNormals()
cowNormals.SetInput(cow.GetOutput())
# We clip with an implicit function. Here we use a plane positioned near
# the center of the cow model and oriented at an arbitrary angle.
plane = vtk.vtkPlane()
plane.SetOrigin(0.25, 0, 0)
plane.SetNormal(-1, -1, 0)
# vtkClipPolyData requires an implicit function to define what it is to
# clip with. Any implicit function, including complex boolean combinations
# can be used. Notice that we can specify the value of the implicit function
# with the SetValue method.
clipper = vtk.vtkClipPolyData()
clipper.SetInput(cowNormals.GetOutput())
clipper.SetClipFunction(plane)
clipper.GenerateClipScalarsOn()
clipper.GenerateClippedOutputOn()
clipper.SetValue(0.5)
clipMapper = vtk.vtkPolyDataMapper()
clipMapper.SetInput(clipper.GetOutput())
clipMapper.ScalarVisibilityOff()
backProp = vtk.vtkProperty()
backProp.SetDiffuseColor(tomato)
clipActor = vtk.vtkActor()
clipActor.SetMapper(clipMapper)
clipActor.GetProperty().SetColor(peacock)
clipActor.SetBackfaceProperty(backProp)
# Here we are cutting the cow. Cutting creates lines where the cut
# function intersects the model. (Clipping removes a portion of the
# model but the dimension of the data does not change.)
#
# The reason we are cutting is to generate a closed polygon at the
# boundary of the clipping process. The cutter generates line
# segments, the stripper then puts them together into polylines. We
# then pull a trick and define polygons using the closed line
# segements that the stripper created.
cutEdges = vtk.vtkCutter()
cutEdges.SetInput(cowNormals.GetOutput())
cutEdges.SetCutFunction(plane)
cutEdges.GenerateCutScalarsOn()
cutEdges.SetValue(0, 0.5)
cutStrips = vtk.vtkStripper()
cutStrips.SetInput(cutEdges.GetOutput())
cutStrips.Update()
cutPoly = vtk.vtkPolyData()
cutPoly.SetPoints(cutStrips.GetOutput().GetPoints())
cutPoly.SetPolys(cutStrips.GetOutput().GetLines())
# Triangle filter is robust enough to ignore the duplicate point at
# the beginning and end of the polygons and triangulate them.
cutTriangles = vtk.vtkTriangleFilter()
cutTriangles.SetInput(cutPoly)
cutMapper = vtk.vtkPolyDataMapper()
cutMapper.SetInput(cutPoly)
cutMapper.SetInput(cutTriangles.GetOutput())
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()
# Create graphics stuff
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(clipActor)
ren.AddActor(cutActor)
ren.AddActor(restActor)
ren.SetBackground(1, 1, 1)
ren.GetActiveCamera().Azimuth(30)
ren.GetActiveCamera().Elevation(30)
ren.GetActiveCamera().Dolly(1.5)
ren.ResetCameraClippingRange()
renWin.SetSize(300, 300)
iren.Initialize()
# 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()
renWin.Render()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example shows how to color an isosurface with other
# data. Basically an isosurface is generated, and a data array is
# selected and used by the mapper to color the surface.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Read some data. The important thing here is to read a function as a
# data array as well as the scalar and vector. (here function 153 is
# named "Velocity Magnitude").Later this data array will be used to
# color the isosurface.
pl3d = vtk.vtkPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.AddFunction(153)
pl3d.Update()
pl3d.DebugOn()
# The contour filter uses the labeled scalar (function number 100
# above to generate the contour surface; all other data is
# interpolated during the contouring process.
iso = vtk.vtkContourFilter()
iso.SetInput(pl3d.GetOutput())
iso.SetValue(0, .24)
normals = vtk.vtkPolyDataNormals()
normals.SetInput(iso.GetOutput())
normals.SetFeatureAngle(45)
# We indicate to the mapper to use the velcoity magnitude, which is a
# vtkDataArray that makes up part of the point attribute data.
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInput(normals.GetOutput())
isoMapper.ScalarVisibilityOn()
isoMapper.SetScalarRange(0, 1500)
isoMapper.SetScalarModeToUsePointFieldData()
isoMapper.ColorByArrayComponent("VelocityMagnitude", 0)
isoActor = vtk.vtkLODActor()
isoActor.SetMapper(isoMapper)
isoActor.SetNumberOfCloudPoints(1000)
outline = vtk.vtkStructuredGridOutlineFilter()
outline.SetInput(pl3d.GetOutput())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
# Create the usual rendering stuff.
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(outlineActor)
ren.AddActor(isoActor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(500, 500)
ren.SetBackground(0.1, 0.2, 0.4)
cam1 = ren.GetActiveCamera()
cam1.SetClippingRange(3.95297, 50)
cam1.SetFocalPoint(9.71821, 0.458166, 29.3999)
cam1.SetPosition(2.7439, -37.3196, 38.7167)
cam1.SetViewUp(-0.16123, 0.264271, 0.950876)
iren.Initialize()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example shows how to use cutting (vtkCutter) and how it
# compares with extracting a plane from a computational grid.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Read some data.
pl3d = vtk.vtkPLOT3DReader()
pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin")
pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin")
pl3d.SetScalarFunctionNumber(100)
pl3d.SetVectorFunctionNumber(202)
pl3d.Update()
# The cutter uses an implicit function to perform the cutting.
# Here we define a plane, specifying its center and normal.
# Then we assign the plane to the cutter.
plane = vtk.vtkPlane()
plane.SetOrigin(pl3d.GetOutput().GetCenter())
plane.SetNormal(-0.287, 0, 0.9579)
planeCut = vtk.vtkCutter()
planeCut.SetInput(pl3d.GetOutput())
planeCut.SetCutFunction(plane)
cutMapper = vtk.vtkPolyDataMapper()
cutMapper.SetInput(planeCut.GetOutput())
cutMapper.SetScalarRange(pl3d.GetOutput().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.SetInput(pl3d.GetOutput())
compPlane.SetExtent(0, 100, 0, 100, 9, 9)
planeMapper = vtk.vtkPolyDataMapper()
planeMapper.SetInput(compPlane.GetOutput())
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.SetInput(pl3d.GetOutput())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineProp = outlineActor.GetProperty()
outlineProp.SetColor(0, 0, 0)
# 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(outlineActor)
ren.AddActor(planeActor)
ren.AddActor(cutActor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(400, 300)
cam1 = ren.GetActiveCamera()
cam1.SetClippingRange(11.1034, 59.5328)
cam1.SetFocalPoint(9.71821, 0.458166, 29.3999)
cam1.SetPosition(-2.95748, -26.7271, 44.5309)
cam1.SetViewUp(0.0184785, 0.479657, 0.877262)
iren.Initialize()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example demonstrates the use of vtkDepthSortPolyData. This is a
# poor man's algorithm to sort polygons for proper transparent
# blending. It sorts polygons based on a single point (i.e.,
# centroid) so the sorting may not work for overlapping or
# intersection polygons.
import vtk
# Create a bunch of spheres that overlap and cannot be easily arranged
# so that the blending works without sorting. They are appended into a
# single vtkPolyData because the filter only sorts within a single
# vtkPolyData input.
sphere = vtk.vtkSphereSource()
sphere.SetThetaResolution(80)
sphere.SetPhiResolution(40)
sphere.SetRadius(1)
sphere.SetCenter(0, 0, 0)
sphere2 = vtk.vtkSphereSource()
sphere2.SetThetaResolution(80)
sphere2.SetPhiResolution(40)
sphere2.SetRadius(0.5)
sphere2.SetCenter(1, 0, 0)
sphere3 = vtk.vtkSphereSource()
sphere3.SetThetaResolution(80)
sphere3.SetPhiResolution(40)
sphere3.SetRadius(0.5)
sphere3.SetCenter(-1, 0, 0)
sphere4 = vtk.vtkSphereSource()
sphere4.SetThetaResolution(80)
sphere4.SetPhiResolution(40)
sphere4.SetRadius(0.5)
sphere4.SetCenter(0, 1, 0)
sphere5 = vtk.vtkSphereSource()
sphere5.SetThetaResolution(80)
sphere5.SetPhiResolution(40)
sphere5.SetRadius(0.5)
sphere5.SetCenter(0, -1, 0)
appendData = vtk.vtkAppendPolyData()
appendData.AddInput(sphere.GetOutput())
appendData.AddInput(sphere2.GetOutput())
appendData.AddInput(sphere3.GetOutput())
appendData.AddInput(sphere4.GetOutput())
appendData.AddInput(sphere5.GetOutput())
# The dephSort object is set up to generate scalars representing
# the sort depth. A camera is assigned for the sorting. The camera
# define the sort vector (position and focal point).
camera = vtk.vtkCamera()
depthSort = vtk.vtkDepthSortPolyData()
depthSort.SetInput(appendData.GetOutput())
depthSort.SetDirectionToBackToFront()
depthSort.SetVector(1, 1, 1)
depthSort.SetCamera(camera)
depthSort.SortScalarsOn()
depthSort.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(depthSort.GetOutput())
mapper.SetScalarRange(0, depthSort.GetOutput().GetNumberOfCells())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetOpacity(0.5)
actor.GetProperty().SetColor(1, 0, 0)
actor.RotateX(-72)
# If an Prop3D is supplied, then its transformation matrix is taken
# into account during sorting.
depthSort.SetProp3D(actor)
# Create the RenderWindow, Renderer and both Actors
ren = vtk.vtkRenderer()
ren.SetActiveCamera(camera)
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(actor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(300, 200)
ren.ResetCamera()
ren.GetActiveCamera().Zoom(2.2)
iren.Initialize()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example shows how to extract a piece of a dataset using an
# implicit function. In this case the implicit function is formed by
# the boolean combination of two ellipsoids.
import vtk
# Here we create two ellipsoidal implicit functions and boolean them
# together tto form a "cross" shaped implicit function.
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(50, 50, 50)
sample.SetImplicitFunction(quadric)
sample.ComputeNormalsOff()
trans = vtk.vtkTransform()
trans.Scale(1, .5, .333)
sphere = vtk.vtkSphere()
sphere.SetRadius(0.25)
sphere.SetTransform(trans)
trans2 = vtk.vtkTransform()
trans2.Scale(.25, .5, 1.0)
sphere2 = vtk.vtkSphere()
sphere2.SetRadius(0.25)
sphere2.SetTransform(trans2)
union = vtk.vtkImplicitBoolean()
union.AddFunction(sphere)
union.AddFunction(sphere2)
union.SetOperationType(0) #union
# Here is where it gets interesting. The implicit function is used to
# extract those cells completely inside the function. They are then
# shrunk to help show what was extracted.
extract = vtk.vtkExtractGeometry()
extract.SetInput(sample.GetOutput())
extract.SetImplicitFunction(union)
shrink = vtk.vtkShrinkFilter()
shrink.SetInput(extract.GetOutput())
shrink.SetShrinkFactor(0.5)
dataMapper = vtk.vtkDataSetMapper()
dataMapper.SetInput(shrink.GetOutput())
dataActor = vtk.vtkActor()
dataActor.SetMapper(dataMapper)
# The outline gives context to the original data.
outline = vtk.vtkOutlineFilter()
outline.SetInput(sample.GetOutput())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineProp = outlineActor.GetProperty()
outlineProp.SetColor(0, 0, 0)
# The usual rendering stuff is created.
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(outlineActor)
ren.AddActor(dataActor)
ren.SetBackground(1, 1, 1)
renWin.SetSize(500, 500)
ren.GetActiveCamera().Zoom(1.5)
iren.Initialize()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example shows how to extract portions of an unstructured grid
# using vtkExtractUnstructuredGrid. vtkConnectivityFilter is also used
# to extract connected components.
#
# The data found here represents a blow molding process. Blow molding
# requires a mold and parison (hot, viscous plastic) which is shaped
# by the mold into the final form. The data file contains several steps
# in time for the analysis.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Create a reader to read the unstructured grid data. We use a
# vtkDataSetReader which means the type of the output is unknown until
# the data file is read. So we follow the reader with a
# vtkCastToConcrete and cast the output to vtkUnstructuredGrid.
reader = vtk.vtkDataSetReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/blow.vtk")
reader.SetScalarsName("thickness9")
reader.SetVectorsName("displacement9")
castToUnstructuredGrid = vtk.vtkCastToConcrete()
castToUnstructuredGrid.SetInput(reader.GetOutput())
warp = vtk.vtkWarpVector()
warp.SetInput(castToUnstructuredGrid.GetUnstructuredGridOutput())
# The connectivity filter extracts the first two regions. These are
# know to represent the mold.
connect = vtk.vtkConnectivityFilter()
connect.SetInput(warp.GetOutput())
connect.SetExtractionModeToSpecifiedRegions()
connect.AddSpecifiedRegion(0)
connect.AddSpecifiedRegion(1)
moldMapper = vtk.vtkDataSetMapper()
moldMapper.SetInput(reader.GetOutput())
moldMapper.ScalarVisibilityOff()
moldActor = vtk.vtkActor()
moldActor.SetMapper(moldMapper)
moldActor.GetProperty().SetColor(.2, .2, .2)
moldActor.GetProperty().SetRepresentationToWireframe()
# Another connectivity filter is used to extract the parison.
connect2 = vtk.vtkConnectivityFilter()
connect2.SetInput(warp.GetOutput())
connect2.SetExtractionModeToSpecifiedRegions()
connect2.AddSpecifiedRegion(2)
# We use vtkExtractUnstructuredGrid because we are interested in
# looking at just a few cells. We use cell clipping via cell id to
# extract the portion of the grid we are interested in.
extractGrid = vtk.vtkExtractUnstructuredGrid()
extractGrid.SetInput(connect2.GetOutput())
extractGrid.CellClippingOn()
extractGrid.SetCellMinimum(0)
extractGrid.SetCellMaximum(23)
parison = vtk.vtkGeometryFilter()
parison.SetInput(extractGrid.GetOutput())
normals2 = vtk.vtkPolyDataNormals()
normals2.SetInput(parison.GetOutput())
normals2.SetFeatureAngle(60)
lut = vtk.vtkLookupTable()
lut.SetHueRange(0.0, 0.66667)
parisonMapper = vtk.vtkPolyDataMapper()
parisonMapper.SetInput(normals2.GetOutput())
parisonMapper.SetLookupTable(lut)
parisonMapper.SetScalarRange(0.12, 1.0)
parisonActor = vtk.vtkActor()
parisonActor.SetMapper(parisonMapper)
# graphics stuff
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(parisonActor)
ren.AddActor(moldActor)
ren.SetBackground(1, 1, 1)
ren.GetActiveCamera().Azimuth(60)
ren.GetActiveCamera().Roll(-90)
ren.GetActiveCamera().Dolly(2)