[vtkusers] what about a vtkStringArray format ?
David Duke
D.Duke at bath.ac.uk
Mon Feb 24 10:05:03 EST 2003
Sebastien MARAUX wrote:
> I think a vtkStringArray would be very useful,
> Is there somebody here who made such a format ?
>
> vtkCharArray is not really easy to use with string assigned as a scalar
> (e.g. naming each cell of a polydata).
>
> It would be very convenient to use a vtkStringArray as any
> vtkDataArray for setting scalars.
Sebastian,
I've also wanted general arrays of strings. I put together one approach
as part of some information visualization work; see
www.cs.bath.ac.uk/~djd/vtk.html (there is a tar archive with the classes
linked near the bottom). The implementation isn't tidy, though; at the
time I found I had to replace the vtk{Point|Cell}Data classes using an
object factory, so that the CopyTuple function dealt correctly with the
strings. See the documentation.
More recently I defined a vtkObjectArray class as a subtype of
vtkVoidArray. This holds pointers to vtkObjectBase objects, i.e.
reference-counted objects. My own reasons for building this are to
support multi-valued attributes in a more general data model, e.g.
support a data array in which each 'value' can be a vector of values.
But if you define a new subtype of vtkObjectBase to hold a string, you
could use a vtkObjectArray to store instances of your new type.
Functions such as SetValue do the right thing with references to
objects, but if you manipulate the array through the pointer, you would
have trouble.
You can find the current code for vtkObjectArray from
www.cs.bath.ac.uk/~djd/software/vtkObjectArray.tar
Its part of work in progress and has had minimal testing, lacks full
comments, and I may again have missed a more obvious solution.
If anyone has a better or simpler way of supporting strings, I too would
be interested.
David
More information about the vtkusers
mailing list