#ifndef _3DTOOLS2MSH_H #define _3DTOOLS2MSH_H #include "iostream" #include "fstream" #include "sstream" #include "string.h" #include "iomanip" #define MESH "-M" #define VALUE "-V" #define OUTFILE "-G" #define FILTER "-F" using namespace std; string& replace_all(string& str,const string& old_value,const string& new_value,int &num) //替换str中所有lod_value为new_value,返回被替换的lod_value的个数 { int count = 0; for(string::size_type pos(0);pos!=string::npos;pos+=new_value.length()){ if((pos=str.find(old_value,pos))!=string::npos){ str.replace(pos,old_value.length(),new_value); count++; } else break; } num = count; return str; } int typeget(char *str, const char* str2,string &str3)//提出头端的子句 { char* strp = strstr(str, str2); // 从字符串str中查找str2, if (strp == NULL) { return 0; // 如果没有找到,返回 } string temp = str; str3=temp.substr(strlen(str2));//提出除str2外的子句 return 1; } int nameget(char *str, const char* str2,string &str3)//提出尾端的子句 { char* strp = strstr(str, str2); // 从字符串str中查找str2, if (strp == NULL) { return 0; // 如果没有找到,返回 } string temp = str; str3=temp.substr(0,strlen(str)-strlen(str2));//提出除str2外的子句 return 1; } struct NODE { double x,y,z; }; struct CUBE { int index[8]; double phys; }; class _3dtools2msh { public: _3dtools2msh(); ~_3dtools2msh(); int meshin(string); int physin(string); int findindex(); int mshout(string,double); private: double xst,yst,zst; int xnum,ynum,znum; double xinter,yinter,zinter; NODE* node; CUBE* cube; int nodenum; int cubenum; }; _3dtools2msh::_3dtools2msh() { node = NULL; cube = NULL; } _3dtools2msh::~_3dtools2msh() { if(node!=NULL) delete[] node; if(cube!=NULL) delete[] cube; } int _3dtools2msh::meshin(string filename) { stringstream stemp; string temp; int space_num; int xnum_t,ynum_t,znum_t; const char* meshname = filename.c_str(); ifstream inmesh; inmesh.open(meshname); if (!inmesh) { cout<>ynum>>xnum>>znum>>yst>>xst>>zst; inmesh>>temp; replace_all(temp,"*"," ",space_num); stemp.clear(); stemp.str(temp); stemp>>ynum_t>>yinter; if (ynum!=ynum_t) { cout<<"syntax error: "<>temp; replace_all(temp,"*"," ",space_num); stemp.clear(); stemp.str(temp); stemp>>xnum_t>>xinter; if (xnum!=xnum_t) { cout<<"syntax error: "<>temp; replace_all(temp,"*"," ",space_num); stemp.clear(); stemp.str(temp); stemp>>znum_t>>zinter; if (znum!=znum_t) { cout<<"syntax error: "<>cube[i].phys; } incube.close(); return 0; } } int _3dtools2msh::findindex() { for (int i = 0; i < xnum; i++) { for (int j = 0; j < ynum; j++) { for (int k = 0; k < znum; k++) { cube[k+j*znum+i*ynum*znum].index[0]=k+j*(znum+1)+i*(ynum+1)*(znum+1); cube[k+j*znum+i*ynum*znum].index[1]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1; cube[k+j*znum+i*ynum*znum].index[2]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+znum+1+(ynum+1)*(znum+1); cube[k+j*znum+i*ynum*znum].index[3]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+(ynum+1)*(znum+1); cube[k+j*znum+i*ynum*znum].index[4]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1; cube[k+j*znum+i*ynum*znum].index[5]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1; cube[k+j*znum+i*ynum*znum].index[6]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+znum+1+(ynum+1)*(znum+1); cube[k+j*znum+i*ynum*znum].index[7]=k+j*(znum+1)+i*(ynum+1)*(znum+1)+1+(ynum+1)*(znum+1); } } } return 0; } int _3dtools2msh::mshout(string filename,double filter) { const char* mshname = filename.c_str(); ofstream outmsh; outmsh.open(mshname); if (!outmsh) { cout<<"fail to create "<