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