ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_grille.h
Revision: 295
Committed: Tue Nov 8 21:46:30 2011 UTC (13 years, 6 months ago) by francois
Content type: text/plain
File size: 15462 byte(s)
Log Message:
Mise a jour des CMakeListe pour rendre les choix possible

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4 francois 106 // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6 5 //------------------------------------------------------------
7 francois 106 // 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 5 // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // tpl_grille.h
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20 francois 106 // Version du 02/03/2006 � 11H24
21 5 //------------------------------------------------------------
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 francois 106 tag=0;
40 5 };
41    
42     virtual ~CELLULE_GRILLE_BASE() {};
43     virtual BOITE_3D get_boite(void)=0;
44     virtual unsigned long get_id() {return id;};
45 francois 106 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 5 unsigned long id;
56 francois 106 int tag;
57 5 };
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 francois 106
90    
91 5 };
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 francois 106
134    
135    
136 5 };
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    
204    
205     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
206     {
207     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
208     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
209     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
210     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
211     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
212     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
213     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
214     for (int i=nxmin;i<nxmax+1;i++)
215     for (int j=nymin;j<nymax+1;j++)
216     for (int k=nzmin;k<nzmax+1;k++)
217     {
218     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
219     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
220     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
221     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
222     if (cellule==NULL) continue;
223     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
224     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
225     }
226     };
227    
228    
229     virtual void inserer(A a)
230     {
231     BOITE_3D bt=a->get_boite_3D();
232     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
233     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
234     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
235     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
236     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
237     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
238     for (int i=nxmin;i<nxmax+1;i++)
239     for (int j=nymin;j<nymax+1;j++)
240     for (int k=nzmin;k<nzmax+1;k++)
241     {
242     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
243     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
244     if (cellule==NULL) continue;
245     cellule->lst_entite_A.ajouter(a);
246     }
247     }
248    
249     virtual void supprimer(A a)
250     {
251     BOITE_3D bt=a->get_boite_3D();
252     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
253     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
254     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
255     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
256     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
257     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
258     for (int i=nxmin;i<nxmax+1;i++)
259     for (int j=nymin;j<nymax+1;j++)
260     for (int k=nzmin;k<nzmax+1;k++)
261     {
262     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
263     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
264     if (cellule==NULL) continue;
265     cellule->lst_entite_A.supprimer(a);
266     }
267     }
268    
269     virtual BOITE_3D get_boite(void)
270     {
271     return boite;
272     }
273    
274     virtual int get_pasx(void)
275     {
276     return nbpasx;
277     }
278    
279     virtual int get_pasy(void)
280     {
281     return nbpasy;
282     }
283    
284     virtual int get_pasz(void)
285     {
286     return nbpasz;
287     }
288    
289 francois 106
290 5 private:
291     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE<A>* > lst_entite_cellule;
292     double pasx;
293     double pasy;
294     double pasz;
295     int nbpasx;
296     int nbpasy;
297     int nbpasz;
298     BOITE_3D boite;
299     };
300    
301    
302    
303     template <class A,class B>
304     class TPL_GRILLE_INFO:public GRILLE_BASE
305     {
306     public:
307     TPL_GRILLE_INFO() {};
308     ~TPL_GRILLE_INFO()
309     {
310     for (int i=0;i<lst_entite_cellule.get_nb();i++)
311     {
312     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(i);
313     delete cellule;
314     }
315     };
316    
317     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
318    
319    
320    
321     virtual TPL_CELLULE_GRILLE_INFO<A,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
322    
323    
324     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
325     {
326     nbpasx=nb_pasx;
327     nbpasy=nb_pasy;
328     nbpasz=nb_pasz;
329     pasx=(xmax-xmin)/nb_pasx;
330     pasy=(ymax-ymin)/nb_pasy;
331     pasz=(zmax-zmin)/nb_pasz;
332     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
333     for (int k=0;k<nb_pasz;k++)
334     for (int j=0;j<nb_pasy;j++)
335     for (int i=0;i<nb_pasx;i++)
336     {
337     double x1=xmin+i*pasx;
338     double x2=xmin+(i+1)*pasx;
339     double y1=ymin+j*pasy;
340     double y2=ymin+(j+1)*pasy;
341     double z1=zmin+k*pasz;
342     double z2=zmin+(k+1)*pasz;
343     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=new TPL_CELLULE_GRILLE_INFO<A,B>(x1,y1,z1,x2,y2,z2);
344     lst_entite_cellule.ajouter(cellule);
345     }
346    
347     }
348    
349     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(double x,double y, double z)
350     {
351     int nx=(int)((x-boite.get_xmin())/pasx);
352     int ny=(int)((y-boite.get_ymin())/pasy);
353     int nz=(int)((z-boite.get_zmin())/pasz);
354     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
355     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
356     return lst_entite_cellule.get(num);
357     };
358    
359     virtual void get_coord_cellule(TPL_CELLULE_GRILLE_INFO<A,B>* cell,int& nx,int& ny,int& nz)
360     {
361     BOITE_3D boitecell=cell->get_boite();
362     double xyz[3];
363     boitecell.get_centre(xyz);
364     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
365     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
366     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
367     };
368    
369    
370     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(int nx,int ny,int nz)
371     {
372     if (nx>=nbpasx) return NULL;
373     if (ny>=nbpasy) return NULL;
374     if (nz>=nbpasz) return NULL;
375     if (nx<0) return NULL;
376     if (ny<0) return NULL;
377     if (nz<0) return NULL;
378     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
379     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
380     return lst_entite_cellule.get(num);
381     };
382    
383    
384     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
385     {
386     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
387     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
388     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
389     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
390     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
391     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
392     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
393     for (int i=nxmin;i<nxmax+1;i++)
394     for (int j=nymin;j<nymax+1;j++)
395     for (int k=nzmin;k<nzmax+1;k++)
396     {
397     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
398     //if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
399     //TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(num);
400     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
401     if (cellule==NULL) continue;
402     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
403     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
404     }
405    
406     };
407    
408    
409     virtual void inserer(A a)
410     {
411     BOITE_3D bt=a->get_boite_3D();
412     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
413     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
414     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
415     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
416     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
417     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
418     for (int i=nxmin;i<nxmax+1;i++)
419     for (int j=nymin;j<nymax+1;j++)
420     for (int k=nzmin;k<nzmax+1;k++)
421     {
422     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
423     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
424     if (cellule==NULL) continue;
425     cellule->lst_entite_A.ajouter(a);
426     }
427     }
428    
429     virtual void supprimer(A a)
430     {
431     BOITE_3D bt=a->get_boite_3D();
432     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
433     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
434     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
435     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
436     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
437     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
438     for (int i=nxmin;i<nxmax+1;i++)
439     for (int j=nymin;j<nymax+1;j++)
440     for (int k=nzmin;k<nzmax+1;k++)
441     {
442     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
443     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
444     if (cellule==NULL) continue;
445     cellule->lst_entite_A.supprimer(a);
446     }
447     }
448    
449     virtual BOITE_3D get_boite(void)
450     {
451     return boite;
452     }
453    
454     virtual int get_pasx(void)
455     {
456     return nbpasx;
457     }
458    
459     virtual int get_pasy(void)
460     {
461     return nbpasy;
462     }
463    
464     virtual int get_pasz(void)
465     {
466     return nbpasz;
467     }
468    
469 francois 106
470     virtual unsigned long determine_keycode(int nx,int ny,int nz)
471     {
472 francois 295 std::vector<int> bits;
473 francois 106 int ok=0,i=0;
474     do
475     {
476     int nnz=nz>>i;
477     int nny=ny>>i;
478     int nnx=nx>>i;
479     int bit1= nnz & 1;
480     int bit2= nny & 1;
481     int bit3= nnx & 1;
482     if ((nnz==0) && (nny==0) && (nnx==0)) ok=1;
483     bits.insert(bits.end(),bit1);
484     bits.insert(bits.end(),bit2);
485     bits.insert(bits.end(),bit3);
486     i++;
487     }
488     while (ok==0);
489     unsigned long keycode=0;
490     for (int i=0;i<bits.size();i++)
491     keycode=keycode+bits[i]*(1<<i);
492     return keycode;
493     }
494    
495 5 private:
496     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE_INFO<A,B>* > lst_entite_cellule;
497     double pasx;
498     double pasy;
499     double pasz;
500     int nbpasx;
501     int nbpasy;
502     int nbpasz;
503     BOITE_3D boite;
504     };
505    
506    
507    
508    
509    
510    
511     #endif