c++中txt文件按照行读取操作记录
数据示例
1305031526.671473 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 1.000000000
数据分别为时间,平移向量以及四元数表示的旋转向量
#include <string>
#include <iostream>
string trajectory_file = "../data/trajectory.txt";
vector<Sophus::SE3<double>, Eigen::aligned_allocator<Sophus::SE3<double>>> poses;
ifstream fin(trajectory_file);
if (!fin)
{
cout<<"Computer can not find file at"<<trajectory_file<<endl;
return 1;
}
while(!fin.eof())
{
double t,t_x,t_y,t_z,q_x,q_y,q_z,q_w;
fin>>t>>t_x>>t_y>>t_z>>q_x>>q_y>>q_z>>q_w;
Eigen::Quaterniond q(q_w,q_x,q_y,q_z);
Eigen::Vector3d v(t_x,t_y,t_z);
Sophus::SE3<double> SE3_qt(q,v);
poses.push_back(SE3_qt);
}