Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <iomanip>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- int main(int argc,char *argv[])
- {
- /*****************************************************
- 1.Definition of Variables
- ******************************************************/
- //FILE *fpr,*fpw1,*fpw2; //file pointer for input&output file
- int color;//
- //int dn1,dn2,dn3,dn4,dn5;
- int r,g,b;
- float x,y,z;
- int id;
- if(argc!=4)
- {
- fprintf(stderr,"Usage: %s (1)xyzrgb.txt\n(2)xyz.bin\n(3)color.bin\n",argv[0]);
- exit(1);
- }
- cout<<"OPEN FILE NAME:"<<argv[1]<<endl;
- ifstream ifs(argv[1]);
- // if((fpr=fopen(argv[1],"r"))==NULL)//original xyzrgb text file
- // {
- // printf("error\n");
- // exit(1);
- // }
- // if((fpw1=fopen(argv[2],"wb"))==NULL)//for xyz
- // {
- // fprintf(stderr,"DSM by GSI.raw\n");
- // exit(1);
- // }
- ofstream ofs_xyz (argv[2],ios::out|ios::binary);
- // if((fpw2=fopen(argv[2],"wb"))==NULL) //for rgb
- // {
- // fprintf(stderr,"DSM by GSI.raw\n");
- // exit(1);
- // }
- ofstream ofs_rgb (argv[3],ios::out|ios::binary);
- //id=0;]
- std::string buf;
- for(size_t i=0; ifs && getline(ifs, buf); i++)
- //while(fscanf(fpr,"%f %f %f %d %d %d",&x,&y,&z,&r,&g,&b)!= EOF)
- {
- std::istringstream is(buf);
- is >>x>>y>>z>>r>>g>>b;
- ofs_xyz.write((char *)&x, sizeof(float));
- ofs_xyz.write((char *)&y, sizeof(float));
- ofs_xyz.write((char *)&z, sizeof(float));
- ofs_rgb.write((char *)&r, sizeof(int));
- ofs_rgb.write((char *)&g, sizeof(int));
- ofs_rgb.write((char *)&b, sizeof(int));
- //id=id+1;
- //cout << x << endl;
- //color=1000000*(int)r+1000*(int)g+(int)b;
- //fwrite(&x,sizeof(float),1,fpw);
- //fwrite(&x,sizeof(float),1,fpw1);
- //fwrite(&y,sizeof(float),1,fpw1);
- //fwrite(&z,sizeof(float),1,fpw1);
- // fwrite(&r,sizeof(int),1,fpw2);
- // fwrite(&g,sizeof(int),1,fpw2);
- // fwrite(&b,sizeof(int),1,fpw2);
- // file_o.write((char *)&sd_color, sizeof(int));
- // //fprintf(fpw,"%f %f %f %d\n",x,y,z,color);
- //fprintf(fpw,"%f %f %f %d %d %d\n",x,y,z,r,g,b);
- }
- ifs.close();
- ofs_xyz.close();
- ofs_rgb.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment