Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************************
- Input file : ASCII - space separated file (x,y,z)
- Processing : ascii to binary
- Output file : binary
- ***********************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- //Decralation of variables
- FILE *fpi,*fpo1,*fpo2;
- float points[3];
- unsigned char colors[3];
- //int num=397;
- if(argc!=4)
- {
- fprintf(stderr,"Usage: %s (1)input_textfile\n(2)output_xyz FILENAME\n(3)output_rgb_FILENAME¥n",argv[0]);
- exit(1);
- }
- //Open CSV file
- if((fpi=fopen(argv[1],"r"))==NULL)
- {
- printf ("The file can't be opened. The program is exit.\n");
- return 0;
- }
- //Open VTK file for save
- if((fpo1=fopen(argv[2],"wb"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- //Open VTK file for save
- if((fpo2=fopen(argv[3],"wb"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- //points=(float *)malloc(num*3*sizeof(float));
- //fread((float *)points,sizeof(float),1,fpi);
- while(fscanf(fpi,"%f %f %f %d %d %d",&points[0],&points[1],&points[2],&colors[0],&colors[1],&colors[2])!=EOF)
- {
- //printf("%f %f %f %d %d %d\n",points[0],points[1],points[2],colors[0],colors[1],colors[2]);
- fwrite(&points,sizeof(float),3,fpo1);
- fwrite(&colors,sizeof(char),3,fpo2);
- //fwrite(&x,sizeof(float),1,fpo);
- //fwrite(&y,sizeof(float),1,fpo);
- //fwrite(&z,sizeof(float),1,fpo);
- }
- fclose(fpi);
- fclose(fpo1);
- fclose(fpo2);
- }
Advertisement
Add Comment
Please, Sign In to add comment