[vtkusers] Connecting to arrays in a reader

David E DeMarle dave.demarle at kitware.com
Thu Jul 17 11:12:20 EDT 2014


Howdy.

On Tue, Jul 15, 2014 at 8:35 PM, Greg Schussman <greg.schussman at gmail.com>
wrote:

> Hi.
>


> 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).
>
>
The "Active" concept in VTK is mostly an artifact of days of yore. The
modern way to tell a filter what array to operate on is with
vtkAlgorithm::SetInputArrayToProcess (
http://www.vtk.org/doc/nightly/html/classvtkAlgorithm.html#a42a55ca2c277aecc909ad592d12978aa).
Most but not all filters respect that.

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?
>
>
You are doing it just right.


> 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??? )
>
>
reader.GetOutputPort()


    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')
>
>

> 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.
>

Close but no cigar. Algorithms produce vtkDataObjects, which contain any
number of vtkArrays. Use SetArrayToProcess to tell the filter which of the
arrays you want it to process.


> 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.
>

You are not the first.


> 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?)
>
>
glyph.SetInputArrayToProcess(0,0,0,"vtkDataObject::FIELD_ASSOCIATION_CELLS",
"thickness0")


> Many thanks in advance for any help/enlightenment.
>
> Greg
>
>
David E DeMarle
Kitware, Inc.
R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4909
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20140717/b3195d7e/attachment.html>


More information about the vtkusers mailing list