float to unsigned short

Terry J. Ligocki tjligocki at lbl.gov
Thu Mar 9 15:21:03 EST 2000


You can use the filter "vtkImageCast" with
"SetOutputScalarTypeToUnsignedChar".  This will work for
"vtkStructuredPoints" or "vtkImageData" (the two are treated the same in
recent versions of Vtk - in older versions you needed to use the
"vtkStructuredPointsToImage" before using "vtkImageData" filters).

Also, there is a useful filter, "vtkImageShiftScale", where you can
shift ("SetShift"), scale ("SetScale"), and cast your data (e.g.
"SetOutputScalarTypeToUnsignedChar").  The operation performed in Vtk
2.3, in pseudo-code, is "output = (cast)(((float)in + Shift) * Scale)",
i.e. the input is cast to "float", "Shift" is added, the result is
multiplied by "Scale", and this is cast to the output type.

Hope this helps...

                Terry J. (Ligocki, tjligocki at lbl.gov)

--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list