[vtkusers] Vector images and Glyphs

W. John neojohn75 at yahoo.com
Wed Mar 5 17:05:26 EST 2008


Hello,
  Looks like this email didn't go through (sorry if is a duplicate).   I have a question about displaying vector fields in VTK using glyphs.  Given a vector field (generated in ITK)

field.vtk
   BINARY
   DATASET STRUCTURED_POINTS
   DIMENSIONS 256 256 20
   SPACING 1 1 2
   ORIGIN 0 0 0
   POINT_DATA 1310720
   SCALARS scalars float 3

When I try to visualize it in VTK, all the glyphs point to the same direction. (along the same axis)

I was wondering if anyone knows what could be wrong.  Here is the code I'm using.  In Paraview the fields and arrows look fine.

Thanks!
-J

=====================

#Create the reader for the data
reader = vtk.vtkStructuredPointsReader()
reader.SetFileName(sys.argv[1])
reader.Update()

#Create arrows
arrow = vtk.vtkArrowSource()

#Mask input points
maxnpts=5000
mask_pts =  vtk.vtkMaskPoints()
mask_pts.SetOnRatio( 10  );
mask_pts.RandomModeOn();
mask_pts.SetMaximumNumberOfPoints(maxnpts);
mask_pts.SetInputConnection( reader.GetOutputPort() );
mask_pts.Update()

#Create glyphs
glyph = vtk.vtkGlyph3D()
glyph.ScalingOn();
glyph.SetScaleFactor(1.35);
glyph.SetColorModeToColorByScale();
glyph.SetScaleModeToScaleByScalar();
glyph.SetVectorModeToUseVector();
glyph.SetInputConnection( mask_pts.GetOutputPort() );
glyph.SetSource( arrow.GetOutput() );
glyph.OrientOn();

glyphmapper = vtk.vtkPolyDataMapper()
glyphmapper.SetInputConnection(glyph.GetOutputPort());
glyphactor = vtk.vtkActor()
glyphactor.SetMapper(glyphmapper)

# Create the standard renderer, render window and interactor
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.AddObserver("KeyPressEvent",   Keypress)

ren.AddActor(glyphactor)

ren.SetBackground(1.0, 1.0, 1.0)
renWin.SetSize(600, 600)
renWin.Render()

def CheckAbort(obj, event):
    if obj.GetEventPending() != 0:
        obj.SetAbortRender(1)
 
renWin.AddObserver("AbortCheckEvent", CheckAbort)

iren.Initialize()
renWin.Render()
iren.Start()
       
---------------------------------
Never miss a thing.   Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080305/5353744a/attachment.htm>


More information about the vtkusers mailing list