ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur/src/mailleur3d.cpp
Revision: 494
Committed: Thu Mar 6 20:39:09 2014 UTC (11 years, 2 months ago) by francois
Original Path: magic/lib/mailleur_auto/src/mailleur3d.cpp
File size: 16142 byte(s)
Log Message:
Possibilité d'enregistrement des mailleurs en cours de maillage pour voir ce qui se passe si il y a un bug

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     cree_octree();
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 283 delete octree_de_front;
112     }
113    
114    
115     void MAILLEUR3D::cree_octree(void)
116     {
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     octree_de_front=new TPL_OCTREE_FCT<MG_FRONT_3D*,FCT_TAILLE >;
125     octree_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     for (int i=0;i<nb_front;i++)
168     {
169     MG_FRONT_3D* ft=get_front(front_courant[l],i);
170     MG_NOEUD* mgnoeud1=ft->get_noeud1();
171     MG_NOEUD* mgnoeud2=ft->get_noeud2();
172     MG_NOEUD* mgnoeud3=ft->get_noeud3();
173     ft->changer_front_voisin(NULL,0);
174     ft->changer_front_voisin(NULL,1);
175     ft->changer_front_voisin(NULL,2);
176     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
177     for (int k=0;k<mgnoeud2->get_lien_triangle()->get_nb();k++)
178     {
179     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
180     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(k);
181     if (tri1==tri2)
182     if (tri1->get_etat_front()==FRONT_ACTIF)
183     if (tri1->get_mgfront()!=ft)
184     {
185     MG_FRONT_3D* ft2=tri1->get_mgfront();
186     if (ft->get_front_voisin(0)==NULL)
187     {
188     ft->changer_front_voisin(ft2,0);
189     ft->changer_angle_voisin(angle_front(ft,ft2),0);
190     }
191     else
192     {
193     double angle=angle_front(ft,ft2);
194     if (angle<ft->get_angle_voisin(0))
195     {
196     ft->changer_front_voisin(ft2,0);
197     ft->changer_angle_voisin(angle,0);
198     }
199     }
200     }
201     }
202     for (int j=0;j<mgnoeud1->get_lien_triangle()->get_nb();j++)
203     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
204     {
205     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud1->get_lien_triangle()->get(j);
206     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
207     if (tri1==tri2)
208     if (tri1->get_etat_front()==FRONT_ACTIF)
209     if (tri1->get_mgfront()!=ft)
210     {
211     MG_FRONT_3D* ft2=tri1->get_mgfront();
212     if (ft->get_front_voisin(1)==NULL)
213     {
214     ft->changer_front_voisin(ft2,1);
215     ft->changer_angle_voisin(angle_front(ft,ft2),1);
216     }
217     else
218     {
219     double angle=angle_front(ft,ft2);
220     if (angle<ft->get_angle_voisin(1))
221     {
222     ft->changer_front_voisin(ft2,1);
223     ft->changer_angle_voisin(angle,1);
224     }
225     }
226     }
227     }
228     for (int j=0;j<mgnoeud2->get_lien_triangle()->get_nb();j++)
229     for (int k=0;k<mgnoeud3->get_lien_triangle()->get_nb();k++)
230     {
231     M3D_TRIANGLE* tri1=(M3D_TRIANGLE*)mgnoeud2->get_lien_triangle()->get(j);
232     M3D_TRIANGLE* tri2=(M3D_TRIANGLE*)mgnoeud3->get_lien_triangle()->get(k);
233     if (tri1==tri2)
234     if (tri1->get_etat_front()==FRONT_ACTIF)
235     if (tri1->get_mgfront()!=ft)
236     {
237     MG_FRONT_3D* ft2=tri1->get_mgfront();
238     if (ft->get_front_voisin(2)==NULL)
239     {
240     ft->changer_front_voisin(ft2,2);
241     ft->changer_angle_voisin(angle_front(ft,ft2),2);
242     }
243     else
244     {
245     double angle=angle_front(ft,ft2);
246     if (angle<ft->get_angle_voisin(2))
247     {
248     ft->changer_front_voisin(ft2,2);
249     ft->changer_angle_voisin(angle,2);
250     }
251     }
252     }
253     }
254     if ( (ft->get_front_voisin(0)==NULL) || (ft->get_front_voisin(1)==NULL)|| (ft->get_front_voisin(2)==NULL))
255     refresh();
256     }
257    
258     }
259 francois 419
260 francois 283 }
261    
262    
263    
264     // FONCTIONS GERANT L ENTITE FRONT (ajout suppression et tout le bordel)
265     MG_FRONT_3D* MAILLEUR3D::ajouter_front_courant(int numero_front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
266     {
267     int numfront;
268     if (numero_front==NONFORCE)
269     {
270     numfront=(int)(triangle->get_longueur()/distance_maximale*10.);
271     if (numfront>10) numfront=10;
272     }
273     else numfront=numero_front;
274     MG_FRONT_3D* mgfront;
275     if (numfront>11) mgfront=ajouter_front(front_attente,noeud1,noeud2,noeud3,triangle);
276     else mgfront=ajouter_front(front_courant[numfront],noeud1,noeud2,noeud3,triangle);
277     mgfront->changer_numero_front(numfront);
278     if (triangle->get_type_entite()==IDM3D_TRIANGLE)
279     {
280     M3D_TRIANGLE* mtri=(M3D_TRIANGLE*)triangle;
281     mtri->change_etat_front(FRONT_ACTIF);
282     mtri->change_mgfront(mgfront);
283     }
284     return mgfront;
285     }
286    
287     MG_FRONT_3D* MAILLEUR3D::ajouter_front(FRONT& front,MG_NOEUD* noeud1,MG_NOEUD* noeud2,MG_NOEUD* noeud3,MG_TRIANGLE* triangle)
288     {
289     MG_FRONT_3D* ft=new MG_FRONT_3D(noeud1,noeud2,noeud3,triangle);
290     ajouter_front(front,ft);
291     octree_de_front->inserer(ft);
292     return ft;
293     }
294    
295     void MAILLEUR3D::ajouter_front(FRONT& front,MG_FRONT_3D *ft)
296     {
297     std::pair<const double,MG_FRONT_3D*> tmp(ft->get_triangle()->get_longueur(),ft);
298     front.insert(tmp);
299     }
300    
301     MG_FRONT_3D* MAILLEUR3D::get_front(FRONT& front,unsigned int num)
302     {
303     FRONT::iterator i=front.begin();
304     for (unsigned long j=0;j<num;j++) i++;
305     return ((*i).second);
306     }
307    
308    
309     unsigned int MAILLEUR3D::get_nb_front(FRONT& front)
310     {
311     return front.size();
312     }
313    
314     unsigned int MAILLEUR3D::get_nb_front_courant(void)
315     {
316    
317     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();
318     }
319    
320     void MAILLEUR3D::supprimer_front_en_avancant(MG_FRONT_3D* ft)
321     {
322     supprimer_front_en_avancant_sans_delete(ft);
323     delete ft;
324     }
325    
326     void MAILLEUR3D::supprimer_front_en_avancant_sans_delete(MG_FRONT_3D* ft)
327     {
328     octree_de_front->supprimer(ft);
329     int numfront=ft->get_numero_front();
330     FRONT* front_original;
331     if (numfront==ATTENTE)
332     front_original=&front_attente;
333     else
334     front_original=front_courant+numfront;
335     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
336     while (ft!=(*j).second) j++;
337     front_original->erase(j);
338     MG_TRIANGLE* mgtri=ft->get_triangle();
339     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
340     {
341     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
342     m3dtri->change_etat_front(FRONT_PASSE);
343     m3dtri->change_mgfront(NULL);
344     }
345     }
346    
347     void MAILLEUR3D::supprimer_front_en_reculant(MG_FRONT_3D* ft)
348     {
349     octree_de_front->supprimer(ft);
350     int numfront=ft->get_numero_front();
351     FRONT* front_original;
352     if (numfront==ATTENTE)
353     front_original=&front_attente;
354     else
355     front_original=front_courant+numfront;
356     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
357     while (ft!=(*j).second) j++;
358     front_original->erase(j);
359     MG_TRIANGLE* mgtri=ft->get_triangle();
360     if (mgtri->get_type_entite()==IDM3D_TRIANGLE)
361     {
362     M3D_TRIANGLE* m3dtri=(M3D_TRIANGLE*)mgtri;
363     m3dtri->change_etat_front(FRONT_NONACTIF);
364     m3dtri->change_mgfront(NULL);
365     }
366     delete ft;
367     }
368    
369     void MAILLEUR3D::echange_de_front(FRONT& front_original,FRONT& front_destination,MG_FRONT_3D* ft)
370     {
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     ajouter_front(front_destination,ft);
375     }
376    
377     void MAILLEUR3D::echange_de_front(MG_FRONT_3D* ft,int num)
378     {
379     int numfront;
380     if (num==NONFORCE)
381     {
382     numfront=(int)(ft->get_triangle()->get_longueur()/distance_maximale*10.);
383     if (numfront>10) numfront=10;
384     }
385     else if (num==ATTENTE) numfront=ATTENTE;
386     else numfront=num;
387     if (numfront>10) numfront=ATTENTE;
388     FRONT* front_original;
389     int num_front_original=ft->get_numero_front();
390     if (num_front_original==ATTENTE)
391     front_original=&front_attente;
392     else
393     front_original=front_courant+num_front_original;
394     FRONT* front_destination;
395     if (numfront==ATTENTE)
396     front_destination=&front_attente;
397     else
398     front_destination=front_courant+numfront;
399    
400    
401    
402     FRONT::iterator j=front_original->lower_bound(ft->get_triangle()->get_longueur());
403     while (ft!=(*j).second) j++;
404     front_original->erase(j);
405     ft->changer_numero_front(numfront);
406     ajouter_front(*front_destination,ft);
407    
408     }
409    
410    
411     void MAILLEUR3D::swap_front(FRONT& front_original,FRONT& front_destination)
412     {
413     front_original.swap(front_destination);
414     }
415    
416    
417    
418     int MAILLEUR3D::premier_front_courant(void)
419     {
420     int num=-1;
421     if (front_courant[0].size()>0) num=0;
422     else if (front_courant[1].size()>0) num=1;
423     else if (front_courant[2].size()>0) num=2;
424     else if (front_courant[3].size()>0) num=3;
425     else if (front_courant[4].size()>0) num=4;
426     else if (front_courant[5].size()>0) num=5;
427     else if (front_courant[6].size()>0) num=6;
428     else if (front_courant[7].size()>0) num=7;
429     else if (front_courant[8].size()>0) num=8;
430     else if (front_courant[9].size()>0) num=9;
431     else if (front_courant[10].size()>0) num=10;
432     return num;
433     }
434    
435    
436    
437     void MAILLEUR3D::active_log(char* nomfile)
438     {
439     activelog=1;
440     nomlog=nomfile;
441     }
442    
443     void MAILLEUR3D::desactive_log(void)
444     {
445     activelog=0;
446     }
447    
448 francois 287 void MAILLEUR3D::change_niveau_optimisation(int num)
449     {
450     niveau_optimisation=num;
451     }
452 francois 283
453 francois 287 int MAILLEUR3D::get_niveau_optimisation(void)
454     {
455     return niveau_optimisation;
456     }
457 francois 283
458 francois 494