ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur_auto/src/mailleur3d.cpp
Revision: 419
Committed: Tue Sep 10 20:10:09 2013 UTC (11 years, 8 months ago) by francois
Original Path: magic/lib/mailleur/src/mailleur3d.cpp
File size: 16347 byte(s)
Log Message:
Suppression d'opération superflue dans le mailleur 3D frontal

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