Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.cpp
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
36#include <cassert>
37#include <cstdio>
38#include <cstdlib>
39#include <csignal>
40#include <string>
41#include <cctype>
42#include <cmath>
43#include <cfloat>
44
45using namespace std;
46
48// if the "include/mmg" dir is in your include path
49//#include "libmmg.h"
50// if your include path do not contain the "mmg" subdirectories
51#include "mmg/libmmg.h"
52
53int main(int argc,char *argv[]) {
54 MMG5_pMesh mmgMesh;
55 MMG5_pSol mmgSol;
56 int ier;
57 string filename,filename_os,filename_o2d,filename_o3d;
58 std::size_t found;
59
60 fprintf(stdout," -- TEST MMGLIB \n");
61
62 if ( argc != 4 ) {
63 printf(" Usage: %s 2d_filein 3d_filein fileout\n",argv[0]);
64 return(1);
65 }
66
68 filename = argv[1];
69
72 /* args of InitMesh:
73 * MMG5_ARG_start: we start to give the args of a variadic func
74 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
75 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
76 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
77 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
78 mmgMesh = NULL;
79 mmgSol = NULL;
81 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
83
89 if ( MMG2D_loadMesh(mmgMesh,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
93 if ( MMG2D_loadSol(mmgMesh,mmgSol,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
94
97 ier = MMG2D_mmg2dlib(mmgMesh,mmgSol);
98
99 if ( ier == MMG5_STRONGFAILURE ) {
100 fprintf(stdout,"BAD ENDING OF MMG2DLIB: UNABLE TO SAVE MESH\n");
101 return(ier);
102 } else if ( ier == MMG5_LOWFAILURE )
103 fprintf(stdout,"BAD ENDING OF MMG2DLIB\n");
104
111 filename_o2d = argv[3];
112
113 found = filename_o2d.find(".mesh");
114 if (found==std::string::npos) {
115 found = filename_o2d.find(".msh");
116 }
117
118 if (found!=std::string::npos) {
119 filename_o2d.replace(found,1,"\0");
120 }
121 filename_o2d += ".2d";
123 /*save result*/
124 if ( MMG2D_saveMesh(mmgMesh,filename_o2d.c_str()) != 1 ) exit(EXIT_FAILURE);
125 /*save metric*/
126 if ( MMG2D_saveSol(mmgMesh,mmgSol,filename_o2d.c_str()) != 1 ) exit(EXIT_FAILURE);
127
130 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
132
135 /* Name and path of the mesh file */
136 filename = argv[2];
137 filename_os = argv[3];
138
139 found = filename_os.find(".mesh");
140 if (found==std::string::npos) {
141 found = filename_os.find(".msh");
142 }
143
144 if (found!=std::string::npos) {
145 filename_os.replace(found,1,"\0");
146 }
147 filename_os += ".s";
148
151 /* args of InitMesh
152 * MMG5_ARG_start: we start to give the args of a variadic func
153 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
154 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
155 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
156 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
157
158 mmgMesh = NULL;
159 mmgSol = NULL;
161 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
163
169 if ( MMGS_loadMesh(mmgMesh,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
175 if ( MMGS_loadSol(mmgMesh,mmgSol,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
176
177
180 ier = MMGS_mmgslib(mmgMesh,mmgSol);
181
182 if ( ier == MMG5_STRONGFAILURE ) {
183 fprintf(stdout,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH\n");
184 return(ier);
185 } else if ( ier == MMG5_LOWFAILURE )
186 fprintf(stdout,"BAD ENDING OF MMGSLIB\n");
187
195 if ( MMGS_saveMesh(mmgMesh,filename_os.c_str()) != 1 ) exit(EXIT_FAILURE);
196
198 if ( MMGS_saveSol(mmgMesh,mmgSol,filename_os.c_str()) != 1 ) exit(EXIT_FAILURE);
199
202 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
204
206 filename_o3d = argv[2];
207
208 found = filename_o3d.find(".mesh");
209 if (found==std::string::npos) {
210 found = filename_o3d.find(".msh");
211 }
212
213 if (found!=std::string::npos) {
214 filename_o3d.replace(found,1,"\0");
215 }
216 filename_o3d += ".3d";
217
220 /* args of InitMesh:
221 * MMG5_ARG_start: we start to give the args of a variadic func
222 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
223 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
224 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
225 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
226 mmgMesh = NULL;
227 mmgSol = NULL;
229 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
231
237 if ( MMG3D_loadMesh(mmgMesh,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
238
244 if ( MMG3D_loadSol(mmgMesh,mmgSol,filename.c_str()) != 1 ) exit(EXIT_FAILURE);
245
248 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
249
250 if ( ier == MMG5_STRONGFAILURE ) {
251 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
252 return(ier);
253 } else if ( ier == MMG5_LOWFAILURE )
254 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
255
263 if ( MMG3D_saveMesh(mmgMesh,filename_o3d.c_str()) != 1 ) exit(EXIT_FAILURE);
264
266 if ( MMG3D_saveSol(mmgMesh,mmgSol,filename_o3d.c_str()) != 1 ) exit(EXIT_FAILURE);
267
270 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
272
273 return(0);
274}
int MMG2D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG2D_Free_all(const int starter,...)
Deallocations before return.
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Free_all(const int starter,...)
Deallocations before return.
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 ier
MMG5_pMesh char * filename
program main
Example for using mmglib (basic use)
Definition: main.F90:6
int MMG2D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
Definition: inout_2d.c:1101
int MMG2D_saveSol(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save metric field in medit solution file format.
Definition: inout_2d.c:1617
int MMG2D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_2d.c:28
int MMG2D_loadSol(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Load a metric field (or other solution) in medit's .sol format.
Definition: inout_2d.c:905
int MMG3D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
Definition: inout_3d.c:1273
int MMG3D_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution).
Definition: inout_3d.c:2143
int MMG3D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_3d.c:1049
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write isotropic or anisotropic metric.
Definition: inout_3d.c:2314
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 MMG2D_mmg2dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg2d.c:63
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg3d.c:975
int MMGS_mmgslib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for mesh adaptation.
Definition: libmmgs.c:545
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:102
#define MMG5_ARG_end
Definition: libmmgtypes.h:179
#define MMG5_STRONGFAILURE
Definition: libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition: libmmgtypes.h:57
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613