ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/CAD4FE/src/CAD4FE_mailleur2d.cpp
Revision: 569
Committed: Thu Oct 16 14:36:31 2014 UTC (10 years, 6 months ago) by foucault
File size: 49853 byte(s)
Log Message:
Mise à jour pour CAD4FE (Gilles) : operation 1 (tentative)

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