[vtk-developers] String Array Support in VTK

Utkarsh Ayachit utkarsh.ayachit at kitware.com
Wed Jan 4 13:05:58 EST 2006

Hey folks,

Currently, Sandia and Kitware are working on intergrating the support
for string arrays with the main stream data arrays, so that string
arrays can be passed around are field/point/cell data and used by
filters etc. This email summarizes the changes that we are making to the
present data array/field data/readers/writes. The changes will be
committed to the main CVS trunk by this weekend. Your
suggestions/objections are welcome, as always.

* vtkDataArray now has a new superclass: vtkAbstractArray.
vtkAbstractArray provides type-agnostic API to access array elements.
vtkDataArray provides a double API to access values -- such an API is
deliberately missing from vtkAbstractArray, since arrays like string
arrays are not castable to doubles.

* vtkAbstractArray has the notion of components/tuples, but does not
make any assumptions about the arragment of these. It's up to the
concrete subclasses how the data is represented in memory.

* vtkFieldData used to provide tuple API to get/set values from data
arrays contained in it. However, now that FieldData can have arrays that
are not vtkDataArrays, this API is not longer valid. The following are
the methods that are no longer available:
  double* GetTuple(const vtkIdType);
  void SetTuple(const vtkIdType i, const double* tuple);
  void GetTuple(const vtkIdType i, double* tuple);
  void InsertTuple(const vtkIdType i, const double* tuple);
  void InsertNextTuple(cons double*);
  double GetComponent(const vtkIdType i, const int j);
  void SetComponent(const vtkIdType i, const int j, const double c);
  void InsertComponent(const vtkIdType i, const int j, const double c);
However, new API is provided to copy tuples arround from one field data
to another using:
  void SetTuple(const vtkIdType i, const vtkIdType j, vtkFieldData* source);
  void InsertTuple(const vtkIdType i, const vtkIdType j, vtkFieldData*
  vtkIdType InsertNextTuple(const vtkIdType j, vtkFieldData* source);

* vtkFieldData provide a vtkDataArray* GetArray(int index) to retrieve
arrays in the field data. This function can will now return a NULL if
the array at the given index is not a data array. It provides
  vtkAbstractArray* GetAbstractArray(int index);
to retrieve an array even if it isn't a vtkDataArray.

* Since vtkFieldData can contain arrays that aren't subclasses of
vtkDataArray, so can vtkDataSetAttributes. However, an attribute can
only be a vtkDataArray subclass i.e. one cannot set a vtkStringArray as
the SCALARS array for a Point Data, for example.

* String Array IO is only supported in XML file formats. If deemed
important, support may be added for lecacy file formats.

*** Array Iterators ***

Another addition to the VTK Arrays, is the notion of Array Iterator. A
vtkArrayIterator subclass is be provided for every vtkAbstractArray
subclass. The iterator is a random access iterator. The iterators are
not available in any of the wrapped languages, however, in C++ they can
be used to write templatized code to processes the array values without
any implicit type conversion and consequent loss of precision.
vtkArrayIteratorTemplateMacro is provided to simply switching between
different types of the arrays. Examples of use of this macro and the
iterators can be found in vtkXMLWriter.cxx / vtkXMLDataReader.cxx /


More information about the vtk-developers mailing list