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

下载本文档

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

文档简介

c 对 txt 文件的读取与写入 这是自己写程序时突然用到这方面的技术 在网 上搜了一下 特存此以备后用 include include include using namespace std i nt main char buffer 256 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 data 6 2 while myfile eof myfile getline buffer 10 sscanf buffer d d cout a b endl data i 0 a data i 1 b i myfile close for int k 0 k i k outfile data k 0 data k 1 endl tob id 3208 cout data k 0 data k 1 endl outfile close return 0 无论读 写都要包含头文件 读 从外部文件中将数据读到程序中来处理 对于程序来说 是从外部读入数据 因此定义输入流 即定义输入流对象 ifsteam infile infile 就是输入流 对象 这个对象当中存放即将从文件读入的数据流 假设有名字为 myfile txt 的文件 存 有两行数字数据 具体方法 int a b ifstream infile infile open myfile txt 注 意文件的路径 infile a b 两行数据可以连续读出到变量里 infile close 如果是个很大的多行存储的文本型文件可以这么读 char buf 1024 临时保存读取出来的文件内容 string message ifstream infile infile open myfile js if infile is open 文件打开成功 说明曾经写入过东西 while infile good infile getline buf 1204 message buf 这里可能对 message 做一些操作 cout message endl infile close 写 将程序中处理后的数据写到文件当中 对程序来说是将数据写出去 即数据离开程序 因此定义输出流对象 ofstream outfile outfile 就是输出流对象 这个对 象用来存放将要写到文件当中的数据 具体做法 ofstream outfile outfile open myfile bat myfile bat 是存放数据的文件名 if outfile is open outfile message endl message 是程序中处理的数据 outfile close else cout 不能打开文件 endl c 对文件的读写操作的例子 从键盘读入一行字 符 把其中的字母依次放在磁盘文件 fa2 dat 中 再把它从磁盘文件读入程序 将其中的 小写字母改成大写字母 再存入磁盘 fa3 dat 中 i nclude i nclude i nclude using namespace std 从键盘上读取字符的函数 void read save char c 80 ofstream outfile f1 dat 以输出方工打开文件 if outfile cerr open error 65 将字母字符存入磁盘文件 cout c i cout endl outfile close void creat data char ch ifstream infile f1 dat ios in 以输入的方式打开文件 if infile cerr open error endl exit 1 ofstream outfile f3 dat 定义输出流 f3 dat 文件 if outfile cerr open error endl exit 1 while infile get ch 当读取字符成功时 if ch 97 ch ch 32 outfile put ch cout ch cout endl 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 int data while ifp data 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 cout data next 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 cout line endl r close 函数用于读取 xyz 的点云文件 点云的格式为 cpp view plain copy 在 CODE 上查看代码片派生到我的代码片 17 6 8 0 0 0 15 16 9 0 0 0 17 6 8 0 0 0 15 15 9 0 0 0 23 7 13 0 0 0 15 15 9 0 0 0 23 7 13 0 0 0 24 7 13 0 0 0 14 15 9 0 0 0 14 15 9 0 0 0 27 6 16 0 0 0 14 14 9 0 0 0 27 6 16 0 0 0 14 14 10 0 0 0 14 15 10 0 0 0 14 14 10 0 0 0 13 13 10 0 0 0 前面 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 else return y p2 y else return x p2 x int ReadPointCloudFile const std string if ifp NULL printf Cannot open point cloud file n return 1 获取行数 即点的数量 用于设置 std vector 的容量 const int BUFSIZE 512 char buf BUFSIZE 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

温馨提示

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

评论

0/150

提交评论