/* ============================================================================= ** This file is part of the mmg software package for the tetrahedral ** mesh modification. ** Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- . ** ** mmg is free software: you can redistribute it and/or modify it ** under the terms of the GNU Lesser General Public License as published ** by the Free Software Foundation, either version 3 of the License, or ** (at your option) any later version. ** ** mmg is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public ** License for more details. ** ** You should have received a copy of the GNU Lesser General Public ** License and of the GNU General Public License along with mmg (in ** files COPYING.LESSER and COPYING). If not, see ** . Please read their terms carefully and ** use this copy of the mmg distribution only if you accept them. ** ============================================================================= */ /** * Example of use of the mmg3d library (basic use of mesh adaptation) * * \author Charles Dapogny (LJLL, UPMC) * \author Cécile Dobrzynski (Inria / IMB, Université de Bordeaux) * \author Pascal Frey (LJLL, UPMC) * \author Algiane Froehly (Inria / IMB, Université de Bordeaux) * \version 5 * \copyright GNU Lesser General Public License. */ #include #include #include #include #include #include #include #include /** Include the mmg3d library hader file */ // if the header file is in the "include" directory // #include "libmmg3d.h" // if the header file is in "include/mmg/mmg3d" #include "mmg/mmg3d/libmmg3d.h" int main(int argc,char *argv[]) { MMG5_pMesh mmgMesh; MMG5_pSol mmgSol; int ier; char *filename, *fileout; fprintf(stdout," -- TEST MMG3DLIB \n"); if ( argc != 3 ) { printf(" Usage: %s filein fileout \n",argv[0]); printf(" Mark as required the triangles of ref 1 and save the new mesh in fileout.\n"); return(1); } /* Name and path of the mesh file */ filename = (char *) calloc(strlen(argv[1]) + 1, sizeof(char)); if ( filename == NULL ) { perror(" ## Memory problem: calloc"); exit(EXIT_FAILURE); } strcpy(filename,argv[1]); fileout = (char *) calloc(strlen(argv[2]) + 1, sizeof(char)); if ( fileout == NULL ) { perror(" ## Memory problem: calloc"); exit(EXIT_FAILURE); } strcpy(fileout,argv[2]); /** ------------------------------ STEP I -------------------------- */ /** 1) Initialisation of mesh and sol structures */ /* args of InitMesh: * MMG5_ARG_start: we start to give the args of a variadic func * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh) * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */ mmgMesh = NULL; mmgSol = NULL; MMG3D_Init_mesh(MMG5_ARG_start, MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol, MMG5_ARG_end); /** Mesh loading */ if ( MMG3D_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE); /** ------------------------------ STEP II -------------------------- */ /* Get triangle references and set the triangles of ref 1 as required */ /** a) get the size of the mesh: np = #vertices, * ne=#tetra,npr=#prisms,nt=#triangles,nq=#quad,ne=#edges */ int nt; if ( MMG3D_Get_meshSize(mmgMesh,NULL,NULL,NULL,&nt,NULL,NULL) !=1 ) { exit(EXIT_FAILURE); } int k; for ( k=1; k<=nt; ++k ) { /* Get the ref of the k^th triangle */ int ref,dummy; if ( MMG3D_Get_triangle(mmgMesh,&dummy,&dummy,&dummy, &ref,NULL) != 1 ) { exit(EXIT_FAILURE); } /* if this ref is 1, mark the triangle as required */ if ( ref == 1 ) { if ( MMG3D_Set_requiredTriangle(mmgMesh,k) != 1 ) { exit(EXIT_FAILURE); } } } /** ------------------------------ STEP III -------------------------- */ /** Save the mesh */ if ( MMG3D_saveMesh(mmgMesh,fileout) != 1 ) { fprintf(stdout,"UNABLE TO SAVE MESH\n"); return(MMG5_STRONGFAILURE); } /** Free the MMG3D5 structures */ MMG3D_Free_all(MMG5_ARG_start, MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol, MMG5_ARG_end); free(filename); filename = NULL; free(fileout); fileout = NULL; return(ier); }