void ReadSTLFile(){
//打开,读入文件
CFileDialog dlg(TRUE,NULL,NULL,
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,\"平板印刷(*.stl)|*.stl|\
if(dlg.DoModal()!=IDOK)
return;
CString lpszPathName=dlg.GetFileName();
inFile.Open(lpszPathName, CFile::modeRead); //open file
inFile.ReadString(cstr); //read \"solid ***\"
inFile.ReadString(cstr); //read the first normal vector line
checkstr=cstr[3]; // ensure the normal vector line exists
// if exist, the third charecter must be \"f\" of \" facet\"
while (checkstr==cstr[3]){
//读入三角面片的法向量
//in order to get the first vector number
cstr.TrimLeft(\" facet normal \");
for (int i = 0; cstr[i] != ' '; i++) //the first number is end before a \" \"
cstrtemp = cstrtemp + cstr[i]; //store all the numbers needed
vect.x = (float)atof(cstrtemp); //translate string into float
cstrtemp.Empty();
for (i++; cstr[i] != ' '; i++) //the second number is also end before a \" \"
cstrtemp = cstrtemp + cstr[i];
vect.y = (float)atof(cstrtemp);
cstrtemp.Empty();
//the third number is end when the line ends
for (i++; i < cstr.GetLength(); i++)
cstrtemp = cstrtemp + cstr[i];
vect.z = (float)atof(cstrtemp);
cstrtemp.Empty();
volume.STLVectorArray.Add(vect); //add the vector to the array
inFile.ReadString(cstr); //read \"outer loop\"
//读入顶点坐标
for (i = 0; i < 3; i++){ //there are three vectors in a vertex
inFile.ReadString(cstr); //read the vertex line
//the following is similar to the method getting normal vector
cstr.TrimLeft(\" vertex \");
//读入X
for (int j = 0; cstr[j] != ' '; j++)
cstrtemp = cstrtemp + cstr[j];
STL_X.X = (float)atof(cstrtemp);
kp.X = STL_X.X;
cstrtemp.Empty();
//读入Y
for (j++; cstr[j] != ' '; j++)
cstrtemp = cstrtemp + cstr[j];
STL_Y.Y = (float)atof(cstrtemp);
kp.Y = STL_Y.Y;
cstrtemp.Empty();
//读入Z
for (j++; j < cstr.GetLength(); j++)
cstrtemp = cstrtemp + cstr[j];
STL_Z.Z = (float)atof(cstrtemp);
kp.Z = STL_Z.Z;
cstrtemp.Empty();
//将kp加入到volume.VolumeKeyPointArray中
volume.VolumeKeyPointArray.Add(kp);
//store the vectex in the array
/*接下来,调用函数StoreTheValue()将STL_X,STL_Y,STL_Z分别加入到STL_XArray,STL_XArray数组中的STL_X所对应的STL_YArray,STL_YArray数组中的STL_Y所对应的STL_ZArray中去。STL_XArray,STL_YArray,STL_ZArray都是按照从小到大排序的数组。StoreTheValue()的实现参见第六章的文献[23]*/
StoreTheValue();
}
inFile.ReadString(cstr); //read \"end loop\"
inFile.ReadString(cstr); //read \"end facet\"
inFile.ReadString(cstr); //read the next normal vector
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容