00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #include "matvecIO.h"
00031 #include <qstringlist.h>
00032
00033 #include <QTextStream>
00034 #include "mytools.h"
00035
00039 QTextStream&
00040 operator>>(QTextStream &is, vec3 &v)
00041 {
00042 QChar ch;
00043 double x,y,z;
00044 is >> ch >> x >> y >> z >> ch;
00045 v[0] = x; v[1] = y; v[2] = z;
00046
00047 return is;
00048 }
00049
00053 QTextStream &
00054 operator<<(QTextStream &os, const vec3 &v)
00055 {
00056 int oldFlags = os.setf(QTextStream::showpos);
00057 os << '[' << v[0] << ' ' << v[1] << ' ' << v[2] << ']';
00058 os.flags(oldFlags);
00059 return os;
00060 }
00061
00065 QTextStream&
00066 operator>>(QTextStream &is, position &p)
00067 {
00068 QChar ch;
00069 double x,y,z;
00070 is >> ch >> x >> y >> z >> ch;
00071 p[0] = x; p[1] = y; p[2] = z;
00072
00073 return is;
00074 }
00075
00079 QTextStream &
00080 operator<<(QTextStream &os, const position &p)
00081 {
00082 int oldFlags = os.setf(QTextStream::showpos);
00083 os << '[' << p[0] << ' ' << p[1] << ' ' << p[2] << ']';
00084 os.flags(oldFlags);
00085 return os;
00086 }
00087
00096 QTextStream &
00097 operator>>(QTextStream &is, mat3 &m)
00098 {
00099 is >> m[0] >> m[3] >> m[6];
00100 is >> m[1] >> m[4] >> m[7];
00101 is >> m[2] >> m[5] >> m[8];
00102 return is;
00103 }
00104
00113 QTextStream &
00114 operator<<(QTextStream &os, const mat3 &m)
00115 {
00116 int oldFlags = os.setf(QTextStream::showpos);
00117 os << '[' << m[0] << ' ' << m[3] << ' ' << m[6] << ']' << endl;
00118 os << '[' << m[1] << ' ' << m[4] << ' ' << m[7] << ']' << endl;
00119 os << '[' << m[2] << ' ' << m[5] << ' ' << m[8] << ']' << endl;
00120 os.flags(oldFlags);
00121 return os;
00122 }
00123
00128 QTextStream &
00129 operator>>(QTextStream &is, Quaternion &q)
00130 {
00131 QChar ch;
00132 double w,x,y,z;
00133 is >> ch >> w >> x >> y >> z >> ch;
00134 q.w = w; q.x = x; q.y = y; q.z = z;
00135 return is;
00136 }
00137
00141 QTextStream&
00142 operator<<(QTextStream &os, const Quaternion &q)
00143 {
00144 int oldFlags = os.setf(QTextStream::showpos);
00145 os <<'('<< q.w <<' '<< q.x <<' '<< q.y <<' '<< q.z <<')';
00146 os.flags(oldFlags);
00147 return os;
00148 }
00149
00155 QTextStream&
00156 operator>>(QTextStream &is, transf &tr)
00157 {
00158 Quaternion q;
00159 vec3 v;
00160
00161 is >> q >> v;
00162 tr.set(q,v);
00163
00164 return is;
00165 }
00166
00170 QTextStream &
00171 operator<<(QTextStream &os, const transf &tr)
00172 {
00173 return os << tr.rotation() << tr.translation();
00174 }
00175
00193 int
00194 readTransRotFromQTextStream(QTextStream &stream,transf &tr)
00195 {
00196 QString line;
00197 QChar axis;
00198 double theta,x,y,z;
00199 transf tmpTr;
00200 vec3 tmpVec;
00201 bool ok;
00202 QStringList strings;
00203
00204 tr = transf::IDENTITY;
00205
00206 while (1) {
00207 line = stream.readLine();
00208 if ( line.isNull() ) break;
00209 if ( !line.isEmpty() && line[0]!='#' ) break;
00210 }
00211
00212 do{
00213 if ( !line.isNull() &&(line[0]=='r' || line[0]=='t' || line[0]=='T' || line[0]=='R')){
00214 if (line[0]=='r') {
00215 strings = QStringList::split(QChar(' '),line);
00216 if (strings.count() < 3) return FAILURE;
00217 theta = strings[1].toDouble(&ok); if (!ok) return FAILURE;
00218 axis = strings[2][0];
00219
00220 if (strings[0]!="rr")
00221 theta *= M_PI/180.0;
00222
00223 if (axis == 'x') tmpVec = vec3::X;
00224 else if (axis == 'y') tmpVec = vec3::Y;
00225 else if (axis == 'z') tmpVec = vec3::Z;
00226 else return FAILURE;
00227
00228 tmpTr = rotate_transf(theta,tmpVec);
00229 }
00230 else if (line[0]=='t') {
00231 strings = QStringList::split(QChar(' '),line);
00232 if (strings.count() < 4) return FAILURE;
00233 x = strings[1].toDouble(&ok); if (!ok) return FAILURE;
00234 y = strings[2].toDouble(&ok); if (!ok) return FAILURE;
00235 z = strings[3].toDouble(&ok); if (!ok) return FAILURE;
00236 tmpVec = vec3(x,y,z);
00237
00238 tmpTr = translate_transf(tmpVec);
00239 }
00240 else if (line[0]=='T') {
00241 QString trStr = line.section(' ',1,-1);
00242 QTextStream lineStream(&trStr,QIODevice::ReadOnly);
00243 lineStream >> tmpTr;
00244 }
00245 else if (line[0]=='R') {
00246 mat3 tmpMat;
00247 stream >> tmpMat;
00248 tmpTr = transf(tmpMat,vec3::ZERO);
00249 line=stream.readLine();
00250 }
00251 tr = tmpTr * tr;
00252 }
00253 line=stream.readLine();
00254 }while ( !line.isNull() && (line[0]=='r' || line[0]=='t' || line[0]=='T' || line[0]=='R'));
00255
00256 return SUCCESS;
00257 }