Visualize Vector Field Example Wrong?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Visualize Vector Field Example Wrong?

Werner Sembach
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
Reply | Threaded
Open this post in threaded view
|

Re: Visualize Vector Field Example Wrong?

Meehan, Bernard
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"
<[hidden email] on behalf of [hidden email]> 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

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Visualize Vector Field Example Wrong?

David Doria-2-3
In reply to this post by Werner Sembach
On Wed, Oct 14, 2015 at 5:40 PM, Werner Sembach <[hidden email]> 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

You are right - something is wrong. As it is, I get this warning:

Warning: In /home/doriad/src/VTK-6.2.0/Common/DataModel/vtkDataSetAttributes.cxx,
line 1165
vtkPointData (0x23e62e0): Can not set attribute Vectors. Incorrect
number of components.

on this line:

image->GetPointData()->SetActiveVectors("ImageScalars");

The warning is resolved if I change

image->AllocateScalars(VTK_FLOAT,2);

to

image->AllocateScalars(VTK_FLOAT,3);

I'm not sure why 2D vectors are not allowed.

Something else is wrong as well, though. Once I add pixel[2] = 0.0; to
each of the pixels (to prevent referencing unallocated memory), the
vectors still don't behave as I'd expect. With them both set to
(10,10), they both point (up, right) as expected. If I change pixel
(20,20) to (10, 10), it now points (down, right), again as I'd expect.
However, when I change it to (-10, -10), it points (up, right) again
(where I'd expect (down, left)), and it turns red (where everything
previously had been blue.

Sorry I don't have an answer, but at least that should help define the
problem :)

David
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Visualize Vector Field Example Wrong?

Werner Sembach
yes i can reproduce the error and now i'm even more confused

(-10,5) behaves like (10,-5)

Am 15.10.2015 um 14:25 schrieb David Doria:

> On Wed, Oct 14, 2015 at 5:40 PM, Werner Sembach <[hidden email]> 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
> You are right - something is wrong. As it is, I get this warning:
>
> Warning: In /home/doriad/src/VTK-6.2.0/Common/DataModel/vtkDataSetAttributes.cxx,
> line 1165
> vtkPointData (0x23e62e0): Can not set attribute Vectors. Incorrect
> number of components.
>
> on this line:
>
> image->GetPointData()->SetActiveVectors("ImageScalars");
>
> The warning is resolved if I change
>
> image->AllocateScalars(VTK_FLOAT,2);
>
> to
>
> image->AllocateScalars(VTK_FLOAT,3);
>
> I'm not sure why 2D vectors are not allowed.
>
> Something else is wrong as well, though. Once I add pixel[2] = 0.0; to
> each of the pixels (to prevent referencing unallocated memory), the
> vectors still don't behave as I'd expect. With them both set to
> (10,10), they both point (up, right) as expected. If I change pixel
> (20,20) to (10, 10), it now points (down, right), again as I'd expect.
> However, when I change it to (-10, -10), it points (up, right) again
> (where I'd expect (down, left)), and it turns red (where everything
> previously had been blue.
>
> Sorry I don't have an answer, but at least that should help define the
> problem :)
>
> David

_______________________________________________
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