[vtkusers] Reading binary data

Rob van Tol rob.vantol at wtcm.be
Tue Apr 22 08:49:37 EDT 2003


Dear vtk-ers,

I wrote a program using vtk, which visualizes trajectories of particles 
moved by a liquid during the filling of a mould. This program uses 
ascii-data and works fine.
Since the data sets are in the order of several megabytes, I would like to 
transfer the ascii data to binary data, and this is where the problem starts.

To investigate the problem I wrote the test program below, using VC++ 6.0, 
to create a rectilinear grid with some data.  If I view the vtkfile 
"pipo.vtk" using mayavi, data is shown, but all the data is smaller than 
8.04e-041. So it is likely that the binary float data is read in a 
different way than it was written.

Can somebody inform me how to write binary data from VC++ 6.0, in such a 
way that it is read correctly by vtk ?

Thank you in advance,

ROB.

//--------------------------------------------------------------------------------------
void main()
{
     FILE *out ;
     float list[8];
     int coord[2];

     out = fopen("pipo.vtk", "w");

     fprintf(out,"# vtk DataFile Version 2.0\n");
     fprintf(out,"#My data in binary format\n");
     fprintf(out,"BINARY\n ");
     fprintf(out,"DATASET RECTILINEAR_GRID\n");
     fprintf(out,"DIMENSIONS 2 2 2\n");

         coord[0]=0;coord[1]=1;
         fprintf(out,"\nX_COORDINATES 2 int\n");
         fwrite( coord, sizeof( int ), 2, out );
         fprintf(out,"\nY_COORDINATES 2 int\n");
         fwrite( coord, sizeof( int ), 2, out );
         fprintf(out,"\nZ_COORDINATES 2 int\n");
         fwrite( coord, sizeof( int ), 2, out );

     fprintf(out,"\nPOINT_DATA 8\n");
     fprintf(out,"SCALARS colors float\n");
     fprintf(out,"LOOKUP_TABLE default\n");

         list[0]=0.0;list[1]=1.0;list[2]=2.0;list[3]=3.0;
         list[4]=4.0;list[5]=5.0;list[6]=6.0;list[7]=7.0;
         fwrite( list, sizeof( float ), 8, out );
}
//--------------------------------------------------------------------------------------


dr. R. van Tol
WTCM Gieterijcentrum
Technologiepark 9
B-9052 Zwijnaarde
tel.:0032 (0)9 2645704
fax:0032 (0)9 2645848
mailto:rob.vantol at wtcm.be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030422/e58739ad/attachment.htm>


More information about the vtkusers mailing list