[vtkusers] Connecting to arrays in a reader
Greg Schussman
greg.schussman at gmail.com
Tue Jul 15 20:35:48 EDT 2014
Hi.
I've been reading the visualization toolkit book and user's guide, googling
a fair bit, and digging through the vtk websites.
I'm not sure how things are meant to connect. I'm working in python. I'm
trying to build and use a reader. Many examples seem to assume there's
only a single field that can be made active. But in my case, the reader is
where I keep all information, and there is no sense (at least in my mind)
of an "active" field, because several may be used at ones (scalar for
surface coloring, one vector field for one set of cone glyphs, and another
vector field for a different set of cone glyphs, all to be displayed at the
same time).
I create the each field this way (where my_voltages is just a python list
that I parsed from a file):
voltage = vtkDoubleArray()
voltage.SetName('voltage')
voltage.SetNumberOfComponents(1)
for v in my_voltages:
voltage.InsertNextValue(v)
And I did the same thing for the 3D fields, except using 3 for the number
of components.
Then, I add these fields to my reader (derived from vtkProgrammableSource)
this way:
# 1D fields:
self.GetPolyDataOutput().GetCellData().AddArray(voltage)
self.GetPolyDataOutput().GetCellData().AddArray(charge)
# 3D fields:
self.GetPolyDataOutput().GetCellData().AddArray(current_density_real)
self.GetPolyDataOutput().GetCellData().AddArray(current_density_imag)
I'm able to iterate through those and print out the correct values and some
of my early scalar visualization with colormaps and such seem to be working.
So, first question is: does what I have done so far seem reasonable or is
there a more vtk-ish way of doing this?
Second question is how to connect to the reader. I'm trying to use it this
way:
cone = vtkConeSource()
cone.SetRadius(0.1)
cone.SetHeight(0.5)
cone.SetResolution(8)
glyph = vtkGlyph3D()
glyph.SetInputConnection( WHAT GOES HERE??? )
glyph.SetSourceConnection(self.cone.GetOutputPort())
glyph.SetScaleModeToDataScalingOff()
glyph.SetScaleFactor(1.0e-3)
glyph.SetVectorModeToUseVector()
glyph.OrientOn()
So the "what goes here" is this question. Because I used a named array,
I'd hope for something like:
glyph.SetInputConnection(reader.GetOutputPort('current_density_real'))
But that doesn't work, and I've seen nothing to suggest that it would.
When I try this as the argument,
reader.GetPolyDataOutput().GetCellData().GetArray('current_density_real')
I get:
TypeError: argument 1: method requires a vtkAlgorithmOutput, a
vtkDoubleArray was provided.
Switching from SetInputConnection() to just SetInput() gives this error
instead
TypeError: argument 1: method requires a vtkDataObject, a
vtkDoubleArray was provided.
Is this a matter of converting an array to an algorithm output? It seems
(probably quite wrongly) to me that algorithms can produce many different
kinds of output, and that a vtkArray would reasonably be one of them. Or,
when using the SetInput(), why wouldn't a vtkArray be a vtkDataObject? Of
course, the easy answer is "that's not how the inheritance diagrams are
drawn", but that doesn't really get me closer to groking the intended grand
scheme of things. I'm not complaining; I'm just confused.
How to I get the glyph to use the vector data (in the vtkArray) as its
input? (or if that's the wrong way to think about this, then what's the
right way?)
Many thanks in advance for any help/enlightenment.
Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140715/fbaf4c93/attachment.html>
More information about the vtkusers
mailing list