Not sure what to tell you. I was able to read an example file with minimal changes. I never intended to write anything you could just insert into your homework. This is a simple program that reads one pose at a time and spits it back out.
Code:
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
struct Vector3 {
float x, y, z;
};
struct joint_angle {
int count;
Vector3 orient;
};
struct pose {
float time;
vector<joint_angle> angle;
};
std::istream & operator>> (std::istream & stream, joint_angle & ja)
{
ja.count = 0;
stream >> ja.orient.x >> ja.orient.y >> ja.orient.z;
/*printf ("ja.orient.x===>%f",ja.orient.x);
printf ("ja.orient.y===>%f",ja.orient.y);
printf ("ja.orient.z===>%f",ja.orient.z);*/
return stream;
}
int simpleRead(ifstream &stream, pose &p);
int main()
{
ifstream file("file.txt");
pose p;
while (simpleRead(file, p)) {
cout << p.time;
for (int i = 0; i < p.angle.size(); i++) {
cout << " " << p.angle[i].orient.x << " " << p.angle[i].orient.y << " " << p.angle[i].orient.z;
}
cout << "\n";
}
return 0;
}
int simpleRead(ifstream &stream, pose &p)
{
// 1. Read time information
stream >> p.time;
if (stream.eof()) return 0;
// 2. Read joint angle information
joint_angle ja;
vector<joint_angle> angles;
char c;
while ( stream >> skipws >> ja >> noskipws >> c ) {
angles.push_back(ja);
if (c == '\n' ) {
break;
}
}
p.angle = angles;
return 1;
}
/* in file.txt:
-0.01 0.03 0.04 -0.5 0.6 0.8 0.3 -0.005 -0.003 -0.008
-0.03 0.05 0.06 -0.005 -0.2 0.3 0.8 1.02 1.03 1.04
*/
Works for me. My assumptions were that there were only one pose per line and that one joint angle was three floats. A pose was made up of multiple angles.
I do feel like I've been tricked into doing all the hard work... but maybe this will help you understand what I'm trying to say.