[vtkusers] Using vtkGlyph3D with Field Data

Shari Rolnick shari at loralee.net
Fri Sep 2 21:34:12 EDT 2005


I'm new at this, so I hope I'm just missing something obvious.  Any help
would be appreciated.

I'm trying to use vtkGlyph3D with field data.  I've created a VTK data
file of the data I'm trying to visualize, and I seem to be able to read
it in with no trouble.  However, when I try to use the glypher, all I
get are four glyphs, one at the tip of each axis and one at their
intersection.  Obviously, I'm doing something wrong, but I can't figure
out what.  Here is my code:

#!/usr/bin/env python

import os
import re
import vtk

import PropertySet

# Set axes
propSet = PropertySet.PropertySet('viz.properties')
size = propSet.size
xAxis = propSet.xAxisVariable
yAxis = propSet.yAxisVariable
zAxis = propSet.zAxisVariable
scalar = propSet.scalarVariable

# extract data from field as polydata (just points), then extract
scalars
dataObjectReader = vtk.vtkDataObjectReader()
dataObjectReader.SetFileName("schoolData.vtk")

do2ds = vtk.vtkDataObjectToDataSetFilter()
do2ds.SetInput(dataObjectReader.GetOutput())
do2ds.SetDataSetTypeToPolyData
do2ds.DefaultNormalizeOn()
do2ds.SetPointComponent(0, xAxis, 0)
do2ds.SetPointComponent(1, yAxis, 0) #, 0, size, 1)
do2ds.SetPointComponent(2, zAxis, 0)
do2ds.Update()

dataSet = do2ds.GetOutput()

# create glyph
cone = vtk.vtkConeSource()
cone.SetResolution(6)

glyph = vtk.vtkGlyph3D()
glyph.SetInput(dataSet)
glyph.SetSource(cone.GetOutput())
glyph.SetVectorModeToUseNormal()
glyph.SetScaleModeToScaleByScalar()
glyph.SetScaleFactor(0.1)
glyph.SetIndexModeToScalar()
print 'Glyph', glyph

glyphMapper = vtk.vtkPolyDataMapper()
glyphMapper.SetInput(glyph.GetOutput())
glyphActor = vtk.vtkActor()
glyphActor.SetMapper(glyphMapper)

# create axes
axes = vtk.vtkAxes()

axesTubes = vtk.vtkTubeFilter()
axesTubes.SetInput(axes.GetOutput())
axesTubes.SetRadius((axes.GetScaleFactor()) / 25.0)
axesTubes.SetNumberOfSides(6)

axesMapper = vtk.vtkPolyDataMapper()
axesMapper.SetInput(axesTubes.GetOutput())
axesActor = vtk.vtkActor()
axesActor.SetMapper(axesMapper)

# label the axes
XText = vtk.vtkVectorText()
XText.SetText(xAxis)
XTextMapper = vtk.vtkPolyDataMapper()
XTextMapper.SetInput(XText.GetOutput())

XActor = vtk.vtkFollower()
XActor.SetMapper(XTextMapper)
XActor.SetScale(0.02, 0.02, 0.02)
XActor.SetPosition(0.35, -0.05, -0.05)
XActor.GetProperty().SetColor(0, 0, 0)

YText = vtk.vtkVectorText()
YText.SetText(yAxis)
YTextMapper = vtk.vtkPolyDataMapper()
YTextMapper.SetInput(YText.GetOutput())

YActor = vtk.vtkFollower()
YActor.SetMapper(YTextMapper)
YActor.SetScale(0.02, 0.02, 0.02)
YActor.SetPosition(-0.05, 0.35, -0.05)
YActor.GetProperty().SetColor(0, 0, 0)

ZText = vtk.vtkVectorText()
ZText.SetText(zAxis)
ZTextMapper = vtk.vtkPolyDataMapper()
ZTextMapper.SetInput(ZText.GetOutput())

ZActor = vtk.vtkFollower()
ZActor.SetMapper(ZTextMapper)
ZActor.SetScale(0.02, 0.02, 0.02)
ZActor.SetPosition(-0.05, -0.05, 0.35)
ZActor.GetProperty().SetColor(0, 0, 0)

#Graphics Stuff

ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetWindowName("vtk - Field Data")

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Add the actors to the renderer, set the background and size
ren1.AddActor(axesActor)
ren1.AddActor(XActor)
ren1.AddActor(YActor)
ren1.AddActor(ZActor)
ren1.AddActor(glyphActor)
renWin.SetSize(400, 400)

camera = vtk.vtkCamera()
camera.SetClippingRange(0.274, 13.72)
camera.SetFocalPoint(0.433816, 0.333131, 0.449)
camera.SetPosition(-1.96987, 1.15145, 1.49053)
camera.SetViewUp(0.378927, 0.911821, 0.158107)

ren1.SetActiveCamera(camera)
XActor.SetCamera(camera)
YActor.SetCamera(camera)
ZActor.SetCamera(camera)

# render the image

iren.Initialize()
renWin.Render()
iren.Start()

The output that I'm getting is this:
Glyph vtkGlyph3D (0x82f46d8)
  Debug: Off
  Modified Time: 470
  Reference Count: 3
  Registered Events: (none)
  Number Of Required Inputs: 1
  Input 0: (0x81b1008)
  Input 1: (0x82fcdb8)
  AbortExecute: Off
  Progress: 0
  Progress Text: (None)
  ErrorCode: NoError
  Output 0: (0x82fdad0)
  Generate Point Ids Off
  PointIdsName: InputPointIds
  Color Mode: ColorByScale
  Source: (0x82fcdb8)
  Scaling: On
  Scale Mode: Scale by scalar
  Scale Factor: 0.1
  Clamping: Off
  Range: (0, 1)
  Orient: On
  Orient Mode: Orient by normal
  Index Mode: Index by scalar value
  InputScalarsSelection: (none)
  InputVectorsSelection: (none)
  InputNormalsSelection: (none)


Warning: In /home/shari/VTK/VTK/Graphics/vtkGlyph3D.cxx, line 173
vtkGlyph3D (0x82f46d8): Turning indexing off: no data to index with

Any ideas?

Thanks!






More information about the vtkusers mailing list