ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mailleur_auto/src/mailleur3d.cpp
Revision: 469
Committed: Wed Nov 27 20:02:22 2013 UTC (11 years, 5 months ago) by francois
File size: 16014 byte(s)
Log Message:
ajout d'un generateur de carte de taille constante pour les nouvelles cartes et decoupage de la librairie mailleur en 2 pour cause d'appel cyclique

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