ait-survey

inverse_normal

Jan 31st, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 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,*fpo;
  16.    
  17.     float points[3];//coordinates
  18.     unsigned char colors[3];
  19.     float normals[3];
  20.     float c_x,c_y,c_z;//inverse coordinates
  21.    
  22.         //int num=397;
  23.        
  24.     if(argc!=3)
  25.     {
  26.                 fprintf(stderr,"Usage: %s (1)input_textfile\n(2)output_xyz FILENAME\n",argv[0]);
  27.                 exit(1);
  28.     }
  29.    
  30.     //Open CSV  file
  31.     if((fpi=fopen(argv[1],"r"))==NULL)
  32.     {
  33.         printf ("The file can't be opened. The program is exit.\n");
  34.        
  35.         return 0;
  36.     }
  37.    
  38.     //Open VTK file for save
  39.     if((fpo=fopen(argv[2],"w"))==NULL)
  40.     {
  41.         printf("The file can't be opened. The program is exit.\n");
  42.        
  43.         return 0;
  44.     }
  45.  
  46.         //points=(float *)malloc(num*3*sizeof(float));
  47.         //fread((float *)points,sizeof(float),1,fpi);
  48.    
  49.     while(fscanf(fpi,"%f %f %f %d %d %d %f %f %f",&points[0],&points[1],&points[2],&colors[0],&colors[1],&colors[2],&normals[0],&normals[1],&normals[2])!=EOF)
  50.     {
  51.        
  52.         //printf("%f %f %f %d %d %d\n",points[0],points[1],points[2],colors[0],colors[1],colors[2]);
  53.         if(normals[2]<0)
  54.         {
  55.             c_x=-1*normals[0];
  56.             c_y=-1*normals[1];
  57.             c_z=-1*normals[2];
  58.             fprintf(fpo,"%f %f %f %d %d %d %f %f %f\n",points[0],points[1],points[2],colors[0],colors[1],colors[2],c_x,c_y,c_z);
  59.         }
  60.         else
  61.     {
  62.         fprintf(fpo,"%f %f %f %d %d %d %f %f %f\n",points[0],points[1],points[2],colors[0],colors[1],colors[2],normals[0],normals[1],normals[2]);
  63. }
  64.     }
  65.    
  66.     fclose(fpi);
  67.     fclose(fpo);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment