ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_mailleur2d.cpp
Revision: 64
Committed: Fri Feb 1 18:27:30 2008 UTC (17 years, 3 months ago) by foucault
Original Path: magic/lib/CAD4FE/CAD4FE/src/CAD4FE_mailleur2d.cpp
File size: 48078 byte(s)
Log Message:
mise a jour final these Gilles Foucault

File Contents

# User Rev Content
1 foucault 27 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuillière et Vincent FRANCOIS
5     // Département de Génie Mécanique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du département
8     // de génie mécanique de l'Université du Québec à
9     // Trois Rivières
10     // Les librairies ne peuvent être utilisées sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // mailleur2d.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 à 11H23
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include "CAD4FE_mailleur2d.h"
27     #include "ot_mathematique.h"
28     //#include "message.h"
29     //#include "affiche.h"
30     #include <fstream>
31     #include <math.h>
32     #include <time.h>
33    
34 foucault 64 #include <CAD4FE_MCEdge.h>
35     #include <CAD4FE_PolyCurve.h>
36 foucault 27 #include <CAD4FE_MCVertex.h>
37     #include "CAD4FE_geometric_tools.h"
38     #include "CAD4FE_InventorText_MG_MAILLAGE.h"
39     #include "CAD4FE_InventorText_MCSegment.h"
40     #include "CAD4FE_OptimizeEdgeSwap.h"
41    
42     using namespace CAD4FE;
43    
44     MAILLEUR2D::MAILLEUR2D(MG_MAILLAGE* mgmai,MG_GEOMETRIE *mggeo,MCFace* __mcFace,FCT_TAILLE* fct_taille):MAILLEUR(),mg_maillage(mgmai),mg_geometrie(mggeo),_mcFace(__mcFace),metrique(fct_taille)
45     {
46     strcpy(filenameNbTriangles,getenv("TEMP"));
47     strcat(filenameNbTriangles,"CAD4FE_mailleur2d.txt");
48     }
49    
50    
51    
52     MAILLEUR2D::~MAILLEUR2D()
53     {
54     }
55    
56    
57    
58    
59     void MAILLEUR2D::maille(void)
60     {
61     if (_mcFace!=NULL) maille(_mcFace);
62     else
63     {
64     // Il faudrait mailler les MC Face de la géométrie :
65     // A faire : une fonction qui parcours les MCFace de la géométrie
66     /* int nb_face=mg_geometrie->get_nb_mg_face();
67     for (int i=0;i<nb_face;i++)
68     {
69     MG_FACE* mgface=mg_geometrie->get_mg_face(i);
70     maille(mgface);
71     } */
72     }
73     }
74    
75     void MAILLEUR2D::maille(MCFace * __mcFace)
76     {
77     creation_metrique=0;
78     lst_tri_qual.clear();
79     //afficheur << MAILLAGEFACE << mgface->get_id() << endaff;
80     initialise_frontiere(__mcFace);
81     cree_grille(__mcFace);
82     initialise_front(__mcFace);
83    
84     if (metrique==NULL)
85     {
86     printf("Mailleur2D::Maille --> Abandon: \nLa fonction carte de taille doit être spécifiée !\n");
87     return;
88     }
89 foucault 64 progresse_front(__mcFace);
90     export_ivanim_all_faces();
91 foucault 27 if (debug){
92     char filename1[5000];
93     strcpy(filename1,getenv("TEMP"));
94     strcat(filename1,"\\void_2D.mai");
95     ofstream o4(filename1,ios::out|ios::trunc);
96     o4.precision(16);
97     o4.setf(ios::showpoint);
98     mg_maillage->enregistrer_sous_mesh_2D(o4);
99    
100     std::ofstream file;
101     char filename2[5000];
102     strcpy(filename2,getenv("TEMP"));
103     strcat(filename2,"\\CAD4FE_Mesher.iv");
104     file.open(filename2);
105     CAD4FE::InventorText_MG_MAILLAGE ivTextRefTess (mg_maillage);
106     ivTextRefTess.ShowFaceSegments = true;
107     ivTextRefTess.ShowSegmentId = false;
108     ivTextRefTess.ShowTriangleId = false;
109     ivTextRefTess.ShowNodeId = false;
110     ivTextRefTess.InverseTriangleNormals = true;
111     ivTextRefTess.TriangleColor=1;
112     file << ivTextRefTess.GetText();
113     file << "\n}\n";
114     file.close();
115     }
116     if ( 0 )
117     {
118     std::ofstream file;
119     char filename2[5000];
120     strcpy(filename2,getenv("TEMP"));
121     strcat(filename2,"\\CAD4FE_Mesher_MCSegments.iv");
122     file.open(filename2);
123     InventorText_MG_MAILLAGE meshIvText (mg_maillage);
124     meshIvText.ShowFaceSegments = true;
125     meshIvText.ShowSegmentId = true;
126     meshIvText.ShowTriangleId = true;
127     meshIvText.ShowNodeId = true;
128     meshIvText.InverseTriangleNormals = true;
129     meshIvText.TriangleColor=1;
130     file<<meshIvText.GetText();
131    
132     file << "DrawStyle {\nstyle LINES\nlineWidth 2\npointSize 3\n}\n";
133     LISTE_MG_SEGMENT::iterator itSegment;
134     for (MG_SEGMENT * seg = mg_maillage->get_premier_segment(itSegment); seg; seg = mg_maillage->get_suivant_segment(itSegment))
135     {
136     if (seg->get_lien_topologie()->get_dimension() == 1)
137     file << "BaseColor { \n rgb 0.0 0.0 0.9\n }\n";
138     if (seg->get_lien_topologie()->get_dimension() == 2)
139     file << "BaseColor { \n rgb 0.0 0.0 0.0\n }\n";
140     MCSegment * mcSeg = (MCSegment *) seg;
141     InventorText_MCSegment mcSegTxt (mcSeg);
142     file << mcSegTxt.GetText();
143     }
144    
145     file << "\n}\n";
146     file.close();
147     }
148    
149     optimise_bascule_segment(__mcFace);
150     optimise(__mcFace);
151    
152     {
153     std::ofstream file(filenameNbTriangles);
154     file.clear();
155     file.flush();
156     file.close();
157     }
158    
159    
160     if (creation_metrique==1)
161     {
162     delete metrique;
163     metrique=NULL;
164     }
165     delete grille_de_segment;
166     delete grille_de_frontiere;
167     delete grille_de_front;
168     segment_frontiere.vide();
169     noeud_frontiere.vide();
170     //ofstream o3("test_2D.mai",ios::out|ios::trunc);
171     //o3.precision(16);
172     //o3.setf(ios::showpoint);
173     //mg_maillage->enregistrer_sous_mesh_2D(o3);
174     }
175    
176 foucault 64 void MAILLEUR2D::export_ivanim()
177     {
178     MG_MAILLAGE * _mesh = mg_maillage;
179 foucault 27
180 foucault 64 std::string filename = "c:\\gilles\\out_";
181     filename += std::string(_mcFace->get_idoriginal())+".ivanim";
182 foucault 27
183 foucault 64 std::ofstream out(filename.c_str());
184     float sleepTime = .1;
185    
186     out << "sleepTime " << sleepTime<<" \n";
187     out << "groupTriang 5 \n";
188    
189     std::set <MG_ARETE*> lst_mg_edges;
190     std::set <MG_SOMMET*> lst_mg_vertices;
191     unsigned nb_loop = _mcFace->get_nb_mg_boucle();
192     for (unsigned it_loop = 0; it_loop < nb_loop; it_loop++)
193     {
194     MG_BOUCLE * loop = _mcFace->get_mg_boucle(it_loop);
195     unsigned nb_edge = loop->get_nb_mg_coarete();
196 foucault 27
197 foucault 64 for (unsigned it_edge = 0; it_edge < nb_edge; it_edge++)
198     {
199     MG_ARETE * edge = (MG_ARETE*)loop->get_mg_coarete(it_edge)->get_arete();
200     lst_mg_edges.insert(edge);
201 foucault 27
202 foucault 64 lst_mg_vertices.insert ((MG_SOMMET*)edge->get_cosommet1()->get_sommet());
203     lst_mg_vertices.insert ((MG_SOMMET*)edge->get_cosommet2()->get_sommet());
204     }
205     }
206    
207     LISTE_MG_TRIANGLE::iterator itTriang;
208     std::set <MG_NOEUD*>lst_mg_noeud;
209     for (MG_TRIANGLE * triangle = _mesh->get_premier_triangle(itTriang); triangle; triangle = _mesh->get_suivant_triangle(itTriang))
210     {
211     if (triangle->get_lien_topologie() == NULL || triangle->get_lien_topologie()->get_dimension() > 2
212     || (MG_FACE*)triangle->get_lien_topologie() != _mcFace)
213     continue;
214    
215     MG_NOEUD * nos[3]={triangle->get_noeud1(),triangle->get_noeud2(),triangle->get_noeud3()};
216     for (int i=0; i<3; i++)
217     {
218     MG_NOEUD * no = nos[i];
219     if (lst_mg_noeud.find(no) == lst_mg_noeud.end())
220     {
221     lst_mg_noeud.insert(no);
222     out << "add coord " << no->get_id() ;
223     out << " " << no->get_x();
224     out << " " << no->get_y() ;
225     out << " " << no->get_z() << " \n";
226     }
227     }
228     }
229    
230     LISTE_MG_NOEUD::iterator itNo;
231     int i=0;
232     for (MG_NOEUD * no = _mesh->get_premier_noeud(itNo); no; no=_mesh->get_suivant_noeud(itNo))
233     {
234     if (lst_mg_noeud.find(no) == lst_mg_noeud.end())
235     {
236     if (no->get_lien_topologie() != NULL && no->get_lien_topologie()->get_dimension() == 0
237     && lst_mg_vertices.find((MG_SOMMET*)no->get_lien_topologie()) != lst_mg_vertices.end())
238     out << "add node " << no->get_id()<<" \n";
239     }
240     }
241    
242    
243     LISTE_MG_SEGMENT::iterator itSegment;
244     for (MG_SEGMENT * seg = _mesh->get_premier_segment(itSegment); seg; seg = _mesh->get_suivant_segment(itSegment))
245     {
246     if (seg->get_lien_topologie() == NULL || seg->get_lien_topologie()->get_dimension() != 1 ||
247     lst_mg_edges.find((MG_ARETE*)seg->get_lien_topologie()) == lst_mg_edges.end())
248     continue;
249     out << "add segment " << seg->get_id() << " ";
250     out << seg->get_noeud1()->get_id() << " ";
251     out << seg->get_noeud2()->get_id() << " \n";
252     }
253    
254     for (MG_TRIANGLE * triangle = _mesh->get_premier_triangle(itTriang); triangle; triangle = _mesh->get_suivant_triangle(itTriang))
255     {
256     if (triangle->get_lien_topologie() == NULL || triangle->get_lien_topologie()->get_dimension() > 2
257     || (MG_FACE*)triangle->get_lien_topologie() != _mcFace)
258     continue;
259     out << "add triangle " << triangle->get_id() << " ";
260     out << triangle->get_noeud1()->get_id() << " ";
261     out << triangle->get_noeud3()->get_id() << " ";
262     out << triangle->get_noeud2()->get_id() << " \n";
263     }
264     /*
265    
266     void MAILLEUR2D::export_ivanim2()
267     for (std::set <MG_ARETE*>::iterator it_mg_edges = lst_mg_edges.begin(); it_mg_edges != lst_mg_edges.end(); it_mg_edges++)
268     {
269     MG_ARETE * edge = *it_mg_edges;
270     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = edge->get_lien_maillage();
271     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
272     MG_ELEMENT_MAILLAGE* element;
273     int nb = lien_maillage->get_nb();
274     int i=0;
275     for (element = lien_maillage->get_premier(it); i++ < nb && element ; element = lien_maillage->get_suivant(it) )
276     {
277     MG_SEGMENT * seg = (MG_SEGMENT *)element;
278     if (mg_maillage->contient(seg) == 0) continue;
279     out << "add segment " << seg->get_id() << " ";
280     out << seg->get_noeud1()->get_id() << " ";
281     out << seg->get_noeud2()->get_id() << " \n";
282     }
283     }
284    
285     for (std::set <MG_SOMMET*>::iterator it_mg_vertices = lst_mg_vertices.begin(); it_mg_vertices != lst_mg_vertices.end(); it_mg_vertices++)
286     {
287     MG_SOMMET * vertex = *it_mg_vertices;
288     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = vertex->get_lien_maillage();
289     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
290     MG_ELEMENT_MAILLAGE* element;
291     int nb = lien_maillage->get_nb();
292     int i=0;
293     for (element = lien_maillage->get_premier(it); i++ < nb && element ; element = lien_maillage->get_suivant(it) )
294     {
295     MG_NOEUD * node = (MG_NOEUD *)element;
296     if (mg_maillage->contient(node) == 0) continue;
297     }
298     } */
299     /*
300     std::map < MG_NOEUD * , unsigned int > indices;
301     LISTE_MG_NOEUD::iterator itNo;
302     int i=0;
303     for (MG_NOEUD * no = _mesh->get_premier_noeud(itNo); no; no=_mesh->get_suivant_noeud(itNo))
304     {
305     out << "add coord " << no->get_id() ;
306     out << " " << no->get_x();
307     out << " " << no->get_y() ;
308     out << " " << no->get_z() << " \n";
309     if (no->get_lien_topologie() != NULL && no->get_lien_topologie()->get_dimension() == 0)
310     out << "add node " << no->get_id()<<" \n";
311     }
312    
313     LISTE_MG_SEGMENT::iterator itSegment;
314     for (MG_SEGMENT * seg = _mesh->get_premier_segment(itSegment); seg; seg = _mesh->get_suivant_segment(itSegment))
315     {
316     if (seg->get_lien_topologie() == NULL || seg->get_lien_topologie()->get_dimension() != 1)
317     continue;
318     out << "add segment " << seg->get_id() << " ";
319     out << seg->get_noeud1()->get_id() << " ";
320     out << seg->get_noeud2()->get_id() << " \n";
321     } */
322    
323     /*LISTE_MG_TRIANGLE::iterator itTriang;
324     for (MG_TRIANGLE * triangle = _mesh->get_premier_triangle(itTriang); triangle; triangle = _mesh->get_suivant_triangle(itTriang))
325     {
326     if (triangle->get_lien_topologie() == NULL || triangle->get_lien_topologie()->get_dimension() > 2)
327     continue;
328     out << "add triangle " << triangle->get_id() << " ";
329     out << triangle->get_noeud1()->get_id() << " ";
330     out << triangle->get_noeud3()->get_id() << " ";
331     out << triangle->get_noeud2()->get_id() << " \n";
332     } */
333    
334     out.close();
335     }
336    
337    
338     void MAILLEUR2D::export_ivanim_all_faces()
339     {
340     MG_MAILLAGE * _mesh = mg_maillage;
341    
342     std::ofstream out("c:\\gilles\\out.ivanim");
343     float sleepTime = .1;
344    
345     out << "sleepTime " << sleepTime<<" \n";
346     out << "groupTriang 5 \n";
347    
348     std::map < MG_NOEUD * , unsigned int > indices;
349     LISTE_MG_NOEUD::iterator itNo;
350     int i=0;
351     for (MG_NOEUD * no = _mesh->get_premier_noeud(itNo); no; no=_mesh->get_suivant_noeud(itNo))
352     {
353     out << "add coord " << no->get_id() ;
354     out << " " << no->get_x();
355     out << " " << no->get_y() ;
356     out << " " << no->get_z() << " \n";
357     if (no->get_lien_topologie() != NULL && no->get_lien_topologie()->get_dimension() == 0)
358     out << "add node " << no->get_id()<<" \n";
359     }
360    
361     LISTE_MG_SEGMENT::iterator itSegment;
362     for (MG_SEGMENT * seg = _mesh->get_premier_segment(itSegment); seg; seg = _mesh->get_suivant_segment(itSegment))
363     {
364     if (seg->get_lien_topologie() == NULL || seg->get_lien_topologie()->get_dimension() != 1)
365     continue;
366     out << "add segment " << seg->get_id() << " ";
367     out << seg->get_noeud1()->get_id() << " ";
368     out << seg->get_noeud2()->get_id() << " \n";
369     }
370    
371     LISTE_MG_TRIANGLE::iterator itTriang;
372     for (MG_TRIANGLE * triangle = _mesh->get_premier_triangle(itTriang); triangle; triangle = _mesh->get_suivant_triangle(itTriang))
373     {
374     if (triangle->get_lien_topologie() == NULL || triangle->get_lien_topologie()->get_dimension() > 2)
375     continue;
376     out << "add triangle " << triangle->get_id() << " ";
377     out << triangle->get_noeud1()->get_id() << " ";
378     out << triangle->get_noeud3()->get_id() << " ";
379     out << triangle->get_noeud2()->get_id() << " \n";
380     }
381    
382     out.close();
383     }
384    
385 foucault 27 void MAILLEUR2D::initialise_frontiere(MCFace* __mcFace)
386     {
387     int nb_boucle=__mcFace->get_nb_mg_boucle();
388     for (int i=0;i<nb_boucle;i++)
389     {
390     MG_BOUCLE* mgboucle=__mcFace->get_mg_boucle(i);
391     int nb_coarete=mgboucle->get_nb_mg_coarete();
392     for (int j=0;j<nb_coarete;j++)
393     {
394     MG_COARETE* coarete=mgboucle->get_mg_coarete(j);
395     MCEdge* mgarete=(MCEdge*)coarete->get_arete();
396     int nb_segment=mgarete->get_lien_maillage()->get_nb();
397     for (int k=0;k<nb_segment;k++)
398     {
399     refresh();
400     MG_SEGMENT* mgsegment=(MG_SEGMENT*)mgarete->get_lien_maillage()->get(k);
401     MG_SEGMENT* mgsegtemp=(MG_SEGMENT*)mg_maillage->get_mg_segmentid(mgsegment->get_id());
402     if (mgsegtemp==NULL) continue;
403     MCSegment * mcSegment = (MCSegment*) mgsegment;
404     MCNode* mcNode=(MCNode*)mcSegment->get_noeud1();
405     segment_frontiere.ajouter(mcSegment);
406     noeud_frontiere.ajouter(mcNode);
407     mcNode=(MCNode*)mcSegment->get_noeud2();
408     if (!noeud_frontiere.est_dans_la_liste(mcNode));
409     {
410     noeud_frontiere.ajouter(mcNode);
411     }
412     }
413    
414     }
415     }
416    
417    
418     }
419    
420     void MAILLEUR2D::cree_grille(MCFace* __mcFace)
421     {
422     double bounding_box[6]={1E308,1E308,1E308,-1E308,-1E308,-1E308};
423     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR itElem;
424     for (MG_ELEMENT_MAILLAGE* elem = __mcFace->get_lien_maillage()->get_premier(itElem);
425     elem; elem = __mcFace->get_lien_maillage()->get_suivant(itElem))
426     {
427     MG_TRIANGLE * triang = (MG_TRIANGLE *) elem;
428     MG_NOEUD * n[3];
429     n[0] = triang->get_noeud1();
430     n[1] = triang->get_noeud2();
431     n[2] = triang->get_noeud3();
432     for (unsigned int i=0; i<3; i++)
433     {
434     for (unsigned int j=0; j<3; j++)
435     {
436     if (n[i]->get_coord()[j] < bounding_box[j])
437     bounding_box[j] = n[i]->get_coord()[j];
438     if (n[i]->get_coord()[j] > bounding_box[j+3])
439     bounding_box[j+3] = n[i]->get_coord()[j];
440     }
441     }
442     }
443    
444     double xyz_taille [3];
445     for (unsigned int i=0; i<3; i++)
446     xyz_taille[i] = (bounding_box[i]+bounding_box[i+3])*.5;
447    
448     double taille;
449     double density_tensor[9];
450     metrique->evaluer(xyz_taille, density_tensor);
451     taille = pow(density_tensor[0],-0.5);
452    
453     int nb_cellule[3];
454     for (unsigned i = 0; i < 3; i++)
455     {
456     double taille_cellule = taille;
457    
458     if ( taille_cellule != 0 )
459     nb_cellule[i] = (bounding_box[i+3]-bounding_box[i])/taille_cellule;
460     else
461     nb_cellule[i] = 1;
462    
463     if (nb_cellule[i] == 0)
464     nb_cellule[i] ++;
465     }
466    
467     const double NB_MAX_CELL = 200000;
468     double alpha = NB_MAX_CELL / (nb_cellule[0]*nb_cellule[1]*nb_cellule[2]);
469     if (alpha < 1)
470     {
471     for (unsigned i = 0; i < 3; i++)
472     {
473     nb_cellule[i] = (int)((double)nb_cellule[i])*pow(alpha,.33);
474     if ( nb_cellule[i] == 0 )
475     nb_cellule[i] = 1;
476     }
477     printf("Nb cells = %d\n", nb_cellule[0]*nb_cellule[1]*nb_cellule[2]);
478     }
479    
480     // increase grid's size by 100% of mesh size
481     for (int i=0; i<3; i++)
482     bounding_box[i] -= taille*1.0;
483     for (int i=0; i<3; i++)
484     bounding_box[i+3] += taille*1.0;
485    
486     grille_de_segment = new TPL_GRILLE<MCSegment*>;
487     grille_de_segment->initialiser(bounding_box[0], bounding_box[1], bounding_box[2], bounding_box[3], bounding_box[4], bounding_box[5], nb_cellule[0], nb_cellule[1], nb_cellule[2]);
488     grille_de_frontiere = new TPL_GRILLE<MCSegment*>;
489     grille_de_frontiere->initialiser(bounding_box[0], bounding_box[1], bounding_box[2], bounding_box[3], bounding_box[4], bounding_box[5], nb_cellule[0], nb_cellule[1], nb_cellule[2]);
490     grille_de_front = new TPL_GRILLE<MG_FRONT_2D*>;
491     grille_de_front->initialiser(bounding_box[0], bounding_box[1], bounding_box[2], bounding_box[3], bounding_box[4], bounding_box[5], nb_cellule[0], nb_cellule[1], nb_cellule[2]);
492     }
493    
494     void MAILLEUR2D::initialise_front(MCFace* __mcFace)
495     {
496 foucault 64 std::set<MCVertex*> isolatedInteriorVertices;
497 foucault 27 MG_FRONT_2D::initialise_compteur_id();
498     int nb_boucle=__mcFace->get_nb_mg_boucle();
499     for (int iboucle=0;iboucle<nb_boucle;iboucle++)
500     {
501     unsigned int nb_front_avant_cette_boucle=get_nb_front(front_courant);
502     MG_BOUCLE* mgboucle=__mcFace->get_mg_boucle(iboucle);
503     unsigned int nbcoaretetotale=mgboucle->get_nb_mg_coarete();
504     MG_COARETE* mgcoarete=mgboucle->get_mg_coarete(0);
505     MCNode* noeud_de_depart;
506     int bon_noeud=0;
507     int numnoeud=0;
508     while (bon_noeud==0)
509     {
510     if (mgcoarete->get_orientation()==MEME_SENS) noeud_de_depart=(MCNode*)mgcoarete->get_arete()->get_cosommet1()->get_sommet()->get_lien_maillage()->get(numnoeud);
511     else noeud_de_depart=(MCNode*)mgcoarete->get_arete()->get_cosommet2()->get_sommet()->get_lien_maillage()->get(numnoeud);
512     MG_NOEUD* noeudtemp=mg_maillage->get_mg_noeudid(noeud_de_depart->get_id());
513     if (noeudtemp==NULL) numnoeud++; else bon_noeud=1;
514     }
515     MG_FRONT_2D* premier_front;
516     MCNode* noeud_courant=noeud_de_depart;
517     MCSegment* segment_courant=NULL;
518     MG_FRONT_2D* front_precedent=NULL;
519     unsigned int nbcoaretetraite=0;
520 foucault 64
521     if (nbcoaretetotale == 1 ) // this edge is a point isolated in the domain of a face
522     {
523     MCEdge * mcEdge = (MCEdge*)mgboucle->get_mg_coarete(0)->get_arete();
524     if (mcEdge->GetPolyCurve()->get_longueur() == 0)
525     {
526     isolatedInteriorVertices.insert( (MCVertex*) mcEdge->get_cosommet1()->get_sommet() );
527     continue;
528     }
529     }
530    
531    
532 foucault 27 do
533     {
534     nbcoaretetraite++;
535     MCNode* noeud_d_arrivee;
536     int bon_noeud=0;
537     int numnoeud=0;
538     while (bon_noeud==0)
539     {
540     if (mgcoarete->get_orientation()==MEME_SENS) noeud_d_arrivee=(MCNode*)mgcoarete->get_arete()->get_cosommet2()->get_sommet()->get_lien_maillage()->get(numnoeud);
541     else noeud_d_arrivee=(MCNode*)mgcoarete->get_arete()->get_cosommet1()->get_sommet()->get_lien_maillage()->get(numnoeud);
542     MG_NOEUD* noeudtemp=mg_maillage->get_mg_noeudid(noeud_d_arrivee->get_id());
543     if (noeudtemp==NULL) numnoeud++; else bon_noeud=1;
544     }
545     MCEdge* mgarete=(MCEdge*)mgcoarete->get_arete();
546     segment_courant=NULL;
547     int passe_aretefermee=0;
548     do
549     {
550     int trouve=0;
551     int i;
552     if ((mgcoarete->get_arete()->get_cosommet1()->get_sommet()==mgcoarete->get_arete()->get_cosommet2()->get_sommet())&&(passe_aretefermee==0))
553     {
554     passe_aretefermee=1;
555     MCSegment* mgsegment_depart1=NULL;
556     MCSegment* mgsegment_depart2=NULL;
557     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
558     MCSegment* mgsegment=(MCSegment*)mgarete->get_lien_maillage()->get_premier(it);
559     do
560     {
561     if ((mgsegment->get_noeud1()==noeud_courant) || (mgsegment->get_noeud2()==noeud_courant)) mgsegment_depart1=mgsegment;
562     mgsegment=(MCSegment*)mgarete->get_lien_maillage()->get_suivant(it);
563     }
564     while (mgsegment_depart1==NULL);
565     do
566     {
567     if ((mgsegment->get_noeud1()==noeud_courant) || (mgsegment->get_noeud2()==noeud_courant)) mgsegment_depart2=mgsegment;
568     mgsegment=(MCSegment*)mgarete->get_lien_maillage()->get_suivant(it);
569     }
570     while (mgsegment_depart2==NULL);
571     MCNode* noeud1_2;
572     MCNode* noeud2_2;
573     if (mgsegment_depart1->get_noeud1()==noeud_courant) noeud1_2=(MCNode*)mgsegment_depart1->get_noeud2(); else noeud1_2=(MCNode*)mgsegment_depart1->get_noeud1();
574     if (mgsegment_depart2->get_noeud1()==noeud_courant) noeud2_2=(MCNode*)mgsegment_depart2->get_noeud2(); else noeud2_2=(MCNode*)mgsegment_depart2->get_noeud1();
575     OT_VECTEUR_3D vecteur1(noeud1_2->get_x()-noeud_courant->get_x(),noeud1_2->get_y()-noeud_courant->get_y(),noeud1_2->get_z()-noeud_courant->get_z());
576     double coo[3];
577     mgarete->deriver(mgarete->get_tmin(),coo);
578     OT_VECTEUR_3D tangeante(coo[0]*mgcoarete->get_orientation(),coo[1]*mgcoarete->get_orientation(),coo[2]*mgcoarete->get_orientation());
579     MCNode* noeud_suivant;
580     if (vecteur1*tangeante>0.)
581     {
582     mgsegment=mgsegment_depart1;
583     noeud_suivant=noeud1_2;
584     }
585     else
586     {
587     mgsegment=mgsegment_depart2;
588     noeud_suivant=noeud2_2;
589     }
590     MG_FRONT_2D* front=ajouter_front(front_courant,noeud_courant,noeud_suivant,mgsegment);
591     grille_de_segment->inserer(mgsegment);
592     if (get_nb_front(front_courant)==nb_front_avant_cette_boucle+1) premier_front=front;
593     front->changer_front_precedent(front_precedent);
594     front_precedent=front;
595     noeud_courant=noeud_suivant;
596     segment_courant=mgsegment;
597     }
598     else
599     {
600     trouve=0;
601     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
602     MG_SEGMENT* mgsegment=(MG_SEGMENT*)mgarete->get_lien_maillage()->get_premier(it);
603     do
604     {
605     if ((mgsegment->get_noeud1()==noeud_courant) || (mgsegment->get_noeud2()==noeud_courant))
606     if (mgsegment!=segment_courant)
607     {
608     trouve=1;
609     MCNode* noeud_suivant;
610     if (mgsegment->get_noeud1()==noeud_courant) noeud_suivant=(MCNode*)mgsegment->get_noeud2();
611     else if (mgsegment->get_noeud2()==noeud_courant) noeud_suivant=(MCNode*)mgsegment->get_noeud1();
612     MG_FRONT_2D* front=ajouter_front(front_courant,noeud_courant,noeud_suivant,(MCSegment*)mgsegment);
613     grille_de_segment->inserer((MCSegment*)mgsegment);
614     if (get_nb_front(front_courant)==nb_front_avant_cette_boucle+1) premier_front=front;
615     else front_precedent->changer_front_suivant(front);
616     front->changer_front_precedent(front_precedent);
617     front_precedent=front;
618     noeud_courant=noeud_suivant;
619     segment_courant=(MCSegment*)mgsegment;
620     }
621     mgsegment=(MG_SEGMENT*)mgarete->get_lien_maillage()->get_suivant(it);
622     }
623     while (trouve==0);
624     }
625     }
626     while (noeud_courant!=noeud_d_arrivee);
627    
628     int trouve=0;
629    
630     if (nbcoaretetraite != nbcoaretetotale)
631     mgcoarete = mgboucle->get_mg_coarete(nbcoaretetraite);
632     else
633     mgcoarete = NULL;
634     }
635     while ( mgcoarete );
636     front_precedent->changer_front_suivant(premier_front);
637     premier_front->changer_front_precedent(front_precedent);
638     }
639    
640 foucault 64 initialise_front (__mcFace, isolatedInteriorVertices);
641 foucault 27 }
642    
643 foucault 64 void MAILLEUR2D::initialise_front (MCFace * __mcFace, std::set<MCVertex*> __isolatedInteriorVertices)
644     {
645     for (std::set<MCVertex*>::iterator itV = __isolatedInteriorVertices.begin();
646     itV != __isolatedInteriorVertices.end();
647     itV ++ )
648     {
649     MCVertex * mcVertex = *itV;
650     MCNode * mcNode = 0;
651     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it_elem;
652     for (MG_ELEMENT_MAILLAGE* elem = mcVertex->get_lien_maillage()->get_premier(it_elem);
653     elem;elem = mcVertex->get_lien_maillage()->get_suivant(it_elem))
654     if (elem->get_type_entite()==IDMCNODE)
655     mcNode = (MCNode*)elem;
656     MG_FRONT_2D *front_rencontre;
657     MCNode *noeud_solution;
658     int solution = genere_noeud(__mcFace, mcNode, &front_rencontre, &noeud_solution);
659    
660     MCSegment* mgsegment;
661     int ierr = insere_segment(__mcFace,&mgsegment,mcNode,noeud_solution,TOUS_FRONT);
662    
663     if (solution==FRONT_RENCONTRE)
664     {
665     MG_FRONT_2D *ft2=front_rencontre;
666     MG_FRONT_2D *ft1=front_rencontre->get_front_precedent();
667     MG_FRONT_2D *nv_ft1=ajouter_front(front_courant,noeud_solution,mcNode,mgsegment);
668     MG_FRONT_2D *nv_ft2=ajouter_front(front_courant,mcNode,noeud_solution,mgsegment);
669     nv_ft1->changer_front_precedent(ft1);
670     ft1->changer_front_suivant(nv_ft1);
671     nv_ft2->changer_front_precedent(nv_ft1);
672     nv_ft1->changer_front_suivant(nv_ft2);
673     nv_ft2->changer_front_suivant(ft2);
674     ft2->changer_front_precedent(nv_ft2);
675     }
676     else if (solution==NOEUD_CREE)
677     {
678     MG_FRONT_2D *nv_ft1=ajouter_front(front_courant,noeud_solution,mcNode,mgsegment);
679     MG_FRONT_2D *nv_ft2=ajouter_front(front_courant,mcNode,noeud_solution,mgsegment);
680     nv_ft1->changer_front_suivant(nv_ft2);
681     nv_ft1->changer_front_precedent(nv_ft2);
682     nv_ft2->changer_front_suivant(nv_ft1);
683     nv_ft2->changer_front_precedent(nv_ft1);
684     }
685     }
686     }
687    
688 foucault 27 void MAILLEUR2D::progresse_front(MCFace * __mcFace)
689     {
690     int compteur=0;
691     int nbpas_compteur=100;
692     int compteur_min=100;
693     int compteur_min_oiv1=100;
694     int compteur_min_oiv2=9000000;
695     _nbTriangles[__mcFace] = 0;
696     clock_t compteur_temps, compteur_temps2;
697     compteur_temps = clock();
698    
699     while (get_nb_front(front_courant)!=0)
700     {
701 foucault 64
702 foucault 27 compteur++;
703    
704     compteur_temps2 = clock();
705     if (compteur_temps2-compteur_temps > CLOCKS_PER_SEC*.1)
706     {
707     std::ofstream file(filenameNbTriangles);
708    
709     file << " id = " << __mcFace->get_id()<< " ";
710     file << "nb triangles = "<<_nbTriangles[__mcFace]<< " ";
711     file << "nb fronts = "<< get_nb_front(front_courant)+get_nb_front(front_attente);
712     file.flush();
713     file.close();
714     compteur_temps = compteur_temps2;
715     }
716    
717     if (debug && _nbTriangles[__mcFace] >= compteur_min && (_nbTriangles[__mcFace]%nbpas_compteur==0))
718     {
719     if(0)
720     {
721     MG_FRONT_2D *f1=get_front(front_courant,0), *fc=f1;
722     std::set < MG_FRONT_2D * > visited;
723     unsigned cpt_front=0;
724     while (cpt_front < get_nb_front(front_courant))
725     {
726     visited.insert (fc);
727     unsigned id = fc->get_noeud1()->get_id();
728     if (id == 60101 || id==60099)
729     printf("* %d *, ",id);
730     else
731     printf("%d, ", id);
732     fc = fc->get_front_suivant();
733     if (visited.find(fc) != visited.end())
734     for (std::multimap<double,MG_FRONT_2D*>::iterator itFr=front_courant.begin();
735     itFr != front_courant.end();
736     itFr++)
737     if ( visited.find(itFr->second) == visited.end())
738     {
739     fc = itFr->second;
740     printf("--\n");
741     break;
742     }
743    
744     cpt_front++;
745     } ;
746     printf("\n\n");
747     }
748    
749     {
750     ofstream o4("c:\\temp\\void_2D.mai",ios::out|ios::trunc);
751     o4.precision(16);
752     o4.setf(ios::showpoint);
753     mg_maillage->enregistrer_sous_mesh_2D(o4);
754     }
755    
756     if ( _nbTriangles[__mcFace]>=compteur_min_oiv1)
757     {
758     char filename2[5000];
759     sprintf(filename2,"%s\\CAD4FE_Mesher_%d.iv",getenv("TEMP"),_nbTriangles[__mcFace]);
760     std::ofstream file(filename2);
761     CAD4FE::InventorText_MG_MAILLAGE ivTextRefTess (mg_maillage);
762     ivTextRefTess.ShowFaceSegments = true;
763     ivTextRefTess.ShowSegmentId = false;
764     ivTextRefTess.ShowTriangleId = false;
765     ivTextRefTess.ShowNodeId = true;
766     ivTextRefTess.InverseTriangleNormals = true;
767     ivTextRefTess.TriangleColor=1;
768     file << ivTextRefTess.GetText();
769     file << "\n}\n";
770     file.close();
771     }
772    
773     if (compteur>=compteur_min_oiv2 )
774     {
775     char filename2[5000];
776     strcpy(filename2,getenv("TEMP"));
777     strcat(filename2,"\\CAD4FE_Mesher_MCSegments.iv");
778     std::ofstream file(filename2);
779    
780     InventorText_MG_MAILLAGE meshIvText (mg_maillage);
781     meshIvText.ShowFaceSegments = true;
782     meshIvText.ShowSegmentId = true;
783     meshIvText.ShowTriangleId = true;
784     meshIvText.ShowNodeId = true;
785     meshIvText.InverseTriangleNormals = true;
786     meshIvText.TriangleColor=1;
787     file<<meshIvText.GetText();
788    
789     file << "DrawStyle {\nstyle LINES\nlineWidth 2\npointSize 3\n}\n";
790     LISTE_MG_SEGMENT::iterator itSegment;
791     for (MG_SEGMENT * seg = mg_maillage->get_premier_segment(itSegment); seg; seg = mg_maillage->get_suivant_segment(itSegment))
792     {
793     if (seg->get_lien_topologie()->get_dimension() == 1)
794     file << "BaseColor { \n rgb 0.0 0.0 0.9\n }\n";
795     if (seg->get_lien_topologie()->get_dimension() == 2)
796     file << "BaseColor { \n rgb 0.0 0.0 0.0\n }\n";
797     MCSegment * mcSeg = (MCSegment *) seg;
798     InventorText_MCSegment mcSegTxt (mcSeg);
799     file << mcSegTxt.GetText();
800     }
801    
802     file << "\n}\n";
803     file.close();
804     }
805     }
806    
807    
808     refresh();
809     MG_FRONT_2D* ft=get_front(front_courant,0);
810     MG_FRONT_2D* ftp=ft->get_front_precedent();
811     MG_FRONT_2D* fts=ft->get_front_suivant();
812     double eps=0.0001*ft->get_segment()->get_longueur();
813     MCNode* nop=ftp->get_noeud1();
814     MCNode* no1=ft->get_noeud1();
815     MCNode* no2=ft->get_noeud2();
816     MCNode* nos=fts->get_noeud2();
817     /* angle precedent et angle suivant */
818     OT_VECTEUR_3D n1n2(no1->get_coord(),no2->get_coord());
819     OT_VECTEUR_3D n2s(no2->get_coord(),nos->get_coord());
820     OT_VECTEUR_3D pn1(nop->get_coord(),no1->get_coord());
821     n1n2.norme();
822     n2s.norme();
823     pn1.norme();
824     double coo[3];
825     int nbRefFaces;
826     __mcFace->calcul_normale_unitaire(no1->GetRefFaceMapping(), coo, &nbRefFaces);
827     // MCFace_calcul_normale_unitaire(__mcFace,no1,coo);
828     OT_VECTEUR_3D nplan(coo);
829     OT_VECTEUR_3D n=nplan&n1n2;
830     n.norme();
831     double pcp=(-1)*(n1n2*pn1);
832     double psp=(-1)*(n*pn1);
833     int anglep;
834     if ((pcp>=0.1786481777)&&(psp>eps)) anglep=1; else anglep=0;
835     // MCFace_calcul_normale_unitaire(__mcFace,no2,coo);
836     __mcFace->calcul_normale_unitaire(no2->GetRefFaceMapping(), coo, &nbRefFaces);
837     OT_VECTEUR_3D nplan2(coo);
838     n=nplan2&n1n2;
839     n.norme();
840     double pcs=(-1.)*(n1n2*n2s);
841     double pss=n*n2s;
842     int angles;
843     if ((pcs>=0.1786481777)&&(pss>eps)) angles=1; else angles=0;
844     int type_cas_front[10];
845     if ( (ftp==fts->get_front_suivant()) && (no1!=nos) && (no2!=nop) ) type_cas_front[CAS_FRONT_3]=1; else type_cas_front[CAS_FRONT_3]=0;
846     if (identifie_front_cas_front_3x(ftp,ft,fts)) type_cas_front[CAS_FRONT_3X]=1; else type_cas_front[CAS_FRONT_3X]=0;
847     if ( ftp->get_front_precedent()==fts->get_front_suivant() && (nos!=no1) && (no2!=nop) ) type_cas_front[CAS_FRONT_4]=1; else type_cas_front[CAS_FRONT_4]=0;
848     if ( (anglep==1) && (angles==1) ) type_cas_front[CAS_FERME_CAVITE]=1; else type_cas_front[CAS_FERME_CAVITE]=0;
849     if ( anglep==1 ) type_cas_front[CAS_FERME_CAVITE_P]=1; else type_cas_front[CAS_FERME_CAVITE_P]=0;
850     if ( angles==1 ) type_cas_front[CAS_FERME_CAVITE_S]=1; else type_cas_front[CAS_FERME_CAVITE_S]=0;
851     type_cas_front[CAS_GENERAL]=1;
852     int solution=PASTROUVE;
853     if (type_cas_front[CAS_FRONT_3]) solution=traite_front(CAS_FRONT_3,__mcFace,ftp,ft,fts);
854     if ((solution==PASTROUVE) && (type_cas_front[CAS_FRONT_3X])) solution=traite_front(CAS_FRONT_3X,__mcFace,ftp,ft,fts);
855     if ((solution==PASTROUVE) && (type_cas_front[CAS_FRONT_4])) solution=traite_front(CAS_FRONT_4,__mcFace,ftp,ft,fts);
856     if ((solution==PASTROUVE) && (type_cas_front[CAS_FERME_CAVITE])) solution=traite_front(CAS_FERME_CAVITE,__mcFace,ftp,ft,fts);
857     if ((solution==PASTROUVE) && (type_cas_front[CAS_FERME_CAVITE_P])) solution=traite_front(CAS_FERME_CAVITE_P,__mcFace,ftp,ft,fts);
858     if ((solution==PASTROUVE) && (type_cas_front[CAS_FERME_CAVITE_S])) solution=traite_front(CAS_FERME_CAVITE_S,__mcFace,ftp,ft,fts);
859     if ((solution==PASTROUVE) && (type_cas_front[CAS_GENERAL]))
860     {
861     solution=traite_front(CAS_GENERAL,__mcFace,ftp,ft,fts);
862     if ((solution!=PASTROUVE)&&(solution!=TROUVE))
863     if (!type_cas_front[solution]) solution=traite_front(solution,__mcFace,ftp,ft,fts); else solution=PASTROUVE;
864     if (solution==PASTROUVE)
865     {
866     echange_de_front(front_courant,front_attente,ft);
867     ft->incremente_ifail();
868     solution=TROUVE;
869     }
870     }
871     if (get_nb_front(front_courant)==0) front_courant.swap(front_attente);
872     }
873    
874     {
875     std::ofstream file(filenameNbTriangles);
876     file << " id = " << __mcFace->get_id()<< " ";
877     file << "nb triangles = "<<_nbTriangles[__mcFace]<< " ";
878     file << "nb fronts = "<< get_nb_front(front_courant)+get_nb_front(front_attente);
879     file.flush();
880     file.close();
881     }
882    
883     }
884    
885     void MAILLEUR2D::optimise_bascule_segment(MCFace* __mcFace)
886     {
887     OptimizeEdgeSwap edgeSwapper(mg_maillage);
888     edgeSwapper.Optimize(__mcFace);
889     initialise_lst_tri_qual(__mcFace);
890     }
891    
892     void MAILLEUR2D::initialise_lst_tri_qual(MCFace* __mcFace)
893     {
894     lst_tri_qual.clear();
895     lst_tri_qual2.clear();
896     LISTE_MG_TRIANGLE::iterator itTri;
897     for (M3D_MCTriangle * mtri = (M3D_MCTriangle *)mg_maillage->get_premier_triangle(itTri);mtri; mtri = (M3D_MCTriangle *)mg_maillage->get_suivant_triangle(itTri))
898     {
899     double qual=OPERATEUR::qualite_triangle(mtri->get_noeud1()->get_coord(),mtri->get_noeud2()->get_coord(),mtri->get_noeud3()->get_coord());
900     mtri->change_qualite(qual);
901     lst_tri_qual.insert(std::make_pair(mtri->get_qualite(),mtri));
902     }
903     }
904    
905     void MAILLEUR2D::optimise(MCFace* __mcFace)
906     {
907     initialise_lst_tri_qual(__mcFace);
908     std::set<MCSegment *> lstSegToUpdate;
909     for (int phase=0;phase<2;phase++)
910     {
911     ORDRE_TRIANGLE& lst=lst_tri_qual;
912     if (phase==1)
913     lst=lst_tri_qual2;
914     int ok=0;
915     do
916     {
917     ORDRE_TRIANGLE::iterator i=lst.begin();
918     if (i==lst.end())
919     {
920     ok=1;
921     continue;
922     }
923     M3D_MCTriangle* tri=(*i).second;
924     if (tri->get_qualite()<0.5)
925     {
926     MCNode* no[3];
927     no[0]=(MCNode*)tri->get_noeud1();
928     no[1]=(MCNode*)tri->get_noeud2();
929     no[2]=(MCNode*)tri->get_noeud3();
930     double crit[3];//,u[3],v[3],x[3],y[3],z[3];
931     MCNode *noeud_optimal[3]={0,0,0};
932     int ierr=bouge_point(__mcFace,no[0],crit[0],&(noeud_optimal[0]));
933     if (ierr==0) crit[0]=0.;
934     ierr=bouge_point(__mcFace,no[1],crit[1],&(noeud_optimal[1]));
935     if (ierr==0) crit[1]=0.;
936     ierr=bouge_point(__mcFace,no[2],crit[2],&(noeud_optimal[2]));
937     if (ierr==0) crit[2]=0.;
938     double critopt=std::max(crit[0],crit[1]);
939     critopt=std::max(critopt,crit[2]);
940     int num=-1;
941     if (critopt>tri->get_qualite())
942     {
943     if (critopt==crit[0]) num=0;
944     if (critopt==crit[1]) num=1;
945     if (critopt==crit[2]) num=2;
946     }
947     if (num!=-1)
948     {
949     no[num]->CopyGeometry(*noeud_optimal[num]);
950     int nb_seg=no[num]->get_lien_segment()->get_nb();
951     // the geometry of adjacent segment (path in the reference BRep)
952     // must be updated according to the new position of the node
953     for (int i=0;i<nb_seg;i++)
954     lstSegToUpdate.insert((MCSegment*)no[num]->get_lien_segment()->get(i));
955     int nb_tri=no[num]->get_lien_triangle()->get_nb();
956     for (int i=0;i<nb_tri;i++)
957     {
958     M3D_MCTriangle* mtri=(M3D_MCTriangle*)no[num]->get_lien_triangle()->get(i);
959     double qual=OPERATEUR::qualite_triangle(mtri->get_noeud1()->get_coord(),mtri->get_noeud2()->get_coord(),mtri->get_noeud3()->get_coord());
960     mtri->change_qualite(qual);
961     }
962     }
963     if (noeud_optimal[0]) delete noeud_optimal[0];
964     if (noeud_optimal[1]) delete noeud_optimal[1];
965     if (noeud_optimal[2]) delete noeud_optimal[2];
966     }
967     else ok=1;
968     if ((tri->get_qualite()<0.5) && (phase==0))
969     {
970     std::pair<const double,M3D_MCTriangle*> tmp(1./tri->get_qualite(),tri);
971     lst_tri_qual2.insert(tmp);
972     }
973     lst.erase(i);
974     }
975     while (ok==0);
976     }
977    
978     // update the geometry of segments which nodes have been moved
979     for (std::set<MCSegment*>::iterator itSeg=lstSegToUpdate.begin();
980     itSeg!=lstSegToUpdate.end();
981     itSeg++)
982     {
983     MCSegment * seg = * itSeg;
984     seg->UpdateGeometry();
985     }
986     }
987    
988    
989     /*void MAILLEUR2D::optimise(MG_FACE* mgface)
990     {
991     for (int phase=0;phase<2;phase++)
992     {
993     ORDRE_TRIANGLE& lst=lst_tri_qual;
994     if (phase==1)
995     lst=lst_tri_qual2;
996     int ok=0;
997     do
998     {
999     ORDRE_TRIANGLE::iterator i=lst.begin();
1000     if (i==lst.end())
1001     {
1002     ok=1;
1003     continue;
1004     }
1005     M3D_MCTriangle* tri=(*i).second;
1006     if (tri->get_qualite()<0.5)
1007     {
1008     MG_NOEUD* no[3];
1009     no[0]=tri->get_noeud1();
1010     no[1]=tri->get_noeud2();
1011     no[2]=tri->get_noeud3();
1012     double crit[3],u[3],v[3],x[3],y[3],z[3];
1013     int ierr=bouge_point(mgface,no[0],crit[0],u[0],v[0],x[0],y[0],z[0]);
1014     if (ierr==0) crit[0]=0.;
1015     ierr=bouge_point(mgface,no[1],crit[1],u[1],v[1],x[1],y[1],z[1]);
1016     if (ierr==0) crit[1]=0.;
1017     ierr=bouge_point(mgface,no[2],crit[2],u[2],v[2],x[2],y[2],z[2]);
1018     if (ierr==0) crit[2]=0.;
1019     double critopt=std::max(crit[0],crit[1]);
1020     critopt=std::max(critopt,crit[2]);
1021     int num=-1;
1022     if (critopt>tri->get_qualite())
1023     {
1024     if (critopt==crit[0]) num=0;
1025     if (critopt==crit[1]) num=1;
1026     if (critopt==crit[2]) num=2;
1027     }
1028     if (num!=-1)
1029     {
1030     no[num]->change_u(u[num]);
1031     no[num]->change_v(v[num]);
1032     no[num]->change_x(x[num]);
1033     no[num]->change_y(y[num]);
1034     no[num]->change_z(z[num]);
1035     int nb_tri=no[num]->get_lien_triangle()->get_nb();
1036     for (int i=0;i<nb_tri;i++)
1037     {
1038     M3D_MCTriangle* mtri=(M3D_MCTriangle*)no[num]->get_lien_triangle()->get(i);
1039     double qual=OPERATEUR::qualite_triangle(mtri->get_noeud1()->get_coord(),mtri->get_noeud2()->get_coord(),mtri->get_noeud3()->get_coord());
1040     mtri->change_qualite(qual);
1041     }
1042     }
1043     }
1044     else ok=1;
1045     if ((tri->get_qualite()<0.5) && (phase==0))
1046     {
1047     std::pair<const double,M3D_MCTriangle*> tmp(1./tri->get_qualite(),tri);
1048     lst_tri_qual2.insert(tmp);
1049     }
1050     lst.erase(i);
1051     }
1052     while (ok==0);
1053     }
1054     } */
1055    
1056    
1057    
1058    
1059     // FONCTIONS GERANT L ENTITE FRONT (ajout suppression et tout le bordel)
1060     MG_FRONT_2D* MAILLEUR2D::ajouter_front(FRONT& front,MCNode* noeud1,MCNode* noeud2,MCSegment* segment)
1061     {
1062     MG_FRONT_2D* ft=new MG_FRONT_2D(noeud1,noeud2,segment);
1063     ajouter_front(front,ft);
1064     grille_de_front->inserer(ft);
1065     return ft;
1066     }
1067    
1068     void MAILLEUR2D::ajouter_front(FRONT& front,MG_FRONT_2D *ft)
1069     {
1070     std::pair<const double,MG_FRONT_2D*> tmp(ft->get_segment()->get_longueur(),ft);
1071     front.insert(tmp);
1072     }
1073    
1074     MG_FRONT_2D* MAILLEUR2D::get_front(FRONT& front,unsigned int num)
1075     {
1076     FRONT::iterator i=front.begin();
1077     for (unsigned long j=0;j<num;j++) i++;
1078     return ((*i).second);
1079     }
1080    
1081    
1082     unsigned int MAILLEUR2D::get_nb_front(FRONT& front)
1083     {
1084     return front.size();
1085     }
1086    
1087    
1088     MG_FRONT_2D * MAILLEUR2D::trouver_front(MG_NOEUD * no1, MG_NOEUD * no2)
1089     {
1090     FRONT::iterator j;
1091     MG_FRONT_2D *ft = 0;
1092     for (j=front_courant.begin(); j!=front_courant.end(); j++)
1093     {
1094     MG_FRONT_2D * ftj = j->second;
1095     if ( ftj->get_noeud1() == no1 && ftj->get_noeud2() == no2 )
1096     {
1097     ft = ftj;
1098     break;
1099     }
1100     }
1101     if (ft == 0)
1102     for (j=front_attente.begin(); j!=front_attente.end(); j++)
1103     {
1104     MG_FRONT_2D * ftj = j->second;
1105     if ( ftj->get_noeud1() == no1 && ftj->get_noeud2() == no2 )
1106     {
1107     ft = ftj;
1108     break;
1109     }
1110     }
1111     return ft;
1112     }
1113    
1114     void MAILLEUR2D::supprimer_front(MG_FRONT_2D* ft)
1115     {
1116     grille_de_front->supprimer(ft);
1117    
1118     FRONT::iterator j=front_courant.lower_bound(ft->get_segment()->get_longueur());
1119     int ok=0;
1120     if (j==front_courant.end()) ok=2;
1121     while (ok==0&&(j!=front_courant.end()))
1122     {
1123     MG_FRONT_2D* fttmp=(*j).second;
1124     if (ft==fttmp) {ok=1;front_courant.erase(j);}
1125     if (fttmp->get_segment()->get_longueur()>ft->get_segment()->get_longueur()) ok=2;
1126     j++;
1127     }
1128     if (ok!=1)
1129     {
1130     j=front_attente.lower_bound(ft->get_segment()->get_longueur());
1131     while (ft!=(*j).second) j++;
1132     front_attente.erase(j);
1133     }
1134    
1135     delete ft;
1136     }
1137    
1138     void MAILLEUR2D::echange_de_front(FRONT& front_original,FRONT& front_destination,MG_FRONT_2D* ft)
1139     {
1140     FRONT::iterator j=front_original.lower_bound(ft->get_segment()->get_longueur());
1141     while (ft!=(*j).second) j++;
1142     front_original.erase(j);
1143     ajouter_front(front_destination,ft);
1144     }