[vtkusers] Storing mixed types in an ImageData
David Gobbi
david.gobbi at gmail.com
Wed Dec 2 08:34:34 EST 2009
On Wed, Dec 2, 2009 at 6:09 AM, David Doria <daviddoria+vtk at gmail.com> wrote:
> There are functions to change the type of all components, e.g.
> vtkImageData::SetScalarTypeToUnsignedChar( )
>
> but is it possible to store different types, say a double and an
> unsigned char, in every index of an ImageData?
No, and it is too late to add that feature now. I'm not sure if it
would be a good idea, either, because it would make the imaging
pipeline more complicated and it is a feature that very few people
would benefit from. If you need two types, you can always have two
images flowing side-by-side through two pipelines.
> Also, to set values, there seems to only be
> SetScalarComponentFromDouble. If you are setting an unsigned char, do
> you have to cast it when you set the value, like:
> unsigned char c;
> SetScalarComponentFromDouble((double)c);
> ?
The cast isn't necessary, C++ will automatically do the conversion,
and because "double" has more precision, there will never be any
compiler warnings, either.
> That seems a bit awkward/silly unless I'm missing something.
Oh, it's not silly at all. What would be silly would be to have a
separate SetScalarComponent() method for each type.
The SetScalarComponentFromDouble() method is supposed to be generic,
it isn't meant to be efficient. To work with image data scalars
efficiently, you have to use GetScalarPointer and manipulate the
memory pointers directly. Or, if you are working with Python, there
are ways to convert the scalars to a python array and work with the
data that way.
Cheers,
David
More information about the vtkusers
mailing list