ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_mailleur2d.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months ago) by francois
File size: 49382 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

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