Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1/* =============================================================================
2** This file is part of the mmg software package for the tetrahedral
3** mesh modification.
4** Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- .
5**
6** mmg is free software: you can redistribute it and/or modify it
7** under the terms of the GNU Lesser General Public License as published
8** by the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** mmg is distributed in the hope that it will be useful, but WITHOUT
12** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14** License for more details.
15**
16** You should have received a copy of the GNU Lesser General Public
17** License and of the GNU General Public License along with mmg (in
18** files COPYING.LESSER and COPYING). If not, see
19** <http://www.gnu.org/licenses/>. Please read their terms carefully and
20** use this copy of the mmg distribution only if you accept them.
21** =============================================================================
22*/
23
35
36#include <assert.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <signal.h>
40#include <string.h>
41#include <ctype.h>
42#include <math.h>
43#include <float.h>
44
46// if the header file is in the "include" directory
47// #include "libmmgs.h"
48// if the header file is in "include/mmg/mmgs"
49#include "mmg/mmgs/libmmgs.h"
50
51int main(int argc,char *argv[]) {
52 MMG5_pMesh mmgMesh;
53 MMG5_pSol mmgSol;
54 int ier;
55 char *inname,*outname;
56
57 fprintf(stdout," -- TEST MMGSLS \n");
58
59 if ( argc != 3 ) {
60 printf(" Usage: %s filein fileout \n",argv[0]);
61 return(1);
62 }
63
64 /* Name and path of the mesh files */
65 inname = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
66 if ( inname == NULL ) {
67 perror(" ## Memory problem: calloc");
68 exit(EXIT_FAILURE);
69 }
70 strcpy(inname,argv[1]);
71
72 outname = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
73 if ( outname == NULL ) {
74 perror(" ## Memory problem: calloc");
75 exit(EXIT_FAILURE);
76 }
77 strcpy(outname,argv[2]);
78
80 /* args of InitMesh:
81 * MMG5_ARG_start: we start to give the args of a variadic func
82 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
83 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
84 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
85 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
86 mmgMesh = NULL;
87 mmgSol = NULL;
89 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppLs,&mmgSol,
91
95
97 if ( MMGS_loadMesh(mmgMesh,inname) != 1 ) exit(EXIT_FAILURE);
98
102
104 /* Ask for level set discretization */
105 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_iso, 1) != 1 )
106 exit(EXIT_FAILURE);
107
108 /* Ask to preserve the initial references of the domain */
109 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_keepRef, 1) != 1 )
110 exit(EXIT_FAILURE);
111
113 if ( MMGS_loadSol(mmgMesh,mmgSol,inname) != 1 )
114 exit(EXIT_FAILURE);
115
117 if ( MMGS_Chk_meshData(mmgMesh,mmgSol) != 1 ) exit(EXIT_FAILURE);
118
122
123
125
126 /* debug mode ON (default value = OFF) */
127 if ( MMGS_Set_iparameter(mmgMesh,mmgSol,MMGS_IPARAM_debug, 1) != 1 )
128 exit(EXIT_FAILURE);
129
131 ier = MMGS_mmgsls(mmgMesh,mmgSol,NULL);
132
133 if ( ier == MMG5_STRONGFAILURE ) {
134 fprintf(stdout,"BAD ENDING OF MMGSLS: UNABLE TO SAVE MESH\n");
135 return(ier);
136 } else if ( ier == MMG5_LOWFAILURE )
137 fprintf(stdout,"BAD ENDING OF MMGSLS\n");
138
139 if ( MMGS_saveMesh(mmgMesh,outname) != 1 )
140 exit(EXIT_FAILURE);
141
142 if ( MMGS_saveSol(mmgMesh,mmgSol,outname) != 1 )
143 exit(EXIT_FAILURE);
144
145 /* 9) free the MMGS5 structures */
147 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
149
150 free(inname);
151 inname = NULL;
152
153 free(outname);
154 outname = NULL;
155
156 return(ier);
157}
int MMGS_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
set an integer parameter of the remesher
int MMGS_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMGS_Free_all(const int starter,...)
Deallocations before return.
int MMGS_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
Check if the numbers of given entities match with mesh and solution size and check mesh data.
int ier
program main
Example for using mmglib (basic use)
Definition main.F90:6
int MMGS_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution) in medit's .sol format.
Definition inout_s.c:1312
int MMGS_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh or .meshb format.
Definition inout_s.c:842
int MMGS_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write an isotropic or anisotropic metric in medit file format.
Definition inout_s.c:1483
int MMGS_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition inout_s.c:41
int MMGS_mmgsls(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_pSol umet)
Main "program" for level-set discretization.
Definition libmmgs.c:298
@ MMGS_IPARAM_keepRef
Definition libmmgs.h:117
@ MMGS_IPARAM_debug
Definition libmmgs.h:112
@ MMGS_IPARAM_iso
Definition libmmgs.h:114
#define MMG5_ARG_ppMesh
#define MMG5_ARG_end
#define MMG5_ARG_ppLs
#define MMG5_STRONGFAILURE
Definition libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition libmmgtypes.h:57
MMG5_Sol * MMG5_pSol
MMG5_Mesh * MMG5_pMesh
#define MMG5_ARG_start
Definition libmmgtypes.h:93
#define MMG5_ARG_ppMet