[vtkusers] Multiple scalars in vtkPolyData

Berk Geveci berklist at nycap.rr.com
Tue Aug 24 08:48:03 EDT 2004


Here is what you do:

* Create a sub-class of vtkDataArray for each scalar you have
* (optional) Assign them names with SetName()
* Add them to point or cell data with AddArray:
output->GetPointData()->AddArray(array)
* Set one of them to be the default scalars:
output->GetPointData()->SetActiveScalars(array_name)
Alternatively, you can add the default scalars with
output->GetPointData()->SetScalars() 
which internally (sort of) does the following:
output->GetPointData()->AddArray(array)
output->GetPointData()->SetActiveScalars(array)

vtkPLOT3DReader in IO does similar things.

To later set the default scalars in a VTK pipeline, use
vtkAssignAttribute. To set which scalar to color by, use
one of the methods in the mapper:
SetScalarModeToXXX()
ColorByComponent()
SelectColorArray()

There are also special methods in the lookup table.

-Berk

On Mon, 2004-08-23 at 18:57, Charles Boivin wrote:
> Hello all,
> 
> I am writing a reader for my own data format; I am using a polygonal
> data set. I have been reading the various material in the VTK books (in
> particular, chapter 5 in "The Visualization Toolkit"), but I am missing
> some information here.
> 
> I have no problems reading the geometry/topology from my files and
> displaying them properly. However, I am struggling a bit with loading
> point and cell data. In particular, the examples in chapter 5 always
> only deal with one scalar for the point or cell data. How do I load
> multiple scalars? And this also begs another question: how can I select
> which one I want to display once I have been able to load several ones?
> 
> Similarly, can multiple vectors be loaded?
> 
> It seems as if functions SetActiveScalars(name) and GetScalars(name)
> are to be used here... but in what order should I use them? Do I have to
> specify how many scalars I have before I start making calls to
> vtkPolyData::GetPointData()->SetScalars()? I am a bit confused here... 
> 
> I would have thought that something along the lines of:
> 
> Loop over all scalars
>    SetActiveScalars(ScalarName[i])
>    Set the values for the scalar for every point
>    GetPointData()->SetScalars(...)
> end loop over scalars
> 
> would work, but I can't get things to display quite properly. Could
> anyone confirm whether this approach makes sense, or point towards an
> example where multiple scalars are being defined? I guess I might also
> have errors elsewhere in the code...
> 
> I apologize if things sound a bit unorganized, but I am a bit confused
> with this at the moment. Any help would be appreciated.
> 
> Thank you,
> 
> Charles Boivin
> _______________________________________________
> 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://www.vtk.org/mailman/listinfo/vtkusers
-- 
Berk Geveci <berklist at nycap.rr.com>




More information about the vtkusers mailing list