ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 632
Committed: Thu Jan 15 18:40:00 2015 UTC (10 years, 3 months ago) by francois
Original Path: magic/lib/mailleur_auto/src/mailleur3d.cpp
File size: 16524 byte(s)
Log Message:
Changement de l'espace de voisinage dans le mailleur 2D et 3D. On utilise un ntree (octree "anisotrope" qui ne se divise pas necessairement en 8). En 2D l'espace de voisinage est maintenant sur l'espace reelle au lieu d'être sur l'espace parametrique.
+Mise sous forme de parametres de certains choix stratégiques du mailleur

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