ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 420
Committed: Thu Sep 12 22:51:58 2013 UTC (11 years, 8 months ago) by francois
File size: 16492 byte(s)
Log Message:
Creation d'un mailleur 3D d'une enveloppe triangulee et orientee non attachee à une geometrie

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