[vtkusers] vtk guru needed (vtkGlyph3D + vtkImageData)

Mathieu Malaterre malat at free.fr
Wed Feb 12 11:34:09 EST 2003


Hi vtk guru,
  Here is a small python script which I would like to improve. As I want 
to display a vector field I would like to use vtkGlyph3D but for that I 
need to have all my vectors in PointData.Vectors (or PointData.Normals). 
The problem is that I use vtkImageGradient which puts stuff in 
PointData.Scalars.

  So what I would like is to move (instead of copying) all the tuples 
from Scalars to Vectors.

Thanks for any help,
mathieu


#beginning of script

from vtk import *

reader = vtkStructuredPointsReader()
reader.SetFileName('gvf.vtk')

grad = vtkImageGradient()
grad.SetInput(reader.GetOutput())
grad.SetDimensionality(2)

grad.UpdateWholeExtent()  #important

size = grad.GetOutput().GetPointData().GetScalars().GetNumberOfTuples()

vec = vtkDoubleArray()
vec.SetNumberOfComponents(3)
vec.Allocate(3*size, 0)

for i in range(size):
   x = grad.GetOutput().GetPointData().GetScalars().GetTuple2(i) 
   vec.InsertNextTuple3(x[0],x[1],0.)  #this is so bad !

grad.GetOutput().GetPointData().SetVectors(vec)


gs = vtkGlyphSource2D ()
gs .SetGlyphTypeToArrow()
gs .SetScale (0.2)
gs .FilledOff()

# Create a table of glyphs
glypher = vtkGlyph3D()
glypher .SetInput (reader.GetOutput())
glypher .SetSource (gs.GetOutput())
glypher.ScalingOff();
glypher.OrientOn();
glypher.SetVectorModeToUseVector();
glypher.SetColorModeToColorByVector();

mapper = vtkPolyDataMapper ()
mapper .SetInput (glypher .GetOutput())

actor = vtkActor()
actor.SetMapper(mapper)

ren = vtkRenderer()
ren.AddActor(actor)

renWin = vtkRenderWindow()
renWin.AddRenderer(ren)

iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

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





More information about the vtkusers mailing list