1 // Classes et fonctions XMeshLab
3 #include "MeshCut_Utils.hxx"
4 #include "MeshCut_Maillage.hxx"
6 #include "MeshCut_Carre.hxx"
7 #include "MeshCut_Cube.hxx"
9 #include "MeshCut_Fonctions.hxx"
10 #include "MeshCut_Cas.hxx"
12 #include "MeshCut_Globals.hxx"
19 using namespace MESHCUT;
22 // ================================== DECLARATION DES VARIABLES GLOBALES ==================================================
24 std::map<std::string, int> MESHCUT::intersections;
26 int MESHCUT::indexNouvellesMailles, MESHCUT::indexNouveauxNoeuds, MESHCUT::offsetMailles;
27 std::string MESHCUT::str_id_GMplus, MESHCUT::str_id_GMmoins;
28 Maillage *MESHCUT::MAILLAGE1, *MESHCUT::MAILLAGE2;
30 std::vector<float> MESHCUT::newXX, MESHCUT::newYY, MESHCUT::newZZ;
31 std::map<TYPE_MAILLE, std::vector<int> > MESHCUT::newCNX;
32 std::map<TYPE_MAILLE, int> MESHCUT::cptNouvellesMailles;
33 std::map<TYPE_MAILLE, std::vector<int> > MESHCUT::GMplus, MESHCUT::GMmoins;
34 std::vector<int> MESHCUT::cutTetras;
39 std::string MESHCUT::str_id_maillagenew;
41 float MESHCUT::normale[3], MESHCUT::pointPlan[3];
43 float MESHCUT::epsilon;
48 // ================================== PROGRAMME PRINCIPAL ==================================================
50 int main(int argc, char *argv[])
66 throw std::exception();
67 char *ficMEDin0 = argv[1];
68 ficMEDin = (string) ficMEDin0;
69 char *ficMEDout0 = argv[2];
70 ficMEDout = (string) ficMEDout0;
71 char *id_maillagenew = argv[3];
72 str_id_maillagenew = (string) id_maillagenew;
75 char *id_GMplus = argv[4];
76 str_id_GMplus = (string) id_GMplus;
77 char *id_GMmoins = argv[5];
78 str_id_GMmoins = (string) id_GMmoins;
80 // Vecteur normal au plan de coupe
81 char *charxn = argv[6];
82 xNormal = char2float(charxn);
83 char *charyn = argv[7];
84 yNormal = char2float(charyn);
85 char *charzn = argv[8];
86 zNormal = char2float(charzn);
88 // Point du plan de coupe
89 char *charxm = argv[9];
90 xm = char2float(charxm);
91 char *charym = argv[10];
92 ym = char2float(charym);
93 char *charzm = argv[11];
94 zm = char2float(charzm);
96 // Tolérance : epsilon = tolérance * longueur arête moyenne - où epsilon est la tolérance absolue (distance)
97 char *chtolerance = argv[12];
98 tolerance = char2float(chtolerance);
103 cout << " Cut a tetrahedron mesh by a plane" << endl;
104 cout << " ---------------------------------" << endl;
105 cout << "Syntax:" << endl << endl;
106 cout << argv[0] << " input.med output.med resuMeshName aboveGroup belowGroup nx ny nz px py pz T " << endl;
107 cout << endl << "where:" << endl;
108 cout << " input.med = name of the original mesh file in med format" << endl;
109 cout << " output.med = name of the result mesh file in med format" << endl;
110 cout << " resuMeshName = name of the result mesh" << endl;
111 cout << " aboveGroup = name of the group of volumes above the cut plane" << endl;
112 cout << " belowGroups = name of the group of volumes below the cut plane" << endl;
113 cout << " nx ny nz = vector normal to the cut plane" << endl;
114 cout << " px py pz = a point of the cut plane" << endl;
115 cout << " T = 0 < T < 1 : vertices of a tetrahedron are considered as belonging" << endl;
116 cout << " the cut plane if their distance to the plane is inferior to L*T" << endl;
117 cout << " where L is the mean edge size of the tetrahedron" << endl;
118 ERREUR("--> check arguments!");
121 cout << "Cut by a plane :" << endl;
122 cout << " source mesh: " << ficMEDin << endl;
123 cout << " result mesh: " << ficMEDout << endl;
124 cout << " mesh name: " << str_id_maillagenew << endl;
125 cout << " group above plane: " << str_id_GMplus << endl;
126 cout << " group below plane: " << str_id_GMmoins << endl;
127 cout << " vector normal to the cut plane: xn=" << xNormal << " yn=" << yNormal << " zn=" << zNormal << endl;
128 cout << " point in the cut plane: xm=" << xm << " ym=" << ym << " zm=" << zm << endl;
129 cout << " tolerance: " << tolerance << endl;
132 if (tolerance <= 0.0)
133 ERREUR("Tolerance must not be negative or null");
135 // Il faut normer la normale
136 float normeNormal = sqrt(xNormal * xNormal + yNormal * yNormal + zNormal * zNormal);
137 if (normeNormal == 0.0)
138 ERREUR("null normal vector");
139 normale[0] = xNormal / normeNormal;
140 normale[1] = yNormal / normeNormal;
141 normale[2] = zNormal / normeNormal;
147 // Calcul du coefficient d de l'équation du plan xn x + yn y + zn n + d = 0
148 d = -normale[0] * xm - normale[1] * ym - normale[2] * zm;
150 intersections.clear();
152 // Initialisation des compteurs de nouvelles mailles
153 for (int itm = (int) POI1; itm <= (int) HEXA20; itm++)
155 TYPE_MAILLE tm = (TYPE_MAILLE) itm;
156 cptNouvellesMailles[tm] = 0;
160 int S[4]; // Signature du T4 courant
161 //int NG[4]; // Num. globaux des sommets
163 // Acquisition maillage initial
164 //cout << chrono() << " - Acquisition du maillage initial" << endl;
165 MAILLAGE1 = new Maillage((string) "TEMP");
166 MAILLAGE1->inputMED(ficMEDin);
167 cout << chrono() << " - End of mesh read" << endl;
168 indexNouveauxNoeuds = MAILLAGE1->nombreNoeudsMaillage;
170 // Le maillage ne contient aucun TETRA4 : on rend le maillage initial sans modification
171 if (!MAILLAGE1->EFFECTIFS_TYPES[TETRA4])
173 cout << "WARNING: mesh does not contain tetra4 elements, it will not be modified" << endl;
174 MAILLAGE1->ID = str_id_maillagenew;
175 MAILLAGE1->outputMED(ficMEDout);
176 cout << chrono() << " - Finished!" << endl << endl;
179 // A partir de cet instant le maillage contient forcément des TETRA4
182 // Chargement des distances noeud-plan DNP
183 DNP = (float*) malloc(sizeof(float) * MAILLAGE1->nombreNoeudsMaillage);
184 for (int k = 0; k < MAILLAGE1->nombreNoeudsMaillage; k++)
185 DNP[k] = distanceNoeudPlan(k + 1);
186 cout << chrono() << " - End of computation of distances between nodes and plane" << endl;
188 // Longueur d'arête moyenne des T4 intersectant le plan de coupe
189 float LONGUEURS = 0.0;
190 int cptLONGUEURS = 0;
191 for (int it4 = 0; it4 < MAILLAGE1->EFFECTIFS_TYPES[TETRA4]; it4++)
195 int *offset = MAILLAGE1->CNX[TETRA4] + 4 * it4;
196 for (int is = 0; is < 4; is++)
198 int ng = *(offset + is);
199 if (DNP[ng - 1] > 0.0)
201 else if (DNP[ng - 1] < 0.0)
206 // Ce tetra est à cheval sur le plan de coupe: on calcule ses longueurs d'arêtes
207 LONGUEURS += longueurSegment(*(offset + 0), *(offset + 1));
209 LONGUEURS += longueurSegment(*(offset + 0), *(offset + 2));
211 LONGUEURS += longueurSegment(*(offset + 0), *(offset + 3));
213 LONGUEURS += longueurSegment(*(offset + 1), *(offset + 2));
215 LONGUEURS += longueurSegment(*(offset + 1), *(offset + 3));
217 LONGUEURS += longueurSegment(*(offset + 2), *(offset + 3));
222 // Aucun TETRA4 intercepté par le plan de coupe : on rend MAILLAGE1
223 if (cptLONGUEURS == 0)
226 << "WARNING: the cut plane does not cut any tetra4 element, initial mesh will not be modified"
228 MAILLAGE1->ID = str_id_maillagenew;
229 MAILLAGE1->outputMED(ficMEDout);
230 cout << chrono() << " - Finished!" << endl << endl;
233 // A partir de cet instant le maillage contient forcément des TETRA4 intersectant le plan de coupe
236 float longueurMoyenne = LONGUEURS / cptLONGUEURS;
237 epsilon = tolerance * longueurMoyenne;
239 int nT4coupe = cptLONGUEURS / 6;
240 cout << chrono() << " - End of computation of mean length of tetra4 edges near the cut plane" << endl;
242 cout << "Number of tetra4 to be cut = " << nT4coupe << endl;
243 cout << "Mean length = " << longueurMoyenne << endl;
244 cout << "Tolerance = " << tolerance << endl;
245 cout << "Epsilon = " << epsilon << endl;
247 // Détermination des positions de noeuds par rapport au plan de coupe - POSN
248 POSN = (int*) malloc(sizeof(int) * MAILLAGE1->nombreNoeudsMaillage);
249 for (int k = 0; k < MAILLAGE1->nombreNoeudsMaillage; k++)
251 if (DNP[k] > epsilon)
253 else if (DNP[k] < -epsilon)
258 cout << chrono() << " - End of nodes qualification above or below the cut plane" << endl;
259 cout << "Start of iteration on tetra4" << endl;
261 for (int it4 = 0; it4 < MAILLAGE1->EFFECTIFS_TYPES[TETRA4]; it4++)
264 for (int is = 0; is < 4; is++)
266 int ng = *(MAILLAGE1->CNX[TETRA4] + 4 * it4 + is);
268 S[is] = *(POSN + ng - 1);
271 // -------------------------------------------------------------------
273 if (S[0] == -1 && S[1] == -1 && S[2] == -1 && S[3] == -1)
274 GMmoins[TETRA4].push_back(it4);
276 else if (S[0] == -1 && S[1] == -1 && S[2] == -1 && S[3] == 0)
277 GMmoins[TETRA4].push_back(it4);
279 else if (S[0] == -1 && S[1] == -1 && S[2] == -1 && S[3] == 1)
280 { // Cas 3 - Arêtes 2 4 5
283 V[2] = intersectionSegmentPlan(it4, 2);
285 V[4] = intersectionSegmentPlan(it4, 4);
286 V[5] = intersectionSegmentPlan(it4, 5);
290 // -------------------------------------------------------------------
292 else if (S[0] == -1 && S[1] == -1 && S[2] == 0 && S[3] == -1)
293 GMmoins[TETRA4].push_back(it4);
295 else if (S[0] == -1 && S[1] == -1 && S[2] == 0 && S[3] == 0)
296 GMmoins[TETRA4].push_back(it4);
298 else if (S[0] == -1 && S[1] == -1 && S[2] == 0 && S[3] == 1)
299 { // Cas 2, arêtes 2 4
302 V[2] = intersectionSegmentPlan(it4, 2);
304 V[4] = intersectionSegmentPlan(it4, 4);
309 // -------------------------------------------------------------------
311 else if (S[0] == -1 && S[1] == -1 && S[2] == 1 && S[3] == -1)
312 { // Cas 3, arêtes 1 3 5
314 V[1] = intersectionSegmentPlan(it4, 1);
316 V[3] = intersectionSegmentPlan(it4, 3);
318 V[5] = intersectionSegmentPlan(it4, 5);
322 else if (S[0] == -1 && S[1] == -1 && S[2] == 1 && S[3] == 0)
323 { // Cas 2, arêtes 1 3
325 V[1] = intersectionSegmentPlan(it4, 1);
327 V[3] = intersectionSegmentPlan(it4, 3);
333 else if (S[0] == -1 && S[1] == -1 && S[2] == 1 && S[3] == 1)
334 { // Cas 4, arêtes 1 2 3 4
336 V[1] = intersectionSegmentPlan(it4, 1);
337 V[2] = intersectionSegmentPlan(it4, 2);
338 V[3] = intersectionSegmentPlan(it4, 3);
339 V[4] = intersectionSegmentPlan(it4, 4);
344 // -------------------------------------------------------------------
346 else if (S[0] == -1 && S[1] == 0 && S[2] == -1 && S[3] == -1)
347 GMmoins[TETRA4].push_back(it4);
349 else if (S[0] == -1 && S[1] == 0 && S[2] == -1 && S[3] == 0)
350 GMmoins[TETRA4].push_back(it4);
352 else if (S[0] == -1 && S[1] == 0 && S[2] == -1 && S[3] == 1)
353 { // Cas 2, arêtes 2 5
356 V[2] = intersectionSegmentPlan(it4, 2);
359 V[5] = intersectionSegmentPlan(it4, 5);
363 // -------------------------------------------------------------------
365 else if (S[0] == -1 && S[1] == 0 && S[2] == 0 && S[3] == -1)
366 GMmoins[TETRA4].push_back(it4);
368 else if (S[0] == -1 && S[1] == 0 && S[2] == 0 && S[3] == 0)
369 GMmoins[TETRA4].push_back(it4);
371 else if (S[0] == -1 && S[1] == 0 && S[2] == 0 && S[3] == 1)
375 V[2] = intersectionSegmentPlan(it4, 2);
382 // -------------------------------------------------------------------
384 else if (S[0] == -1 && S[1] == 0 && S[2] == 1 && S[3] == -1)
385 { // Cas 2, arêtes 1 5
387 V[1] = intersectionSegmentPlan(it4, 1);
391 V[5] = intersectionSegmentPlan(it4, 5);
395 else if (S[0] == -1 && S[1] == 0 && S[2] == 1 && S[3] == 0)
398 V[1] = intersectionSegmentPlan(it4, 1);
406 else if (S[0] == -1 && S[1] == 0 && S[2] == 1 && S[3] == 1)
407 { // Cas 2, arêtes 1 2
409 V[1] = intersectionSegmentPlan(it4, 1);
410 V[2] = intersectionSegmentPlan(it4, 2);
417 // -------------------------------------------------------------------
419 else if (S[0] == -1 && S[1] == 1 && S[2] == -1 && S[3] == -1)
420 { // Cas 3, arêtes 0 3 4
421 V[0] = intersectionSegmentPlan(it4, 0);
424 V[3] = intersectionSegmentPlan(it4, 3);
425 V[4] = intersectionSegmentPlan(it4, 4);
430 else if (S[0] == -1 && S[1] == 1 && S[2] == -1 && S[3] == 0)
431 { // Cas 2, arêtes 0 3
432 V[0] = intersectionSegmentPlan(it4, 0);
435 V[3] = intersectionSegmentPlan(it4, 3);
441 else if (S[0] == -1 && S[1] == 1 && S[2] == -1 && S[3] == 1)
442 { // Cas 4, arêtes 0 2 3 5
443 V[0] = intersectionSegmentPlan(it4, 0);
445 V[2] = intersectionSegmentPlan(it4, 2);
446 V[3] = intersectionSegmentPlan(it4, 3);
448 V[5] = intersectionSegmentPlan(it4, 5);
452 // -------------------------------------------------------------------
454 else if (S[0] == -1 && S[1] == 1 && S[2] == 0 && S[3] == -1)
455 { // Cas 2, arêtes 0 4
456 V[0] = intersectionSegmentPlan(it4, 0);
460 V[4] = intersectionSegmentPlan(it4, 4);
465 else if (S[0] == -1 && S[1] == 1 && S[2] == 0 && S[3] == 0)
467 V[0] = intersectionSegmentPlan(it4, 0);
476 else if (S[0] == -1 && S[1] == 1 && S[2] == 0 && S[3] == 1)
477 { // Cas 2, arêtes 0 2
478 V[0] = intersectionSegmentPlan(it4, 0);
480 V[2] = intersectionSegmentPlan(it4, 2);
487 // -------------------------------------------------------------------
489 else if (S[0] == -1 && S[1] == 1 && S[2] == 1 && S[3] == -1)
490 { // Cas 4, arêtes 0 1 4 5
491 V[0] = intersectionSegmentPlan(it4, 0);
492 V[1] = intersectionSegmentPlan(it4, 1);
495 V[4] = intersectionSegmentPlan(it4, 4);
496 V[5] = intersectionSegmentPlan(it4, 5);
500 else if (S[0] == -1 && S[1] == 1 && S[2] == 1 && S[3] == 0)
501 { // Cas 2, arêtes 0 1
502 V[0] = intersectionSegmentPlan(it4, 0);
503 V[1] = intersectionSegmentPlan(it4, 1);
511 else if (S[0] == -1 && S[1] == 1 && S[2] == 1 && S[3] == 1)
512 { // Cas 3, arêtes 0 1 2
513 V[0] = intersectionSegmentPlan(it4, 0);
514 V[1] = intersectionSegmentPlan(it4, 1);
515 V[2] = intersectionSegmentPlan(it4, 2);
522 // -------------------------------------------------------------------
524 else if (S[0] == 0 && S[1] == -1 && S[2] == -1 && S[3] == -1)
525 GMmoins[TETRA4].push_back(it4);
527 else if (S[0] == 0 && S[1] == -1 && S[2] == -1 && S[3] == 0)
528 GMmoins[TETRA4].push_back(it4);
530 else if (S[0] == 0 && S[1] == -1 && S[2] == -1 && S[3] == 1)
531 { // Cas 2, arêtes 4 5
536 V[4] = intersectionSegmentPlan(it4, 4);
537 V[5] = intersectionSegmentPlan(it4, 5);
541 // -------------------------------------------------------------------
543 else if (S[0] == 0 && S[1] == -1 && S[2] == 0 && S[3] == -1)
544 GMmoins[TETRA4].push_back(it4);
546 else if (S[0] == 0 && S[1] == -1 && S[2] == 0 && S[3] == 0)
547 GMmoins[TETRA4].push_back(it4);
549 else if (S[0] == 0 && S[1] == -1 && S[2] == 0 && S[3] == 1)
555 V[4] = intersectionSegmentPlan(it4, 4);
560 // -------------------------------------------------------------------
562 else if (S[0] == 0 && S[1] == -1 && S[2] == 1 && S[3] == -1)
563 { // Cas 2, arêtes 3 5
567 V[3] = intersectionSegmentPlan(it4, 3);
569 V[5] = intersectionSegmentPlan(it4, 5);
573 else if (S[0] == 0 && S[1] == -1 && S[2] == 1 && S[3] == 0)
578 V[3] = intersectionSegmentPlan(it4, 3);
584 else if (S[0] == 0 && S[1] == -1 && S[2] == 1 && S[3] == 1)
585 { // Cas 2, arêtes 3 4
589 V[3] = intersectionSegmentPlan(it4, 3);
590 V[4] = intersectionSegmentPlan(it4, 4);
595 // -------------------------------------------------------------------
597 else if (S[0] == 0 && S[1] == 0 && S[2] == -1 && S[3] == -1)
598 GMmoins[TETRA4].push_back(it4);
600 else if (S[0] == 0 && S[1] == 0 && S[2] == -1 && S[3] == 0)
601 GMmoins[TETRA4].push_back(it4);
603 else if (S[0] == 0 && S[1] == 0 && S[2] == -1 && S[3] == 1)
610 V[5] = intersectionSegmentPlan(it4, 5);
614 // -------------------------------------------------------------------
616 else if (S[0] == 0 && S[1] == 0 && S[2] == 0 && S[3] == -1)
617 GMmoins[TETRA4].push_back(it4);
619 else if (S[0] == 0 && S[1] == 0 && S[2] == 0 && S[3] == 0)
621 cout << "WARNING: TETRA4 number " << it4
622 << " entirely in the tolerance zone near the cut plane" << endl;
623 cout << " --> affected to group " << str_id_GMmoins << endl;
624 GMmoins[TETRA4].push_back(it4);
627 else if (S[0] == 0 && S[1] == 0 && S[2] == 0 && S[3] == 1)
628 GMplus[TETRA4].push_back(it4);
630 // -------------------------------------------------------------------
632 else if (S[0] == 0 && S[1] == 0 && S[2] == 1 && S[3] == -1)
639 V[5] = intersectionSegmentPlan(it4, 5);
643 else if (S[0] == 0 && S[1] == 0 && S[2] == 1 && S[3] == 0)
644 GMplus[TETRA4].push_back(it4);
646 else if (S[0] == 0 && S[1] == 0 && S[2] == 1 && S[3] == 1)
647 GMplus[TETRA4].push_back(it4);
649 // -------------------------------------------------------------------
651 else if (S[0] == 0 && S[1] == 1 && S[2] == -1 && S[3] == -1)
652 { // Cas 2, arêtes 3 4
656 V[3] = intersectionSegmentPlan(it4, 3);
657 V[4] = intersectionSegmentPlan(it4, 4);
662 else if (S[0] == 0 && S[1] == 1 && S[2] == -1 && S[3] == 0)
667 V[3] = intersectionSegmentPlan(it4, 3);
673 else if (S[0] == 0 && S[1] == 1 && S[2] == -1 && S[3] == 1)
674 { // Cas 2, arêtes 3 5
678 V[3] = intersectionSegmentPlan(it4, 3);
680 V[5] = intersectionSegmentPlan(it4, 5);
684 // -------------------------------------------------------------------
686 else if (S[0] == 0 && S[1] == 1 && S[2] == 0 && S[3] == -1)
692 V[4] = intersectionSegmentPlan(it4, 4);
697 else if (S[0] == 0 && S[1] == 1 && S[2] == 0 && S[3] == 0)
698 GMplus[TETRA4].push_back(it4);
700 else if (S[0] == 0 && S[1] == 1 && S[2] == 0 && S[3] == 1)
701 GMplus[TETRA4].push_back(it4);
703 // -------------------------------------------------------------------
705 else if (S[0] == 0 && S[1] == 1 && S[2] == 1 && S[3] == -1)
706 { // Cas 2, arêtes 4 5
711 V[4] = intersectionSegmentPlan(it4, 4);
712 V[5] = intersectionSegmentPlan(it4, 5);
716 else if (S[0] == 0 && S[1] == 1 && S[2] == 1 && S[3] == 0)
717 GMplus[TETRA4].push_back(it4);
719 else if (S[0] == 0 && S[1] == 1 && S[2] == 1 && S[3] == 1)
720 GMplus[TETRA4].push_back(it4);
722 // -------------------------------------------------------------------
724 else if (S[0] == 1 && S[1] == -1 && S[2] == -1 && S[3] == -1)
725 { // Cas 3, arêtes 0 1 2
726 V[0] = intersectionSegmentPlan(it4, 0);
727 V[1] = intersectionSegmentPlan(it4, 1);
728 V[2] = intersectionSegmentPlan(it4, 2);
735 else if (S[0] == 1 && S[1] == -1 && S[2] == -1 && S[3] == 0)
736 { // Cas 2, arêtes 0 1
737 V[0] = intersectionSegmentPlan(it4, 0);
738 V[1] = intersectionSegmentPlan(it4, 1);
746 else if (S[0] == 1 && S[1] == -1 && S[2] == -1 && S[3] == 1)
747 { // Cas 4, arêtes 0 1 4 5
748 V[0] = intersectionSegmentPlan(it4, 0);
749 V[1] = intersectionSegmentPlan(it4, 1);
752 V[4] = intersectionSegmentPlan(it4, 4);
753 V[5] = intersectionSegmentPlan(it4, 5);
757 // -------------------------------------------------------------------
759 else if (S[0] == 1 && S[1] == -1 && S[2] == 0 && S[3] == -1)
760 { // Cas 2, arêtes 0 2
761 V[0] = intersectionSegmentPlan(it4, 0);
763 V[2] = intersectionSegmentPlan(it4, 2);
770 else if (S[0] == 1 && S[1] == -1 && S[2] == 0 && S[3] == 0)
772 V[0] = intersectionSegmentPlan(it4, 0);
781 else if (S[0] == 1 && S[1] == -1 && S[2] == 0 && S[3] == 1)
782 { // Cas 2, arêtes 0 4
783 V[0] = intersectionSegmentPlan(it4, 0);
787 V[4] = intersectionSegmentPlan(it4, 4);
792 // -------------------------------------------------------------------
794 else if (S[0] == 1 && S[1] == -1 && S[2] == 1 && S[3] == -1)
795 { // Cas 4, arêtes 0 2 3 5
796 V[0] = intersectionSegmentPlan(it4, 0);
798 V[2] = intersectionSegmentPlan(it4, 2);
799 V[3] = intersectionSegmentPlan(it4, 3);
801 V[5] = intersectionSegmentPlan(it4, 5);
805 else if (S[0] == 1 && S[1] == -1 && S[2] == 1 && S[3] == 0)
806 { // Cas 2, arêtes 0 3
807 V[0] = intersectionSegmentPlan(it4, 0);
810 V[3] = intersectionSegmentPlan(it4, 3);
816 else if (S[0] == 1 && S[1] == -1 && S[2] == 1 && S[3] == 1)
817 { // Cas 3, arêtes 0 3 4
818 V[0] = intersectionSegmentPlan(it4, 0);
821 V[3] = intersectionSegmentPlan(it4, 3);
822 V[4] = intersectionSegmentPlan(it4, 4);
827 // -------------------------------------------------------------------
829 else if (S[0] == 1 && S[1] == 0 && S[2] == -1 && S[3] == -1)
830 { // Cas 2, arêtes 1 2
832 V[1] = intersectionSegmentPlan(it4, 1);
833 V[2] = intersectionSegmentPlan(it4, 2);
840 else if (S[0] == 1 && S[1] == 0 && S[2] == -1 && S[3] == 0)
843 V[1] = intersectionSegmentPlan(it4, 1);
851 else if (S[0] == 1 && S[1] == 0 && S[2] == -1 && S[3] == 1)
852 { // Cas 2, arêtes 1 5
854 V[1] = intersectionSegmentPlan(it4, 1);
858 V[5] = intersectionSegmentPlan(it4, 5);
862 // -------------------------------------------------------------------
864 else if (S[0] == 1 && S[1] == 0 && S[2] == 0 && S[3] == -1)
868 V[2] = intersectionSegmentPlan(it4, 2);
875 else if (S[0] == 1 && S[1] == 0 && S[2] == 0 && S[3] == 0)
876 GMplus[TETRA4].push_back(it4);
878 else if (S[0] == 1 && S[1] == 0 && S[2] == 0 && S[3] == 1)
879 GMplus[TETRA4].push_back(it4);
881 // -------------------------------------------------------------------
883 else if (S[0] == 1 && S[1] == 0 && S[2] == 1 && S[3] == -1)
884 { // Cas 2, arêtes 2 5
887 V[2] = intersectionSegmentPlan(it4, 2);
890 V[5] = intersectionSegmentPlan(it4, 5);
894 else if (S[0] == 1 && S[1] == 0 && S[2] == 1 && S[3] == 0)
895 GMplus[TETRA4].push_back(it4);
897 else if (S[0] == 1 && S[1] == 0 && S[2] == 1 && S[3] == 1)
898 GMplus[TETRA4].push_back(it4);
900 // -------------------------------------------------------------------
902 else if (S[0] == 1 && S[1] == 1 && S[2] == -1 && S[3] == -1)
903 { // Cas 4, arêtes 1 2 3 4
905 V[1] = intersectionSegmentPlan(it4, 1);
906 V[2] = intersectionSegmentPlan(it4, 2);
907 V[3] = intersectionSegmentPlan(it4, 3);
908 V[4] = intersectionSegmentPlan(it4, 4);
913 else if (S[0] == 1 && S[1] == 1 && S[2] == -1 && S[3] == 0)
914 { // Cas 2, arêtes 1 3
916 V[1] = intersectionSegmentPlan(it4, 1);
918 V[3] = intersectionSegmentPlan(it4, 3);
924 else if (S[0] == 1 && S[1] == 1 && S[2] == -1 && S[3] == 1)
925 { // Cas 3, arêtes 1 3 5
927 V[1] = intersectionSegmentPlan(it4, 1);
929 V[3] = intersectionSegmentPlan(it4, 3);
931 V[5] = intersectionSegmentPlan(it4, 5);
935 // -------------------------------------------------------------------
937 else if (S[0] == 1 && S[1] == 1 && S[2] == 0 && S[3] == -1)
938 { // Cas 2, arêtes 2 4
941 V[2] = intersectionSegmentPlan(it4, 2);
943 V[4] = intersectionSegmentPlan(it4, 4);
948 else if (S[0] == 1 && S[1] == 1 && S[2] == 0 && S[3] == 0)
949 GMplus[TETRA4].push_back(it4);
951 else if (S[0] == 1 && S[1] == 1 && S[2] == 0 && S[3] == 1)
952 GMplus[TETRA4].push_back(it4);
954 // -------------------------------------------------------------------
956 else if (S[0] == 1 && S[1] == 1 && S[2] == 1 && S[3] == -1)
957 { // Cas 3, arêtes 2 4 5
960 V[2] = intersectionSegmentPlan(it4, 2);
962 V[4] = intersectionSegmentPlan(it4, 4);
963 V[5] = intersectionSegmentPlan(it4, 5);
967 else if (S[0] == 1 && S[1] == 1 && S[2] == 1 && S[3] == 0)
968 GMplus[TETRA4].push_back(it4);
970 else if (S[0] == 1 && S[1] == 1 && S[2] == 1 && S[3] == 1)
971 GMplus[TETRA4].push_back(it4);
974 ERREUR("Case not taken into account");
977 cout << chrono() << " - End of iteration on tetra4" << endl;
979 // cout << "indexNouveauxNoeuds = " << indexNouveauxNoeuds << endl;
980 newXX.resize(indexNouveauxNoeuds - MAILLAGE1->nombreNoeudsMaillage);
981 newYY.resize(indexNouveauxNoeuds - MAILLAGE1->nombreNoeudsMaillage);
982 newZZ.resize(indexNouveauxNoeuds - MAILLAGE1->nombreNoeudsMaillage);
984 if (cptNouvellesMailles[TETRA4])
985 newCNX[TETRA4].resize(4 * cptNouvellesMailles[TETRA4]);
986 if (cptNouvellesMailles[PYRAM5])
987 newCNX[PYRAM5].resize(5 * cptNouvellesMailles[PYRAM5]);
988 if (cptNouvellesMailles[PENTA6])
989 newCNX[PENTA6].resize(6 * cptNouvellesMailles[PENTA6]);
991 // =========================================================================================
992 // 2. Constitution du maillage final
993 // =========================================================================================
995 cout << chrono() << " - Constitution of final mesh" << endl;
997 MAILLAGE2 = new Maillage(str_id_maillagenew);
998 MAILLAGE2->dimensionMaillage = MAILLAGE1->dimensionMaillage;
999 MAILLAGE2->dimensionEspace = MAILLAGE1->dimensionEspace;
1000 strcpy(MAILLAGE2->axisname, MAILLAGE1->axisname);
1001 strcpy(MAILLAGE2->unitname, MAILLAGE1->unitname);
1002 MAILLAGE2->nombreNoeudsMaillage = indexNouveauxNoeuds;
1003 MAILLAGE2->nombreMaillesMaillage = MAILLAGE1->nombreMaillesMaillage + cptNouvellesMailles[TETRA4]
1004 + cptNouvellesMailles[PYRAM5] + cptNouvellesMailles[PENTA6];
1006 // ---------- Coordonnées
1007 // Optimisation de la mémoire au détriment du temps
1009 // Héritage des coordonnées MAILLAGE1
1010 MAILLAGE2->XX = (float*) malloc(sizeof(float) * MAILLAGE2->nombreNoeudsMaillage);
1011 for (int i = 0; i < MAILLAGE1->nombreNoeudsMaillage; i++)
1012 *(MAILLAGE2->XX + i) = *(MAILLAGE1->XX + i);
1013 free(MAILLAGE1->XX);
1014 MAILLAGE2->YY = (float*) malloc(sizeof(float) * MAILLAGE2->nombreNoeudsMaillage);
1015 for (int i = 0; i < MAILLAGE1->nombreNoeudsMaillage; i++)
1016 *(MAILLAGE2->YY + i) = *(MAILLAGE1->YY + i);
1017 free(MAILLAGE1->YY);
1018 MAILLAGE2->ZZ = (float*) malloc(sizeof(float) * MAILLAGE2->nombreNoeudsMaillage);
1019 for (int i = 0; i < MAILLAGE1->nombreNoeudsMaillage; i++)
1020 *(MAILLAGE2->ZZ + i) = *(MAILLAGE1->ZZ + i);
1021 free(MAILLAGE1->ZZ);
1023 // Coordonnées des noeuds créés
1024 for (int i = 0; i < MAILLAGE2->nombreNoeudsMaillage - MAILLAGE1->nombreNoeudsMaillage; i++)
1026 *(MAILLAGE2->XX + MAILLAGE1->nombreNoeudsMaillage + i) = newXX[i];
1027 *(MAILLAGE2->YY + MAILLAGE1->nombreNoeudsMaillage + i) = newYY[i];
1028 *(MAILLAGE2->ZZ + MAILLAGE1->nombreNoeudsMaillage + i) = newZZ[i];
1029 // cout << "Nouveaux noeuds, indice " << i << " : " << newXX[i] << " " << newYY[i] << " " << newZZ[i] << " " << endl;
1032 // Legacy mailles maillage 1 (volumes seulement)
1033 for (int itm = (int) TETRA4; itm <= (int) HEXA20; itm++)
1035 TYPE_MAILLE tm = (TYPE_MAILLE) itm;
1036 if (tm != TETRA4 && tm != PYRAM5 && tm != PENTA6)
1038 // Pour les types autres que TETRA4 PYRAM5 PENTA6 on fait seulement pointer CNX2 vers CNX1
1039 if (MAILLAGE1->EFFECTIFS_TYPES[tm])
1040 MAILLAGE2->CNX[tm] = MAILLAGE1->CNX[tm];
1041 MAILLAGE2->EFFECTIFS_TYPES[tm] = MAILLAGE1->EFFECTIFS_TYPES[tm];
1045 // Pour les types TETRA4 PYRAM5 PENTA6 on recopie CNX1 et on ajoute à la suite les newCNX
1046 // cout << "Legacy " << tm << " effectif " << MAILLAGE1->EFFECTIFS_TYPES[tm] << endl;
1047 int tailleType = Nnoeuds(tm);
1049 MAILLAGE2->CNX[tm] = (int*) malloc(sizeof(int) * tailleType * (MAILLAGE1->EFFECTIFS_TYPES[tm]
1050 + cptNouvellesMailles[tm]));
1051 for (int i = 0; i < MAILLAGE1->EFFECTIFS_TYPES[tm]; i++)
1052 for (int j = 0; j < tailleType; j++)
1053 *(MAILLAGE2->CNX[tm] + tailleType * i + j) = *(MAILLAGE1->CNX[tm] + tailleType * i + j);
1055 for (int i = 0; i < cptNouvellesMailles[tm]; i++)
1056 for (int j = 0; j < tailleType; j++)
1057 *(MAILLAGE2->CNX[tm] + tailleType * (MAILLAGE1->EFFECTIFS_TYPES[tm] + i) + j) = newCNX[tm][i * tailleType
1060 MAILLAGE2->EFFECTIFS_TYPES[tm] = MAILLAGE1->EFFECTIFS_TYPES[tm] + cptNouvellesMailles[tm];
1066 // cout << "Maillage 2 - CNX TETRA4 : " << endl;
1068 // for (int i = 0; i < MAILLAGE2->EFFECTIFS_TYPES[TETRA4]; i++)
1070 // cout << "Maille " << i << " : ";
1071 // for (int j = 0; j < 4; j++)
1072 // cout << MAILLAGE2->CNX[TETRA4][i * 4 + j] << " ";
1076 // cout << "Maillage 2 - CNX PENTA6 : " << endl;
1078 // for (int i = 0; i < MAILLAGE2->EFFECTIFS_TYPES[PENTA6]; i++)
1080 // cout << "Maille " << i << " : ";
1081 // for (int j = 0; j < 6; j++)
1082 // cout << MAILLAGE2->CNX[PENTA6][i * 6 + j] << " ";
1087 // Groupes de mailles
1088 MAILLAGE2->GM = MAILLAGE1->GM;
1089 MAILLAGE2->GM[str_id_GMplus] = GMplus;
1090 MAILLAGE2->GM[str_id_GMmoins] = GMmoins;
1092 MAILLAGE2->GN = MAILLAGE1->GN;
1094 MAILLAGE2->eliminationMailles(TETRA4, cutTetras);
1096 cout << chrono() << " - MED file writing" << endl;
1098 MAILLAGE2->outputMED(ficMEDout);
1099 cout << chrono() << " - Finished!" << endl << endl;