[vtkusers] vtk guru needed (vtkGlyph3D + vtkImageData)

Mathieu Malaterre malat at free.fr
Wed Feb 12 11:55:20 EST 2003


Oups !
  I forget to mention the most import stuff...my data are 2D. So 
PointData.Scalars is a 2 Tuple whereas Vectors should be 3.

mathieu


Berk Geveci wrote:

>Just do
>
>grad.GetOutput().GetPointData().SetVectors(
>     grad.GetOutput().GetPointData().GetScalars())
>
>However, this will only work if you are using VTK 4.0 or newer.
>
>-Berk
>
>
>On Wed, 2003-02-12 at 11:34, Mathieu Malaterre wrote:
>  
>
>>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()
>>
>>
>>_______________________________________________
>>This is the private VTK discussion list. 
>>Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
>>Follow this link to subscribe/unsubscribe:
>>http://public.kitware.com/mailman/listinfo/vtkusers
>>    
>>
>
>
>
>
>
>
>
>  
>





More information about the vtkusers mailing list