ait-survey

xyzrgb-txt2bin(point cloud)

May 12th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <iostream>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <iomanip>
  9. #include <sstream>
  10. #include <cstdlib>
  11.  
  12. using namespace std;
  13.  
  14. int main(int argc,char *argv[])
  15. {
  16.  
  17.     /*****************************************************
  18.             1.Definition of Variables
  19.         ******************************************************/
  20.     //FILE *fpr,*fpw1,*fpw2;  //file pointer for input&output file
  21.  
  22.     int color;//
  23.         //int dn1,dn2,dn3,dn4,dn5;
  24.     int r,g,b;
  25.     float x,y,z;
  26.     int id;
  27.  
  28.     if(argc!=4)
  29.     {
  30.         fprintf(stderr,"Usage: %s (1)xyzrgb.txt\n(2)xyz.bin\n(3)color.bin\n",argv[0]);
  31.         exit(1);
  32.     }
  33.  
  34.     cout<<"OPEN FILE NAME:"<<argv[1]<<endl;
  35.  
  36.     ifstream ifs(argv[1]);
  37. //    if((fpr=fopen(argv[1],"r"))==NULL)//original xyzrgb text file
  38. //    {
  39. //        printf("error\n");
  40. //        exit(1);
  41. //    }
  42.  
  43.  
  44. //    if((fpw1=fopen(argv[2],"wb"))==NULL)//for xyz
  45. //    {
  46. //        fprintf(stderr,"DSM by GSI.raw\n");
  47. //        exit(1);
  48. //    }
  49.     ofstream ofs_xyz (argv[2],ios::out|ios::binary);
  50.  
  51.  
  52. //    if((fpw2=fopen(argv[2],"wb"))==NULL) //for rgb
  53. //    {
  54. //        fprintf(stderr,"DSM by GSI.raw\n");
  55. //        exit(1);
  56. //    }
  57.     ofstream ofs_rgb (argv[3],ios::out|ios::binary);
  58.  
  59.             //id=0;]
  60.  
  61.     std::string buf;
  62.  
  63.     for(size_t i=0; ifs && getline(ifs, buf); i++)
  64.     //while(fscanf(fpr,"%f %f %f %d %d %d",&x,&y,&z,&r,&g,&b)!= EOF)
  65.     {
  66.         std::istringstream is(buf);
  67.  
  68.         is >>x>>y>>z>>r>>g>>b;
  69.         ofs_xyz.write((char *)&x, sizeof(float));
  70.         ofs_xyz.write((char *)&y, sizeof(float));
  71.         ofs_xyz.write((char *)&z, sizeof(float));
  72.         ofs_rgb.write((char *)&r, sizeof(int));
  73.         ofs_rgb.write((char *)&g, sizeof(int));
  74.         ofs_rgb.write((char *)&b, sizeof(int));
  75.                 //id=id+1;
  76.             //cout << x << endl;
  77.             //color=1000000*(int)r+1000*(int)g+(int)b;
  78.                 //fwrite(&x,sizeof(float),1,fpw);
  79.                 //fwrite(&x,sizeof(float),1,fpw1);
  80.                 //fwrite(&y,sizeof(float),1,fpw1);
  81.                 //fwrite(&z,sizeof(float),1,fpw1);
  82. //              fwrite(&r,sizeof(int),1,fpw2);
  83. //              fwrite(&g,sizeof(int),1,fpw2);
  84. //              fwrite(&b,sizeof(int),1,fpw2);
  85. //              file_o.write((char *)&sd_color, sizeof(int));
  86. //          //fprintf(fpw,"%f %f %f %d\n",x,y,z,color);
  87.             //fprintf(fpw,"%f %f %f %d %d %d\n",x,y,z,r,g,b);
  88.     }
  89.     ifs.close();
  90.     ofs_xyz.close();
  91.     ofs_rgb.close();
  92. }
Advertisement
Add Comment
Please, Sign In to add comment