[vtkusers] Visualize Vector Field Example Wrong?

Meehan, Bernard MEEHANBT at nv.doe.gov
Wed Oct 14 20:30:05 EDT 2015


I think that you need to have a three-component vector in order to use the
vtkGlyph3D filter like it sounds you want to use it. I think that the
example you reference may be wrong Š I didn¹t read it very carefully
though. Here¹s a small script you can tinker with:

import vtk

# Create some source to work from.
sphere = vtk.vtkSphereSource()
sphere.Update()

# Extract the polydata object reference.
polydata  = sphere.GetOutputDataObject(0)

# Create a 2-component vector and a 3-component vector for testing.
vector_3 = vtk.vtkFloatArray()
vector_3.SetName("Three Components")
vector_3.SetNumberOfComponents(3)
vector_3.SetNumberOfTuples(polydata.GetNumberOfPoints())

vector_2 = vtk.vtkFloatArray()
vector_2.SetName("Two Components")
vector_2.SetNumberOfComponents(2)
vector_2.SetNumberOfTuples(polydata.GetNumberOfPoints())

for i in range(polydata.GetNumberOfPoints()):
  x, y, z = polydata.GetPoint(i)
  vector_2.SetTuple2(i, -y, x)
  vector_3.SetTuple3(i, -y, x, 0.)

# Add the vectors to the polydata object.
polydata.GetPointData().AddArray(vector_3)
# Correct behavior with 3-component vector.
polydata.GetPointData().SetActiveVectors("Three Components")
# Incorrect behavior with 2-component vector.
# polydata.GetPointData().SetActiveVectors("Two Components")
sphere.Update()

# Create a glyph filter to see the vectors.
arrow = vtk.vtkArrowSource()
glyphs = vtk.vtkGlyph3D()
glyphs.SetSourceConnection(arrow.GetOutputPort())
glyphs.SetInputConnection(sphere.GetOutputPort())
glyphs.Update()

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(glyphs.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(.1, .2, .6)

render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

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

render_window.Render()
iren.Start()


On 10/14/15, 2:40 PM, "vtkusers on behalf of Werner Sembach"
<vtkusers-bounces at vtk.org on behalf of werner at sembach.de> wrote:

>Hello,
>i want to do exactly this:
>http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/VectorField
>but when you try the example code the 2nd coordinate of the vectors is
>completly ignored (even the picture on the wiki shows 2 parrallel
>vectors while in the code the vectors are (10, 10) and (-10, 5).
>hope someone can help me
>_______________________________________________
>Powered by www.kitware.com
>
>Visit other Kitware open-source projects at
>http://www.kitware.com/opensource/opensource.html
>
>Please keep messages on-topic and check the VTK FAQ at:
>http://www.vtk.org/Wiki/VTK_FAQ
>
>Search the list archives at: http://markmail.org/search/?q=vtkusers
>
>Follow this link to subscribe/unsubscribe:
>http://public.kitware.com/mailman/listinfo/vtkusers



More information about the vtkusers mailing list