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);

}
Beispiel #2
0
/* 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);
}
Beispiel #3
0
int main()
{
    int i, NmbVer, NmbQad, ver, dim, *RefTab, (*QadTab)[5], (*TriTab)[4];
    long long InpMsh, OutMsh;
    float (*VerTab)[3];


    /*-----------------------------------*/
    /* Ouverture du maillage "quad.mesh" */
    /*-----------------------------------*/

    if(!(InpMsh = GmfOpenMesh("quad.meshb", GmfRead, &ver, &dim)))
        return(1);

    printf("InpMsh : idx = %d, version = %d, dimension = %d\n", InpMsh, ver, dim);

    if(dim != 3)
        exit(1);

    /* Lecture des nombres d'elements et de noeuds pour l'allocation de memoire */
    NmbVer = GmfStatKwd(InpMsh, GmfVertices);
    printf("InpMsh : nmb vertices = %d\n", NmbVer);
    VerTab = malloc((NmbVer+1) * 3 * sizeof(float));
    RefTab = malloc((NmbVer+1) * sizeof(int));

    NmbQad = GmfStatKwd(InpMsh, GmfQuadrilaterals);
    printf("InpMsh : nmb quads = %d\n", NmbQad);
    QadTab = malloc((NmbQad+1) * 5 * sizeof(int));
    TriTab = malloc((NmbQad+1) * 2 * 4 * sizeof(int));

    /* Lecture des noeuds */
    GmfGetBlock(    InpMsh, GmfVertices, NULL, \
                    GmfFloat, &VerTab[1][0], &VerTab[2][0], \
                    GmfFloat, &VerTab[1][1], &VerTab[2][1], \
                    GmfFloat, &VerTab[1][2], &VerTab[2][2], \
                    GmfInt, &RefTab[1], &RefTab[2] );

    /* Lecture des quadrangles */
    GmfGetBlock(    InpMsh, GmfQuadrilaterals, NULL, \
                    GmfInt, &QadTab[1][0], &QadTab[2][0], \
                    GmfInt, &QadTab[1][1], &QadTab[2][1], \
                    GmfInt, &QadTab[1][2], &QadTab[2][2], \
                    GmfInt, &QadTab[1][3], &QadTab[2][3], \
                    GmfInt, &QadTab[1][4], &QadTab[2][4] );

    /* Fermeture du maillage quad */
    GmfCloseMesh(InpMsh);


    /*-----------------------------------*/
    /* Creation du maillage en triangles */
    /*-----------------------------------*/

    if(!(OutMsh = GmfOpenMesh("tri.meshb", GmfWrite, ver, dim)))
        return(1);

    /* Ecriture du nombre de noeuds */
    GmfSetKwd(OutMsh, GmfVertices, NmbVer);

    /* Puis ecriture des noeuds */
    GmfSetBlock(OutMsh, GmfVertices, NULL, \
                    GmfFloat, &VerTab[1][0], &VerTab[2][0], \
                    GmfFloat, &VerTab[1][1], &VerTab[2][1], \
                    GmfFloat, &VerTab[1][2], &VerTab[2][2], \
                    GmfInt, &RefTab[1], &RefTab[2] );


    /*  Ecriture du nombre de triangles */
    GmfSetKwd(OutMsh, GmfTriangles, 2*NmbQad);
    printf("OutMsh : nmb triangles = %d\n", 2*NmbQad);

    /* Puis boucle de conversion des quads en deux triangles */

    for(i=1;i<=NmbQad;i++)
    {
        TriTab[i*2-1][0] = QadTab[i][0];
        TriTab[i*2-1][1] = QadTab[i][1];
        TriTab[i*2-1][2] = QadTab[i][2];
        TriTab[i*2-1][3] = QadTab[i][4];

        TriTab[i*2][0] = QadTab[i][0];
        TriTab[i*2][1] = QadTab[i][2];
        TriTab[i*2][2] = QadTab[i][3];
        TriTab[i*2][3] = QadTab[i][4];
    }

    /* Ecriture des triangles */
    GmfSetBlock(OutMsh, GmfTriangles, NULL, \
                    GmfInt, &TriTab[1][0], &TriTab[2][0], \
                    GmfInt, &TriTab[1][1], &TriTab[2][1], \
                    GmfInt, &TriTab[1][2], &TriTab[2][2], \
                    GmfInt, &TriTab[1][3], &TriTab[2][3] );

    /* Ne pas oublier de fermer le fichier */
    GmfCloseMesh(OutMsh);

    free(QadTab);
    free(TriTab);
    free(RefTab);
    free(VerTab);

    return(0);
}
Beispiel #4
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);
}
Beispiel #5
0
/* 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);
}