ait-survey

xyzrgb_txt2xyz-color_raw

Jan 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. /*********************************************************************************
  2.  Input file : ASCII - space separated file (x,y,z)
  3.  Processing : ascii to binary
  4.  Output file : binary
  5.  
  6.  ***********************************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     //Decralation of variables
  15.     FILE *fpi,*fpo1,*fpo2;
  16.    
  17.     float points[3];
  18.     unsigned char colors[3];
  19.    
  20.         //int num=397;
  21.        
  22.     if(argc!=4)
  23.     {
  24.                 fprintf(stderr,"Usage: %s (1)input_textfile\n(2)output_xyz FILENAME\n(3)output_rgb_FILENAME¥n",argv[0]);
  25.                 exit(1);
  26.     }
  27.    
  28.     //Open CSV  file
  29.     if((fpi=fopen(argv[1],"r"))==NULL)
  30.     {
  31.         printf ("The file can't be opened. The program is exit.\n");
  32.        
  33.         return 0;
  34.     }
  35.    
  36.     //Open VTK file for save
  37.     if((fpo1=fopen(argv[2],"wb"))==NULL)
  38.     {
  39.         printf("The file can't be opened. The program is exit.\n");
  40.        
  41.         return 0;
  42.     }
  43.    
  44.         //Open VTK file for save
  45.     if((fpo2=fopen(argv[3],"wb"))==NULL)
  46.     {
  47.         printf("The file can't be opened. The program is exit.\n");
  48.        
  49.         return 0;
  50.     }
  51.         //points=(float *)malloc(num*3*sizeof(float));
  52.         //fread((float *)points,sizeof(float),1,fpi);
  53.    
  54.     while(fscanf(fpi,"%f %f %f %d %d %d",&points[0],&points[1],&points[2],&colors[0],&colors[1],&colors[2])!=EOF)
  55.     {
  56.  
  57.         //printf("%f %f %f %d %d %d\n",points[0],points[1],points[2],colors[0],colors[1],colors[2]);
  58.        
  59.         fwrite(&points,sizeof(float),3,fpo1);
  60.         fwrite(&colors,sizeof(char),3,fpo2);
  61.             //fwrite(&x,sizeof(float),1,fpo);
  62.             //fwrite(&y,sizeof(float),1,fpo);
  63.             //fwrite(&z,sizeof(float),1,fpo);
  64.     }
  65.    
  66.     fclose(fpi);
  67.     fclose(fpo1);
  68.     fclose(fpo2);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment