ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 54
Committed: Fri Sep 28 19:43:11 2007 UTC (17 years, 7 months ago) by francois
Original Path: magic/lib/mailleur/mailleur/src/mailleur3d.cpp
File size: 21910 byte(s)
Log Message:

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