/*
* 程序目标:读取txt文件中的坐标,并且存储在vector、矩阵和数组中
*
* 摘要:
*1.这篇文章包含两个基础内容,文件流操作和vector操作,可以参考下面两篇文章:
*2.文件流操作:https://blog.youkuaiyun.com/a125930123/article/details/53542261
*3.vector操作:https://blog.youkuaiyun.com/armman/article/details/1501974
*
* 当前版本:1.1
* 作者:Shoen
* 完成日期:2018年3月29日
*/
//#include <stdafx.h>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
////************利用点的vector存储读取的坐标*************//
//vector是一个序列,读取每个值的方式是 vector.at(i)
int main()
{
ifstream circle;
//定义点的vector
//typedef Point_<double> Point2d;
vector<Point3d> points;
//定义点,作为push_back的对象
//这个需要注意,vector的每一项需要作为一个整体来pushback,数组就pushback数组,类就pushback类。
Point3d temp;
//定义两个变量,用来存储读取的数据
double temp1 = 0, temp2 = 0, temp3 = 0;
circle.open("Circle.txt");
//!circle.eof() 用来控制什么时候读取终止
for (int i = 0; !circle.eof(); i++)
{
//读取txt文件的坐标值
circle >> temp1 >> temp2 >>temp3;
temp.x = temp1;
temp.y = temp2;
temp.z = temp3;
points.push_back(temp);
}
double **swp; //动态申请二维数组 n行 m列
swp = new double *[points.size()];
for (int i = 0; i<points.size(); i++)
{
swp[i] = new double[3];
}
for (int i = 0; i < points.size(); i++)
{
swp[i][0] = points.at(i).x;
swp[i][1] = points.at(i).y;
swp[i][2] = points.at(i).z;
cout << "[" << points.at(i).x << " , " << points.at(i).y <<" , "<< points.at(i).z<< "]" << endl;
cout << "[" << swp[i][0] << " , " << swp[i][1] << " , " << swp[i][2] << "]" << endl;
}
cout<< swp[0][0] << endl;
circle.close();
system("pause");
/*
Point3f p3f(3, 4, 5);
cout << "【三维点】" << endl << p3f << endl;
*/
return 0;
}