ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 966
Committed: Thu Sep 6 16:46:34 2018 UTC (6 years, 8 months ago) by couturad
Original Path: magic/lib/mailleur_auto/src/mailleur3d.cpp
File size: 16755 byte(s)
Log Message:
Ajout de l'histogramme a MAGIC_PLOT
Ajout d'une sortie OK ou FAIL (int) au MAILLEUR afin de gerer certaines exceptions
Ajout d'une phase RSA a la fin du generateur DCR

File Contents

# User Rev Content
1 francois 283 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuilli�e et Vincent FRANCOIS
5     // D�artement de G�ie M�anique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du d�artement
8     // de g�ie m�anique de l'Universit�du Qu�ec �
9     // Trois Rivi�es
10     // Les librairies ne peuvent �re utilis�s sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // mailleur3d.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 �11H23
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26    
27    
28     //#pragma hdrstop
29     #include "tpl_set.h"
30     #include "mailleur3d.h"
31     #include "m3d_triangle.h"
32     #include "mg_gestionnaire.h"
33 francois 287 #include "mailleur3d_optimisation.h"
34 francois 283 //---------------------------------------------------------------------------
35    
36     //#pragma package(smart_init)
37    
38    
39    
40 francois 494 MAILLEUR3D::MAILLEUR3D(MG_MAILLAGE* mgmai,MG_GEOMETRIE *mggeo,FCT_TAILLE* fct_taille,bool save,MG_VOLUME* mgvol,int destruction):MAILLEUR(save),mg_maillage(mgmai),mg_geometrie(mggeo),mg_volume(mgvol),metrique(fct_taille),activelog(0),niveau_optimisation(2),type_mailleur(FRONTAL),typedestruction(destruction)
41 francois 283 {
42 francois 494 strcpy(nomfichierdbg,"mailleurautomatique.magicdbg");
43 francois 283 }
44    
45    
46 francois 494 MAILLEUR3D::MAILLEUR3D(FCT_TAILLE *metri,MG_MAILLAGE* mgmai,OT_CPU* comp,int destruction):MAILLEUR(false,comp),metrique(metri),type_mailleur(OCTAL),mg_maillage(mgmai),coef(2.),typedestruction(destruction)
47 francois 283 {
48 francois 494 strcpy(nomfichierdbg,"mailleurautomatique.magicdbg");
49 francois 283 }
50    
51    
52     MAILLEUR3D::~MAILLEUR3D()
53     {
54     }
55    
56    
57    
58    
59 couturad 966 int MAILLEUR3D::maille(MG_GROUPE_TOPOLOGIQUE* mggt)
60 francois 283 {
61     if (type_mailleur==FRONTAL)
62     {
63 couturad 966 if (mg_volume!=NULL)
64     {
65     if(maille(mg_volume)==FAIL) return FAIL;
66     }
67 francois 283 else
68     {
69     TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> lst;
70     if (mggt!=NULL)
71     {
72 couturad 906 std::map<MG_ELEMENT_TOPOLOGIQUE*,MG_ELEMENT_TOPOLOGIQUE*>::iterator it;
73     for(MG_ELEMENT_TOPOLOGIQUE* ele=mggt->get_premier(it);ele!=NULL;ele=mggt->get_suivant(it))
74     {
75     lst.ajouter(ele);
76     ele->get_topologie_sousjacente(&lst);
77     }
78 francois 283 }
79     int nb_vol=mg_geometrie->get_nb_mg_volume();
80     for (int i=0;i<nb_vol;i++)
81     {
82     MG_VOLUME* mgvol=mg_geometrie->get_mg_volume(i);
83     if (mggt!=NULL)
84     if (lst.existe(mgvol)==0) continue;
85 couturad 966 if(maille(mg_volume)==FAIL) return FAIL;
86 francois 283 }
87     }
88 francois 287 }
89 francois 283 if (type_mailleur==OCTAL)
90     {
91 couturad 966 if(maille(metrique)==FAIL) return FAIL;
92 francois 283 }
93 couturad 966 return OK;
94 francois 283 }
95    
96    
97    
98 couturad 966 int MAILLEUR3D::maille(MG_VOLUME* mgvol,TPL_LISTE_ENTITE<MG_TRIANGLE*> *lsttri,TPL_LISTE_ENTITE<MG_TETRA*> *lsttet)
99 francois 283 {
100 francois 632 cree_ntree();
101 francois 419 distance_maximale=metrique->get_valeur_maximale(0);
102 francois 445 affiche((char*)" Construction du front");
103 francois 283 initialise_front(mgvol);
104     if (lsttri!=NULL) insere_contrainte_triangle(mgvol,lsttri);
105     if (lsttet!=NULL) insere_contrainte_tetra(mgvol,lsttet);
106 francois 445 affiche((char*)" Progression du front");
107 couturad 966 if(progresse_front(mgvol)==FAIL)
108     {
109     delete ntree_de_front;
110     return FAIL;
111     }
112 francois 445 affiche((char*)" Construction du maillage final");
113 francois 283 detruit_element_inactif();
114 francois 445 affiche((char*)" Optimisation du maillage final");
115 francois 287 MAILLEUR3D_OPTIMISATION opt(mg_maillage,niveau_optimisation);
116 francois 445 if (affichageactif==1) opt.active_affichage(affiche2);
117 francois 288 opt.optimise(mgvol);
118 francois 632 delete ntree_de_front;
119 couturad 966 return OK;
120 francois 283 }
121    
122    
123 francois 632 void MAILLEUR3D::cree_ntree(void)
124 francois 283 {
125 francois 467 BOITE_3D boite=metrique->get_boite_3D();
126     double xmin=boite.get_xmin();
127     double ymin=boite.get_ymin();
128     double zmin=boite.get_zmin();
129     double xmax=boite.get_xmax();
130     double ymax=boite.get_ymax();
131     double zmax=boite.get_zmax();
132 francois 632 ntree_de_front=new TPL_NTREE_FCT<MG_FRONT_3D*,FCT_TAILLE >;
133     ntree_de_front->initialiser(*metrique,xmin,ymin,zmin,xmax,ymax,zmax);
134 francois 283 }
135    
136     void MAILLEUR3D::initialise_front(MG_VOLUME* mgvol)
137     {
138 francois 420 cree_front(mgvol);
139     recherche_voisin_front();
140     }
141    
142     void MAILLEUR3D::cree_front(MG_VOLUME* mgvol)
143     {
144 francois 283 // constitution du front
145     int nbcoq=mgvol->get_nb_mg_coquille();
146     for (int i=0;i<nbcoq;i++)
147     {
148     MG_COQUILLE* mgcoq=mgvol->get_mg_coquille(i);
149     int nbcoface=mgcoq->get_nb_mg_coface();
150     for (int j=0;j<nbcoface;j++)
151     {
152     MG_COFACE* coface=mgcoq->get_mg_coface(j);
153     MG_FACE* mgface=coface->get_face();
154    
155     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = mgface->get_lien_maillage();
156     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
157     MG_ELEMENT_MAILLAGE* element;
158     for (element = lien_maillage->get_premier(it); element; element = lien_maillage->get_suivant(it) )
159     {
160     MG_TRIANGLE* mgtri=(MG_TRIANGLE*)element;
161     MG_TRIANGLE* tritemp=mg_maillage->get_mg_triangleid(mgtri->get_id());
162     if (tritemp==NULL) continue;
163     if (coface->get_orientation()==1) ajouter_front_courant(NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud2(),mgtri->get_noeud3(),mgtri);
164     else ajouter_front_courant(NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud3(),mgtri->get_noeud2(),mgtri);
165     }
166     }
167     }
168 francois 420 }
169     void MAILLEUR3D::recherche_voisin_front(void)
170     {
171 francois 283 // recherche des voisins
172     for (int l=0;l<11;l++)
173     {
174     int nb_front=get_nb_front(front_courant[l]);
175 francois 551 FRONT::iterator it;
176     for (MG_FRONT_3D *ft=get_premier_front(front_courant[l],it);ft!=NULL;ft=get_suivant_front(front_courant[l],it))
177     {
178     //MG_FRONT_3D* ft=get_front(front_courant[l],i);
179 francois 283 MG_NOEUD* mgnoeud1=ft->get_noeud1();
180     MG_NOEUD* mgnoeud2=ft->get_noeud2();
181     MG_NOEUD* mgnoeud3=ft->get_noeud3();
182     ft->changer_front_voisin(NULL,0);
183     ft->changer_front_voisin(NULL,1);
184     ft->changer_front_voisin(NULL,2);
185     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
186     for (int k=0;k<mgnoeud2->get_lien_triangle()->get_nb();k++)
187     {
188     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
189     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(k);
190     if (tri1==tri2)
191     if (tri1->get_etat_front()==FRONT_ACTIF)
192     if (tri1->get_mgfront()!=ft)
193     {
194     MG_FRONT_3D* ft2=tri1->get_mgfront();
195     if (ft->get_front_voisin(0)==NULL)
196     {
197     ft->changer_front_voisin(ft2,0);
198     ft->changer_angle_voisin(angle_front(ft,ft2),0);
199     }
200     else
201     {
202     double angle=angle_front(ft,ft2);
203     if (angle<ft->get_angle_voisin(0))
204     {
205     ft->changer_front_voisin(ft2,0);
206     ft->changer_angle_voisin(angle,0);
207     }
208     }
209     }
210     }
211     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
212     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
213     {
214     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
215     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
216     if (tri1==tri2)
217     if (tri1->get_etat_front()==FRONT_ACTIF)
218     if (tri1->get_mgfront()!=ft)
219     {
220     MG_FRONT_3D* ft2=tri1->get_mgfront();
221     if (ft->get_front_voisin(1)==NULL)
222     {
223     ft->changer_front_voisin(ft2,1);
224     ft->changer_angle_voisin(angle_front(ft,ft2),1);
225     }
226     else
227     {
228     double angle=angle_front(ft,ft2);
229     if (angle<ft->get_angle_voisin(1))
230     {
231     ft->changer_front_voisin(ft2,1);
232     ft->changer_angle_voisin(angle,1);
233     }
234     }
235     }
236     }
237     for (int j=0;j<mgnoeud2->get_lien_triangle()->get_nb();j++)
238     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
239     {
240     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(j);
241     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
242     if (tri1==tri2)
243     if (tri1->get_etat_front()==FRONT_ACTIF)
244     if (tri1->get_mgfront()!=ft)
245     {
246     MG_FRONT_3D* ft2=tri1->get_mgfront();
247     if (ft->get_front_voisin(2)==NULL)
248     {
249     ft->changer_front_voisin(ft2,2);
250     ft->changer_angle_voisin(angle_front(ft,ft2),2);
251     }
252     else
253     {
254     double angle=angle_front(ft,ft2);
255     if (angle<ft->get_angle_voisin(2))
256     {
257     ft->changer_front_voisin(ft2,2);
258     ft->changer_angle_voisin(angle,2);
259     }
260     }
261     }
262     }
263     if ( (ft->get_front_voisin(0)==NULL) || (ft->get_front_voisin(1)==NULL)|| (ft->get_front_voisin(2)==NULL))
264     refresh();
265     }
266    
267     }
268 francois 419
269 francois 283 }
270    
271    
272    
273     // FONCTIONS GERANT L ENTITE FRONT (ajout suppression et tout le bordel)
274     MG_FRONT_3D* MAILLEUR3D::ajouter_front_courant(int numero_front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
275     {
276     int numfront;
277     if (numero_front==NONFORCE)
278     {
279     numfront=(int)(triangle->get_longueur()/distance_maximale*10.);
280     if (numfront>10) numfront=10;
281     }
282     else numfront=numero_front;
283     MG_FRONT_3D* mgfront;
284     if (numfront>11) mgfront=ajouter_front(front_attente,noeud1,noeud2,noeud3,triangle);
285     else mgfront=ajouter_front(front_courant[numfront],noeud1,noeud2,noeud3,triangle);
286     mgfront->changer_numero_front(numfront);
287     if (triangle->get_type_entite()==IDM3D_TRIANGLE)
288     {
289     M3D_TRIANGLE* mtri=(M3D_TRIANGLE*)triangle;
290     mtri->change_etat_front(FRONT_ACTIF);
291     mtri->change_mgfront(mgfront);
292     }
293     return mgfront;
294     }
295    
296     MG_FRONT_3D* MAILLEUR3D::ajouter_front(FRONT& front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
297     {
298     MG_FRONT_3D* ft=new MG_FRONT_3D(noeud1,noeud2,noeud3,triangle);
299     ajouter_front(front,ft);
300 francois 632 ntree_de_front->inserer(ft);
301 francois 283 return ft;
302     }
303    
304     void MAILLEUR3D::ajouter_front(FRONT& front,MG_FRONT_3D *ft)
305     {
306     std::pair<const double,MG_FRONT_3D*> tmp(ft->get_triangle()->get_longueur(),ft);
307     front.insert(tmp);
308     }
309    
310 francois 551 MG_FRONT_3D* MAILLEUR3D::get_premier_front(FRONT& front)
311 francois 283 {
312 francois 551 if (front.size()==0) return NULL;
313     FRONT::iterator it=front.begin();
314     return (*it).second;
315 francois 283 }
316    
317 francois 551 MG_FRONT_3D* MAILLEUR3D::get_premier_front(FRONT& front,FRONT::iterator &it)
318     {
319     if (front.size()==0) return NULL;
320     it=front.begin();
321     return (*it).second;
322     }
323 francois 283
324 francois 551 MG_FRONT_3D* MAILLEUR3D::get_suivant_front(FRONT& front,FRONT::iterator &it)
325     {
326     it++;
327     if (it==front.end()) return NULL;
328     return (*it).second;
329     }
330    
331    
332 francois 283 unsigned int MAILLEUR3D::get_nb_front(FRONT& front)
333     {
334     return front.size();
335     }
336    
337     unsigned int MAILLEUR3D::get_nb_front_courant(void)
338     {
339    
340     return front_courant[0].size()+front_courant[1].size()+front_courant[2].size()+front_courant[3].size()+front_courant[4].size()+front_courant[5].size()+front_courant[6].size()+front_courant[7].size()+front_courant[8].size()+front_courant[9].size()+front_courant[10].size();
341     }
342    
343     void MAILLEUR3D::supprimer_front_en_avancant(MG_FRONT_3D* ft)
344     {
345     supprimer_front_en_avancant_sans_delete(ft);
346     delete ft;
347     }
348    
349     void MAILLEUR3D::supprimer_front_en_avancant_sans_delete(MG_FRONT_3D* ft)
350     {
351 francois 632 ntree_de_front->supprimer(ft);
352 francois 283 int numfront=ft->get_numero_front();
353     FRONT* front_original;
354     if (numfront==ATTENTE)
355     front_original=&front_attente;
356     else
357     front_original=front_courant+numfront;
358     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
359     while (ft!=(*j).second) j++;
360     front_original->erase(j);
361     MG_TRIANGLE* mgtri=ft->get_triangle();
362     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
363     {
364     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
365     m3dtri->change_etat_front(FRONT_PASSE);
366     m3dtri->change_mgfront(NULL);
367     }
368     }
369    
370     void MAILLEUR3D::supprimer_front_en_reculant(MG_FRONT_3D* ft)
371     {
372 francois 632 ntree_de_front->supprimer(ft);
373 francois 283 int numfront=ft->get_numero_front();
374     FRONT* front_original;
375     if (numfront==ATTENTE)
376     front_original=&front_attente;
377     else
378     front_original=front_courant+numfront;
379     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
380     while (ft!=(*j).second) j++;
381     front_original->erase(j);
382     MG_TRIANGLE* mgtri=ft->get_triangle();
383     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
384     {
385     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
386     m3dtri->change_etat_front(FRONT_NONACTIF);
387     m3dtri->change_mgfront(NULL);
388     }
389     delete ft;
390     }
391    
392     void MAILLEUR3D::echange_de_front(FRONT& front_original,FRONT& front_destination,MG_FRONT_3D* ft)
393     {
394     FRONT::iterator j=front_original.lower_bound(ft->get_triangle()->get_longueur());
395     while (ft!=(*j).second) j++;
396     front_original.erase(j);
397     ajouter_front(front_destination,ft);
398     }
399    
400     void MAILLEUR3D::echange_de_front(MG_FRONT_3D* ft,int num)
401     {
402     int numfront;
403     if (num==NONFORCE)
404     {
405     numfront=(int)(ft->get_triangle()->get_longueur()/distance_maximale*10.);
406     if (numfront>10) numfront=10;
407     }
408     else if (num==ATTENTE) numfront=ATTENTE;
409     else numfront=num;
410     if (numfront>10) numfront=ATTENTE;
411     FRONT* front_original;
412     int num_front_original=ft->get_numero_front();
413     if (num_front_original==ATTENTE)
414     front_original=&front_attente;
415     else
416     front_original=front_courant+num_front_original;
417     FRONT* front_destination;
418     if (numfront==ATTENTE)
419     front_destination=&front_attente;
420     else
421     front_destination=front_courant+numfront;
422    
423    
424    
425     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
426     while (ft!=(*j).second) j++;
427     front_original->erase(j);
428     ft->changer_numero_front(numfront);
429     ajouter_front(*front_destination,ft);
430    
431     }
432    
433    
434     void MAILLEUR3D::swap_front(FRONT& front_original,FRONT& front_destination)
435     {
436     front_original.swap(front_destination);
437     }
438    
439    
440    
441     int MAILLEUR3D::premier_front_courant(void)
442     {
443     int num=-1;
444     if (front_courant[0].size()>0) num=0;
445     else if (front_courant[1].size()>0) num=1;
446     else if (front_courant[2].size()>0) num=2;
447     else if (front_courant[3].size()>0) num=3;
448     else if (front_courant[4].size()>0) num=4;
449     else if (front_courant[5].size()>0) num=5;
450     else if (front_courant[6].size()>0) num=6;
451     else if (front_courant[7].size()>0) num=7;
452     else if (front_courant[8].size()>0) num=8;
453     else if (front_courant[9].size()>0) num=9;
454     else if (front_courant[10].size()>0) num=10;
455     return num;
456     }
457    
458    
459    
460     void MAILLEUR3D::active_log(char* nomfile)
461     {
462     activelog=1;
463     nomlog=nomfile;
464     }
465    
466     void MAILLEUR3D::desactive_log(void)
467     {
468     activelog=0;
469     }
470    
471 francois 287 void MAILLEUR3D::change_niveau_optimisation(int num)
472     {
473     niveau_optimisation=num;
474     }
475 francois 283
476 francois 287 int MAILLEUR3D::get_niveau_optimisation(void)
477     {
478     return niveau_optimisation;
479     }
480 francois 283
481 francois 494