Advertisement
d10070dd

sample2

Sep 14th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5.  
  6.     //Decralation of variables
  7.     int  i;
  8.     int r,g,b;
  9.     unsigned long newline_count=0;
  10.     FILE *fpi,*fpo;
  11.     float x,y,z;
  12.  
  13.  
  14.     if(argc!=3)
  15.     {
  16.         fprintf(stderr,"Usage: %s (1)CSVFile\n(2)VTKFile\n",argv[0]);
  17.  
  18.         return 0;
  19.     }
  20.  
  21.     //Open VTK file for save
  22.     if((fpo=fopen(argv[2],"w"))==NULL)
  23.     {
  24.         printf("The file can't be opened. The program is exit.\n");
  25.  
  26.         return 0;
  27.     }
  28.  
  29.     //count how many lines
  30.     /*
  31.     while((c==fgetc(fpi))!=EOF
  32.     {
  33.         if(c=='\n')
  34.         newline_count++;
  35.     }
  36.     */
  37.  
  38.     while (fscanf(fpi,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!=EOF)
  39.     {
  40.  
  41.         newline_count=newline_count+1;
  42.     }
  43.  
  44.  
  45.     printf("total=%ld\n",newline_count);
  46.  
  47.     //writing VTK file
  48.     fprintf(fpo,"# vtk DataFile Version 3.0\n");
  49.     fprintf(fpo,"vtk output\n");
  50.     fprintf(fpo,"ASCII\n");
  51.     fprintf(fpo,"DATASET UNSTRUCTURED_GRID\n");
  52.     fprintf(fpo,"PINTS %ld float\n",newline_count);
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.     fseek(fpi,0,SEEK_SET);
  64.  
  65.     while (fscanf(fpi,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!=EOF)
  66.     {
  67.         printf("%f,%f,%f,%d,%d,%d\n", x, y, z, r, g, b);
  68.         fprintf(fpo,"%f %f %f\n",x,y,z);
  69.     }
  70.  
  71.     fprintf(fpo,"CELLS %ld %ld\n",newline_count,newline_count*2);
  72.  
  73.     for(i=0;i<newline_count;i++)
  74.     {
  75.         fprintf(fpo,"1\n");
  76.     }
  77.  
  78.     fprintf(fpo,"POINT_DATA %ld\n",newline_count);
  79.  
  80.     fprintf(fpo,"COLOR_SCALARS RGB 3\n");
  81.  
  82.     fseek(fpi,0,SEEK_SET);
  83.  
  84.     while (fscanf(fpi,"%f,%f,%f,%d,%d,%d", &x, &y, &z, &r, &g, &b)!=EOF)
  85.     {
  86.  
  87.         fprintf(fpo,"%f %f 5f\n",(float)r/255,(float)g/255,(float)b/255);
  88.     }
  89.  
  90.  
  91.  
  92.     fclose(fpi);
  93.     fclose(fpo);
  94.  
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement