点云数据处理.docx_第1页
点云数据处理.docx_第2页
点云数据处理.docx_第3页
点云数据处理.docx_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

c+对txt文件的读取与写入 /* 这是自己写程序时突然用到这方面的技术,在网上搜了一下,特存此以备后用 */ #include #include #include using namespace std; int main() char buffer256; ifstream myfile (c:a.txt); ofstream outfile(c:b.txt); if(!myfile) cout Unable to open myfile; exit(1); / terminate with error if(!outfile) cout Unable to open otfile; exit(1); / terminate with error int a,b; int i=0,j=0; int data62; while (! myfile.eof() ) myfile.getline (buffer,10); sscanf(buffer,%d %d,&a,&b); couta bendl; datai0=a; datai1=b; i+; myfile.close(); for(int k=0;ki;k+) outfiledatak0 datak1endl; tob_id_3208 coutdatak0 datak1endl; outfile.close(); return 0; 无论读写都要包含头文件 读:从外部文件中将数据读到程序中来处理 对于程序来说,是从外部读入数据,因此定义输入流,即定义输入流对象:ifsteam infile,infile就是输入流对象。 这个对象当中存放即将从文件读入的数据流。假设有名字为myfile.txt的文件,存有两行数字数据,具体方法: int a,b; ifstream infile; infile.open(myfile.txt); /注意文件的路径 infileab; /两行数据可以连续读出到变量里 infile.close() 如果是个很大的多行存储的文本型文件可以这么读: char buf1024; /临时保存读取出来的文件内容 string message; ifstream infile; infile.open(myfile.js); if(infile.is_open() /文件打开成功,说明曾经写入过东西 while(infile.good() & !infile.eof() memset(buf,0,1024); infile.getline(buf,1204); message = buf; . /这里可能对message做一些操作 coutmessageendl; infile.close(); 写:将程序中处理后的数据写到文件当中 对程序来说是将数据写出去,即数据离开程序,因此定义输出流对象ofstream outfile,outfile就是输出流对象,这个对象用来存放将要写到文件当中的数据。具体做法: ofstream outfile; outfile.open(myfile.bat); /myfile.bat是存放数据的文件名 if(outfile.is_open() outfilemessageendl; /message是程序中处理的数据 outfile.close(); else cout不能打开文件!endl; c+对文件的读写操作的例子 /*/从键盘读入一行字符,把其中的字母依次放在磁盘文件fa2.dat中,再把它从磁盘文件读入程序, 将其中的小写字母改成大写字母,再存入磁盘fa3.dat中*/ i nclude i nclude i nclude using namespace std; /从键盘上读取字符的函数 void read_save() char c80; ofstream outfile(f1.dat);/以输出方工打开文件 if(!outfile) cerropen error!=65&ci=97&ci=122)/保证输入的字符是字符 outfile.put(ci);/将字母字符存入磁盘文件 coutci; coutendl; outfile.close(); void creat_data() char ch; ifstream infile(f1.dat,ios:in);/以输入的方式打开文件 if(!infile) cerropen error!endl; exit(1); ofstream outfile(f3.dat);/定义输出流f3.dat文件 if(!outfile) cerropen error!endl; exit(1); while(infile.get(ch)/当读取字符成功时 if(ch=97) ch=ch-32; outfile.put(ch); coutch; coutendl; infile.close(); outfile.close(); int main() read_save(); creat_data(); system(pause); return 0; / win32console.cpp : 定义控制台应用程序的入口点。 /C+读取txt文件的方法 #include stdafx.h #include #include using namespace std; typedef struct node int data; struct node *next; node; node *creat(ifstream &ifp) node *h=NULL,*p=NULL,*q=NULL; int data; while (ifpdata) p=new node; p-data=data; p-next=NULL; if (!h) h=p; else q-next=p; q=p; return h; void prt(node *h) if (h) coutdatanext); int _tmain(int argc, _TCHAR* argv) /-file1 open ifstream fp(d:data.txt,ifstream:in); node *hst=creat(fp); fp.close(); prt(hst); /-file2 open ifstream r(d:test.txt,ifstream:in); if(!r) cout打开文件出错!line) coutlineendl; r.close(); 函数用于读取.xyz的点云文件,点云的格式为:cpp view plain copy 在CODE上查看代码片派生到我的代码片17.371559 -6.531680 -8.080792 0.242422 0.419118 0.874970 15.640106 -16.101347 -9.550241 -0.543610 -0.382877 0.746922 17.750742 -6.395478 -8.307115 0.333093 0.494766 0.802655 15.432834 -15.947010 -9.587061 -0.548083 -0.385148 0.742473 23.626318 -7.729815 -13.608750 0.081697 0.502976 0.860431 15.300377 -15.610346 -9.547507 -0.569658 -0.341132 0.747743 23.975805 -7.512131 -13.775388 0.082388 0.564137 0.821561 24.251831 -7.345085 -13.949208 0.099309 0.574142 0.812711 14.999881 -15.463743 -9.748975 -0.629676 -0.333713 0.701530 14.804974 -15.162496 -9.758424 -0.616575 -0.334426 0.712737 27.607445 -6.731058 -16.160894 0.387612 0.713240 0.583991 14.560967 -14.955154 -9.909436 -0.638394 -0.335827 0.692584 27.938255 -6.707172 -16.443462 0.379390 0.740941 0.554139 14.290791 -14.852806 -10.137550 -0.692395 -0.381273 0.612552 14.386531 -15.114174 -10.178914 -0.719801 -0.337913 0.606384 14.001437 -14.247000 -10.103112 -0.735267 -0.343587 0.584235 13.762934 -13.909647 -10.200064 -0.752330 -0.295280 0.588906 前面3个数字是坐标,后面3个数字是法向量,有多少行就代表有多少个点。 代码:cpp view plain copy 在CODE上查看代码片派生到我的代码片struct Point3d Point3d()x=y=z=0.0f; float x; float y; float z; bool operator(const Point3d& p2 ) const if (x = p2.x) if (y = p2.y) return (z p2.z); else return (y p2.y); else return (x p2.x); ; int ReadPointCloudFile(const std:string& strPath) FILE *ifp = fopen(strPath.c_str(),r); if(ifp = NULL) printf(Cannot open point cloud file.n); return -1; /获取行数,即点的数量,用于设置std:vector的容量 const int BUFSIZE = 512; char bufBUFSIZE; int rowNumber = 0; while(fgets(buf,BUFSIZE,ifp) != NULL) +rowNumber; fclose(ifp); ifp = 0; /重新打开文件,读取所有点的信息 ifp = fopen(strPath.c_str(),r); Point3d pointCoor; Point3d pointNormal; std:vector vecPtCoor; /点坐标 std:vector vecPtNormal; /法向量 vecPtCoor.reserve(rowNumber); vecPtNormal.reserve(rowNumber); while(fgets(buf,BUFSIZE,ifp) != NULL) / read info l

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论