[vtkusers] binary VTK

Dominik Szczerba domi at vision.ee.ethz.ch
Tue Sep 26 06:58:51 EDT 2006


VTK stores legacy binary data in big endian, you need to swap yourself 
if you are (as I assume) on a little endian machine.
--ds

Marocchino, Alberto wrote:
>  
> Hello everybody, I ha indeed a problem with vtk binary file.
> I have tried to write a vtk binary file in F77... I could not.. so I 
> have tried to write it with C but I cannot make paraview read what I am 
> writing!
> This is the program I am using to outputting a slice with a vtk format, 
> I should be able to read it. The problem is that the shape looks correct 
> but the values are completely wrong!
> can you please suggest me something? So once it is working I can try to 
> reproduce exactly the same stuff in F77.
> Cheers
> Alberto
>  
>  
>  
> #include <stdio.h>
> #include <string.h>
> #include <time.h>
> #include <math.h>
>  
> main()
> {
>       double v[10];
>       double Pv[10];
>       float r[10];
>       float mat[10][10];
>       double matD[10][10];
>       int i,j;
>       FILE *fw;
>       FILE *fr;
>       FILE *VTK;
>       FILE *VTKD;
>       fw=fopen("output_BIN.dat","w");
>       VTK=fopen("output_VTK.vtk","w");
>       VTKD=fopen("output_VTK_double.vtk","w");
>       for (i=0;i<=5;i++) v[i]=double(i)*1.0;
>          
>       for (i=0;i<=5;i++) Pv[i]=double(v[i]);   
>       for (i=0;i<=5;i++) fwrite(&Pv[i],sizeof(double),1,fw);
>      
>       fclose(fw);
>      
>      
>       //initialize the matrix
>       for (i=0;i<10;i++)
>       {
>           for (j=0;j<10;j++)
>           {
>               if(i<5 && j<5) mat[i][j]=float(0.0);
>               if(i>4 && j<5) mat[i][j]=float(10.0);
>               if(i<5 && j>4) mat[i][j]=float(200.0);
>               if(i>4 && j>4) mat[i][j]=float(500.0);
>           }
>       }
>      
>       //setting in the file the VTK path
>       fprintf(VTK,"# vtk DataFile Version 3.0\n");
>       fprintf(VTK,"Structured Grid Dataset\n");
>       fprintf(VTK,"BINARY\n");
>       fprintf(VTK,"DATASET STRUCTURED_POINTS\n");
>       fprintf(VTK,"DIMENSIONS 1 10 10\n");
>       fprintf(VTK,"ORIGIN 0 0 0\n");
>       fprintf(VTK,"SPACING 1 1.3333E-3 1.3333E-3\n");
>       fprintf(VTK,"POINT_DATA 100\n");
>       fprintf(VTK,"SCALARS Density float\n");
>       fprintf(VTK,"LOOKUP_TABLE default\n");
>    
>    
>       for (i=0;i<10;i++)
>       {
>           for (j=0;j<10;j++)
>           {
>               fwrite(&mat[i][j],sizeof(float),1,VTK);
>           }
>       } 
>       fclose(VTK);
>       
>       
> }
>  
>  
>  
> ==============================
> Marocchino Alberto
>  
> PhD / Research Assistant
>  
> Plasma Physics Group,
> Blackett Laboratory,
> Imperial College,
> Prince Consort Road,
> London, SW7 2BW, U.K.
>  
> tel. 44 20 7594 7649
> fax. 44 20 7594 7658
> Skype coyote_from_los_alamos
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

-- 
Dominik Szczerba, Ph.D.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi



More information about the vtkusers mailing list