Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
inout_s.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/CNRS/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
37#include "libmmgs.h"
38#include "libmmgs_private.h"
39#include <math.h>
40
42 FILE *inm;
43 MMG5_pTria pt1,pt2;
44 MMG5_pPoint ppt;
45 double *norm,*n,dd;
46 float fc;
47 long posnp,posnt,posne,posncor,posnq,posned,posnr;
48 long posntreq,posnpreq,posnormal,posnc1;
49 MMG5_int k,ia,nq,nri,ip,idn,ng,npreq,nref;
50 int i;
51 MMG5_int ncor,nedreq,ntreq,posnedreq,bpos;
52 int binch,bin,iswp,bdim;
53 MMG5_int na;
54 char *ptr,*data;
55 char chaine[MMG5_FILESTR_LGTH],strskip[MMG5_FILESTR_LGTH];
56
57 posnp = posnt = posne = posncor = posnq = 0;
58 posned = posnr = posnpreq = posntreq = posnc1 = npreq = 0;
59 posnedreq = posnormal = 0;
60 ncor = nri = ng = nedreq = nq = ntreq = 0;
61 bin = 0;
62 iswp = 0;
63 bpos = ia = idn = ip = 0;
64 mesh->np = mesh->nt = mesh->nti = mesh->npi = 0;
65
66 nref = 0;
67
68 MMG5_SAFE_CALLOC(data,strlen(filename)+7,char,return -1);
69
70 strcpy(data,filename);
71 ptr = strstr(data,".mesh");
72 if ( !ptr ) {
73 /* data contains the filename without extension */
74 strcat(data,".meshb");
75 if( !(inm = fopen(data,"rb")) ) {
76 /* our file is not a .meshb file, try with .mesh ext */
77 ptr = strstr(data,".mesh");
78 *ptr = '\0';
79 strcat(data,".mesh");
80 if( !(inm = fopen(data,"rb")) ) {
81 MMG5_SAFE_FREE(data);
82 return 0;
83 }
84 }
85 else bin = 1;
86 }
87 else {
88 ptr = strstr(data,".meshb");
89 if ( ptr ) bin = 1;
90 if( !(inm = fopen(data,"rb")) ) {
91 MMG5_SAFE_FREE(data);
92 return 0;
93 }
94 }
95
96 if ( mesh->info.imprim >= 0 )
97 fprintf(stdout," %%%% %s OPENED\n",data);
98 MMG5_SAFE_FREE(data);
99
100 if (!bin) {
101 strcpy(chaine,"D");
102 while(fscanf(inm,"%127s",&chaine[0])!=EOF && strncmp(chaine,"End",strlen("End")) ) {
103 if ( chaine[0] == '#' ) {
104 while(1){ // skip until end of line or file
105 char *s = fgets(strskip,MMG5_FILESTR_LGTH,inm);
106 if(!s) break; // nothing could be read
107 if(s[strlen(s)-1]=='\n') break; // end of line
108 }
109 continue;
110 }
111 if(!strncmp(chaine,"MeshVersionFormatted",strlen("MeshVersionFormatted"))) {
112 MMG_FSCANF(inm,"%d",&mesh->ver);
113 continue;
114 } else if(!strncmp(chaine,"Dimension",strlen("Dimension"))) {
115 MMG_FSCANF(inm,"%d",&mesh->dim);
116 if(mesh->dim!=3) {
117 fprintf(stderr,"BAD DIMENSION : %d\n",mesh->dim);
118 return -1;
119 }
120 continue;
121 } else if(!strncmp(chaine,"Vertices",strlen("Vertices"))) {
122 MMG_FSCANF(inm,"%" MMG5_PRId "",&mesh->npi);
123 posnp = ftell(inm);
124 continue;
125 } else if(!strncmp(chaine,"RequiredVertices",strlen("RequiredVertices"))) {
126 MMG_FSCANF(inm,"%" MMG5_PRId "",&npreq);
127 posnpreq = ftell(inm);
128 continue;
129 } else if(!strncmp(chaine,"Triangles",strlen("Triangles"))) {
130 MMG_FSCANF(inm,"%" MMG5_PRId "",&mesh->nti);
131 posnt = ftell(inm);
132 continue;
133 }
134 else if(!strncmp(chaine,"RequiredTriangles",strlen("RequiredTriangles"))) {
135 MMG_FSCANF(inm,"%" MMG5_PRId "",&ntreq);
136 posntreq = ftell(inm);
137 continue;
138 } else if(!strncmp(chaine,"Quadrilaterals",strlen("Quadrilaterals"))) {
139 MMG_FSCANF(inm,"%" MMG5_PRId "",&nq);
140 posnq = ftell(inm);
141 continue;
142 } else if(!strncmp(chaine,"Corners",strlen("Corners"))) {
143 MMG_FSCANF(inm,"%" MMG5_PRId "",&ncor);
144 posncor = ftell(inm);
145 continue;
146 } else if(!strncmp(chaine,"Edges",strlen("Edges"))) {
147 MMG_FSCANF(inm,"%" MMG5_PRId "",&mesh->na);
148 posned = ftell(inm);
149 continue;
150 } else if(!strncmp(chaine,"RequiredEdges",strlen("RequiredEdges"))) {
151 MMG_FSCANF(inm,"%" MMG5_PRId "",&nedreq);
152 posnedreq = ftell(inm);
153 continue;
154 } else if(!strncmp(chaine,"Ridges",strlen("Ridges"))) {
155 MMG_FSCANF(inm,"%" MMG5_PRId "",&nri);
156 posnr = ftell(inm);
157 continue;
158 } else if(!ng && !strncmp(chaine,"Normals",strlen("Normals"))) {
159 MMG_FSCANF(inm,"%" MMG5_PRId "",&ng);
160 posnormal = ftell(inm);
161 continue;
162 } else if(!strncmp(chaine,"NormalAtVertices",strlen("NormalAtVertices"))) {
163 MMG_FSCANF(inm,"%" MMG5_PRId "",&mesh->nc1);
164 posnc1 = ftell(inm);
165 continue;
166 }
167 }
168 } else { //binary file
169 bdim = 0;
170 MMG_FREAD(&mesh->ver,MMG5_SW,1,inm);
171 iswp=0;
172 if(mesh->ver==16777216)
173 iswp=1;
174 else if(mesh->ver!=1) {
175 fprintf(stdout,"BAD FILE ENCODING\n");
176 }
177 MMG_FREAD(&mesh->ver,MMG5_SW,1,inm);
178 if(iswp) mesh->ver = MMG5_swapbin(mesh->ver);
179 while(fread(&binch,MMG5_SW,1,inm)!=0 && binch!=54 ) {
180 if(iswp) binch=MMG5_swapbin(binch);
181 if(binch==54) break;
182 if(!bdim && binch==3) { //Dimension
183 MMG_FREAD(&bdim,MMG5_SW,1,inm); //NulPos=>20
184 if(iswp) bdim=MMG5_swapbin(bdim);
185 MMG_FREAD(&bdim,MMG5_SW,1,inm);
186 if(iswp) bdim=MMG5_swapbin(bdim);
187 mesh->dim = bdim;
188 if(bdim!=3) {
189 fprintf(stderr,"BAD MESH DIMENSION : %d\n",mesh->dim);
190 return -1;
191 }
192 continue;
193 } else if(!mesh->npi && binch==4) { //Vertices
194 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
195 if(iswp) bpos=MMG5_swapbin(bpos);
196 MMG_FREAD(&mesh->npi,MMG5_SW,1,inm);
197 if(iswp) mesh->npi=MMG5_swapbin(mesh->npi);
198 posnp = ftell(inm);
199 rewind(inm);
200 fseek(inm,bpos,SEEK_SET);
201 continue;
202 } else if(binch==15) { //RequiredVertices
203 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
204 if(iswp) bpos=MMG5_swapbin(bpos);
205 MMG_FREAD(&npreq,MMG5_SW,1,inm);
206 if(iswp) npreq=MMG5_swapbin(npreq);
207 posnpreq = ftell(inm);
208 rewind(inm);
209 fseek(inm,bpos,SEEK_SET);
210 continue;
211 } else if(!mesh->nti && binch==6) {//Triangles
212 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
213 if(iswp) bpos=MMG5_swapbin(bpos);
214 MMG_FREAD(&mesh->nti,MMG5_SW,1,inm);
215 if(iswp) mesh->nti=MMG5_swapbin(mesh->nti);
216 posnt = ftell(inm);
217 rewind(inm);
218 fseek(inm,bpos,SEEK_SET);
219 continue;
220 } else if(binch==17) { //RequiredTriangles
221 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
222 if(iswp) bpos=MMG5_swapbin(bpos);
223 MMG_FREAD(&ntreq,MMG5_SW,1,inm);
224 if(iswp) ntreq=MMG5_swapbin(ntreq);
225 posntreq = ftell(inm);
226 rewind(inm);
227 fseek(inm,bpos,SEEK_SET);
228 continue;
229 } else if(binch==7) {//Quadrilaterals
230 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
231 if(iswp) bpos=MMG5_swapbin(bpos);
232 MMG_FREAD(&nq,MMG5_SW,1,inm);
233 if(iswp) nq=MMG5_swapbin(nq);
234 posnq = ftell(inm);
235 rewind(inm);
236 fseek(inm,bpos,SEEK_SET);
237 continue;
238 } else if(!ncor && binch==13) { //Corners
239 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
240 if(iswp) bpos=MMG5_swapbin(bpos);
241 MMG_FREAD(&ncor,MMG5_SW,1,inm);
242 if(iswp) ncor=MMG5_swapbin(ncor);
243 posncor = ftell(inm);
244 rewind(inm);
245 fseek(inm,bpos,SEEK_SET);
246 continue;
247 } else if(!mesh->na && binch==5) { //Edges
248 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
249 if(iswp) bpos=MMG5_swapbin(bpos);
250 MMG_FREAD(&mesh->na,MMG5_SW,1,inm);
251 if(iswp) mesh->na=MMG5_swapbin(mesh->na);
252 posned = ftell(inm);
253 rewind(inm);
254 fseek(inm,bpos,SEEK_SET);
255 continue;
256 } else if(binch==16) { //RequiredEdges
257 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
258 if(iswp) bpos=MMG5_swapbin(bpos);
259 MMG_FREAD(&nedreq,MMG5_SW,1,inm);
260 if(iswp) nedreq=MMG5_swapbin(nedreq);
261 posnedreq = ftell(inm);
262 rewind(inm);
263 fseek(inm,bpos,SEEK_SET);
264 continue;
265 } else if(binch==14) { //Ridges
266 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
267 if(iswp) bpos=MMG5_swapbin(bpos);
268 MMG_FREAD(&nri,MMG5_SW,1,inm);
269 if(iswp) nri=MMG5_swapbin(nri);
270 posnr = ftell(inm);
271 rewind(inm);
272 fseek(inm,bpos,SEEK_SET);
273 continue;
274 } else if(!ng && binch==60) { //Normals
275 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
276 if(iswp) bpos=MMG5_swapbin(bpos);
277 MMG_FREAD(&ng,MMG5_SW,1,inm);
278 if(iswp) ng=MMG5_swapbin(ng);
279 posnormal = ftell(inm);
280 rewind(inm);
281 fseek(inm,bpos,SEEK_SET);
282 continue;
283 } else if(binch==20) { //NormalAtVertices
284 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
285 if(iswp) bpos=MMG5_swapbin(bpos);
286 MMG_FREAD(&mesh->nc1,MMG5_SW,1,inm);
287 if(iswp) mesh->nc1=MMG5_swapbin(mesh->nc1);
288 posnc1 = ftell(inm);
289 rewind(inm);
290 fseek(inm,bpos,SEEK_SET);
291 continue;
292 } else {
293 MMG_FREAD(&bpos,MMG5_SW,1,inm); //NulPos
294 if(iswp) bpos=MMG5_swapbin(bpos);
295 rewind(inm);
296 fseek(inm,bpos,SEEK_SET);
297 }
298 }
299 }
300
301 if ( !mesh->npi || !mesh->nti ) {
302 fprintf(stdout," ** MISSING DATA\n");
303 return -1;
304 }
305 mesh->np = mesh->npi;
306 mesh->nt = mesh->nti + 2*nq;
307
308 /* mem alloc */
309 if ( !MMGS_zaldy(mesh) ) return -1;
310
311 /* read vertices */
312
313 rewind(inm);
314 fseek(inm,posnp,SEEK_SET);
315 for (k=1; k<=mesh->np; k++) {
316 ppt = &mesh->point[k];
317 if (mesh->ver < 2) { /*float*/
318 if (!bin) {
319 for (i=0 ; i<3 ; i++) {
320 MMG_FSCANF(inm,"%f",&fc);
321 ppt->c[i] = (double) fc;
322 }
323 MMG_FSCANF(inm,"%" MMG5_PRId "",&ppt->ref);
324 } else {
325 for (i=0 ; i<3 ; i++) {
326 MMG_FREAD(&fc,MMG5_SW,1,inm);
327 if(iswp) fc=MMG5_swapf(fc);
328 ppt->c[i] = (double) fc;
329 }
330 MMG_FREAD(&ppt->ref,MMG5_SW,1,inm);
331 if(iswp) ppt->ref=MMG5_swapbin(ppt->ref);
332 }
333 } else {
334 if (!bin) {
335 MMG_FSCANF(inm,"%lf %lf %lf %" MMG5_PRId "",&ppt->c[0],&ppt->c[1],&ppt->c[2],&ppt->ref);
336 }
337 else {
338 for (i=0 ; i<3 ; i++) {
339 MMG_FREAD(&ppt->c[i],MMG5_SD,1,inm);
340 if(iswp) ppt->c[i]=MMG5_swapd(ppt->c[i]);
341 }
342 MMG_FREAD(&ppt->ref,MMG5_SW,1,inm);
343 if(iswp) ppt->ref=MMG5_swapbin(ppt->ref);
344 }
345 }
346 if ( ppt->ref < 0 ) {
347 ppt->ref = -ppt->ref;
348 ++nref;
349 }
350 ppt->tag = MG_NUL;
351 }
352
353 /* read triangles and set seed */
354 if ( mesh->nti ) {
355 rewind(inm);
356 fseek(inm,posnt,SEEK_SET);
357 for (k=1; k<=mesh->nti; k++) {
358 pt1 = &mesh->tria[k];
359 if (!bin) {
360 MMG_FSCANF(inm,"%" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId "",&pt1->v[0],&pt1->v[1],&pt1->v[2],&pt1->ref);
361 }
362 else {
363 for (i=0 ; i<3 ; i++) {
364 MMG_FREAD(&pt1->v[i],MMG5_SW,1,inm);
365 if(iswp) pt1->v[i]=MMG5_swapbin(pt1->v[i]);
366 }
367 MMG_FREAD(&pt1->ref,MMG5_SW,1,inm);
368 if(iswp) pt1->ref=MMG5_swapbin(pt1->ref);
369 }
370 for (i=0; i<3; i++) {
371 ppt = &mesh->point[pt1->v[i]];
372 ppt->tag &= ~MG_NUL;
373 }
374 }
375 /* get required triangles */
376 if(ntreq) {
377 rewind(inm);
378 fseek(inm,posntreq,SEEK_SET);
379 for (k=1; k<=ntreq; k++) {
380 if(!bin) {
381 MMG_FSCANF(inm,"%d",&i);
382 }
383 else {
384 MMG_FREAD(&i,MMG5_SW,1,inm);
385 if(iswp) i=MMG5_swapbin(i);
386 }
387 if ( i>mesh->nti ) {
388 fprintf(stderr,"\n ## Warning: %s: required triangle number %8d"
389 " ignored.\n",__func__,i);
390 } else {
391 pt1 = &mesh->tria[i];
392 pt1->tag[0] |= MG_REQ;
393 pt1->tag[1] |= MG_REQ;
394 pt1->tag[2] |= MG_REQ;
395 }
396 }
397 }
398 }
399
400 /* read quads: automatic conversion to triangles */
401 if ( nq > 0 ) {
402 rewind(inm);
403 fseek(inm,posnq,SEEK_SET);
404
405 printf(" ## Warning: %s: quadrangles automatically converted into"
406 " triangles\n.",__func__);
407
408 for (k=1; k<=nq; k++) {
409 mesh->nti++;
410 pt1 = &mesh->tria[mesh->nti];
411 mesh->nti++;
412 pt2 = &mesh->tria[mesh->nti];
413
414 if (!bin) {
415 MMG_FSCANF(inm,"%" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId "",&pt1->v[0],&pt1->v[1],&pt1->v[2],&pt2->v[2],&pt1->ref);
416 }
417 else {
418 for (i=0 ; i<3 ; i++) {
419 MMG_FREAD(&pt1->v[i],MMG5_SW,1,inm);
420 if(iswp) pt1->v[i]=MMG5_swapbin(pt1->v[i]);
421 }
422 MMG_FREAD(&pt2->v[2],MMG5_SW,1,inm);
423 if(iswp) pt2->v[2]=MMG5_swapbin(pt2->v[2]);
424 MMG_FREAD(&pt1->ref,MMG5_SW,1,inm);
425 if(iswp) pt1->ref=MMG5_swapbin(pt1->ref);
426 }
427 if ( pt1->ref < 0 ) {
428 pt1->ref = -pt1->ref;
429 nref += 2;
430 }
431
432 pt2->v[0] = pt1->v[0];
433 pt2->v[1] = pt1->v[2];
434 pt2->ref = pt1->ref;
435 for (i=0; i<3; i++) {
436 ppt = &mesh->point[pt1->v[i]];
437 ppt->tag &= ~MG_NUL;
438 ppt = &mesh->point[pt2->v[i]];
439 ppt->tag &= ~MG_NUL;
440 }
441 }
442 mesh->nt = mesh->nti;
443 }
444
445 if(ncor) {
446 rewind(inm);
447 fseek(inm,posncor,SEEK_SET);
448 for (k=1; k<=ncor; k++) {
449 if(!bin) {
450 MMG_FSCANF(inm,"%d",&i);
451 }
452 else {
453 MMG_FREAD(&i,MMG5_SW,1,inm);
454 if(iswp) i=MMG5_swapbin(i);
455 }
456 if(i>mesh->np) {
457 fprintf(stderr,"\n ## Warning: %s: corner number %8d ignored.\n",
458 __func__,i);
459 } else {
460 ppt = &mesh->point[i];
461 ppt->tag |= MG_CRN;
462 }
463 }
464 }
465
466 /* read required vertices */
467 if(npreq) {
468 rewind(inm);
469 fseek(inm,posnpreq,SEEK_SET);
470 for (k=1; k<=npreq; k++) {
471 if(!bin) {
472 MMG_FSCANF(inm,"%d",&i);
473 }
474 else {
475 MMG_FREAD(&i,MMG5_SW,1,inm);
476 if(iswp) i=MMG5_swapbin(i);
477 }
478 if(i>mesh->np) {
479 fprintf(stderr,"\n ## Warning: %s: required Vertices number %8d ignored\n",
480 __func__,i);
481 } else {
482 ppt = &mesh->point[i];
483 ppt->tag |= MG_REQ;
484 ppt->tag &= ~MG_NUL;
485 }
486 }
487 }
488
489 /* Read mesh edges */
490 na = mesh->na;
491 if ( mesh->na ) {
492 rewind(inm);
493 fseek(inm,posned,SEEK_SET);
494
495 for (k=1; k<=mesh->na; k++) {
496 if (!bin) {
497 MMG_FSCANF(inm,"%" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId "",&mesh->edge[k].a,&mesh->edge[k].b,&mesh->edge[k].ref);
498 }
499 else {
500 MMG_FREAD(&mesh->edge[k].a,MMG5_SW,1,inm);
501 if(iswp) mesh->edge[k].a=MMG5_swapbin(mesh->edge[k].a);
502 MMG_FREAD(&mesh->edge[k].b,MMG5_SW,1,inm);
503 if(iswp) mesh->edge[k].b=MMG5_swapbin(mesh->edge[k].b);
504 MMG_FREAD(&mesh->edge[k].ref,MMG5_SW,1,inm);
505 if(iswp) mesh->edge[k].ref=MMG5_swapbin(mesh->edge[k].ref);
506 }
507 if ( mesh->edge[k].ref < 0 ) {
508 mesh->edge[k].ref = -mesh->edge[k].ref;
509 ++nref;
510 }
511 mesh->edge[k].tag |= MG_REF;
512 mesh->point[mesh->edge[k].a].tag |= MG_REF;
513 mesh->point[mesh->edge[k].b].tag |= MG_REF;
514 }
515
516 /* get ridges */
517 if ( nri ) {
518 rewind(inm);
519 fseek(inm,posnr,SEEK_SET);
520 for (k=1; k<=nri; k++) {
521 if(!bin) {
522 MMG_FSCANF(inm,"%" MMG5_PRId "",&ia);
523 }
524 else {
525 MMG_FREAD(&ia,MMG5_SW,1,inm);
526 if(iswp) ia=MMG5_swapbin(ia);
527 }
528 if ( (ia>na) || (ia<0) ) {
529 fprintf(stderr,"\n ## Warning: %s: ridge number %8" MMG5_PRId " ignored.\n",
530 __func__,ia);
531 }
532 else {
533 mesh->edge[ia].tag |= MG_GEO;
534 }
535 }
536 }
537
538 if ( nedreq ) {
539 rewind(inm);
540 fseek(inm,posnedreq,SEEK_SET);
541 for (k=1; k<=nedreq; k++) {
542 if(!bin) {
543 MMG_FSCANF(inm,"%" MMG5_PRId "",&ia);
544 }
545 else {
546 MMG_FREAD(&ia,MMG5_SW,1,inm);
547 if(iswp) ia=MMG5_swapbin(ia);
548 }
549 if ( (ia>na) || (ia<0) ) {
550 fprintf(stderr,"\n ## Warning: %s: required edge number %8" MMG5_PRId " ignored\n",
551 __func__,ia);
552 }
553 else {
554 mesh->edge[ia].tag |= MG_REQ;
555 }
556 }
557 }
558 }
559
560 /* read geometric entities */
561 if ( mesh->nc1 && !ng ) {
562 fprintf(stderr,"\n ## Warning: %s: your mesh don't contains Normals but contains"
563 " NormalAtVertices. The NormalAtVertices are deleted. \n",__func__);
564 mesh->nc1 = 0;
565 }
566
567 if ( ng > 0 ) {
568 MMG5_SAFE_CALLOC(norm,3*ng+1,double,return -1);
569
570 rewind(inm);
571 fseek(inm,posnormal,SEEK_SET);
572 for (k=1; k<=ng; k++) {
573 n = &norm[3*(k-1)+1];
574 if ( mesh->ver == 1 ) {
575 if (!bin) {
576 for (i=0 ; i<3 ; i++) {
577 MMG_FSCANF(inm,"%f",&fc);
578 n[i] = (double) fc;
579 }
580 } else {
581 for (i=0 ; i<3 ; i++) {
582 MMG_FREAD(&fc,MMG5_SW,1,inm);
583 if(iswp) fc=MMG5_swapf(fc);
584 n[i] = (double) fc;
585 }
586 }
587 }
588 else {
589 if (!bin) {
590 MMG_FSCANF(inm,"%lf %lf %lf",&n[0],&n[1],&n[2]);
591 }
592 else {
593 for (i=0 ; i<3 ; i++) {
594 MMG_FREAD(&n[i],MMG5_SD,1,inm);
595 if(iswp) n[i]=MMG5_swapd(n[i]);
596 }
597 }
598 }
599 dd = n[0]*n[0] + n[1]*n[1] + n[2]*n[2];
600 if ( dd > MMG5_EPSD2 ) {
601 dd = 1.0 / sqrt(dd);
602 n[0] *= dd;
603 n[1] *= dd;
604 n[2] *= dd;
605 }
606 }
607
608 rewind(inm);
609 fseek(inm,posnc1,SEEK_SET);
610
611 for (k=1; k<=mesh->nc1; k++) {
612 if (!bin) {
613 MMG_FSCANF(inm,"%" MMG5_PRId " %" MMG5_PRId "",&ip,&idn);
614 }
615 else {
616 MMG_FREAD(&ip,MMG5_SW,1,inm);
617 if(iswp) ip=MMG5_swapbin(ip);
618 MMG_FREAD(&idn,MMG5_SW,1,inm);
619 if(iswp) idn=MMG5_swapbin(idn);
620 }
621 if ( idn > 0 && ip < mesh->np+1 )
622 memcpy(&mesh->point[ip].n,&norm[3*(idn-1)+1],3*sizeof(double));
623 }
624 MMG5_SAFE_FREE(norm);
625 }
626
627 if ( nref ) {
628 fprintf(stdout,"\n $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n");
629 fprintf(stdout," WARNING : %" MMG5_PRId " entities with unexpected refs (ref< 0).\n",nref);
630 fprintf(stdout," We take their absolute values.\n");
631 fprintf(stdout," $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ \n\n");
632 }
633
634 if ( abs(mesh->info.imprim) > 4 ) {
635 fprintf(stdout," NUMBER OF VERTICES %8" MMG5_PRId " / %8" MMG5_PRId " CORNERS/REQ. %" MMG5_PRId " / %" MMG5_PRId "\n",mesh->npi,mesh->npmax,ncor,npreq);
636 fprintf(stdout," NUMBER OF TRIANGLES %8" MMG5_PRId " / %8" MMG5_PRId "\n",mesh->nti,mesh->ntmax);
637
638 if ( mesh->na )
639 fprintf(stdout," NUMBER OF EDGES %8" MMG5_PRId " RIDGES %6" MMG5_PRId "\n",mesh->na,nri);
640 }
641 fclose(inm);
642 return 1;
643}
644
646 FILE* inm;
647 long posNodes,posElts,*posNodeData;
648 int ier,bin,iswp,nsols;
649 MMG5_int nelts;
650
651 mesh->dim = 3;
652
654 &posNodes,&posElts,&posNodeData,
655 &bin,&iswp,&nelts,&nsols);
656 if ( ier < 1 ) return (ier);
657
658 if ( nsols > 1 ) {
659 fprintf(stderr,"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
660 fclose(inm);
661 MMG5_SAFE_FREE(posNodeData);
662 return -1;
663 }
664
665 if ( !MMGS_zaldy(mesh) ) {
666 fclose(inm);
667 MMG5_SAFE_FREE(posNodeData);
668 return -1;
669 }
670
671 mesh->ne = mesh->nprism = 0;
672
673 if ( !mesh->nt ) {
674 fprintf(stderr," ** MISSING DATA.\n");
675 fprintf(stderr," Check that your mesh contains triangles.\n");
676 fprintf(stderr," Exit program.\n");
677 fclose(inm);
678 MMG5_SAFE_FREE(posNodeData);
679 return -1;
680 }
681
682
683 if (mesh->npmax < mesh->np || mesh->ntmax < mesh->nt ) {
684 fclose(inm);
685 MMG5_SAFE_FREE(posNodeData);
686 return -1;
687 }
688
690 posNodes,posElts,posNodeData,
691 bin,iswp,nelts,nsols);
692 MMG5_SAFE_FREE(posNodeData);
693 if ( ier < 1 ) {
694 fprintf(stderr," ** ERROR WHEN PARSING THE INPUT FILE\n");
695 return ier;
696 }
697
698 if ( sol ) {
699 /* Check the metric type */
700 ier = MMG5_chkMetricType(mesh,&sol->type,&sol->entities,inm);
701 }
702
703 return ier;
704}
705
707 FILE* inm;
708 long posNodes,posElts,*posNodeData;
709 int ier,bin,iswp,nsols;
710 MMG5_int nelts;
711
712 mesh->dim = 3;
713
715 &posNodes,&posElts,&posNodeData,
716 &bin,&iswp,&nelts,&nsols);
717 if ( ier < 1 ) return (ier);
718
719 mesh->nsols = nsols;
720 if ( *sol ) MMG5_DEL_MEM(mesh,*sol);
721 MMG5_ADD_MEM(mesh,nsols*sizeof(MMG5_Sol),"solutions array",
722 printf(" Exit program.\n"); fclose(inm);
723 MMG5_SAFE_FREE(posNodeData);
724 return -1);
725 MMG5_SAFE_CALLOC(*sol,nsols,MMG5_Sol,return -1);
726
727 if ( !MMGS_zaldy(mesh) ) {
728 fclose(inm);
729 MMG5_SAFE_FREE(posNodeData);
730 return -1;
731 }
732
733 mesh->ne = mesh->nprism = 0;
734
735 if ( !mesh->nt ) {
736 fprintf(stderr," ** MISSING DATA.\n");
737 fprintf(stderr," Check that your mesh contains triangles.\n");
738 fprintf(stderr," Exit program.\n");
739 fclose(inm);
740 MMG5_SAFE_FREE(posNodeData);
741 return -1;
742 }
743
744
745 if (mesh->npmax < mesh->np || mesh->ntmax < mesh->nt ) {
746 fclose(inm);
747 MMG5_SAFE_FREE(posNodeData);
748 return -1;
749 }
750
752 posNodes,posElts,posNodeData,
753 bin,iswp,nelts,nsols);
754
755 if ( ier < 1 ) {
756 fprintf(stderr," ** ERROR WHEN PARSING THE INPUT FILE\n");
757 }
758
759 MMG5_SAFE_FREE(posNodeData);
760
761 return ier;
762}
763
765 int ier=0;
766 const char *filenameptr,*solnameptr;
767 char *tmp,*soltmp;
768
769 if ( filename && strlen(filename) ) {
770 filenameptr = filename;
771 solnameptr = filename;
772 }
773 else if (mesh->namein && strlen(mesh->namein) ) {
774 filenameptr = mesh->namein;
775 if ( sol && strlen(sol->namein) ) {
776 solnameptr = sol->namein;
777 }
778 else {
779 solnameptr = mesh->namein;
780 }
781 }
782 else {
783 fprintf(stderr," ## Error: %s: please provide input file name"
784 " (either in the mesh structure or as function argument).\n",
785 __func__);
786 return -1;
787 }
788
789 MMG5_SAFE_MALLOC(tmp,strlen(filenameptr)+1,char,return -1);
790 strcpy(tmp,filenameptr);
791
792 /* read mesh/sol files */
793 char *ptr = MMG5_Get_filenameExt(tmp);
794 int fmtin = MMG5_Get_format(ptr,MMG5_FMT_MeditASCII);
795
796 switch ( fmtin ) {
797
798 case ( MMG5_FMT_GmshASCII ): case ( MMG5_FMT_GmshBinary ):
800 break;
801
802 case ( MMG5_FMT_VtkVtp ):
804 break;
805
806 case ( MMG5_FMT_VtkVtu ):
808 break;
809
810 case ( MMG5_FMT_VtkVtk ):
812 break;
813
814 case ( MMG5_FMT_MeditASCII ): case ( MMG5_FMT_MeditBinary ):
816 if ( ier < 1 ) { break; }
817
818 /* Facultative metric */
819 if ( sol ) {
820 MMG5_SAFE_MALLOC(soltmp,strlen(solnameptr)+1,char,return -1);
821 strcpy(soltmp,solnameptr);
822
823 if ( MMGS_loadSol(mesh,sol,tmp) == -1) {
824 fprintf(stderr,"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
825 ier = 0;
826 }
827 MMG5_SAFE_FREE(soltmp);
828 }
829 break;
830
831 default:
832 fprintf(stderr," ** I/O AT FORMAT %s NOT IMPLEMENTED.\n",MMG5_Get_formatName(fmtin) );
833 ier= 0;
834 }
835
837
838 return ier;
839}
840
841
843 FILE *inm;
844 MMG5_pPoint ppt;
845 MMG5_pTria pt;
846 MMG5_pxPoint go;
847 MMG5_int k,np,nt,nc,ng,nn,nr,nre,ntreq,bpos;
848 int bin,binch;
849 // int outm;
850 char *data,*ptr,chaine[MMG5_FILESTR_LGTH];
851
852 mesh->ver = 2;
853
854 bin = 0;
855
856 MMG5_SAFE_CALLOC(data,strlen(filename)+7,char,return 0);
857
858 strcpy(data,filename);
859 ptr = strstr(data,".mesh");
860 if ( !ptr ) {
861 strcat(data,".meshb");
862 if( !(inm = fopen(data,"wb")) ) {
863 ptr = strstr(data,".mesh");
864 *ptr = '\0';
865 strcat(data,".mesh");
866 if( !(inm = fopen(data,"w")) ) {
867 MMG5_SAFE_FREE(data);
868 return 0;
869 }
870 } else {
871 bin = 1;
872 }
873 }
874 else {
875 ptr = strstr(data,".meshb");
876 if( ptr ) {
877 bin = 1;
878 if( !(inm = fopen(data,"wb")) ) {
879 fprintf(stderr," ** UNABLE TO OPEN %s.\n",data);
880 MMG5_SAFE_FREE(data);
881 return 0;
882 }
883 } else {
884 if( !(inm = fopen(data,"w")) ) {
885 fprintf(stderr," ** UNABLE TO OPEN %s.\n",data);
886 MMG5_SAFE_FREE(data);
887 return 0;
888 }
889 }
890 }
891 if ( mesh->info.imprim >= 0 )
892 fprintf(stdout," %%%% %s OPENED\n",data);
893 MMG5_SAFE_FREE(data);
894
895 /* file header */
896 if(!bin) {
897 strcpy(&chaine[0],"MeshVersionFormatted 2\n");
898 fprintf(inm,"%s",chaine);
899 strcpy(&chaine[0],"\n\nDimension 3\n");
900 fprintf(inm,"%s ",chaine);
901 } else {
902 binch = 1; //MeshVersionFormatted
903 fwrite(&binch,MMG5_SW,1,inm);
904 binch = 2; //version
905 fwrite(&binch,MMG5_SW,1,inm);
906 binch = 3; //Dimension
907 fwrite(&binch,MMG5_SW,1,inm);
908 bpos = 20; //Pos
909 fwrite(&bpos,MMG5_SW,1,inm);
910 binch = 3;
911 fwrite(&binch,MMG5_SW,1,inm);
912
913 }
914 /* vertices */
915 np = nc = ng = nn = nre = 0;
916 for (k=1; k<=mesh->np; k++) {
917 ppt = &mesh->point[k];
918 ppt->tmp = 0;
919 if ( MG_VOK(ppt) ) {
920 np++;
921 ppt->tmp = np;
922 if ( ppt->tag & MG_CRN ) nc++;
923 if ( ppt->tag & MG_REQ ) nre++;
924 if ( MG_EDG(ppt->tag) ) ng++;
925 }
926 }
927
928 if(!bin) {
929 strcpy(&chaine[0],"\n\nVertices\n");
930 fprintf(inm,"%s",chaine);
931 fprintf(inm,"%" MMG5_PRId "\n",np);
932 } else {
933 binch = 4; //Vertices
934 fwrite(&binch,MMG5_SW,1,inm);
935 bpos += (3+(1+3*mesh->ver)*np)*MMG5_SW; //NullPos
936 fwrite(&bpos,MMG5_SW,1,inm);
937 fwrite(&np,MMG5_SW,1,inm);
938 }
939 for (k=1; k<=mesh->np; k++) {
940 ppt = &mesh->point[k];
941 if ( MG_VOK(ppt) ) {
942 if(!bin) {
943 fprintf(inm,"%.15lg %.15lg %.15lg %" MMG5_PRId "\n",ppt->c[0],ppt->c[1],ppt->c[2],MMG5_abs(ppt->ref));
944 } else {
945 fwrite((unsigned char*)&ppt->c[0],MMG5_SD,1,inm);
946 fwrite((unsigned char*)&ppt->c[1],MMG5_SD,1,inm);
947 fwrite((unsigned char*)&ppt->c[2],MMG5_SD,1,inm);
948 ppt->ref = MMG5_abs(ppt->ref);
949 fwrite((unsigned char*)&ppt->ref,MMG5_SW,1,inm);
950 }
951 if ( !((ppt->tag & MG_GEO) || ppt->tag & MG_CRN) ) nn++;
952 }
953 }
954
955 nt = 0;
956 for (k=1; k<=mesh->nt; k++) {
957 pt = &mesh->tria[k];
958 if ( !MG_EOK(pt) ) continue;
959 nt++;
960 }
961
962 /* write corners */
963 if ( nc ) {
964 if(!bin) {
965 strcpy(&chaine[0],"\n\nCorners\n");
966 fprintf(inm,"%s",chaine);
967 fprintf(inm,"%" MMG5_PRId "\n",nc);
968 } else {
969 binch = 13; //
970 fwrite(&binch,MMG5_SW,1,inm);
971 bpos += (3+nc)*MMG5_SW; //NullPos
972 fwrite(&bpos,MMG5_SW,1,inm);
973 fwrite(&nc,MMG5_SW,1,inm);
974 }
975 for (k=1; k<=mesh->np; k++) {
976 ppt = &mesh->point[k];
977 if ( MG_VOK(ppt) && ppt->tag & MG_CRN ) {
978 if(!bin) {
979 fprintf(inm,"%" MMG5_PRId "\n",ppt->tmp);
980 } else {
981 fwrite(&ppt->tmp,MMG5_SW,1,inm);
982 }
983 }
984 }
985 }
986 if ( nre ) {
987 if(!bin) {
988 strcpy(&chaine[0],"\n\nRequiredVertices\n");
989 fprintf(inm,"%s",chaine);
990 fprintf(inm,"%" MMG5_PRId "\n",nre);
991 } else {
992 binch = 15; //
993 fwrite(&binch,MMG5_SW,1,inm);
994 bpos += (3+nre)*MMG5_SW; //NullPos
995 fwrite(&bpos,MMG5_SW,1,inm);
996 fwrite(&nre,MMG5_SW,1,inm);
997 }
998 for (k=1; k<=mesh->np; k++) {
999 ppt = &mesh->point[k];
1000 if ( MG_VOK(ppt) && ppt->tag & MG_REQ ) {
1001 if(!bin) {
1002 fprintf(inm,"%" MMG5_PRId "\n",ppt->tmp);
1003 } else {
1004 fwrite(&ppt->tmp,MMG5_SW,1,inm);
1005 }
1006 }
1007 }
1008 }
1009
1010 /* write edges, ridges */
1011 if ( mesh->na ) {
1012 if(!bin) {
1013 strcpy(&chaine[0],"\n\nEdges\n");
1014 fprintf(inm,"%s",chaine);
1015 fprintf(inm,"%" MMG5_PRId "\n",mesh->na);
1016 } else {
1017 binch = 5; //Edges
1018 fwrite(&binch,MMG5_SW,1,inm);
1019 bpos += (3 + 3*mesh->na)*MMG5_SW;//Pos
1020 fwrite(&bpos,MMG5_SW,1,inm);
1021 fwrite(&mesh->na,MMG5_SW,1,inm);
1022 }
1023 nre = nr = 0;
1024 for (k=1; k<=mesh->na; k++) {
1025 if(!bin) {
1026 fprintf(inm,"%" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId "\n",
1027 mesh->edge[k].a,mesh->edge[k].b,mesh->edge[k].ref);
1028 } else {
1029 fwrite(&mesh->edge[k].a,MMG5_SW,1,inm);
1030 fwrite(&mesh->edge[k].b,MMG5_SW,1,inm);
1031 fwrite(&mesh->edge[k].ref,MMG5_SW,1,inm);
1032 }
1033 if ( mesh->edge[k].tag & MG_REQ ) nre++;
1034 if ( mesh->edge[k].tag & MG_GEO ) nr++;
1035 }
1036 /* ridges */
1037 if ( nr ) {
1038 if(!bin) {
1039 strcpy(&chaine[0],"\n\nRidges\n");
1040 fprintf(inm,"%s",chaine);
1041 fprintf(inm,"%" MMG5_PRId "\n",nr);
1042 } else {
1043 binch = 14; //Ridges
1044 fwrite(&binch,MMG5_SW,1,inm);
1045 bpos += (3 + nr)*MMG5_SW;//Pos
1046 fwrite(&bpos,MMG5_SW,1,inm);
1047 fwrite(&nr,MMG5_SW,1,inm);
1048 }
1049 for (k=1; k<=mesh->na; k++) {
1050 if ( mesh->edge[k].tag & MG_GEO ) {
1051 if(!bin) {
1052 fprintf(inm,"%" MMG5_PRId "\n",k);
1053 } else {
1054 fwrite(&k,MMG5_SW,1,inm);
1055 }
1056 }
1057 }
1058 }
1059 if ( nre ) {
1060 if(!bin) {
1061 strcpy(&chaine[0],"\n\nRequiredEdges\n");
1062 fprintf(inm,"%s",chaine);
1063 fprintf(inm,"%" MMG5_PRId "\n",nre);
1064 } else {
1065 binch = 16; //RequiredEdges
1066 fwrite(&binch,MMG5_SW,1,inm);
1067 bpos += (3 + nre)*MMG5_SW;//Pos
1068 fwrite(&bpos,MMG5_SW,1,inm);
1069 fwrite(&nre,MMG5_SW,1,inm);
1070 }
1071 for (k=1; k<=mesh->na; k++)
1072 if ( mesh->edge[k].tag & MG_REQ ) {
1073 if(!bin) {
1074 fprintf(inm,"%" MMG5_PRId "\n",k);
1075 } else {
1076 fwrite(&k,MMG5_SW,1,inm);
1077 }
1078 }
1079 }
1080 }
1081
1082 /* write triangles */
1083 if ( mesh->nt ) {
1084 if(!bin) {
1085 strcpy(&chaine[0],"\n\nTriangles\n");
1086 fprintf(inm,"%s",chaine);
1087 fprintf(inm,"%" MMG5_PRId "\n",nt);
1088 } else {
1089 binch = 6; //Triangles
1090 fwrite(&binch,MMG5_SW,1,inm);
1091 bpos += (3+4*nt)*MMG5_SW; //Pos
1092 fwrite(&bpos,MMG5_SW,1,inm);
1093 fwrite(&nt,MMG5_SW,1,inm);
1094 }
1095
1096 ntreq = 0;
1097 for (k=1; k<=mesh->nt; k++) {
1098 pt = &mesh->tria[k];
1099 if ( MG_EOK(pt) ) {
1100 if(!bin) {
1101 fprintf(inm,"%" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId " %" MMG5_PRId "\n",mesh->point[pt->v[0]].tmp,mesh->point[pt->v[1]].tmp
1102 ,mesh->point[pt->v[2]].tmp,MMG5_abs(pt->ref));
1103 } else {
1104 fwrite(&mesh->point[pt->v[0]].tmp,MMG5_SW,1,inm);
1105 fwrite(&mesh->point[pt->v[1]].tmp,MMG5_SW,1,inm);
1106 fwrite(&mesh->point[pt->v[2]].tmp,MMG5_SW,1,inm);
1107 pt->ref = MMG5_abs(pt->ref);
1108 fwrite(&pt->ref,MMG5_SW,1,inm);
1109 }
1110
1111 if ( (pt->tag[0] & MG_REQ) && (pt->tag[1] & MG_REQ) && (pt->tag[2] & MG_REQ) ) {
1112 ntreq++;
1113 }
1114 }
1115 }
1116 if ( ntreq ) {
1117 if(!bin) {
1118 strcpy(&chaine[0],"\n\nRequiredTriangles\n");
1119 fprintf(inm,"%s",chaine);
1120 fprintf(inm,"%" MMG5_PRId "\n",ntreq);
1121 } else {
1122 binch = 17; //ReqTriangles
1123 fwrite(&binch,MMG5_SW,1,inm);
1124 bpos += (3+ntreq)*MMG5_SW; //Pos
1125 fwrite(&bpos,MMG5_SW,1,inm);
1126 fwrite(&ntreq,MMG5_SW,1,inm);
1127 }
1128 for (k=0; k<=mesh->nt; k++) {
1129 pt = &mesh->tria[k];
1130 if ( (pt->tag[0] & MG_REQ) && (pt->tag[1] & MG_REQ) && pt->tag[2] & MG_REQ ) {
1131 if(!bin) {
1132 fprintf(inm,"%" MMG5_PRId "\n",k);
1133 } else {
1134 fwrite(&k,MMG5_SW,1,inm);
1135 }
1136 }
1137 }
1138 }
1139 }
1140
1141 if ( (!mesh->xp) || (!mesh->xpoint) ) nn = ng = 0;
1142
1143 /* write normals */
1144 if ( nn ) {
1145 if(!bin) {
1146 strcpy(&chaine[0],"\n\nNormals\n");
1147 fprintf(inm,"%s",chaine);
1148 fprintf(inm,"%" MMG5_PRId "\n",nn);
1149 } else {
1150 binch = 60; //normals
1151 fwrite(&binch,MMG5_SW,1,inm);
1152 bpos += (3+(3*mesh->ver)*nn)*MMG5_SW; //Pos
1153 fwrite(&bpos,MMG5_SW,1,inm);
1154 fwrite(&nn,MMG5_SW,1,inm);
1155 }
1156 for (k=1; k<=mesh->np; k++) {
1157 ppt = &mesh->point[k];
1158 if ( !MG_VOK(ppt) ) continue;
1159 else if ( !(ppt->tag & MG_GEO) && !(ppt->tag & MG_CRN) ) {
1160 if ( ppt->tag & MG_REF ) {
1161 go = &mesh->xpoint[ppt->xp];
1162 if(!bin) {
1163 fprintf(inm,"%.15lg %.15lg %.15lg \n",go->n1[0],go->n1[1],go->n1[2]);
1164 } else {
1165 fwrite((unsigned char*)&go->n1[0],MMG5_SD,1,inm);
1166 fwrite((unsigned char*)&go->n1[1],MMG5_SD,1,inm);
1167 fwrite((unsigned char*)&go->n1[2],MMG5_SD,1,inm);
1168 }
1169 }
1170 else {
1171 if(!bin) {
1172 fprintf(inm,"%.15lg %.15lg %.15lg \n",ppt->n[0],ppt->n[1],ppt->n[2]);
1173 } else {
1174 fwrite((unsigned char*)&ppt->n[0],MMG5_SD,1,inm);
1175 fwrite((unsigned char*)&ppt->n[1],MMG5_SD,1,inm);
1176 fwrite((unsigned char*)&ppt->n[2],MMG5_SD,1,inm);
1177 }
1178 }
1179 }
1180 }
1181 if(!bin) {
1182 strcpy(&chaine[0],"\n\nNormalAtVertices\n");
1183 fprintf(inm,"%s",chaine);
1184 fprintf(inm,"%" MMG5_PRId "\n",nn);
1185 } else {
1186 binch = 20; //normalatvertices
1187 fwrite(&binch,MMG5_SW,1,inm);
1188 bpos += (3 + 2*nn)*MMG5_SW;//Pos
1189 fwrite(&bpos,MMG5_SW,1,inm);
1190 fwrite(&nn,MMG5_SW,1,inm);
1191 }
1192 nn = 0;
1193 for (k=1; k<=mesh->np; k++) {
1194 ppt = &mesh->point[k];
1195 if ( MG_VOK(ppt) && !((ppt->tag & MG_GEO) || (ppt->tag & MG_CRN) ) ) {
1196 if(!bin) {
1197 fprintf(inm,"%" MMG5_PRId " %" MMG5_PRId "\n",ppt->tmp,++nn);
1198 } else {
1199 fwrite(&ppt->tmp,MMG5_SW,1,inm);
1200 ++nn;
1201 fwrite(&nn,MMG5_SW,1,inm);
1202 }
1203 }
1204 }
1205/*
1206 nn = 0;
1207 for (k=1; k<=mesh->nt; k++) {
1208 pt = &mesh->tria[k];
1209 if ( !MG_EOK(pt) ) continue;
1210 for (i=0; i<3; i++) {
1211 ppt = &mesh->point[pt->v[i]];
1212 if ( ppt->tag & MG_GEO ) nn++;
1213 }
1214 }
1215 GmfSetKwd(outm,GmfNormalAtTriangleVertices,nn);
1216 for (k=1; k<=mesh->nt; k++) {
1217 pt = &mesh->tria[k];
1218 if ( !MG_EOK(pt) ) continue;
1219 for (i=0; i<3; i++) {
1220 ppt = &mesh->point[pt->v[i]];
1221 if ( ppt->tag & MG_GEO ) nn++;
1222 }
1223*/
1224 }
1225
1226 /* write tangents (only if we have already analyzed the mesh =>
1227 * mesh->xpoint is allocated ) */
1228 if ( ng && mesh->xpoint ) {
1229 /* Write tangents */
1230 if(!bin) {
1231 strcpy(&chaine[0],"\n\nTangents\n");
1232 fprintf(inm,"%s",chaine);
1233 fprintf(inm,"%" MMG5_PRId "\n",ng);
1234 } else {
1235 binch = 59; //tangent
1236 fwrite(&binch,MMG5_SW,1,inm);
1237 bpos += (3+(3*mesh->ver)*ng)*MMG5_SW; //Pos
1238 fwrite(&bpos,MMG5_SW,1,inm);
1239 fwrite(&ng,MMG5_SW,1,inm);
1240 }
1241 for (k=1; k<=mesh->np; k++) {
1242 ppt = &mesh->point[k];
1243 if ( MG_VOK(ppt) && MG_EDG(ppt->tag) ) {
1244 if(!bin) {
1245 fprintf(inm,"%.15lg %.15lg %.15lg \n",ppt->n[0],ppt->n[1],ppt->n[2]);
1246 } else {
1247 fwrite((unsigned char*)&ppt->n[0],MMG5_SD,1,inm);
1248 fwrite((unsigned char*)&ppt->n[1],MMG5_SD,1,inm);
1249 fwrite((unsigned char*)&ppt->n[2],MMG5_SD,1,inm);
1250 }
1251 }
1252 }
1253 if(!bin) {
1254 strcpy(&chaine[0],"\n\nTangentAtVertices\n");
1255 fprintf(inm,"%s",chaine);
1256 fprintf(inm,"%" MMG5_PRId "\n",ng);
1257 } else {
1258 binch = 61; //tangentatvertices
1259 fwrite(&binch,MMG5_SW,1,inm);
1260 bpos += (3 + 2*ng)*MMG5_SW;//Pos
1261 fwrite(&bpos,MMG5_SW,1,inm);
1262 fwrite(&ng,MMG5_SW,1,inm);
1263 }
1264 ng = 0;
1265 for (k=1; k<=mesh->np; k++) {
1266 ppt = &mesh->point[k];
1267 if ( MG_VOK(ppt) && MG_EDG(ppt->tag) ) {
1268 if(!bin) {
1269 fprintf(inm,"%" MMG5_PRId " %" MMG5_PRId "\n",ppt->tmp,++ng);
1270 } else {
1271 fwrite(&ppt->tmp,MMG5_SW,1,inm);
1272 ++ng;
1273 fwrite(&(ng),MMG5_SW,1,inm);
1274 }
1275 }
1276 }
1277 }
1278
1279 if ( abs(mesh->info.imprim) > 4 ) {
1280 fprintf(stdout," NUMBER OF VERTICES %8" MMG5_PRId " CORNERS %6" MMG5_PRId "\n",np,nc);
1281 fprintf(stdout," NUMBER OF TRIANGLES %8" MMG5_PRId "\n",nt);
1282
1283 if ( mesh->na )
1284 fprintf(stdout," NUMBER OF EDGES %8" MMG5_PRId " RIDGES %6" MMG5_PRId "\n",mesh->na,nr);
1285 if ( nn+ng )
1286 fprintf(stdout," NUMBER OF NORMALS %8" MMG5_PRId " TANGENTS %6" MMG5_PRId "\n",nn,ng);
1287 }
1288 /* end of file */
1289 if(!bin) {
1290 strcpy(&chaine[0],"\n\nEnd\n");
1291 fprintf(inm,"%s",chaine);
1292 } else {
1293 binch = 54; //End
1294 fwrite(&binch,MMG5_SW,1,inm);
1295 bpos += 2*MMG5_SW; //bpos + End key
1296 fwrite(&bpos,MMG5_SW,1,inm);
1297 }
1298 fclose(inm);
1299 return 1;
1300}
1301
1303
1304 return MMG5_saveMshMesh(mesh,&sol,filename,1);
1305}
1306
1308
1310}
1311
1313
1314 FILE *inm;
1315 long posnp;
1316 int iswp,ier,*type,ver,bin,nsols,dim;
1317 MMG5_int k,np;
1318
1320 ier = MMG5_loadSolHeader(filename,3,&inm,&ver,&bin,&iswp,&np,&dim,&nsols,
1321 &type,&posnp,mesh->info.imprim);
1322
1323 if ( ier < 1 ) return ier;
1324
1325 if ( nsols!=1 ) {
1326 fprintf(stderr,"Error: SEVERAL SOLUTIONS FOUND (%d)\n",nsols);
1327 fclose(inm);
1328 MMG5_SAFE_FREE(type);
1329 return -1;
1330 }
1331
1332 if ( mesh->np != np ) {
1333 fprintf(stderr," ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
1334 "THE MESH (%" MMG5_PRId ") DIFFERS FROM THE NUMBER OF VERTICES IN "
1335 "THE SOLUTION (%" MMG5_PRId ") \n",mesh->np,np);
1336 fclose(inm);
1337 MMG5_SAFE_FREE(type);
1338 return -1;
1339 }
1340
1341 /* #MMG5_loadSolHeader function reads only solutions at vertices so we don't
1342 have to check the entites on which the metric applies */
1343 int entities = MMG5_Vertex;
1344 ier = MMG5_chkMetricType(mesh,type,&entities,inm);
1345 if ( ier < 1 ) {
1346 MMG5_SAFE_FREE(type);
1347 return ier;
1348 }
1349
1350 /* Allocate and store the header information for each solution */
1351 if ( !MMGS_Set_solSize(mesh,met,MMG5_Vertex,mesh->np,type[0]) ) {
1352 fclose(inm);
1353 MMG5_SAFE_FREE(type);
1354 return -1;
1355 }
1356 /* For binary file, we read the verson inside the file */
1357 if ( ver ) met->ver = ver;
1358
1359 MMG5_SAFE_FREE(type);
1360
1361 /* Read mesh solutions */
1362 rewind(inm);
1363 fseek(inm,posnp,SEEK_SET);
1364
1365 /* isotropic metric */
1366 if ( met->ver == 1 ) {
1367 /* Simple precision */
1368 for (k=1; k<=mesh->np; k++) {
1369 if ( MMG5_readFloatSol3D(met,inm,bin,iswp,k) < 0 ) return -1;
1370 }
1371 }
1372 else {
1373 /* Double precision */
1374 for (k=1; k<=mesh->np; k++) {
1375 if ( MMG5_readDoubleSol3D(met,inm,bin,iswp,k) < 0 ) return -1;
1376 }
1377 }
1378
1379 fclose(inm);
1380
1381 /* stats */
1383
1384 return 1;
1385}
1386
1388 MMG5_pSol psl;
1389 FILE *inm;
1390 long posnp;
1391 int iswp,ier,*type,ver,bin,nsols,dim;
1392 MMG5_int j,k,np;
1393 char data[16];
1394 static char mmgWarn = 0;
1395
1397 ier = MMG5_loadSolHeader(filename,3,&inm,&ver,&bin,&iswp,&np,&dim,&nsols,
1398 &type,&posnp,mesh->info.imprim);
1399 if ( ier < 1 ) return ier;
1400
1401 if ( mesh->np != np ) {
1402 fprintf(stderr," ** MISMATCHES DATA: THE NUMBER OF VERTICES IN "
1403 "THE MESH (%" MMG5_PRId ") DIFFERS FROM THE NUMBER OF VERTICES IN "
1404 "THE SOLUTION (%" MMG5_PRId ") \n",mesh->np,np);
1405 fclose(inm);
1406 MMG5_SAFE_FREE(type);
1407 return -1;
1408 }
1409
1411 mesh->nsols = nsols;
1412
1413 if ( nsols > MMG5_NSOLS_MAX ) {
1414 fprintf(stderr,"\n ## Error: %s: unexpected number of data (%d).\n",
1415 __func__,nsols);
1416 MMG5_SAFE_FREE(type);
1417 fclose(inm);
1418 return -1;
1419 }
1420
1421 if ( *sol ) MMG5_DEL_MEM(mesh,*sol);
1422 MMG5_ADD_MEM(mesh,nsols*sizeof(MMG5_Sol),"solutions array",
1423 printf(" Exit program.\n"); fclose(inm);
1424 MMG5_SAFE_FREE(type);
1425 return -1);
1426 MMG5_SAFE_CALLOC(*sol,nsols,MMG5_Sol,return -1);
1427
1428 for ( j=0; j<nsols; ++j ) {
1429 psl = *sol + j;
1430
1431 /* Give an arbitrary name to the solution because the Medit format has no
1432 * name field */
1433 sprintf(data,"sol_%" MMG5_PRId "",j);
1434 if ( !MMGS_Set_inputSolName(mesh,psl,data) ) {
1435 if ( !mmgWarn ) {
1436 mmgWarn = 1;
1437 fprintf(stderr,"\n ## Warning: %s: unable to set solution name for"
1438 " at least 1 solution.\n",__func__);
1439 }
1440 }
1441
1442 /* Allocate and store the header information for each solution */
1443 if ( !MMGS_Set_solSize(mesh,psl,MMG5_Vertex,mesh->np,type[j]) ) {
1444 MMG5_SAFE_FREE(type);
1445 fclose(inm);
1446 return -1;
1447 }
1448 /* For binary files, we read the verson inside the file */
1449 if ( ver ) psl->ver = ver;
1450 }
1451 MMG5_SAFE_FREE(type);
1452
1453 /* read mesh solutions */
1454 rewind(inm);
1455 fseek(inm,posnp,SEEK_SET);
1456
1457 if ( (*sol)[0].ver == 1 ) {
1458 /* Single precision */
1459 for (k=1; k<=mesh->np; k++) {
1460 for ( j=0; j<nsols; ++j ) {
1461 psl = *sol + j;
1462 if ( MMG5_readFloatSol3D(psl,inm,bin,iswp,k) < 0 ) return -1;
1463 }
1464 }
1465 }
1466 else {
1467 /* Double precision */
1468 for (k=1; k<=mesh->np; k++) {
1469 for ( j=0; j<nsols; ++j ) {
1470 psl = *sol + j;
1471 if ( MMG5_readDoubleSol3D(psl,inm,bin,iswp,k) < 0 ) return -1;
1472 }
1473 }
1474 }
1475 fclose(inm);
1476
1477 /* stats */
1479
1480 return 1;
1481}
1482
1484 FILE* inm;
1485 MMG5_pPoint ppt;
1486 int binch,bin,ier;
1487 MMG5_int bpos,k;
1488
1489 if ( !met->m ) {
1490 fprintf(stderr,"\n ## Warning: %s: no metric data to save.\n",__func__);
1491 return 1;
1492 }
1493
1494 met->ver = 2;
1495 bpos = 0;
1496 ier = MMG5_saveSolHeader( mesh,filename,&inm,met->ver,&bin,&bpos,mesh->np,met->dim,
1497 1,&met->entities,&met->type,&met->size);
1498
1499 if ( ier < 1 ) return ier;
1500
1501 for (k=1; k<=mesh->np; k++) {
1502 ppt = &mesh->point[k];
1503 if ( !MG_VOK(ppt) ) continue;
1504
1505 MMG5_writeDoubleSol3D(mesh,met,inm,bin,k,1);
1506 fprintf(inm,"\n");
1507 }
1508
1509 /* end of file */
1510 if(!bin) {
1511 fprintf(inm,"\n\nEnd\n");
1512 } else {
1513 binch = 54; //End
1514 fwrite(&binch,MMG5_SW,1,inm);
1515 }
1516 fclose(inm);
1517 return 1;
1518}
1519
1521 MMG5_pSol psl;
1522 FILE* inm;
1523 MMG5_pPoint ppt;
1524 int binch,bin,ier,npointSols,ncellSols;
1525 int *type,*entities,j,*size;
1526 MMG5_int k,bpos;
1527
1528 if ( !(*sol)[0].m ) return -1;
1529
1530 (*sol)[0].ver = 2;
1531
1532 MMG5_SAFE_CALLOC(type,mesh->nsols,int,return 0);
1533 MMG5_SAFE_CALLOC(size,mesh->nsols,int,MMG5_SAFE_FREE(type);return 0);
1534 MMG5_SAFE_CALLOC(entities,mesh->nsols,int,
1535 MMG5_SAFE_FREE(type);MMG5_SAFE_FREE(size);return 0);
1536
1537 npointSols = 0;
1538 ncellSols = 0;
1539 for (k=0; k<mesh->nsols; ++k ) {
1540
1541 if ( ((*sol)[k].entities==MMG5_Noentity) || ((*sol)[k].entities==MMG5_Vertex) ) {
1542 ++npointSols;
1543 }
1544 else if ( (*sol)[k].entities == MMG5_Triangle ) {
1545 ++ncellSols;
1546 }
1547 else {
1548 printf("\n ## Warning: %s: unexpected entity type for solution %" MMG5_PRId ": %s."
1549 "\n Ignored.\n",
1550 __func__,k,MMG5_Get_entitiesName((*sol)[k].entities));
1551 }
1552
1553 type[k] = (*sol)[k].type;
1554 size[k] = (*sol)[k].size;
1555 entities[k] = (*sol)[k].entities;
1556 }
1557
1558 bpos = 0;
1559 ier = MMG5_saveSolHeader( mesh,filename,&inm,(*sol)[0].ver,&bin,&bpos,mesh->np,
1560 (*sol)[0].dim,mesh->nsols,entities,type,size);
1561
1562 if ( ier < 1 ) return ier;
1563
1564 for (k=1; k<=mesh->np; k++) {
1565 ppt = &mesh->point[k];
1566 if ( !MG_VOK(ppt) ) continue;
1567
1568 for ( j=0; j<mesh->nsols; ++j ) {
1569 psl = *sol + j;
1570
1571 if ( (psl->entities==MMG5_Noentity) || (psl->entities==MMG5_Vertex) ) {
1572 MMG5_writeDoubleSol3D(mesh,psl,inm,bin,k,0);
1573 }
1574 }
1575 fprintf(inm,"\n");
1576 }
1577
1578 MMG5_saveSolAtTrianglesHeader( mesh,inm,(*sol)[0].ver,bin,&bpos,mesh->nsols,
1579 ncellSols,entities,type,size );
1580
1581 for (k=1; k<=mesh->nt; k++) {
1582 MMG5_pTria ptt = &mesh->tria[k];
1583 if ( !MG_EOK(ptt) ) continue;
1584
1585 for ( j=0; j<mesh->nsols; ++j ) {
1586 psl = *sol + j;
1587 if ( psl->entities==MMG5_Triangle ) {
1588 MMG5_writeDoubleSol3D(mesh,psl,inm,bin,k,0);
1589 }
1590 }
1591 fprintf(inm,"\n");
1592 }
1593
1594 MMG5_SAFE_FREE(type);
1595 MMG5_SAFE_FREE(size);
1596 MMG5_SAFE_FREE(entities);
1597
1598 /* End file */
1599 if(!bin) {
1600 fprintf(inm,"\n\nEnd\n");
1601 } else {
1602 binch = 54; //End
1603 fwrite(&binch,MMG5_SW,1,inm);
1604 }
1605 fclose(inm);
1606 return 1;
1607}
1608
1610 int ier=0;
1611 const char *filenameptr,*solnameptr;
1612 char *tmp,*soltmp;
1613
1614 if ( filename && strlen(filename) ) {
1615 filenameptr = filename;
1616 solnameptr = filename;
1617 }
1618 else if (mesh->namein && strlen(mesh->namein) ) {
1619 filenameptr = mesh->namein;
1620 if ( sol && strlen(sol->namein) ) {
1621 solnameptr = sol->namein;
1622 }
1623 else {
1624 solnameptr = mesh->namein;
1625 }
1626 }
1627 else {
1628 fprintf(stderr," ## Error: %s: please provide input file name"
1629 " (either in the mesh structure or as function argument).\n",
1630 __func__);
1631 return 0;
1632 }
1633
1634 MMG5_SAFE_MALLOC(tmp,strlen(filenameptr)+1,char,return 0);
1635 strcpy(tmp,filenameptr);
1636
1637 /* read mesh/sol files */
1638 char *ptr = MMG5_Get_filenameExt(tmp);
1639 int fmt = MMG5_Get_format(ptr,MMG5_FMT_MeditASCII);
1640
1641 int8_t savesolFile = 0;
1642
1643 switch ( fmt ) {
1644 case ( MMG5_FMT_GmshASCII ): case ( MMG5_FMT_GmshBinary ):
1646 break;
1647 case ( MMG5_FMT_VtkVtp ):
1649 break;
1650 case ( MMG5_FMT_VtkVtu ):
1652 break;
1653 case ( MMG5_FMT_VtkVtk ):
1655 break;
1656 default:
1658 savesolFile = 1;
1659 break;
1660 }
1661
1662 if ( ier && savesolFile ) {
1663 /* Medit or tetgen output: save the solution in a .sol file */
1664 if ( sol && sol->np ) {
1665 MMG5_SAFE_MALLOC(soltmp,strlen(solnameptr)+1,char,return 0);
1666 strcpy(soltmp,solnameptr);
1667
1668 if ( MMGS_saveSol(mesh,sol,soltmp) == -1) {
1669 fprintf(stderr,"\n ## ERROR: WRONG DATA TYPE OR WRONG SOLUTION NUMBER.\n");
1670 ier = 0;
1671 }
1672 MMG5_SAFE_FREE(soltmp);
1673 }
1674 }
1675
1676 return ier;
1677}
const char * MMG5_Get_formatName(enum MMG5_Format fmt)
const char * MMG5_Get_entitiesName(enum MMG5_entities ent)
int MMG5_Get_format(char *ptr, int fmt)
char * MMG5_Get_filenameExt(char *filename)
int MMGS_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
Set the name of the input solution file.
int MMGS_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
Initialize an array of solution fields: set dimension, types and number of fields.
int ier
tmp[*strlen0]
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
MMG5_pMesh char * filename
int MMG5_readDoubleSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, MMG5_int pos)
Definition: inout.c:2271
int MMG5_chkMetricType(MMG5_pMesh mesh, int *type, int *entities, FILE *inm)
Definition: inout.c:2663
void MMG5_printSolStats(MMG5_pMesh mesh, MMG5_pSol *sol)
Definition: inout.c:2725
float MMG5_swapf(float sbin)
Definition: inout.c:80
int MMG5_saveSolAtTrianglesHeader(MMG5_pMesh mesh, FILE *inm, int ver, int bin, MMG5_int *bpos, int nsols, int nsolsAtTriangles, int *entities, int *type, int *size)
Definition: inout.c:2526
int MMG5_saveSolHeader(MMG5_pMesh mesh, const char *filename, FILE **inm, int ver, int *bin, MMG5_int *bpos, MMG5_int np, int dim, int nsols, int *entities, int *type, int *size)
Definition: inout.c:2389
int MMG5_loadMshMesh_part1(MMG5_pMesh mesh, const char *filename, FILE **inm, long *posNodes, long *posElts, long **posNodeData, int *bin, int *iswp, MMG5_int *nelts, int *nsols)
Definition: inout.c:278
void MMG5_writeDoubleSol3D(MMG5_pMesh mesh, MMG5_pSol sol, FILE *inm, int bin, MMG5_int pos, int metricData)
Definition: inout.c:2320
int MMG5_readFloatSol3D(MMG5_pSol sol, FILE *inm, int bin, int iswp, int pos)
Definition: inout.c:2222
double MMG5_swapd(double sbin)
Definition: inout.c:97
int MMG5_loadMshMesh_part2(MMG5_pMesh mesh, MMG5_pSol *sol, FILE **inm, const long posNodes, const long posElts, const long *posNodeData, const int bin, const int iswp, const MMG5_int nelts, const int nsols)
Definition: inout.c:664
int MMG5_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename, int metricData)
Definition: inout.c:1583
void MMG5_printMetStats(MMG5_pMesh mesh, MMG5_pSol met)
Definition: inout.c:2707
int MMG5_loadSolHeader(const char *filename, int meshDim, FILE **inm, int *ver, int *bin, int *iswp, MMG5_int *np, int *dim, int *nsols, int **type, long *posnp, int imprim)
Definition: inout.c:2076
int MMG5_swapbin(int sbin)
Definition: inout.c:42
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_loadAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Load one or more solutions in a solution file in medit file format.
Definition: inout_s.c:1387
int MMGS_loadMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Load a mesh and possibly a solution in .msh format from file.
Definition: inout_s.c:645
int MMGS_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh or .meshb format.
Definition: inout_s.c:842
int MMGS_saveMshMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Write mesh and optionally one data field in MSH file format (.msh extension).
Definition: inout_s.c:1302
int MMGS_saveGenericMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save mesh data in a file whose format depends on the filename extension.
Definition: inout_s.c:1609
int MMGS_saveMshMesh_and_allData(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Save a mesh and multiple data fields in MSH format, ascii or binary depending on the filename extensi...
Definition: inout_s.c:1307
int MMGS_loadMshMesh_and_allData(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Load a mesh and all data from a file in MSH format.
Definition: inout_s.c:706
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_saveAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Save one or more solutions in a solution file in medit file format.
Definition: inout_s.c:1520
int MMGS_loadGenericMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and all data from a file. The format will be guessed from the filename extension.
Definition: inout_s.c:764
int MMGS_loadVtuMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and possibly data in VTU (VTK) format from file.
Definition: inoutcpp_s.cpp:235
int MMGS_saveVtuMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Write mesh and optionally one data field vtu Vtk file format (.vtu extension).
Definition: inoutcpp_s.cpp:315
int MMGS_loadVtpMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and optionally a solution in VTP (VTK) format from file.
Definition: inoutcpp_s.cpp:75
int MMGS_saveVtkMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Write mesh and optionally one data field in Vtk file format (.vtk extension).
Definition: inoutcpp_s.cpp:350
int MMGS_loadVtkMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Load a mesh and possibly data in VTK format from file.
Definition: inoutcpp_s.cpp:155
int MMGS_saveVtpMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save a mesh and optionally one data field in VTP format.
Definition: inoutcpp_s.cpp:385
API headers and documentation for the mmgs library.
int MMGS_zaldy(MMG5_pMesh mesh)
Definition: zaldy_s.c:263
@ MMG5_FMT_MeditBinary
Definition: libmmgtypes.h:242
@ MMG5_FMT_VtkVtk
Definition: libmmgtypes.h:249
@ MMG5_FMT_GmshBinary
Definition: libmmgtypes.h:244
@ MMG5_FMT_GmshASCII
Definition: libmmgtypes.h:243
@ MMG5_FMT_MeditASCII
Definition: libmmgtypes.h:241
@ MMG5_FMT_VtkVtp
Definition: libmmgtypes.h:248
@ MMG5_FMT_VtkVtu
Definition: libmmgtypes.h:247
#define MMG5_NSOLS_MAX
Definition: libmmgtypes.h:187
@ MMG5_Noentity
Definition: libmmgtypes.h:229
@ MMG5_Vertex
Definition: libmmgtypes.h:230
@ MMG5_Triangle
Definition: libmmgtypes.h:232
#define MG_REQ
#define MG_GEO
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define MG_EOK(pt)
#define MG_NUL
#define MMG5_SD
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MG_EDG(tag)
#define MMG_FREAD(ptr, size, count, stream)
#define MMG5_SW
#define MG_VOK(ppt)
#define MG_CRN
#define MMG5_SAFE_MALLOC(ptr, size, type, law)
#define MMG5_FILESTR_LGTH
#define MMG5_EPSD2
#define MG_REF
#define MMG5_SAFE_FREE(ptr)
#define MMG_FSCANF(stream, format,...)
#define MMG5_DEL_MEM(mesh, ptr)
MMG5_int b
Definition: libmmgtypes.h:312
uint16_t tag
Definition: libmmgtypes.h:316
MMG5_int ref
Definition: libmmgtypes.h:313
MMG5_int a
Definition: libmmgtypes.h:312
MMG mesh structure.
Definition: libmmgtypes.h:613
MMG5_int ntmax
Definition: libmmgtypes.h:620
MMG5_int nc1
Definition: libmmgtypes.h:623
MMG5_Info info
Definition: libmmgtypes.h:659
MMG5_int ne
Definition: libmmgtypes.h:620
MMG5_pPoint point
Definition: libmmgtypes.h:649
MMG5_int npmax
Definition: libmmgtypes.h:620
MMG5_pxPoint xpoint
Definition: libmmgtypes.h:650
MMG5_int xp
Definition: libmmgtypes.h:628
MMG5_int nt
Definition: libmmgtypes.h:620
MMG5_pTria tria
Definition: libmmgtypes.h:655
MMG5_int np
Definition: libmmgtypes.h:620
MMG5_pEdge edge
Definition: libmmgtypes.h:657
MMG5_int nti
Definition: libmmgtypes.h:620
MMG5_int npi
Definition: libmmgtypes.h:620
MMG5_int nprism
Definition: libmmgtypes.h:621
MMG5_int na
Definition: libmmgtypes.h:620
char * namein
Definition: libmmgtypes.h:660
Structure to store vertices of an MMG mesh.
Definition: libmmgtypes.h:276
double n[3]
Definition: libmmgtypes.h:278
MMG5_int tmp
Definition: libmmgtypes.h:286
double c[3]
Definition: libmmgtypes.h:277
uint16_t tag
Definition: libmmgtypes.h:290
MMG5_int xp
Definition: libmmgtypes.h:285
MMG5_int ref
Definition: libmmgtypes.h:284
int entities
Definition: libmmgtypes.h:679
double * m
Definition: libmmgtypes.h:680
Structure to store triangles of a MMG mesh.
Definition: libmmgtypes.h:338
MMG5_int ref
Definition: libmmgtypes.h:341
uint16_t tag[3]
Definition: libmmgtypes.h:348
MMG5_int v[3]
Definition: libmmgtypes.h:340
Structure to store surface vertices of an MMG mesh.
Definition: libmmgtypes.h:300
double n1[3]
Definition: libmmgtypes.h:301