/* save scalar signed distance function */ int saveDistance(pSol sol, pMesh mesh, pMesh mesh2, int n) { double dbuf[GmfMaxTyp]; float fbuf[GmfMaxTyp]; int k,i,inm,type,typtab[GmfMaxTyp]; char *ptr,data[128]; strcpy(data,mesh->name); ptr = strstr(data,".mesh"); if ( ptr ) *ptr = '\0'; sprintf(data,"%s.%d.sol",data,n); if ( !(inm = GmfOpenMesh(data,GmfWrite,sol->ver,sol->dim)) ) { fprintf(stderr," ** UNABLE TO OPEN %s\n",data); return(0); } fprintf(stdout," %%%% %s OPENED\n",data); type = 1; typtab[0] = GmfSca; /* write sol */ GmfSetKwd(inm,GmfSolAtVertices,sol->np,type,typtab); if ( sol->ver == GmfFloat ) { for (k=0; k<sol->np; k++) { for (i=0; i<typtab[0]; i++) fbuf[i] = sol->d[k]; GmfSetLin(inm,GmfSolAtVertices,fbuf); } } else { for (k=0; k<sol->np; k++) { for (i=0; i<typtab[0]; i++) dbuf[i] = sol->d[k]; GmfSetLin(inm,GmfSolAtVertices,dbuf); } } GmfCloseMesh(inm); return(1); }
int Mesh2::Save(const string & filename) { int ver = GmfFloat, outm; if ( !(outm = GmfOpenMesh(filename.c_str(),GmfWrite,ver,2)) ) { cerr <<" -- Mesh2::Save UNABLE TO OPEN :"<< filename << endl; return(1); } float fx,fy; GmfSetKwd(outm,GmfVertices,this->nv); for (int k=0; k<nv; k++) { const Vertex & P = this->vertices[k]; GmfSetLin(outm,GmfVertices,fx=P.x,fy=P.y,P.lab); } GmfSetKwd(outm,GmfTriangles,nt); for (int k=0; k<nt; k++) { const Element & K(this->elements[k]); int i0=this->operator()(K[0])+1; int i1=this->operator()(K[1])+1; int i2=this->operator()(K[2])+1; int lab=K.lab; GmfSetLin(outm,GmfTriangles,i0,i1,i2,lab); } GmfSetKwd(outm,GmfEdges,nbe); for (int k=0; k<nbe; k++) { const BorderElement & K(this->borderelements[k]); int i0=this->operator()(K[0])+1; int i1=this->operator()(K[1])+1; int lab=K.lab; GmfSetLin(outm,GmfEdges,i0,i1,lab); } GmfCloseMesh(outm); return (0); }
/* superopose the contours of mesh and mesh2 */ int saveContour(pMesh mesh, pMesh mesh2) { pPoint ppt; pTria pt1; pEdge pa; int k,inm; char *ptr,data[128]; mesh->ver = GmfDouble; strcpy(data,mesh->name); ptr = strstr(data,".mesh"); if ( !ptr ) { strcat(data,".fin.mesh"); if( !(inm = GmfOpenMesh(data, GmfWrite, mesh->ver,mesh->dim)) ) { fprintf(stderr," ** UNABLE TO OPEN %s.\n",data); return(0); } } else { *ptr = '\0'; if( !(inm = GmfOpenMesh(data, GmfWrite, mesh->ver,mesh->dim)) ) { fprintf(stderr," ** UNABLE TO OPEN %s.\n",data); return(0); } } fprintf(stdout," %%%% %s OPENED\n",data); GmfSetKwd(inm,GmfVertices,mesh->np+ mesh2->np); if ( mesh->dim == 2 ) { for(k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; GmfSetLin(inm,GmfVertices,ppt->c[0],ppt->c[1],ppt->ref); } for(k=1; k<=mesh2->np; k++) { ppt = &mesh2->point[k]; GmfSetLin(inm,GmfVertices,ppt->c[0],ppt->c[1],ppt->ref); } } else { for(k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; GmfSetLin(inm,GmfVertices,ppt->c[0],ppt->c[1], ppt->c[2],ppt->ref); } } /* write triangles */ GmfSetKwd(inm,GmfTriangles,mesh2->nt); for (k=1; k<=mesh2->nt; k++) { pt1 = &mesh2->tria[k]; GmfSetLin(inm,GmfTriangles,pt1->v[0]+ mesh2->np,pt1->v[1]+mesh2->np,pt1->v[2]+mesh2->np,pt1->ref); } /* write edges */ GmfSetKwd(inm,GmfEdges,mesh->na + mesh2->na); for (k=1; k<=mesh->na; k++) { pa = &mesh->edge[k]; if ( pa->ref == 10 ) { GmfSetLin(inm,GmfEdges,pa->v[0],pa->v[1],7); } } for (k=1; k<=mesh2->na; k++) { pa = &mesh2->edge[k]; if ( pa->ref == 1) { GmfSetLin(inm,GmfEdges,pa->v[0]+mesh->np,pa->v[1]+mesh->np,1); } } GmfCloseMesh(inm); return(1); }
/* write mesh */ int saveMesh(pMesh mesh, pMesh mesh2, int n) { pPoint ppt; pTria pt1; pEdge pa; pTetra pt; int k,inm; char *ptr,data[128]; mesh->ver = GmfDouble; strcpy(data,mesh2->name); ptr = strstr(data,".mesh"); if ( ptr ) *ptr = '\0'; sprintf(data,"%s.%d.mesh",data,n); if ( !(inm = GmfOpenMesh(data,GmfWrite,mesh->ver,mesh->dim)) ) { fprintf(stderr," ** UNABLE TO OPEN %s\n",data); return(0); } fprintf(stdout," %%%% %s OPENED\n",data); GmfSetKwd(inm,GmfVertices,mesh->np); if ( mesh->dim == 2 ) { for(k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; GmfSetLin(inm,GmfVertices,ppt->c[0],ppt->c[1],ppt->ref); } } else { for(k=1; k<=mesh->np; k++) { ppt = &mesh->point[k]; GmfSetLin(inm,GmfVertices,ppt->c[0],ppt->c[1], ppt->c[2],ppt->ref); } } /* write triangles */ GmfSetKwd(inm,GmfTriangles,mesh->nt); for (k=1; k<=mesh->nt; k++) { pt1 = &mesh->tria[k]; GmfSetLin(inm,GmfTriangles,pt1->v[0],pt1->v[1],pt1->v[2],pt1->ref); } /* write tetrahedra */ GmfSetKwd(inm,GmfTetrahedra,mesh->ne); for (k=1; k<=mesh->ne; k++) { pt = &mesh->tetra[k]; if ( !pt->v[0] ) continue; GmfSetLin(inm,GmfTetrahedra,pt->v[0],pt->v[1],pt->v[2],pt->v[3],pt->ref); } /* write edges */ if(mesh->dim==2){ GmfSetKwd(inm,GmfEdges,mesh->na); for (k=1; k<=mesh->na; k++) { pa = &mesh->edge[k]; if ( !pa->v[0] ) continue; GmfSetLin(inm,GmfEdges,pa->v[0],pa->v[1],pa->ref); } } GmfCloseMesh(inm); return(1); }