Commit 1fb1b0b9 authored by Prabhu Ramachandran's avatar Prabhu Ramachandran

NEW: Added translated Tcl examples. Thanks to Jose Paulo Moitinho de

Almeida for an initial version.
parent e70640cd
#!/usr/bin/env python
# This example demonstrates the use of the contour filter, and the use of
# the vtkSampleFunction to generate a volume of data samples from an
# implicit function.
import vtk
# VTK supports implicit functions of the form f(x,y,z)=constant. These
# functions can represent things spheres, cones, etc. Here we use a
# general form for a quadric to create an elliptical data field.
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
# vtkSampleFunction samples an implicit function over the x-y-z range
# specified (here it defaults to -1,1 in the x,y,z directions).
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(30, 30, 30)
sample.SetImplicitFunction(quadric)
# Create five surfaces F(x,y,z) = constant between range specified. The
# GenerateValues() method creates n isocontour values between the range
# specified.
contours = vtk.vtkContourFilter()
contours.SetInput(sample.GetOutput())
contours.GenerateValues(5, 0.0, 1.2)
contMapper = vtk.vtkPolyDataMapper()
contMapper.SetInput(contours.GetOutput())
contMapper.SetScalarRange(0.0, 1.2)
contActor = vtk.vtkActor()
contActor.SetMapper(contMapper)
# We'll put a simple outline around the data.
outline = vtk.vtkOutlineFilter()
outline.SetInput(sample.GetOutput())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.GetProperty().SetColor(0,0,0)
# The usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren.SetBackground(1, 1, 1)
ren.AddActor(contActor)
ren.AddActor(outlineActor)
iren.Initialize()
renWin.Render()
iren.Start()
#!/usr/bin/env python
# This example demonstrates the use of glyphing. We also use a mask filter
# to select a subset of points to glyph.
import vtk
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Read a data file. This originally was a Cyberware laser digitizer scan
# of Fran J.'s face. Surface normals are generated based on local geometry
# (i.e., the polygon normals surrounding eash point are averaged). We flip
# the normals because we want them to point out from Fran's face.
fran = vtk.vtkPolyDataReader()
fran.SetFileName(VTK_DATA_ROOT + "/Data/fran_cut.vtk")
normals = vtk.vtkPolyDataNormals()
normals.SetInput(fran.GetOutput())
normals.FlipNormalsOn()
franMapper = vtk.vtkPolyDataMapper()
franMapper.SetInput(normals.GetOutput())
franActor = vtk.vtkActor()
franActor.SetMapper(franMapper)
franActor.GetProperty().SetColor(1.0, 0.49, 0.25)
# We subsample the dataset because we want to glyph just a subset of
# the points. Otherwise the display is cluttered and cannot be easily
# read. The RandonModeOn and SetOnRatio combine to random select one out
# of every 10 points in the dataset.
ptMask = vtk.vtkMaskPoints()
ptMask.SetInput(normals.GetOutput())
ptMask.SetOnRatio(10)
ptMask.RandomModeOn()
# In this case we are using a cone as a glyph. We transform the cone so
# its base is at 0,0,0. This is the point where glyph rotation occurs.
cone = vtk.vtkConeSource()
cone.SetResolution(6)
transform = vtk.vtkTransform()
transform.Translate(0.5, 0.0, 0.0)
transformF = vtk.vtkTransformPolyDataFilter()
transformF.SetInput(cone.GetOutput())
transformF.SetTransform(transform)
# vtkGlyph3D takes two inputs: the input point set (SetInput) which can be
# any vtkDataSet; and the glyph (SetSource) which must be a vtkPolyData.
# We are interested in orienting the glyphs by the surface normals that
# we previosuly generated.
glyph = vtk.vtkGlyph3D()
glyph.SetInput(ptMask.GetOutput())
glyph.SetSource(transformF.GetOutput())
glyph.SetVectorModeToUseNormal()
glyph.SetScaleModeToScaleByVector()
glyph.SetScaleFactor(0.004)
spikeMapper = vtk.vtkPolyDataMapper()
spikeMapper.SetInput(glyph.GetOutput())
spikeActor = vtk.vtkActor()
spikeActor.SetMapper(spikeMapper)
spikeActor.GetProperty().SetColor(0.0, 0.79, 0.34)
# 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(franActor)
ren.AddActor(spikeActor)
renWin.SetSize(500, 500)
ren.SetBackground(0.1, 0.2, 0.4)
# Set a nice camera position.
cam1 = ren.GetActiveCamera()
cam1.Zoom(1.4)
cam1.Azimuth(110)
iren.Initialize()
renWin.Render()
iren.Start()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment