[vtkusers] help: balls and arrows
Randy Heiland
heiland at ncsa.uiuc.edu
Thu Jan 17 07:14:25 EST 2002
On Jan 16, 5:36pm, Robert Ellis Parrott wrote:
> Subject: [vtkusers] help: balls and arrows
>
> Here's probably a dumb question from a new user:
>
> I'm trying to visualize particles moving in space by attaching a sphere to
...
Rob,
I'm not sure what your problem was since you didn't include your full example,
however, here's a simple, self-contained example that does what you describe
(I've commented out the scalars part and also use default sizes/scaling):
--Randy
#
# -- Simple example showing 2 balls & arrows
#
from vtk import *
ren = vtkRenderer()
ren.SetBackground(0.0,0.0,0.0)
ren.TwoSidedLightingOn()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(300,300)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
#------------------------------------
pts = vtkPoints()
pts.InsertPoint(0,-1.0,0.0,0.0)
pts.InsertPoint(1,1.0,0.0,0.0)
vels = vtkDoubleArray()
vels.SetNumberOfComponents(3)
vels.SetNumberOfTuples(2)
vels.SetTuple3(0, 0.0,1.0,0.0)
vels.SetTuple3(1, 0.0,-1.0,0.0)
particleData = vtkPolyData()
particleData.SetPoints(pts)
#particleData.GetPointData().SetScalars(scls);
particleData.GetPointData().SetVectors(vels);
sphere = vtkSphereSource()
arrow = vtkArrowSource()
particles = vtkGlyph3D()
particles.SetInput(particleData)
particles.SetSource(sphere.GetOutput())
particles.SetScaleModeToDataScalingOff()
#particles.SetColorModeToColorByScalar()
#particles.SetRange(0.0,5.0)
vectors = vtkGlyph3D()
vectors.SetInput(particleData)
vectors.SetSource(arrow.GetOutput())
#vectors.SetScaleFactor(0.0025)
vectors.SetVectorModeToUseVector()
vectors.SetScaleModeToScaleByVector()
vectors.SetColorModeToColorByScalar()
particleMapper = vtkPolyDataMapper()
particleMapper.SetInput(particles.GetOutput())
vectorMapper = vtkPolyDataMapper()
vectorMapper.SetInput(vectors.GetOutput())
particleActor = vtkActor()
particleActor.SetMapper(particleMapper)
vectorActor = vtkActor()
vectorActor.SetMapper(vectorMapper)
ren.AddActor(particleActor)
ren.AddActor(vectorActor)
iren.Initialize()
iren.Start()
More information about the vtkusers
mailing list