56 iCubMesh(QString fileName,
double rz=0.0,
double ry=0.0,
double rx=0.0,
double tx=0.0,
double ty=0.0,
double tz=0.0)
60 QFile objFile(fileName);
61 if(!objFile.open(QIODevice::ReadOnly))
63 QMessageBox::critical(0,QObject::tr(
"Missing Obj File"),
64 QObject::tr(
"<qt>File not found:<br>%1</qt>").arg(fileName));
72 while(!objFile.atEnd())
74 objFile.readLine(buffer,4096);
76 QStringList parameters=
tokenize(line.simplified(),
' ');
78 if (parameters[0]==
"v") ++v;
79 else if (parameters[0]==
"vn") ++
n;
80 else if (parameters[0]==
"f") ++
nFaces;
84 vx=
new float[v];
vy=
new float[v];
vz=
new float[v];
85 nx=
new float[
n];
ny=
new float[
n];
nz=
new float[
n];
90 double grad2rad=
M_PI/180.0;
94 double cz=cos(rz),sz=sin(rz);
95 double cy=cos(ry),sy=sin(ry);
96 double cx=cos(rx),sx=sin(rx);
100 objFile.open(QIODevice::ReadOnly);
106 double xmin=1E+20,xmax=-xmin;
107 double ymin=1E+20,ymax=-ymin;
108 double zmin=1E+20,zmax=-zmin;
110 while(!objFile.atEnd())
112 objFile.readLine(buffer,4096);
113 QString line(buffer);
114 QStringList parameters=
tokenize(line.simplified(),
' ');
116 if (parameters[0]==
"v")
118 if (parameters[1].toDouble()<xmin) xmin=parameters[1].toDouble();
119 if (parameters[1].toDouble()>xmax) xmax=parameters[1].toDouble();
120 if (parameters[2].toDouble()<ymin) ymin=parameters[2].toDouble();
121 if (parameters[2].toDouble()>ymax) ymax=parameters[2].toDouble();
122 if (parameters[3].toDouble()<zmin) zmin=parameters[3].toDouble();
123 if (parameters[3].toDouble()>zmax) zmax=parameters[3].toDouble();
125 x1=parameters[1].toDouble();
126 y1=parameters[2].toDouble();
127 z1=parameters[3].toDouble();
138 vy[v]=ty+cx*y3-sx*z3;
139 vz[v]=tz+sx*y3+cx*z3;
143 else if (parameters[0]==
"vn")
145 x1=(cz*parameters[1].toDouble()-sz*parameters[2].toDouble());
146 y1=(sz*parameters[1].toDouble()+cz*parameters[2].toDouble());
147 z1=parameters[3].toDouble();
159 else if (parameters[0]==
"f")
161 num=
tokenize(parameters[1].simplified(),
'/');
165 num=
tokenize(parameters[2].simplified(),
'/');
169 num=
tokenize(parameters[3].simplified(),
'/');