ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/poly_occ/src/tpl_grille.h
Revision: 1009
Committed: Mon Mar 25 16:40:06 2019 UTC (6 years, 1 month ago) by francois
Content type: text/plain
File size: 16776 byte(s)
Log Message:
ajout de fichier pour les polycristaux (ajout temporaire)

File Contents

# User Rev Content
1 francois 1009 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du d�partement
8     // de g�nie m�canique de l'Universit� du Qu�bec �
9     // Trois Rivi�res
10     // Les librairies ne peuvent �tre utilis�es sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // tpl_grille.h
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 � 11H24
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23     #ifndef _TPLGRILLE_
24     #define _TPLGRILLE_
25    
26    
27     #include "ot_boite_3d.h"
28     #include "tpl_liste_entite.h"
29     #include "tpl_map_entite.h"
30    
31     class CELLULE_GRILLE_BASE
32     {
33     public:
34     CELLULE_GRILLE_BASE()
35     {
36     static unsigned long idmax=0;
37     id=idmax;
38     idmax++;
39     tag=0;
40     };
41    
42     virtual ~CELLULE_GRILLE_BASE() {};
43     virtual BOITE_3D get_boite(void)=0;
44     virtual unsigned long get_id() {return id;};
45     virtual int get_tag(void)
46     {
47     return tag;
48     };
49     virtual void change_tag(int val)
50     {
51     tag=val;
52     };
53    
54     private :
55     unsigned long id;
56     int tag;
57     };
58    
59    
60     class GRILLE_BASE
61     {
62     public:
63     GRILLE_BASE() {};
64     virtual ~GRILLE_BASE() {};
65     virtual int get_nb_cellule(void)=0;
66     virtual CELLULE_GRILLE_BASE* get_cellule(int num)=0;
67     };
68    
69    
70     template <class A>
71     class TPL_CELLULE_GRILLE:public CELLULE_GRILLE_BASE
72     {
73     public:
74     TPL_CELLULE_GRILLE(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_GRILLE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
75     {
76     };
77     virtual ~TPL_CELLULE_GRILLE() {};
78     BOITE_3D get_boite(void) {return boite;};
79     BOITE_3D boite;
80     TPL_LISTE_ENTITE<A> lst_entite_A;
81     int get_nb_entite(void)
82     {
83     return lst_entite_A.get_nb();
84     };
85     A get_entite(int num)
86     {
87     return lst_entite_A.get(num);
88     };
89    
90    
91     };
92    
93     template <class A,class B>
94     class TPL_CELLULE_GRILLE_INFO:public CELLULE_GRILLE_BASE
95     {
96     public:
97     TPL_CELLULE_GRILLE_INFO(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_GRILLE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
98     {
99     };
100     virtual ~TPL_CELLULE_GRILLE_INFO() {};
101     BOITE_3D get_boite(void) {return boite;};
102     BOITE_3D boite;
103     TPL_LISTE_ENTITE<A> lst_entite_A;
104     B tab[8];
105     int get_nb_entite(void)
106     {
107     return lst_entite_A.get_nb();
108     };
109     A get_entite(int num)
110     {
111     return lst_entite_A.get(num);
112     };
113    
114     B get_info(int num) {return tab[num];};
115     void change_info(int num,B val) {tab[num]=val;};
116    
117     };
118    
119    
120    
121     template <class A>
122     class TPL_GRILLE:public GRILLE_BASE
123     {
124     public:
125     TPL_GRILLE() {};
126     ~TPL_GRILLE()
127     {
128     for (int i=0;i<lst_entite_cellule.get_nb();i++)
129     {
130     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(i);
131     delete cellule;
132     }
133    
134    
135    
136     };
137    
138     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
139    
140     virtual TPL_CELLULE_GRILLE<A>* get_cellule(int num) {return lst_entite_cellule.get(num); };
141    
142    
143     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
144     {
145     nbpasx=nb_pasx;
146     nbpasy=nb_pasy;
147     nbpasz=nb_pasz;
148     pasx=(xmax-xmin)/nb_pasx;
149     pasy=(ymax-ymin)/nb_pasy;
150     pasz=(zmax-zmin)/nb_pasz;
151     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
152     for (int k=0;k<nb_pasz;k++)
153     for (int j=0;j<nb_pasy;j++)
154     for (int i=0;i<nb_pasx;i++)
155     {
156     double x1=xmin+i*pasx;
157     double x2=xmin+(i+1)*pasx;
158     double y1=ymin+j*pasy;
159     double y2=ymin+(j+1)*pasy;
160     double z1=zmin+k*pasz;
161     double z2=zmin+(k+1)*pasz;
162     TPL_CELLULE_GRILLE<A>* cellule=new TPL_CELLULE_GRILLE<A>(x1,y1,z1,x2,y2,z2);
163     lst_entite_cellule.ajouter(cellule);
164     }
165    
166     }
167    
168     virtual TPL_CELLULE_GRILLE<A> *get_cellule(double x,double y, double z)
169     {
170     int nx=(int)((x-boite.get_xmin())/pasx);
171     int ny=(int)((y-boite.get_ymin())/pasy);
172     int nz=(int)((z-boite.get_zmin())/pasz);
173     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
174     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
175     return lst_entite_cellule.get(num);
176     };
177    
178     virtual void get_coord_cellule(TPL_CELLULE_GRILLE<A>* cell,int& nx,int& ny,int& nz)
179     {
180     BOITE_3D boitecell=cell->get_boite();
181     double xyz[3];
182     boitecell.get_centre(xyz);
183     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
184     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
185     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
186     };
187    
188    
189     virtual TPL_CELLULE_GRILLE<A> *get_cellule(int nx,int ny,int nz)
190     {
191     if (nx>=nbpasx) return NULL;
192     if (ny>=nbpasy) return NULL;
193     if (nz>=nbpasz) return NULL;
194     if (nx<0) return NULL;
195     if (ny<0) return NULL;
196     if (nz<0) return NULL;
197     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
198     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
199     return lst_entite_cellule.get(num);
200     };
201    
202    
203     virtual void rechercher(BOITE_3D bt,TPL_MAP_ENTITE<A>& liste_entite_trouve)
204     {
205     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
206     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
207     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
208     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
209     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
210     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
211     for (int i=nxmin;i<nxmax+1;i++)
212     for (int j=nymin;j<nymax+1;j++)
213     for (int k=nzmin;k<nzmax+1;k++)
214     {
215     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
216     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
217     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
218     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
219     if (cellule==NULL) continue;
220     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
221     if (bt*cellule->lst_entite_A.get(ii)->get_boite_3D())
222     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
223     }
224     };
225    
226     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
227     {
228     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
229     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
230     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
231     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
232     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
233     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
234     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
235     for (int i=nxmin;i<nxmax+1;i++)
236     for (int j=nymin;j<nymax+1;j++)
237     for (int k=nzmin;k<nzmax+1;k++)
238     {
239     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
240     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
241     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
242     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
243     if (cellule==NULL) continue;
244     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
245     if (bt*cellule->lst_entite_A.get(ii)->get_boite_3D())
246     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
247     }
248     };
249    
250    
251     virtual void inserer(A a)
252     {
253     BOITE_3D bt=a->get_boite_3D();
254     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
255     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
256     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
257     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
258     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
259     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
260     for (int i=nxmin;i<nxmax+1;i++)
261     for (int j=nymin;j<nymax+1;j++)
262     for (int k=nzmin;k<nzmax+1;k++)
263     {
264     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
265     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
266     if (cellule==NULL) continue;
267     cellule->lst_entite_A.ajouter(a);
268     }
269     }
270    
271     virtual void supprimer(A a)
272     {
273     BOITE_3D bt=a->get_boite_3D();
274     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
275     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
276     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
277     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
278     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
279     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
280     for (int i=nxmin;i<nxmax+1;i++)
281     for (int j=nymin;j<nymax+1;j++)
282     for (int k=nzmin;k<nzmax+1;k++)
283     {
284     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
285     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
286     if (cellule==NULL) continue;
287     cellule->lst_entite_A.supprimer(a);
288     }
289     }
290    
291     virtual BOITE_3D get_boite(void)
292     {
293     return boite;
294     }
295    
296     virtual int get_pasx(void)
297     {
298     return nbpasx;
299     }
300    
301     virtual int get_pasy(void)
302     {
303     return nbpasy;
304     }
305    
306     virtual int get_pasz(void)
307     {
308     return nbpasz;
309     }
310    
311    
312     private:
313     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE<A>* > lst_entite_cellule;
314     double pasx;
315     double pasy;
316     double pasz;
317     int nbpasx;
318     int nbpasy;
319     int nbpasz;
320     BOITE_3D boite;
321     };
322    
323    
324    
325     template <class A,class B>
326     class TPL_GRILLE_INFO:public GRILLE_BASE
327     {
328     public:
329     TPL_GRILLE_INFO() {};
330     ~TPL_GRILLE_INFO()
331     {
332     for (int i=0;i<lst_entite_cellule.get_nb();i++)
333     {
334     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(i);
335     delete cellule;
336     }
337     };
338    
339     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
340    
341    
342    
343     virtual TPL_CELLULE_GRILLE_INFO<A,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
344    
345    
346     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
347     {
348     nbpasx=nb_pasx;
349     nbpasy=nb_pasy;
350     nbpasz=nb_pasz;
351     pasx=(xmax-xmin)/nb_pasx;
352     pasy=(ymax-ymin)/nb_pasy;
353     pasz=(zmax-zmin)/nb_pasz;
354     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
355     for (int k=0;k<nb_pasz;k++)
356     for (int j=0;j<nb_pasy;j++)
357     for (int i=0;i<nb_pasx;i++)
358     {
359     double x1=xmin+i*pasx;
360     double x2=xmin+(i+1)*pasx;
361     double y1=ymin+j*pasy;
362     double y2=ymin+(j+1)*pasy;
363     double z1=zmin+k*pasz;
364     double z2=zmin+(k+1)*pasz;
365     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=new TPL_CELLULE_GRILLE_INFO<A,B>(x1,y1,z1,x2,y2,z2);
366     lst_entite_cellule.ajouter(cellule);
367     }
368    
369     }
370    
371     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(double x,double y, double z)
372     {
373     int nx=(int)((x-boite.get_xmin())/pasx);
374     int ny=(int)((y-boite.get_ymin())/pasy);
375     int nz=(int)((z-boite.get_zmin())/pasz);
376     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
377     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
378     return lst_entite_cellule.get(num);
379     };
380    
381     virtual void get_coord_cellule(TPL_CELLULE_GRILLE_INFO<A,B>* cell,int& nx,int& ny,int& nz)
382     {
383     BOITE_3D boitecell=cell->get_boite();
384     double xyz[3];
385     boitecell.get_centre(xyz);
386     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
387     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
388     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
389     };
390    
391    
392     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(int nx,int ny,int nz)
393     {
394     if (nx>=nbpasx) return NULL;
395     if (ny>=nbpasy) return NULL;
396     if (nz>=nbpasz) return NULL;
397     if (nx<0) return NULL;
398     if (ny<0) return NULL;
399     if (nz<0) return NULL;
400     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
401     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
402     return lst_entite_cellule.get(num);
403     };
404    
405    
406     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
407     {
408     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
409     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
410     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
411     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
412     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
413     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
414     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
415     for (int i=nxmin;i<nxmax+1;i++)
416     for (int j=nymin;j<nymax+1;j++)
417     for (int k=nzmin;k<nzmax+1;k++)
418     {
419     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
420     //if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
421     //TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(num);
422     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
423     if (cellule==NULL) continue;
424     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
425     if (bt*cellule->lst_entite_A.get(ii)->get_boite_3D())
426     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
427     }
428    
429     };
430    
431    
432     virtual void inserer(A a)
433     {
434     BOITE_3D bt=a->get_boite_3D();
435     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
436     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
437     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
438     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
439     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
440     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
441     for (int i=nxmin;i<nxmax+1;i++)
442     for (int j=nymin;j<nymax+1;j++)
443     for (int k=nzmin;k<nzmax+1;k++)
444     {
445     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
446     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
447     if (cellule==NULL) continue;
448     cellule->lst_entite_A.ajouter(a);
449     }
450     }
451    
452     virtual void supprimer(A a)
453     {
454     BOITE_3D bt=a->get_boite_3D();
455     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
456     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
457     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
458     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
459     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
460     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
461     for (int i=nxmin;i<nxmax+1;i++)
462     for (int j=nymin;j<nymax+1;j++)
463     for (int k=nzmin;k<nzmax+1;k++)
464     {
465     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
466     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
467     if (cellule==NULL) continue;
468     cellule->lst_entite_A.supprimer(a);
469     }
470     }
471    
472     virtual BOITE_3D get_boite(void)
473     {
474     return boite;
475     }
476    
477     virtual int get_pasx(void)
478     {
479     return nbpasx;
480     }
481    
482     virtual int get_pasy(void)
483     {
484     return nbpasy;
485     }
486    
487     virtual int get_pasz(void)
488     {
489     return nbpasz;
490     }
491    
492    
493     virtual unsigned long determine_keycode(int nx,int ny,int nz)
494     {
495     std::vector<int> bits;
496     int ok=0,i=0;
497     do
498     {
499     int nnz=nz>>i;
500     int nny=ny>>i;
501     int nnx=nx>>i;
502     int bit1= nnz & 1;
503     int bit2= nny & 1;
504     int bit3= nnx & 1;
505     if ((nnz==0) && (nny==0) && (nnx==0)) ok=1;
506     bits.insert(bits.end(),bit1);
507     bits.insert(bits.end(),bit2);
508     bits.insert(bits.end(),bit3);
509     i++;
510     }
511     while (ok==0);
512     unsigned long keycode=0;
513     for (int i=0;i<bits.size();i++)
514     keycode=keycode+bits[i]*(1<<i);
515     return keycode;
516     }
517    
518     private:
519     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE_INFO<A,B>* > lst_entite_cellule;
520     double pasx;
521     double pasy;
522     double pasz;
523     int nbpasx;
524     int nbpasy;
525     int nbpasz;
526     BOITE_3D boite;
527     };
528    
529    
530    
531    
532    
533    
534     #endif