//写出obj
ofstream writeObj;
writeObj.open(folderfilepath+"writeobj.obj");
for (int k = 0; k < m_vVert.size(); k++){
ZVert vtemp = m_vVert[k];
double vix = vtemp.Co3d().x;
double viy = vtemp.Co3d().y;
double viz = vtemp.Co3d().z;
ostringstream oss;
oss << vix;
string strx = oss.str();
ostringstream oss1;
oss1 << viy;
string stry = oss1.str();
ostringstream oss2;
oss2 << viz;
string strz = oss2.str();
//endl换行无效,改为\r\n
writeObj << "v " << strx << " " << stry << " " << strz << "\r\n";
}
for (int ci = 0; ci < m_vFace.size(); ci++){
ZFace &fa = m_vFace[ci];
int indx1 = fa.GetIndex(0);
int indx2 = fa.GetIndex(1);
int indx3 = fa.GetIndex(2);
//obj face id start from 1 not 0
writeObj << "f " << indx1 + 1 << "// " << indx2 + 1 << "// " << indx3 + 1 << "// " <<"\r\n";
}
writeObj.close();
//调用exe
//system("HierarSpherePara.exe ");
string file_path = folderfilepath+"writeobj.obj";
string txt_out_path = folderfilepath+"writeobj.obj.txt";
string txt_out_path2 = folderfilepath+"result_record.txt";
string exefilepath = folderfilepath+"HierarSpherePara.exe";
LPCSTR exestr = exefilepath.c_str();
string exefilepath1 = folderfilepath;
LPCSTR exestr1 = exefilepath1.c_str();
HINSTANCE hd ;
hd = ShellExecute(NULL,"open",exestr, "writeobj.obj 1 20 ", exestr1, SW_SHOW);
//读入参数化好 的结果文件
string out_file_path = folderfilepath+"writeobj.obj_op.obj";
//不管执行的程序是否成功运行,运行的时间是长是短,ShellExecute函数都会立即返回
if (( long )hd > 32)
{
//确保输出了obj文件
while(1){
if(LoadMeshfromObj(out_file_path.c_str())){
//AfxMessageBox("读取参数化后的obj成功!");
break;
}
}
//删除文件
//BOOL d,d1,d2,d3 = false;
while(1){ //删除导出的obj
if(DeleteFile(file_path.c_str())){
break;
}
}
while(1){ //删除新生成的obj
if(DeleteFile(out_file_path.c_str())){
break;
}
}
return true;
}
else{
AfxMessageBox("exe执行失败!");
return false;
}