ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 61
Committed: Fri Nov 16 16:39:29 2007 UTC (17 years, 6 months ago) by francois
Original Path: magic/lib/mailleur/mailleur/src/mailleur3d.cpp
File size: 22128 byte(s)
Log Message:
Bub mailleur 3D + visualisation du front optimisée

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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 <time.h>
30     #include "tpl_set.h"
31     #include "mailleur3d.h"
32     #include "m3d_triangle.h"
33 francois 35 #include "mg_gestionnaire.h"
34 5 //---------------------------------------------------------------------------
35    
36     //#pragma package(smart_init)
37    
38    
39    
40 francois 61 MAILLEUR3D::MAILLEUR3D(MG_MAILLAGE* mgmai,MG_GEOMETRIE *mggeo,MG_VOLUME* mgvol,FCT_TAILLE* fct_taille):MAILLEUR(),mg_maillage(mgmai),mg_geometrie(mggeo),mg_volume(mgvol),metrique(fct_taille),activelog(0),niveau_optimisation(2)
41 5 {
42    
43     for (int i=0;i<100;i++)
44     {
45     cpu[i]=0.;
46     nbfois[i]=0;
47     }
48     }
49    
50    
51    
52     MAILLEUR3D::~MAILLEUR3D()
53     {
54     }
55    
56    
57    
58    
59     void MAILLEUR3D::maille(void)
60     {
61     if (mg_volume!=NULL) maille(mg_volume);
62     else
63     {
64     int nb_vol=mg_geometrie->get_nb_mg_volume();
65     for (int i=0;i<nb_vol;i++)
66     {
67     MG_VOLUME* mgvol=mg_geometrie->get_mg_volume(i);
68     maille(mgvol);
69     }
70    
71     }
72    
73     }
74    
75    
76    
77 francois 54 void MAILLEUR3D::maille(MG_VOLUME* mgvol,TPL_LISTE_ENTITE<MG_TRIANGLE*> *lsttri,TPL_LISTE_ENTITE<MG_TETRA*> *lsttet)
78 5 {
79     initialise_frontiere(mgvol);
80     cree_octree();
81     int creation_metrique=0;
82     if (metrique==NULL)
83     {
84     metrique=new FCT_TAILLE_VOLUME(distance_maximale,octree_de_frontiere);
85     creation_metrique=1;
86     }
87 francois 35 else distance_maximale=metrique->get_valeur_maximale(0);
88 francois 54 if (affichageactif==1) (*affiche)(" Construction du front");
89 francois 35 initialise_front(mgvol);
90 francois 54 if (lsttri!=NULL) insere_contrainte_triangle(mgvol,lsttri);
91     if (lsttet!=NULL) insere_contrainte_tetra(mgvol,lsttet);
92     if (affichageactif==1) (*affiche)(" Progression du front");
93 francois 61 //mg_maillage->get_gestionnaire()->enregistrer("c:\\void.magic");
94 5 progresse_front(mgvol);
95 francois 54 if (affichageactif==1) (*affiche)(" Construction du maillage final");
96 5 detruit_element_inactif();
97 francois 54 if (affichageactif==1) (*affiche)(" Optimisation du maillage final");
98 francois 61 int nbaoptimiser;
99     int nbaoptimiserapres=mg_maillage->get_nb_mg_tetra();
100     do
101     {
102     nbaoptimiser=nbaoptimiserapres;
103     optimise(mgvol,nbaoptimiserapres);
104     }
105     while (nbaoptimiserapres!=nbaoptimiser);
106 5 if (creation_metrique==1) delete metrique;
107    
108     delete octree_de_triangle;
109     delete octree_de_frontiere;
110     delete octree_de_front;
111    
112     triangle_frontiere.vide();
113     noeud_frontiere.vide();
114     noeud_arete_frontiere.vide();
115     }
116    
117     void MAILLEUR3D::initialise_frontiere(MG_VOLUME* mgvol)
118     {
119     clock_t cpu1=clock(); //debug
120     int nbcoq=mgvol->get_nb_mg_coquille();
121     for (int i=0;i<nbcoq;i++)
122     {
123     MG_COQUILLE* mgcoq=mgvol->get_mg_coquille(i);
124     int nbcoface=mgcoq->get_nb_mg_coface();
125     for (int j=0;j<nbcoface;j++)
126     {
127     MG_COFACE* coface=mgcoq->get_mg_coface(j);
128     MG_FACE* mgface=coface->get_face();
129     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = mgface->get_lien_maillage();
130     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
131     MG_ELEMENT_MAILLAGE* element;
132     for (element = lien_maillage->get_premier(it); element; element = lien_maillage->get_suivant(it) )
133     {
134     MG_TRIANGLE* mgtri=(MG_TRIANGLE*)element;
135     MG_TRIANGLE* tritemp=mg_maillage->get_mg_triangleid(mgtri->get_id());
136     if (tritemp==NULL) continue;
137     triangle_frontiere.ajouter(mgtri);
138     noeud_frontiere.ajouter(mgtri->get_noeud1());
139     noeud_frontiere.ajouter(mgtri->get_noeud2());
140     noeud_frontiere.ajouter(mgtri->get_noeud3());
141     }
142     int nbbou=mgface->get_nb_mg_boucle();
143     for (int l=0;l<nbbou;l++)
144     {
145     MG_BOUCLE* mgbou=mgface->get_mg_boucle(l);
146     int nbcoarete=mgbou->get_nb_mg_coarete();
147     for (int m=0;m<nbcoarete;m++)
148     {
149     MG_COARETE* mgcoarete=mgbou->get_mg_coarete(m);
150     MG_ARETE* mgarete=mgcoarete->get_arete();
151     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = mgarete->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_SEGMENT* mgseg=(MG_SEGMENT*)element;
157     MG_SEGMENT* segtemp=mg_maillage->get_mg_segmentid(mgseg->get_id());
158     if (segtemp==NULL) continue;
159     noeud_arete_frontiere.ajouter(mgseg->get_noeud1());
160     noeud_arete_frontiere.ajouter(mgseg->get_noeud2());
161     }
162     }
163     }
164     }
165     }
166    
167     clock_t cpu2=clock(); //debug
168     cpu[0]=cpu[0]+(cpu2-cpu1)/CLK_TCK; //debug
169     nbfois[0]++; //debug
170     }
171    
172     void MAILLEUR3D::cree_octree(void)
173     {
174     double xmin,ymin,zmin;
175     double xmax,ymax,zmax;
176    
177     clock_t cpu1=clock(); // debug
178     int nb_noeud=noeud_arete_frontiere.get_nb();
179     for (int i=0;i<nb_noeud;i++)
180     {
181     MG_NOEUD* mgnoeud=noeud_arete_frontiere.get(i);
182     if (i==0)
183     {
184     xmin=mgnoeud->get_x();
185     xmax=mgnoeud->get_x();
186     ymin=mgnoeud->get_y();
187     ymax=mgnoeud->get_y();
188     zmin=mgnoeud->get_z();
189     zmax=mgnoeud->get_z();
190     }
191     else
192     {
193     xmin=std::min(xmin,mgnoeud->get_x());
194     ymin=std::min(ymin,mgnoeud->get_y());
195     zmin=std::min(zmin,mgnoeud->get_z());
196     xmax=std::max(xmax,mgnoeud->get_x());
197     ymax=std::max(ymax,mgnoeud->get_y());
198     zmax=std::max(zmax,mgnoeud->get_z());
199     }
200     double xdiff=xmax-xmin;
201     double ydiff=ymax-ymin;
202     double zdiff=zmax-zmin;
203     xmin=xmin-0.125*xdiff;
204     xmax=xmax+0.125*xdiff;
205     ymin=ymin-0.125*ydiff;
206     ymax=ymax+0.125*ydiff;
207     zmin=zmin-0.125*zdiff;
208     zmax=zmax+0.125*zdiff;
209    
210     }
211     octree_de_triangle=new TPL_OCTREE<MG_TRIANGLE*,MG_NOEUD*>;
212     octree_de_frontiere=new TPL_OCTREE<MG_TRIANGLE*,MG_NOEUD*>;
213     octree_de_front=new TPL_OCTREE<MG_FRONT_3D*,MG_NOEUD*>;
214     octree_de_triangle->initialiser(&noeud_arete_frontiere,1,xmin,ymin,zmin,xmax,ymax,zmax);
215     octree_de_frontiere->initialiser(octree_de_triangle);
216     octree_de_front->initialiser(octree_de_triangle);
217    
218     int nb_triangle=triangle_frontiere.get_nb();
219     for (int j=0;j<nb_triangle;j++)
220     {
221     octree_de_frontiere->inserer(triangle_frontiere.get(j));
222     octree_de_triangle->inserer(triangle_frontiere.get(j));
223     }
224     clock_t cpu2=clock(); //debug
225     cpu[1]=cpu[1]+(cpu2-cpu1)/CLK_TCK; //debug
226     nbfois[1]++; //debug
227     }
228    
229     void MAILLEUR3D::initialise_front(MG_VOLUME* mgvol)
230     {
231     clock_t cpu1=clock(); //debug
232     // constitution du front
233     int nbcoq=mgvol->get_nb_mg_coquille();
234     for (int i=0;i<nbcoq;i++)
235     {
236     MG_COQUILLE* mgcoq=mgvol->get_mg_coquille(i);
237     int nbcoface=mgcoq->get_nb_mg_coface();
238     for (int j=0;j<nbcoface;j++)
239     {
240     MG_COFACE* coface=mgcoq->get_mg_coface(j);
241     MG_FACE* mgface=coface->get_face();
242    
243     TPL_SET<MG_ELEMENT_MAILLAGE*> * lien_maillage = mgface->get_lien_maillage();
244     TPL_SET<MG_ELEMENT_MAILLAGE*>::ITERATEUR it;
245     MG_ELEMENT_MAILLAGE* element;
246     for (element = lien_maillage->get_premier(it); element; element = lien_maillage->get_suivant(it) )
247     {
248     MG_TRIANGLE* mgtri=(MG_TRIANGLE*)element;
249     MG_TRIANGLE* tritemp=mg_maillage->get_mg_triangleid(mgtri->get_id());
250     if (tritemp==NULL) continue;
251     if (coface->get_orientation()==1) ajouter_front_courant(NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud2(),mgtri->get_noeud3(),mgtri);
252     else ajouter_front_courant(NONFORCE,mgtri->get_noeud1(),mgtri->get_noeud3(),mgtri->get_noeud2(),mgtri);
253     }
254     }
255     }
256    
257     // recherche des voisins
258     for (int l=0;l<11;l++)
259     {
260     int nb_front=get_nb_front(front_courant[l]);
261     for (int i=0;i<nb_front;i++)
262     {
263     MG_FRONT_3D* ft=get_front(front_courant[l],i);
264     MG_NOEUD* mgnoeud1=ft->get_noeud1();
265     MG_NOEUD* mgnoeud2=ft->get_noeud2();
266     MG_NOEUD* mgnoeud3=ft->get_noeud3();
267     ft->changer_front_voisin(NULL,0);
268     ft->changer_front_voisin(NULL,1);
269     ft->changer_front_voisin(NULL,2);
270     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
271     for (int k=0;k<mgnoeud2->get_lien_triangle()->get_nb();k++)
272     {
273     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
274     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(k);
275     if (tri1==tri2)
276     if (tri1->get_etat_front()==FRONT_ACTIF)
277     if (tri1->get_mgfront()!=ft)
278     {
279     MG_FRONT_3D* ft2=tri1->get_mgfront();
280     if (ft->get_front_voisin(0)==NULL)
281     {
282     ft->changer_front_voisin(ft2,0);
283     ft->changer_angle_voisin(angle_front(ft,ft2),0);
284     }
285     else
286     {
287     double angle=angle_front(ft,ft2);
288     if (angle<ft->get_angle_voisin(0))
289     {
290     ft->changer_front_voisin(ft2,0);
291     ft->changer_angle_voisin(angle,0);
292     }
293     }
294     }
295     }
296     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
297     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
298     {
299     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
300     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
301     if (tri1==tri2)
302     if (tri1->get_etat_front()==FRONT_ACTIF)
303     if (tri1->get_mgfront()!=ft)
304     {
305     MG_FRONT_3D* ft2=tri1->get_mgfront();
306     if (ft->get_front_voisin(1)==NULL)
307     {
308     ft->changer_front_voisin(ft2,1);
309     ft->changer_angle_voisin(angle_front(ft,ft2),1);
310     }
311     else
312     {
313     double angle=angle_front(ft,ft2);
314     if (angle<ft->get_angle_voisin(1))
315     {
316     ft->changer_front_voisin(ft2,1);
317     ft->changer_angle_voisin(angle,1);
318     }
319     }
320     }
321     }
322     for (int j=0;j<mgnoeud2->get_lien_triangle()->get_nb();j++)
323     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
324     {
325     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(j);
326     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
327     if (tri1==tri2)
328     if (tri1->get_etat_front()==FRONT_ACTIF)
329     if (tri1->get_mgfront()!=ft)
330     {
331     MG_FRONT_3D* ft2=tri1->get_mgfront();
332     if (ft->get_front_voisin(2)==NULL)
333     {
334     ft->changer_front_voisin(ft2,2);
335     ft->changer_angle_voisin(angle_front(ft,ft2),2);
336     }
337     else
338     {
339     double angle=angle_front(ft,ft2);
340     if (angle<ft->get_angle_voisin(2))
341     {
342     ft->changer_front_voisin(ft2,2);
343     ft->changer_angle_voisin(angle,2);
344     }
345     }
346     }
347     }
348     if ( (ft->get_front_voisin(0)==NULL) || (ft->get_front_voisin(1)==NULL)|| (ft->get_front_voisin(2)==NULL))
349     refresh();
350     }
351    
352     }
353     clock_t cpu2=clock(); //debug
354     cpu[2]=cpu[2]+(cpu2-cpu1)/CLK_TCK; //debug
355     nbfois[2]++; //debug
356     }
357    
358    
359    
360     // FONCTIONS GERANT L ENTITE FRONT (ajout suppression et tout le bordel)
361     MG_FRONT_3D* MAILLEUR3D::ajouter_front_courant(int numero_front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
362     {
363     int numfront;
364     if (numero_front==NONFORCE)
365     {
366     numfront=(int)(triangle->get_longueur()/distance_maximale*10.);
367     if (numfront>10) numfront=10;
368     }
369     else numfront=numero_front;
370     MG_FRONT_3D* mgfront;
371     if (numfront>11) mgfront=ajouter_front(front_attente,noeud1,noeud2,noeud3,triangle);
372     else mgfront=ajouter_front(front_courant[numfront],noeud1,noeud2,noeud3,triangle);
373     mgfront->changer_numero_front(numfront);
374     if (triangle->get_type_entite()==IDM3D_TRIANGLE)
375     {
376     M3D_TRIANGLE* mtri=(M3D_TRIANGLE*)triangle;
377     mtri->change_etat_front(FRONT_ACTIF);
378     mtri->change_mgfront(mgfront);
379     }
380     return mgfront;
381     }
382    
383     MG_FRONT_3D* MAILLEUR3D::ajouter_front(FRONT& front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
384     {
385     MG_FRONT_3D* ft=new MG_FRONT_3D(noeud1,noeud2,noeud3,triangle);
386     ajouter_front(front,ft);
387     octree_de_front->inserer(ft);
388     return ft;
389     }
390    
391     void MAILLEUR3D::ajouter_front(FRONT& front,MG_FRONT_3D *ft)
392     {
393     std::pair<const double,MG_FRONT_3D*> tmp(ft->get_triangle()->get_longueur(),ft);
394     front.insert(tmp);
395     }
396    
397     MG_FRONT_3D* MAILLEUR3D::get_front(FRONT& front,unsigned int num)
398     {
399     FRONT::iterator i=front.begin();
400     for (unsigned long j=0;j<num;j++) i++;
401     return ((*i).second);
402     }
403    
404    
405     unsigned int MAILLEUR3D::get_nb_front(FRONT& front)
406     {
407     return front.size();
408     }
409    
410     unsigned int MAILLEUR3D::get_nb_front_courant(void)
411     {
412    
413     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();
414     }
415    
416     void MAILLEUR3D::supprimer_front_en_avancant(MG_FRONT_3D* ft)
417     {
418     octree_de_front->supprimer(ft);
419     int numfront=ft->get_numero_front();
420     FRONT* front_original;
421     if (numfront==ATTENTE)
422     front_original=&front_attente;
423     else
424     front_original=front_courant+numfront;
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     MG_TRIANGLE* mgtri=ft->get_triangle();
429     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
430     {
431     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
432     m3dtri->change_etat_front(FRONT_PASSE);
433     m3dtri->change_mgfront(NULL);
434     }
435     delete ft;
436     }
437    
438     void MAILLEUR3D::supprimer_front_en_reculant(MG_FRONT_3D* ft)
439     {
440     octree_de_front->supprimer(ft);
441     int numfront=ft->get_numero_front();
442     FRONT* front_original;
443     if (numfront==ATTENTE)
444     front_original=&front_attente;
445     else
446     front_original=front_courant+numfront;
447     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
448     while (ft!=(*j).second) j++;
449     front_original->erase(j);
450     MG_TRIANGLE* mgtri=ft->get_triangle();
451     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
452     {
453     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
454     m3dtri->change_etat_front(FRONT_NONACTIF);
455     m3dtri->change_mgfront(NULL);
456     }
457     delete ft;
458     }
459    
460     void MAILLEUR3D::echange_de_front(FRONT& front_original,FRONT& front_destination,MG_FRONT_3D* ft)
461     {
462     FRONT::iterator j=front_original.lower_bound(ft->get_triangle()->get_longueur());
463     while (ft!=(*j).second) j++;
464     front_original.erase(j);
465     ajouter_front(front_destination,ft);
466     }
467    
468     void MAILLEUR3D::echange_de_front(MG_FRONT_3D* ft,int num)
469     {
470     int numfront;
471     if (num==NONFORCE)
472     {
473     numfront=(int)(ft->get_triangle()->get_longueur()/distance_maximale*10.);
474     if (numfront>10) numfront=10;
475     }
476     else if (num==ATTENTE) numfront=ATTENTE;
477     else numfront=num;
478     if (numfront>10) numfront=ATTENTE;
479     FRONT* front_original;
480     int num_front_original=ft->get_numero_front();
481     if (num_front_original==ATTENTE)
482     front_original=&front_attente;
483     else
484     front_original=front_courant+num_front_original;
485     FRONT* front_destination;
486     if (numfront==ATTENTE)
487     front_destination=&front_attente;
488     else
489     front_destination=front_courant+numfront;
490    
491    
492    
493     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
494     while (ft!=(*j).second) j++;
495     front_original->erase(j);
496     ft->changer_numero_front(numfront);
497     ajouter_front(*front_destination,ft);
498    
499     }
500    
501    
502     void MAILLEUR3D::swap_front(FRONT& front_original,FRONT& front_destination)
503     {
504     front_original.swap(front_destination);
505     }
506    
507    
508    
509     int MAILLEUR3D::premier_front_courant(void)
510     {
511     int num=-1;
512     if (front_courant[0].size()>0) num=0;
513     else if (front_courant[1].size()>0) num=1;
514     else if (front_courant[2].size()>0) num=2;
515     else if (front_courant[3].size()>0) num=3;
516     else if (front_courant[4].size()>0) num=4;
517     else if (front_courant[5].size()>0) num=5;
518     else if (front_courant[6].size()>0) num=6;
519     else if (front_courant[7].size()>0) num=7;
520     else if (front_courant[8].size()>0) num=8;
521     else if (front_courant[9].size()>0) num=9;
522     else if (front_courant[10].size()>0) num=10;
523     return num;
524     }
525    
526    
527    
528     void MAILLEUR3D::active_log(char* nomfile)
529     {
530     activelog=1;
531     nomlog=nomfile;
532     }
533    
534     void MAILLEUR3D::desactive_log(void)
535     {
536     activelog=0;
537     }
538    
539 francois 35
540 francois 54