forked from FreeFem/FreeFem-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetgen.cpp
2723 lines (2168 loc) · 78.8 KB
/
tetgen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************/
/* This file is part of FreeFem++. */
/* */
/* FreeFem++ 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. */
/* */
/* FreeFem++ 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 */
/* along with FreeFem++. If not, see <http://www.gnu.org/licenses/>. */
/****************************************************************************/
// SUMMARY : ...
// LICENSE : LGPLv3
// ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
// AUTHORS : Jacques Morice
// E-MAIL : [email protected]
// *INDENT-OFF* //
//ff-c++-LIBRARY-dep: tetgen
//ff-c++-cpp-dep:
// *INDENT-ON* //
/*
* Thank to the ARN () FF2A3 grant
* ref:ANR-07-CIS7-002-01
*/
// FH July 2009
// comment all
// Th3_t->BuildBound();
// Th3_t->BuildAdj();
// Th3_t->Buildbnormalv();
// Th3_t->BuildjElementConteningVertex();
// is now in the constructor of Mesh3 to be consistante.
//
#include "ff++.hpp"
#include "msh3.hpp"
#define TETLIBRARY
#include "tetgen.h"
using namespace Fem2D;
/*
* // function to return inside point in a volume mesh
* // A rajouter par la suite //
* void insidepoint( const Mesh3 &Th3
*
*/
// subroutine use for tetegen call
typedef const Mesh3 *pmesh3;
void mesh3_tetgenio_out (const tetgenio &out, Mesh3 &Th3);
void mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, Mesh3 &Th3);
void mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, const int &label_face, Mesh3 &Th3);
Mesh3*mesh3_tetgenio_out (const tetgenio &out);
Mesh3*mesh3_tetgenio_out (const tetgenio &out, const int &label_tet);
Mesh3*mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, const int &label_face);
Mesh3*Convexhull_3Dpoints (char *switch_tetgen, const int &nv_t, const double *Xcoord, const double *Ycoord, const double *Zcoord, const int &label_tet);
Mesh3*RemplissageSurf3D_tetgen (char *switch_tetgen, const Mesh3 &Th3, const int &label_tet);
Mesh3*RemplissageSurf3D_tetgen_new (char *switch_tetgen, const Mesh3 &Th3, const int &label_tet,
const int &nbhole, const double *tabhole,
const int &nbregion, const double *tabregion,
const int &nbfacecl, const double *tabfacecl);
Mesh3*Transfo_Mesh2_tetgen (const double &precis_mesh, char *switch_tetgen, const Mesh &Th2, const double *tab_XX, const double *tab_YY, const double *tab_ZZ,
int &border_only, int &recollement_border, int &point_confondus_ok,
const int &label_tet, const map<int, int> &maptri);
Mesh3*Transfo_Mesh2_tetgen_new (const double &precis_mesh, char *switch_tetgen, const Mesh &Th2, const double *tab_XX, const double *tab_YY, const double *tab_ZZ,
int &border_only, int &recollement_border, int &point_confondus_ok,
const int &label_tet, const map<int, int> &maptri,
const int &nbhole, const double *tabhole,
const int &nbregion, const double *tabregion,
const int &nbfacecl, const double *tabfacecl);
Mesh3*ReconstructionRefine_tetgen (char *switch_tetgen, const Mesh3 &Th3,
const int &nbhole, const double *tabhole,
const int &nbregion, const double *tabregion,
const int &nbfacecl, const double *tabfacecl, const double *tsizevol);
class Build2D3D_Op: public E_F0mps
{
public:
Expression eTh;
Expression xx, yy, zz;
static const int n_name_param = 13 + 2; //
static basicAC_F0::name_and_type name_param [];
Expression nargs[n_name_param];
KN_<long> arg (int i, Stack stack, KN_<long> a) const
{return nargs[i] ? GetAny<KN_<long> >((*nargs[i])(stack)) : a;}
KN_<double> arg (int i, Stack stack, KN_<double> a) const
{return nargs[i] ? GetAny<KN_<double> >((*nargs[i])(stack)) : a;}
double arg (int i, Stack stack, double a) const {return nargs[i] ? GetAny<double>((*nargs[i])(stack)) : a;}
long arg (int i, Stack stack, long a) const {return nargs[i] ? GetAny<long>((*nargs[i])(stack)) : a;}
string*arg (int i, Stack stack, string *a) const {return nargs[i] ? GetAny<string *>((*nargs[i])(stack)) : a;}
public:
Build2D3D_Op (const basicAC_F0 &args, Expression tth)
: eTh(tth), xx(0), yy(0), zz(0) {
if (verbosity) {cout << "construction par BuilLayeMesh_Op" << endl;}
args.SetNameParam(n_name_param, name_param, nargs);
const E_Array *a1 = 0;
if (nargs[0]) {a1 = dynamic_cast<const E_Array *>(nargs[0]);}
int err = 0;
if (a1) {
if (a1->size() != 3) {
CompileError("Build2D3D (Th,transfo=[X,Y,Z],) ");
}
xx = to<double>((*a1)[0]);
yy = to<double>((*a1)[1]);
zz = to<double>((*a1)[2]);
}
if (nargs[2] && nargs[13]) {
CompileError("uncompatible movemesh3 (Th, region= , reftet= ");
}
if (nargs[3] && nargs[14]) {
CompileError("uncompatible movemesh3 (Th, label= , refface= ");
}
}
AnyType operator () (Stack stack) const;
};
basicAC_F0::name_and_type Build2D3D_Op::name_param [] = {
{"transfo", &typeid(E_Array)}, // 0
{"switch", &typeid(string *)},
{"reftet", &typeid(long)}, // 2
{"refface", &typeid(KN_<long>)},// 3
{"facemerge", &typeid(long)},
{"ptmerge", &typeid(double)},
// nouvelle variable
{"nbofholes", &typeid(long)}, // 6
{"holelist", &typeid(KN_<double>)},
{"nbofregions", &typeid(long)},
{"regionlist", &typeid(KN_<double>)},
{"nboffacetcl", &typeid(long)},
{"facetcl", &typeid(KN_<double>)}, // 11
// mesure mesh
{"mesuremesh", &typeid(long)},
{"region", &typeid(long)}, // 13
{"label", &typeid(KN_<long>)} // 14
};
class Build2D3D: public OneOperator {
public:
Build2D3D (): OneOperator(atype<pmesh3>(), atype<pmesh>()) {}
E_F0*code (const basicAC_F0 &args) const {
return new Build2D3D_Op(args, t[0]->CastTo(args[0]));
}
};
AnyType Build2D3D_Op::operator () (Stack stack) const {
MeshPoint *mp(MeshPointStack(stack)), mps = *mp;
Mesh *pTh = GetAny<Mesh *>((*eTh)(stack));
ffassert(pTh);
Mesh &Th = *pTh;
Mesh *m = pTh; // question a quoi sert *m ??
int nbv = Th.nv;// nombre de sommet
int nbt = Th.nt;// nombre de triangles
int neb = Th.neb; // nombre d'aretes fontiere
if (verbosity) {cout << " Vertex Triangle Border " << nbv << " " << nbt << " " << neb << endl;}
if (verbosity > 1) {cout << " ======================= " << endl;}
if (verbosity > 1) {cout << " == Build2D_3D_Op==" << endl;}
KN<long> zzempty;
string stringempty = string("pqaAAYCQ");
string *switch_tet = (arg(1, stack, &stringempty));
int label_tet(arg(2, stack, arg(13, stack, 0L)));
KN<long> nrf(arg(3, stack, arg(14, stack, zzempty)));
int point_confondus_ok(arg(4, stack, 0L));
double precis_mesh(arg(5, stack, -1.));
// new parameters
KN<double> zdzempty;
int nbhole(arg(6, stack, 0L));
KN<double> tabhole(arg(7, stack, zdzempty));
int nbregion(arg(8, stack, 0L));
KN<double> tabregion(arg(9, stack, zdzempty));
int nbfacecl(arg(10, stack, 0L));
KN<double> tabfacecl(arg(11, stack, zdzempty));
if (nbhole && nbhole * 3 != tabhole.N())
{ExecError(" nbhole and holes are incompatibale ");}
if (!nbhole) {
nbhole = tabhole.N() / 3; // modif FH dec 2010...
}
// mesuremesh parameters
int mesureM(arg(12, stack, 1L));
int surface_orientation = 1;
if (mesureM < 0) {
surface_orientation = -1;
}
if (nbregion == 0) {nbregion = tabregion.N() / 5;}
if (nbhole == 0) {nbhole = tabhole.N() / 3;}
if (nbfacecl == 0) {nbfacecl = tabfacecl.N() / 2;}
// assertion au niveau de la taille
ffassert(tabhole.N() == 3 * nbhole);
ffassert(tabregion.N() == 5 * nbregion);
ffassert(tabfacecl.N() == 2 * nbfacecl);
//= ===================================
// How to change string* into char*
//= ===================================
cout << "string" << switch_tet << endl;
size_t size_switch_tet = switch_tet->size() + 1;
char *switch_tetgen = new char[size_switch_tet];
strncpy(switch_tetgen, switch_tet->c_str(), size_switch_tet);
cout << "switch_tetgen=" << switch_tetgen << endl;
// exit(1);
ffassert(nrf.N() % 2 == 0);
map<int, int> mapf;
for (int i = 0; i < nrf.N(); i += 2) {
if (nrf[i] != nrf[i + 1]) {
mapf[nrf[i]] = nrf[i + 1];
}
}
map<int, int> mapfme;
Transfo_Mesh2_map_face(Th, mapfme);
// Map utilisateur
map<int, int>::iterator imap;
for (int ii = 0; ii < nrf.N(); ii += 2) {
imap = mapfme.find(nrf[ii]);
if (imap != mapfme.end()) {
imap->second = nrf[ii + 1];
}
}
// KN<double> txx(nbv), tyy(nbv), tzz(nbv);
// KN<int> takemesh(nbv);
double *txx = new double[nbv];
double *tyy = new double[nbv];
double *tzz = new double[nbv];
int *takemesh = new int[nbv];
MeshPoint *mp3(MeshPointStack(stack));
for (int ii = 0; ii < nbv; ii++) {
takemesh[ii] = 0;
}
Mesh &rTh = Th;
for (int it = 0; it < nbt; ++it) {
for (int iv = 0; iv < 3; ++iv) {
int i = Th(it, iv);
if (takemesh[i] == 0) {
mp3->setP(&Th, it, iv);
if (xx) {
txx[i] = GetAny<double>((*xx)(stack));
}
if (yy) {
tyy[i] = GetAny<double>((*yy)(stack));
}
if (zz) {
tzz[i] = GetAny<double>((*zz)(stack));
}
takemesh[i] = takemesh[i] + 1;
}
}
}
delete [] takemesh;
int border_only = 0;
int recollement_border = 1;
/*
* Mesh3 *Th3=Transfo_Mesh2_tetgen( precis_mesh, switch_tetgen, Th, txx, tyy, tzz, border_only,
* recollement_border, point_confondus_ok, label_tet, mapfme);
*/
Mesh3 *Th3_tmp = MoveMesh2_func(precis_mesh, Th, txx, tyy, tzz, border_only, recollement_border, point_confondus_ok);
/* delete array */
delete [] txx;
delete [] tyy;
delete [] tzz;
/* check orientation of the mesh and flip if necessary*/
Th3_tmp->flipSurfaceMesh3(surface_orientation);
int addcheckorientation = 0;
if (addcheckorientation == 1) {
if (verbosity > 0) {
cout << "check :: orientation des surfaces" << endl;
}
Th3_tmp->BuildBoundaryElementAdj();
if (verbosity > 0) {
cout << "fin check :: orientation des surfaces" << endl;
}
}
/* set label of surface Th3_tmp */
for (int ii = 0; ii < Th3_tmp->nbe; ii++) {
const Triangle3 &K(Th3_tmp->be(ii));
int iv[3];
int lab;
iv[0] = Th3_tmp->operator () (K[0]);
iv[1] = Th3_tmp->operator () (K[1]);
iv[2] = Th3_tmp->operator () (K[2]);
map<int, int>::const_iterator imap;
imap = mapfme.find(K.lab);
if (imap != mapfme.end()) {
lab = imap->second;
} else {
lab = K.lab;
}
Th3_tmp->be(ii).set(Th3_tmp->vertices, iv, lab);
}
/* mesh domains with tetgen */
Mesh3 *Th3 = RemplissageSurf3D_tetgen_new(switch_tetgen, *Th3_tmp, label_tet,
nbhole, tabhole, nbregion, tabregion,
nbfacecl, tabfacecl);
/*
* Mesh3 *Th3=Transfo_Mesh2_tetgen_new( precis_mesh, switch_tetgen, Th, txx, tyy, tzz, border_only,
* recollement_border, point_confondus_ok, label_tet, mapfme,
* nbhole, tabhole, nbregion, tabregion, nbfacecl,tabfacecl);
*
*/
delete Th3_tmp;
// Th3->BuildBound();
// Th3->BuildAdj();
// Th3->Buildbnormalv();
// Th3->BuildjElementConteningVertex();
Th3->BuildGTree();
// Th3->decrement();
Add2StackOfPtr2FreeRC(stack, Th3);
delete [] switch_tetgen;
*mp = mps;
if (verbosity > 0) {
cout << "FreeFem++: End check mesh given by tetgen" << endl;
}
return Th3;
}
// Fonction pour tetgen
// new parameter
void mesh3_tetgenio_out (const tetgenio &out, Mesh3 &Th3) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
// new parameter
if (out.numberoftetrahedronattributes != 1) {
cout << "out.numberoftetrahedronattributes" << out.numberoftetrahedronattributes << endl;
}
i = 0;
for (int nnv = 0; nnv < Th3.nv; nnv++) {
Th3.vertices[nnv].x = out.pointlist[i];
Th3.vertices[nnv].y = out.pointlist[i + 1];
Th3.vertices[nnv].z = out.pointlist[i + 2];
Th3.vertices[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
i = 0;
for (int nnt = 0; nnt < Th3.nt; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
// lab = label_tet;
for (int jj = 0; jj < 4; jj++) {
assert(iv[jj] >= 0 && iv[jj] < Th3.nv);
}
// cout << "nnt= " << nnt << " " << lab << " " << out.tetrahedronattributelist[nnt] << endl;
lab = out.tetrahedronattributelist[nnt];
// cout << "nnt= " << lab << " " << out.tetrahedronattributelist[nnt] << endl;
Th3.elements[nnt].set(Th3.vertices, iv, lab);
i = i + 4;
}
for (int ibe = 0; ibe < Th3.nbe; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
for (int jj = 0; jj < 3; jj++) {
if (iv[jj] >= Th3.nv || iv[jj] < 0) {cout << "iv[jj]=" << iv[jj] << " triangle" << ibe << endl;}
assert(iv[jj] >= 0 && iv[jj] < Th3.nv);
}
Th3.be(ibe).set(Th3.vertices, iv, out.trifacemarkerlist[ibe]);
}
/*
* if( out.numberoftetrahedronattributes != 1 ){
* cout << "out.numberoftetrahedronattributes" << out.numberoftetrahedronattributes << endl;
* exit(1);
* }
*/
}
void mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, Mesh3 &Th3) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
i = 0;
for (int nnv = 0; nnv < Th3.nv; nnv++) {
Th3.vertices[nnv].x = out.pointlist[i];
Th3.vertices[nnv].y = out.pointlist[i + 1];
Th3.vertices[nnv].z = out.pointlist[i + 2];
Th3.vertices[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
i = 0;
for (int nnt = 0; nnt < Th3.nt; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
lab = label_tet;
// lab = out.tetrahedronmarkerlist[nnt];
Th3.elements[nnt].set(Th3.vertices, iv, lab);
i = i + 4;
}
for (int ibe = 0; ibe < Th3.nbe; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
Th3.be(ibe).set(Th3.vertices, iv, out.trifacemarkerlist[ibe]);
}
}
void mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, const int &label_face, Mesh3 &Th3) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
i = 0;
for (int nnv = 0; nnv < Th3.nv; nnv++) {
Th3.vertices[nnv].x = out.pointlist[i];
Th3.vertices[nnv].y = out.pointlist[i + 1];
Th3.vertices[nnv].z = out.pointlist[i + 2];
Th3.vertices[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
i = 0;
for (int nnt = 0; nnt < Th3.nt; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
lab = label_tet;
// lab = out.tetrahedronmarkerlist[nnt];
Th3.elements[nnt].set(Th3.vertices, iv, lab);
i = i + 4;
}
if (verbosity) {cout << &out.trifacemarkerlist << endl;}
for (int ibe = 0; ibe < Th3.nbe; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
Th3.be(ibe).set(Th3.vertices, iv, label_face);
}
}
// verison Mesh3 *
Mesh3*mesh3_tetgenio_out (const tetgenio &out) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
// Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
// new parameter
if (out.numberoftetrahedronattributes != 1) {
cout << "out.numberoftetrahedronattributes" << out.numberoftetrahedronattributes << endl;
}
Vertex3 *v = new Vertex3[out.numberofpoints];
Tet *t = new Tet[out.numberoftetrahedra];
Tet *tt = t;
Triangle3 *b = new Triangle3[out.numberoftrifaces];
Triangle3 *bb = b;
i = 0;
for (int nnv = 0; nnv < out.numberofpoints; nnv++) {
v[nnv].x = out.pointlist[i];
v[nnv].y = out.pointlist[i + 1];
v[nnv].z = out.pointlist[i + 2];
v[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
// test pour la distance minimale entre les points
// {
// double dist,dist1;
// dist = 1000000000000.;
// for(int nnv=0; nnv<out.numberofpoints; nnv++){
// for(int nnv1=nnv+1; nnv1< out.numberofpoints; nnv1++){
// dist1=(v[nnv].x-v[nnv1].x)*(v[nnv].x-v[nnv1].x)+(v[nnv].y-v[nnv1].y)*(v[nnv].y-v[nnv1].y)
// +(v[nnv].z-v[nnv1].z)*(v[nnv].z-v[nnv1].z);
// dist=min(dist,sqrt(dist1));
// if( sqrt(dist1) < 1e-12){
// cout << "point confondus" << nnv << "<--->" <<nnv1 << endl;
// if( sqrt( pow(v[nnv].x,2)+pow(v[nnv].y,2)+pow(v[nnv].z,2) ) > 1e-10 ) cout << v[nnv] << " " << v[nnv1] << endl;
// }
// }
// }
// cout << "dist entre les points du maillage tetgen" << dist << endl;
// }
i = 0;
for (int nnt = 0; nnt < out.numberoftetrahedra; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
// lab = label_tet;
for (int jj = 0; jj < 4; jj++) {
assert(iv[jj] >= 0 && iv[jj] < out.numberofpoints);
}
// cout << "nnt= " << nnt << " " << lab << " " << out.tetrahedronattributelist[nnt] << endl;
lab = out.tetrahedronattributelist[nnt];
// cout << "nnt= " << lab << " " << out.tetrahedronattributelist[nnt] << endl;
// Th3.elements[nnt].set( Th3.vertices, iv, lab);
(*tt++).set(v, iv, lab);
i = i + 4;
}
for (int ibe = 0; ibe < out.numberoftrifaces; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
for (int jj = 0; jj < 3; jj++) {
if (iv[jj] >= out.numberofpoints || iv[jj] < 0) {cout << "iv[jj]=" << iv[jj] << " triangle" << ibe << endl;}
assert(iv[jj] >= 0 && iv[jj] < out.numberofpoints);
}
// Th3.be(ibe).set( Th3.vertices, iv, out.trifacemarkerlist[ibe]);
(*bb++).set(v, iv, out.trifacemarkerlist[ibe]);
}
Mesh3 *T_TH3 = new Mesh3(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces, v, t, b);
cout << "FreeFem++: Check mesh given by tetgen" << endl;
// return T_TH3;
if (TestElementMesh3(*T_TH3) != 1) {
return T_TH3;
} else {
// Mesh3 *T2_TH3 = TestElementMesh3_patch( *T_TH3 );
// return T2_TH3;
exit(1);
}
}
Mesh3*mesh3_tetgenio_out (const tetgenio &out, const int &label_tet) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
// Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
Vertex3 *v = new Vertex3[out.numberofpoints];
Tet *t = new Tet[out.numberoftetrahedra];
Tet *tt = t;
Triangle3 *b = new Triangle3[out.numberoftrifaces];
Triangle3 *bb = b;
i = 0;
for (int nnv = 0; nnv < out.numberofpoints; nnv++) {
v[nnv].x = out.pointlist[i];
v[nnv].y = out.pointlist[i + 1];
v[nnv].z = out.pointlist[i + 2];
v[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
i = 0;
for (int nnt = 0; nnt < out.numberoftetrahedra; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
lab = label_tet;
// lab = out.tetrahedronmarkerlist[nnt];
// Th3.elements[nnt].set( Th3.vertices, iv, lab);
(*tt++).set(v, iv, lab);
i = i + 4;
}
for (int ibe = 0; ibe < out.numberoftrifaces; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
// Th3.be(ibe).set( Th3.vertices, iv, out.trifacemarkerlist[ibe]);
(*bb++).set(v, iv, out.trifacemarkerlist[ibe]);
}
Mesh3 *T_TH3 = new Mesh3(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces, v, t, b);
// return T_TH3;
cout << "FreeFem++: Check mesh given by tetgen" << endl;
if (TestElementMesh3(*T_TH3) != 1) {
return T_TH3;
} else {
// cout << "patch pour tetgen " << endl;
// Mesh3 *T2_TH3 = TestElementMesh3_patch( *T_TH3 );
// return T2_TH3;
exit(1);
}
}
Mesh3*mesh3_tetgenio_out (const tetgenio &out, const int &label_tet, const int &label_face) {
int i;
// All indices start from 1.
if (out.firstnumber != 1) {
cout << " probleme ???" << endl;
exit(1);
}
if (out.numberoffacets != 0) {
cout << "tetgen: faces non triangulaire" << endl;
exit(1);
}
if (out.numberofcorners != 4) {
cout << "tetgen: element subparametric of order 2" << endl;
exit(1);
}
if (verbosity) {
cout << "Th3 :: Vertex Element Border :: " << out.numberofpoints << " " << out.numberoftetrahedra << " " << out.numberoftrifaces << endl;
}
// Th3.set(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces);
Vertex3 *v = new Vertex3[out.numberofpoints];
Tet *t = new Tet[out.numberoftetrahedra];
Tet *tt = t;
Triangle3 *b = new Triangle3[out.numberoftrifaces];
Triangle3 *bb = b;
i = 0;
for (int nnv = 0; nnv < out.numberofpoints; nnv++) {
v[nnv].x = out.pointlist[i];
v[nnv].y = out.pointlist[i + 1];
v[nnv].z = out.pointlist[i + 2];
v[nnv].lab = out.pointmarkerlist[nnv];
i = i + 3;
}
i = 0;
for (int nnt = 0; nnt < out.numberoftetrahedra; nnt++) {
int iv[4], lab;
iv[0] = out.tetrahedronlist[i] - 1;
iv[1] = out.tetrahedronlist[i + 1] - 1;
iv[2] = out.tetrahedronlist[i + 2] - 1;
iv[3] = out.tetrahedronlist[i + 3] - 1;
lab = label_tet;
// lab = out.tetrahedronmarkerlist[nnt];
// Th3.elements[nnt].set( Th3.vertices, iv, lab);
(*tt++).set(v, iv, lab);
i = i + 4;
}
if (verbosity) {cout << &out.trifacemarkerlist << endl;}
for (int ibe = 0; ibe < out.numberoftrifaces; ibe++) {
int iv[3];
iv[0] = out.trifacelist[3 * ibe] - 1;
iv[1] = out.trifacelist[3 * ibe + 1] - 1;
iv[2] = out.trifacelist[3 * ibe + 2] - 1;
// Th3.be(ibe).set( Th3.vertices, iv, label_face);
(*bb++).set(v, iv, label_face);
}
Mesh3 *T_TH3 = new Mesh3(out.numberofpoints, out.numberoftetrahedra, out.numberoftrifaces, v, t, b);
if (TestElementMesh3(*T_TH3) != 1) {
return T_TH3;
} else {
exit(1);
// Mesh3 *T2_TH3 = TestElementMesh3_patch( *T_TH3 );
// return T2_TH3;
}
}
Mesh3*Convexhull_3Dpoints (char *switch_tetgen, const int &nv_t, const double *Xcoord, const double *Ycoord,
const double *Zcoord, const int &label_tet, const int &label_face) {
// Mesh3 *T_Th3= new Mesh3;
tetgenio in, out;
// tetgenio::facet *f;
// tetgenio::polygon *p;
if (verbosity > 3) {
cout << " tetgenio: vertex " << endl;
}
int itet, jtet;
in.firstnumber = 1;
in.numberofpoints = nv_t;
in.pointlist = new REAL[in.numberofpoints * 3];
in.pointmarkerlist = new int[in.numberofpoints];
itet = 0;
jtet = 0;
for (int nnv = 0; nnv < nv_t; nnv++) {
in.pointlist[itet] = Xcoord[nnv];
in.pointlist[itet + 1] = Ycoord[nnv];
in.pointlist[itet + 2] = Zcoord[nnv];
in.pointmarkerlist[nnv] = 0;
itet = itet + 3;
}
assert(itet == in.numberofpoints * 3);
in.numberoffacets = 0;
if (verbosity > 1) {cout << "tetgen: before tetrahedralize( , &in, &out): switch=" << switch_tetgen << endl;}
tetrahedralize(switch_tetgen, &in, &out);
if (verbosity > 1) {cout << "tetgen: finish tetrahedralize( , &in, &out);" << endl;}
// mesh3_tetgenio_out( out, label_tet, label_face,*T_Th3);
Mesh3 *T_Th3 = mesh3_tetgenio_out(out, label_tet, label_face);
if (verbosity > 1) {cout << " Finish Mesh3 tetgen :: Vertex, Element, Border" << T_Th3->nv << " " << T_Th3->nt << " " << T_Th3->nbe << endl;}
if (verbosity > 1) {cout << "FreeFem++: End check mesh given by tetgen" << endl;}
return T_Th3;
}
Mesh3*RemplissageSurf3D_tetgen (char *switch_tetgen, const Mesh3 &Th3, const int &label_tet) {
// Mesh3 *T_Th3= new Mesh3;
assert(Th3.nt == 0);
int nv_t = Th3.nv;
int nt_t = Th3.nt;
int nbe_t = Th3.nbe;
if (verbosity) {cout << "3D RemplissageSurf3D:: Vertex triangle2 border " << nv_t << " " << nt_t << " " << nbe_t << endl;}
// Creation des tableau de tetgen
tetgenio in, out;
// tetgenio::facet *f;
// tetgenio::polygon *p;
if (verbosity) {cout << " tetgenio: vertex " << endl;}
int itet, jtet;
// All indices start from 1.
in.firstnumber = 1;
in.numberofpoints = nv_t;
in.pointlist = new REAL[in.numberofpoints * 3];
in.pointmarkerlist = new int[in.numberofpoints];
itet = 0;
jtet = 0;
for (int nnv = 0; nnv < nv_t; nnv++) {
in.pointlist[itet] = Th3.vertices[nnv].x;
in.pointlist[itet + 1] = Th3.vertices[nnv].y;
in.pointlist[itet + 2] = Th3.vertices[nnv].z;
in.pointmarkerlist[nnv] = Th3.vertices[nnv].lab;
itet = itet + 3;
}
assert(itet == in.numberofpoints * 3);
if (verbosity) {cout << " tetgenio: facet " << endl;}
// Version avec des facettes
in.numberoffacets = nbe_t;
in.facetlist = new tetgenio::facet[in.numberoffacets];
in.facetmarkerlist = new int[in.numberoffacets];
for (int ibe = 0; ibe < nbe_t; ibe++) {
tetgenio::facet *f;
tetgenio::polygon *p;
f = &in.facetlist[ibe];
f->numberofpolygons = 1;
f->polygonlist = new tetgenio::polygon[f->numberofpolygons];
f->numberofholes = 0;
f->holelist = NULL;
p = &f->polygonlist[0];
p->numberofvertices = 3;
p->vertexlist = new int[3];
// creation of elements
const Triangle3 &K(Th3.be(ibe));// const Triangle2 & K(Th2.elements[ii]); // Version Mesh2
p->vertexlist[0] = Th3.operator () (K[0]) + 1;
p->vertexlist[1] = Th3.operator () (K[1]) + 1;
p->vertexlist[2] = Th3.operator () (K[2]) + 1;
for (int kkk = 0; kkk < 3; kkk++) {
assert(p->vertexlist[kkk] <= in.numberofpoints && p->vertexlist[kkk] > 0);
}
in.facetmarkerlist[ibe] = K.lab;
}
if (verbosity > 1) {
cout << "tetgen: before tetrahedralize( , &in, &out);" << endl;
}
tetrahedralize(switch_tetgen, &in, &out);
if (verbosity > 1) {
cout << "tetgen: after tetrahedralize( , &in, &out);" << endl;
}
// mesh3_tetgenio_out( out, label_tet, *T_Th3);
Mesh3 *T_Th3 = mesh3_tetgenio_out(out, label_tet);
if (verbosity > 1) {
cout << " Finish Mesh3 tetgen :: Vertex, Element, Border" << T_Th3->nv << " " << T_Th3->nt << " " << T_Th3->nbe << endl;
cout << "FreeFem++: End check mesh given by tetgen" << endl;
}
return T_Th3;
}
Mesh3*RemplissageSurf3D_tetgen_new (char *switch_tetgen, const Mesh3 &Th3, const int &label_tet,
const int &nbhole, const double *tabhole,
const int &nbregion, const double *tabregion,
const int &nbfacecl, const double *tabfacecl) {
// Mesh3 *T_Th3= new Mesh3;