Tuesday, October 11, 2005

How to convert a raw file to VTK

Sometimes you get volume-data aka vtkImageData in raw format like from our website http://www.digitalfishlibrary.org/ In order o be able to read that with vtk (the vtkStructurePointReader will do) you will have to follow these steps:

1. Add a vtkHeader
Because editing the whole file with vi would take to long we build the header in an extra file. The header should look like:


# vtk DataFile Version 2.0
My great file
BINARY
DATASET STRUCTURED_POINTS
DIMENSIONS 222 346 1434
Put here the dimensions x, y, z
ASPECT_RATIO 0.1 0.0625 0.0625
The spacing or voxel size
ORIGIN 0 0 0
POINT_DATA 110148408
x*y*z
SCALARS volume_scalars short 1
short=16 Bit, char=8 Bit
LOOKUP_TABLE default


Save the file for instance as vtk_header

2. Swap Bytes
Depending on the Endianess and in case you are using 16 Bit, short, data you might need to swap the byte order. You can easily find out if you need this step by just skipping it and seeing if the stuff looks right in vtk. To do it use the following Linux command (Sorry, Windows-People):

dd if=source.raw of=swapped.raw conv=swab

3. Merge the files
Now merge the header with the rawfile using for instance cat:

cat header source.raw > file.vtk

4. Read into VTK
Juts modify one of the Volume16Reader examples and replace the read part with (Java):

vtkStructuredPointsReader v16 = new vtkStructuredPointsReader();
v16.SetFileName("file.vtk");

0 Comments:

Post a Comment

<< Home