ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_grille.h
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Content type: text/plain
Original Path: magic/lib/template/template/src/tpl_grille.h
File size: 14666 byte(s)
Log Message:

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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     };
40    
41     virtual ~CELLULE_GRILLE_BASE() {};
42     virtual BOITE_3D get_boite(void)=0;
43     virtual unsigned long get_id() {return id;};
44     unsigned long id;
45     };
46    
47    
48     class GRILLE_BASE
49     {
50     public:
51     GRILLE_BASE() {};
52     virtual ~GRILLE_BASE() {};
53     virtual int get_nb_cellule(void)=0;
54     virtual CELLULE_GRILLE_BASE* get_cellule(int num)=0;
55     };
56    
57    
58     template <class A>
59     class TPL_CELLULE_GRILLE:public CELLULE_GRILLE_BASE
60     {
61     public:
62     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)
63     {
64     };
65     virtual ~TPL_CELLULE_GRILLE() {};
66     BOITE_3D get_boite(void) {return boite;};
67     BOITE_3D boite;
68     TPL_LISTE_ENTITE<A> lst_entite_A;
69     int get_nb_entite(void)
70     {
71     return lst_entite_A.get_nb();
72     };
73     A get_entite(int num)
74     {
75     return lst_entite_A.get(num);
76     };
77     };
78    
79     template <class A,class B>
80     class TPL_CELLULE_GRILLE_INFO:public CELLULE_GRILLE_BASE
81     {
82     public:
83     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)
84     {
85     };
86     virtual ~TPL_CELLULE_GRILLE_INFO() {};
87     BOITE_3D get_boite(void) {return boite;};
88     BOITE_3D boite;
89     TPL_LISTE_ENTITE<A> lst_entite_A;
90     B tab[8];
91     int get_nb_entite(void)
92     {
93     return lst_entite_A.get_nb();
94     };
95     A get_entite(int num)
96     {
97     return lst_entite_A.get(num);
98     };
99    
100     B get_info(int num) {return tab[num];};
101     void change_info(int num,B val) {tab[num]=val;};
102    
103     };
104    
105    
106    
107     template <class A>
108     class TPL_GRILLE:public GRILLE_BASE
109     {
110     public:
111     TPL_GRILLE() {};
112     ~TPL_GRILLE()
113     {
114     for (int i=0;i<lst_entite_cellule.get_nb();i++)
115     {
116     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(i);
117     delete cellule;
118     }
119     };
120    
121     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
122    
123     virtual TPL_CELLULE_GRILLE<A>* get_cellule(int num) {return lst_entite_cellule.get(num); };
124    
125    
126     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
127     {
128     nbpasx=nb_pasx;
129     nbpasy=nb_pasy;
130     nbpasz=nb_pasz;
131     pasx=(xmax-xmin)/nb_pasx;
132     pasy=(ymax-ymin)/nb_pasy;
133     pasz=(zmax-zmin)/nb_pasz;
134     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
135     for (int k=0;k<nb_pasz;k++)
136     for (int j=0;j<nb_pasy;j++)
137     for (int i=0;i<nb_pasx;i++)
138     {
139     double x1=xmin+i*pasx;
140     double x2=xmin+(i+1)*pasx;
141     double y1=ymin+j*pasy;
142     double y2=ymin+(j+1)*pasy;
143     double z1=zmin+k*pasz;
144     double z2=zmin+(k+1)*pasz;
145     TPL_CELLULE_GRILLE<A>* cellule=new TPL_CELLULE_GRILLE<A>(x1,y1,z1,x2,y2,z2);
146     lst_entite_cellule.ajouter(cellule);
147     }
148    
149     }
150    
151     virtual TPL_CELLULE_GRILLE<A> *get_cellule(double x,double y, double z)
152     {
153     int nx=(int)((x-boite.get_xmin())/pasx);
154     int ny=(int)((y-boite.get_ymin())/pasy);
155     int nz=(int)((z-boite.get_zmin())/pasz);
156     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
157     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
158     return lst_entite_cellule.get(num);
159     };
160    
161     virtual void get_coord_cellule(TPL_CELLULE_GRILLE<A>* cell,int& nx,int& ny,int& nz)
162     {
163     BOITE_3D boitecell=cell->get_boite();
164     double xyz[3];
165     boitecell.get_centre(xyz);
166     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
167     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
168     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
169     };
170    
171    
172     virtual TPL_CELLULE_GRILLE<A> *get_cellule(int nx,int ny,int nz)
173     {
174     if (nx>=nbpasx) return NULL;
175     if (ny>=nbpasy) return NULL;
176     if (nz>=nbpasz) return NULL;
177     if (nx<0) return NULL;
178     if (ny<0) return NULL;
179     if (nz<0) return NULL;
180     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
181     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
182     return lst_entite_cellule.get(num);
183     };
184    
185    
186    
187    
188     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
189     {
190     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
191     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
192     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
193     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
194     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
195     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
196     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
197     for (int i=nxmin;i<nxmax+1;i++)
198     for (int j=nymin;j<nymax+1;j++)
199     for (int k=nzmin;k<nzmax+1;k++)
200     {
201     /*int num=i+j*nbpasx+k*nbpasy*nbpasx;
202     if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
203     TPL_CELLULE_GRILLE<A>* cellule=lst_entite_cellule.get(num);*/
204     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
205     if (cellule==NULL) continue;
206     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
207     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
208     }
209     };
210    
211    
212     virtual void inserer(A a)
213     {
214     BOITE_3D bt=a->get_boite_3D();
215     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
216     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
217     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
218     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
219     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
220     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
221     for (int i=nxmin;i<nxmax+1;i++)
222     for (int j=nymin;j<nymax+1;j++)
223     for (int k=nzmin;k<nzmax+1;k++)
224     {
225     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
226     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
227     if (cellule==NULL) continue;
228     cellule->lst_entite_A.ajouter(a);
229     }
230     }
231    
232     virtual void supprimer(A a)
233     {
234     BOITE_3D bt=a->get_boite_3D();
235     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
236     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
237     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
238     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
239     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
240     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
241     for (int i=nxmin;i<nxmax+1;i++)
242     for (int j=nymin;j<nymax+1;j++)
243     for (int k=nzmin;k<nzmax+1;k++)
244     {
245     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
246     TPL_CELLULE_GRILLE<A>* cellule=get_cellule(i,j,k);
247     if (cellule==NULL) continue;
248     cellule->lst_entite_A.supprimer(a);
249     }
250     }
251    
252     virtual BOITE_3D get_boite(void)
253     {
254     return boite;
255     }
256    
257     virtual int get_pasx(void)
258     {
259     return nbpasx;
260     }
261    
262     virtual int get_pasy(void)
263     {
264     return nbpasy;
265     }
266    
267     virtual int get_pasz(void)
268     {
269     return nbpasz;
270     }
271    
272     private:
273     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE<A>* > lst_entite_cellule;
274     double pasx;
275     double pasy;
276     double pasz;
277     int nbpasx;
278     int nbpasy;
279     int nbpasz;
280     BOITE_3D boite;
281     };
282    
283    
284    
285    
286    
287     template <class A,class B>
288     class TPL_GRILLE_INFO:public GRILLE_BASE
289     {
290     public:
291     TPL_GRILLE_INFO() {};
292     ~TPL_GRILLE_INFO()
293     {
294     for (int i=0;i<lst_entite_cellule.get_nb();i++)
295     {
296     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(i);
297     delete cellule;
298     }
299     };
300    
301     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
302    
303    
304    
305     virtual TPL_CELLULE_GRILLE_INFO<A,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
306    
307    
308     virtual void initialiser(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int nb_pasx,int nb_pasy,int nb_pasz)
309     {
310     nbpasx=nb_pasx;
311     nbpasy=nb_pasy;
312     nbpasz=nb_pasz;
313     pasx=(xmax-xmin)/nb_pasx;
314     pasy=(ymax-ymin)/nb_pasy;
315     pasz=(zmax-zmin)/nb_pasz;
316     boite.reinit(xmin,ymin,zmin,xmax,ymax,zmax);
317     for (int k=0;k<nb_pasz;k++)
318     for (int j=0;j<nb_pasy;j++)
319     for (int i=0;i<nb_pasx;i++)
320     {
321     double x1=xmin+i*pasx;
322     double x2=xmin+(i+1)*pasx;
323     double y1=ymin+j*pasy;
324     double y2=ymin+(j+1)*pasy;
325     double z1=zmin+k*pasz;
326     double z2=zmin+(k+1)*pasz;
327     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=new TPL_CELLULE_GRILLE_INFO<A,B>(x1,y1,z1,x2,y2,z2);
328     lst_entite_cellule.ajouter(cellule);
329     }
330    
331     }
332    
333     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(double x,double y, double z)
334     {
335     int nx=(int)((x-boite.get_xmin())/pasx);
336     int ny=(int)((y-boite.get_ymin())/pasy);
337     int nz=(int)((z-boite.get_zmin())/pasz);
338     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
339     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
340     return lst_entite_cellule.get(num);
341     };
342    
343     virtual void get_coord_cellule(TPL_CELLULE_GRILLE_INFO<A,B>* cell,int& nx,int& ny,int& nz)
344     {
345     BOITE_3D boitecell=cell->get_boite();
346     double xyz[3];
347     boitecell.get_centre(xyz);
348     nx=(int)((xyz[0]-boite.get_xmin())/pasx);
349     ny=(int)((xyz[1]-boite.get_ymin())/pasy);
350     nz=(int)((xyz[2]-boite.get_zmin())/pasz);
351     };
352    
353    
354     virtual TPL_CELLULE_GRILLE_INFO<A,B> *get_cellule(int nx,int ny,int nz)
355     {
356     if (nx>=nbpasx) return NULL;
357     if (ny>=nbpasy) return NULL;
358     if (nz>=nbpasz) return NULL;
359     if (nx<0) return NULL;
360     if (ny<0) return NULL;
361     if (nz<0) return NULL;
362     int num=nx+ny*nbpasx+nz*nbpasy*nbpasx;
363     if ((num<0) || (num>=lst_entite_cellule.get_nb()) ) return NULL;
364     return lst_entite_cellule.get(num);
365     };
366    
367    
368     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
369     {
370     BOITE_3D bt(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
371     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
372     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
373     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
374     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
375     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
376     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
377     for (int i=nxmin;i<nxmax+1;i++)
378     for (int j=nymin;j<nymax+1;j++)
379     for (int k=nzmin;k<nzmax+1;k++)
380     {
381     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
382     //if ((num<0) || (num>=lst_entite_cellule.get_nb())) continue;
383     //TPL_CELLULE_GRILLE_INFO<A,B>* cellule=lst_entite_cellule.get(num);
384     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
385     if (cellule==NULL) continue;
386     for (int ii=0;ii<cellule->lst_entite_A.get_nb();ii++)
387     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(ii));
388     }
389    
390     };
391    
392    
393     virtual void inserer(A a)
394     {
395     BOITE_3D bt=a->get_boite_3D();
396     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
397     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
398     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
399     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
400     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
401     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
402     for (int i=nxmin;i<nxmax+1;i++)
403     for (int j=nymin;j<nymax+1;j++)
404     for (int k=nzmin;k<nzmax+1;k++)
405     {
406     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
407     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
408     if (cellule==NULL) continue;
409     cellule->lst_entite_A.ajouter(a);
410     }
411     }
412    
413     virtual void supprimer(A a)
414     {
415     BOITE_3D bt=a->get_boite_3D();
416     int nxmin=(int)((bt.get_xmin()-boite.get_xmin())/pasx);
417     int nymin=(int)((bt.get_ymin()-boite.get_ymin())/pasy);
418     int nzmin=(int)((bt.get_zmin()-boite.get_zmin())/pasz);
419     int nxmax=(int)((bt.get_xmax()-boite.get_xmin())/pasx);
420     int nymax=(int)((bt.get_ymax()-boite.get_ymin())/pasy);
421     int nzmax=(int)((bt.get_zmax()-boite.get_zmin())/pasz);
422     for (int i=nxmin;i<nxmax+1;i++)
423     for (int j=nymin;j<nymax+1;j++)
424     for (int k=nzmin;k<nzmax+1;k++)
425     {
426     //int num=i+j*nbpasx+k*nbpasy*nbpasx;
427     TPL_CELLULE_GRILLE_INFO<A,B>* cellule=get_cellule(i,j,k);
428     if (cellule==NULL) continue;
429     cellule->lst_entite_A.supprimer(a);
430     }
431     }
432    
433     virtual BOITE_3D get_boite(void)
434     {
435     return boite;
436     }
437    
438     virtual int get_pasx(void)
439     {
440     return nbpasx;
441     }
442    
443     virtual int get_pasy(void)
444     {
445     return nbpasy;
446     }
447    
448     virtual int get_pasz(void)
449     {
450     return nbpasz;
451     }
452    
453     private:
454     TPL_LISTE_ENTITE<TPL_CELLULE_GRILLE_INFO<A,B>* > lst_entite_cellule;
455     double pasx;
456     double pasy;
457     double pasz;
458     int nbpasx;
459     int nbpasy;
460     int nbpasz;
461     BOITE_3D boite;
462     };
463    
464    
465    
466    
467    
468    
469     #endif