ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 35
Committed: Thu Aug 16 21:24:14 2007 UTC (17 years, 9 months ago) by francois
Original Path: magic/lib/mailleur/mailleur/src/mailleur3d.cpp
File size: 21669 byte(s)
Log Message:
Mailleur 3D + divers bugs + origine des elements de maillages

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