Volume data formatWritten by Paul BourkeOriginal: March 1994, Updated: September 2000
The format discussed here for storing volumetric data is not a "standard" but rather the method I've used over the years for various volume rendering applications. I suggest it will meet the needs of most people who have volumetric data on a uniform 3 dimensional grid. A bit like the PPM file format for images, this format has an ASCII (human readable) header followed by binary data. Unlike PPM it explicitly specifies the "endian" of the file as well as having more header fields. The format has no explicit support for floating point data although the extension for this is pretty trivial. Header
The header consists of a number of lines (5) separated by linefeed characters, ASCII Hex "0a". The header lines are described as follows:
One advantage of an ASCII header is that the standard UNIX command "head -5" can be used to quickly determine the details of a volumetric file. it is also particularly easy to parse in C/C++. ExampleAn example of a legal header is given below, it represents a grid 500 x 500 x 100, with wider z axis cells. The grid is centered about the origin in the x and y axis, the z axis starts at the origin. The data consists of signed short integers in big endian format. This is a comment line, created by Paul Bourke 500 500 100 1.0 1.0 2.0 -250.0 -250.0 0.0 16 0Data
The data in binary form follows immediately after the linefeed at
the end of the fifth line of the header. The data is not compressed
so the total expected data is straightforward to calculate, the
product of the three dimensions multiplied by the data type size divided
by 8. If the image dimensions are nx, ny, nz, and the data type is one
byte then the volumetric data will be The data is stored with the first coordinate varying fastest, then the second, then the third. For example, using the x, y, z convention in this document the writing of a byte grid might be #define Nx 500 #define Ny 500 #define Nz 100 : : unsigned char grid[Nx][Ny][Nz]; FILE *fptr; int x,y,z; : : /* Write the volumentic data file */ fprintf(fptr,"This is a comment line, created by Paul Bourke\n"); fprintf(fptr,"%d %d %d\n",Nx,Ny,Nz); fprintf(fptr,"1.0 1.0 2.0\n"); fprintf(fptr,"-250.0 -250.0 0.0\n"); fprintf(fptr,"8 1\n"); for (z=0;z<Nz;z++) { for (y=0;y<Ny;y++) { for (x=0;x<Nx;x++) { fputc(grid[x][y][z],fptr); } } } |