ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_octree.h
Revision: 481
Committed: Tue Jan 28 16:10:58 2014 UTC (11 years, 3 months ago) by francois
Content type: text/plain
File size: 47779 byte(s)
Log Message:
unification de la facon d'ecrire les fichiers tous en minuscules

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4 francois 276 // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6 5 //------------------------------------------------------------
7 francois 276 // 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_octree.h
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20 francois 276 // Version du 02/03/2006 � 11H24
21 5 //------------------------------------------------------------
22     //------------------------------------------------------------
23     #ifndef _TPLOCTREE_
24     #define _TPLOCTREE_
25    
26    
27 francois 481 #include "ot_boite_3d.h"
28 5 #include "tpl_liste_entite.h"
29     #include "tpl_map_entite.h"
30 francois 65 #include <math.h>
31 5
32 francois 65 #define ID 0
33     #define IF 1
34     #define IR 2
35     #define IB 3
36     #define IL 4
37     #define IU 5
38     #define IDF 6
39     #define ILD 7
40     #define ILF 8
41     #define IRD 9
42     #define IRF 10
43     #define IDB 11
44     #define IRB 12
45     #define ILB 13
46     #define IUF 14
47     #define ILU 15
48     #define IRU 16
49     #define IUB 17
50    
51 francois 102 using namespace std;
52 francois 65
53     class OUTIL_OCTREE
54     {
55     public:
56     OUTIL_OCTREE()
57     {
58     };
59     ~OUTIL_OCTREE()
60     {
61     };
62    
63     unsigned long determine_keycode(int nx,int ny,int nz)
64     {
65     vector<int> bits;
66     int ok=0,i=0;
67     do
68     {
69     int nnz=nz>>i;
70     int nny=ny>>i;
71     int nnx=nx>>i;
72     int bit1= nnz & 1;
73     int bit2= nny & 1;
74     int bit3= nnx & 1;
75     if ((nnz==0) && (nny==0) && (nnx==0)) ok=1;
76     bits.insert(bits.end(),bit1);
77     bits.insert(bits.end(),bit2);
78     bits.insert(bits.end(),bit3);
79     i++;
80     }
81     while (ok==0);
82     unsigned long keycode=0;
83     for (int i=0;i<bits.size();i++)
84     keycode=keycode+bits[i]*(1<<i);
85     return keycode;
86     }
87    
88    
89     bool adjacent(int direction,int octant)
90     {
91     bool tabadj[18][8]=
92     {
93     {true, true, true, true, false, false, false, false},
94     {true, true, false, false, true, true, false, false},
95     {false, true, false, true, false, true, false, true},
96     {false, false, true, true, false, false, true, true},
97     {true, false, true, false, true, false, true, false},
98     {false, false, false, false, true, true, true, true},
99     {true, true, false, false, false, false, false, false},
100     {true, false, true, false, false, false, false, false},
101     {true, false, false, false, true, false, false, false},
102     {false, true, false, true, false, false, false, false},
103     {false, true, false, false, false, true, false, false},
104     {false, false, true, true, false, false, false, false},
105     {false, false, false, true, false, false, false, true},
106     {false, false, true, false, false, false, true, false},
107     {false, false, false, false, true, true, false, false},
108     {false, false, false, false, true, false, true, false},
109     {false, false, false, false, false, true, false, true},
110     {false, false, false, false, false, false, true, true},
111    
112     };
113    
114     return tabadj[direction][octant];
115     }
116    
117    
118     int reflect(int direction,int octant)
119     {
120     int tabreflect[18][8]=
121     {
122     {4, 5, 6, 7, 0, 1, 2, 3},
123     {2, 3, 0, 1, 6, 7, 4, 5},
124     {1, 0, 3, 2, 5, 4, 7, 6},
125     {2, 3, 0, 1, 6, 7, 4, 5},
126     {1, 0, 3, 2, 5, 4, 7, 6},
127     {4, 5, 6, 7, 0, 1, 2, 3},
128     {6, 7, 4, 5, 2, 3, 0, 1},
129     {5, 4, 7, 6, 1, 0, 3, 2},
130     {3, 2, 1, 0, 7, 6, 5, 4},
131     {5, 4, 7, 6, 1, 0, 3, 2},
132     {3, 2, 1, 0, 7, 6, 5, 4},
133     {6, 7, 4, 5, 2, 3, 0, 1},
134     {3, 2, 1, 0, 7, 6, 5, 4},
135     {3, 2, 1, 0, 7, 6, 5, 4},
136     {6, 7, 4, 5, 2, 3, 0, 1},
137     {5, 4, 7, 6, 1, 0, 3, 2},
138     {5, 4, 7, 6, 1, 0, 3, 2},
139     {6, 7, 4, 5, 2, 3, 0, 1}
140    
141     };
142    
143     return tabreflect[direction][octant];
144     }
145    
146    
147    
148     int commonface(int direction,int octant)
149     {
150     int tabcommonface[12][8]=
151     {
152     {-1, -1, 0, 0, 1, 1, -1, -1},
153     {-1, 0, -1, 0, 4, -1, 4, -1},
154     {-1, 1, 4, -1, -1, 1, 4, -1},
155     {0, -1, 0, -1, -1, 2, -1, 2},
156     {1, -1, -1, 2, 1, -1, -1, 2},
157     {0, 0, -1, -1, -1, -1, 3, 3},
158     {-1, 2, 3, -1, -1, 2, 3, -1},
159     {4, -1, -1, 3, 4, -1, -1, 3},
160     {1, 1, -1, -1, -1, -1, 5, 5},
161     {4, -1, 4, -1, -1, 5, -1, 5},
162     {-1, 2, -1, 2, 5, -1, 5, -1},
163     {-1, -1, 3, 3, 5, 5, -1, -1},
164     } ;
165     return tabcommonface[direction-6][octant];
166    
167     }
168    
169     int filsvoisin(int direction,int numvoisin)
170     {
171     int tab[6][4]=
172     {
173     {4, 5, 6, 7},
174     {2, 3, 6, 7},
175     {0, 2, 4, 6},
176     {0, 1, 4, 5},
177     {1, 3, 5, 7},
178     {0, 1, 2, 3}
179     };
180     return tab[direction][numvoisin];
181     }
182    
183     int sommetface(int numface,int numsommet)
184     {
185     int tab[6][4]=
186     {
187     {0,1,2,3},
188     {0,1,5,4},
189     {1,2,6,5},
190     {3,2,6,7},
191     {0,3,7,4},
192     {4,5,6,7},
193     };
194     return tab[numface][numsommet];
195     }
196    
197     int sommetarete(int numarete,int numsommet)
198     {
199     int tab[12][2]=
200     {
201     {0,1},
202     {0,3},
203     {0,4},
204     {1,2},
205     {1,5},
206     {3,2},
207     {2,6},
208     {3,7},
209     {4,5},
210     {4,7},
211     {5,6},
212     {7,6},
213     };
214     return tab[numarete-6][numsommet];
215     }
216    
217    
218    
219    
220    
221     int areteface(int numface,int numarete)
222     {
223     int tab[6][4]=
224     {
225     {6,9,11,7},
226     {6,10,14,8},
227     {9,12,16,10},
228     {11,12,17,13},
229     {7,13,15,8},
230     {14,16,17,15},
231     };
232     return tab[numface][numarete];
233     }
234    
235     int faceadjacente(int numface,int numarete)
236     {
237     int tab[6][4]=
238     {
239     {1,2,3,4},
240     {0,2,5,4},
241     {0,3,5,1},
242     {0,2,5,4},
243     {0,3,5,1},
244     {1,2,3,4},
245     };
246     return tab[numface][numarete];
247     }
248    
249    
250    
251     };
252    
253    
254 5 class CELLULE_OCTREE_BASE
255     {
256     public:
257     CELLULE_OCTREE_BASE()
258     {
259     static unsigned long idmax=0;
260     id=idmax;
261     idmax++;
262     };
263    
264     virtual ~CELLULE_OCTREE_BASE() {};
265     virtual BOITE_3D get_boite(void)=0;
266     virtual CELLULE_OCTREE_BASE* get_fils(int num)=0;
267     virtual int get_feuille(void)=0;
268 francois 65 virtual int get_niveau(void)=0;
269     virtual int get_sontype(void)=0;
270 5 virtual unsigned long get_id() {return id;};
271     unsigned long id;
272     };
273    
274    
275     class OCTREE_BASE
276     {
277     public:
278     OCTREE_BASE() {};
279     virtual ~OCTREE_BASE() {};
280     virtual int get_nb_cellule(void)=0;
281     virtual CELLULE_OCTREE_BASE* get_cellule(int num)=0;
282 francois 65 virtual int get_niveau_max(void)=0;
283 5 };
284    
285    
286     template <class A,class CONDITION>
287     class TPL_CELLULE_OCTREE:public CELLULE_OCTREE_BASE
288     {
289     public:
290 francois 65 TPL_CELLULE_OCTREE(TPL_CELLULE_OCTREE<A,CONDITION> *cell,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax,int niv,int st):CELLULE_OCTREE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax),niveau(niv),pere(cell),sontype(st)
291 5 {
292     };
293     virtual ~TPL_CELLULE_OCTREE() {};
294     BOITE_3D get_boite(void) {return boite;};
295 francois 65 int get_niveau(void) {return niveau;};
296 5 BOITE_3D boite;
297     int feuille;
298     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
299     TPL_LISTE_ENTITE<A> lst_entite_A;
300     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_fils(int num) {return fils[num];};
301 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_pere(void) {return pere;};
302 5 virtual int get_feuille(void) {return feuille;};
303 francois 276
304     virtual void vide(void)
305     {
306     lst_entite_A.vide();
307     }
308    
309 francois 65 int get_sontype(void)
310     {
311     return sontype;
312     }
313 5 int get_nb_entite(void)
314     {
315     return lst_entite_A.get_nb();
316     };
317     A get_entite(int num)
318     {
319     return lst_entite_A.get(num);
320     };
321 francois 65 TPL_CELLULE_OCTREE< A ,CONDITION> *fils[8];
322     TPL_CELLULE_OCTREE< A ,CONDITION> *pere;
323 5
324 francois 65
325     int niveau;
326     int sontype;
327 5 };
328    
329     template <class A,class CONDITION,class B>
330     class TPL_CELLULE_INFO:public CELLULE_OCTREE_BASE
331     {
332     public:
333     TPL_CELLULE_INFO(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_OCTREE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
334     {
335     };
336     virtual ~TPL_CELLULE_INFO() {};
337     BOITE_3D get_boite(void) {return boite;};
338     BOITE_3D boite;
339     int feuille;
340     TPL_CELLULE_INFO< A ,CONDITION,B> *fils[8];
341     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
342     TPL_LISTE_ENTITE<A> lst_entite_A;
343     B tab[8];
344     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_fils(int num) {return fils[num];};
345     virtual int get_feuille(void) {return feuille;};
346     int get_nb_entite(void)
347     {
348     return lst_entite_A.get_nb();
349     };
350     A get_entite(int num)
351     {
352     return lst_entite_A.get(num);
353     };
354    
355     B get_info(int num) {return tab[num];};
356     void change_info(int num,B val) {tab[num]=val;};
357    
358     };
359    
360    
361    
362     template <class A,class CONDITION>
363     class TPL_OCTREE:public OCTREE_BASE
364     {
365     public:
366 francois 65 TPL_OCTREE():niveaumax(0) {};
367 5 ~TPL_OCTREE()
368     {
369     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
370     {
371     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(i1);
372     delete cellule;
373     }
374     };
375    
376     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
377 francois 65 virtual int get_nb_feuille(void) {return lst_entite_feuille.get_nb();};
378 5
379     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
380    
381     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_cellule(int num) {return lst_entite_cellule.get(num); };
382 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_feuille(int num) {return lst_entite_feuille.get(num); };
383 5
384    
385     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
386     {
387 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
388 5 lst_entite_cellule.ajouter(root_cellule);
389     for (int i=0;i<lst_entite->get_nb();i++)
390     {
391     CONDITION cond=lst_entite->get(i);
392     BOITE_3D boite_cond=cond->get_boite_3D();
393     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
394     }
395     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
396     {
397     root_cellule->feuille=0;
398     double dx=xmax-xmin;
399     double dy=ymax-ymin;
400     double dz=zmax-zmin;
401 francois 65 root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
402     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
403     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
404     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,3);
405     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
406     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,5);
407     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,6);
408     root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,7);
409 5 }
410     else root_cellule->feuille=1;
411     for (int j=0;j<lst_entite_cellule.get_nb();j++)
412     {
413     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
414     cellule->lst_entite_CONDITION.vide();
415     }
416     }
417    
418     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
419     {
420 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
421 5 lst_entite_cellule.ajouter(root_cellule);
422 francois 276 typename TPL_MAP_ENTITE<CONDITION>::ITERATEUR it;
423     for (CONDITION cond=lst_entite->get_premier(it);cond!=NULL;cond=lst_entite->get_suivant(it))
424 5 {
425     BOITE_3D boite_cond=cond->get_boite_3D();
426     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
427     }
428     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
429     {
430     root_cellule->feuille=0;
431     double dx=xmax-xmin;
432     double dy=ymax-ymin;
433     double dz=zmax-zmin;
434 francois 65 root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
435     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
436     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
437     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,3);
438     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
439     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,5);
440     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,6);
441     root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,7);
442 5 }
443     else root_cellule->feuille=1;
444     for (int j=0;j<lst_entite_cellule.get_nb();j++)
445     {
446     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
447     cellule->lst_entite_CONDITION.vide();
448     }
449     }
450    
451     virtual void initialiser(OCTREE_BASE* oc)
452     {
453     BOITE_3D boite=oc->get_cellule(0)->get_boite();
454     double xmin=boite.get_xmin();
455     double xmax=boite.get_xmax();
456     double ymin=boite.get_ymin();
457     double ymax=boite.get_ymax();
458     double zmin=boite.get_zmin();
459     double zmax=boite.get_zmax();
460 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,oc->get_cellule(0)->get_sontype());
461 5 lst_entite_cellule.ajouter(cellule);
462 francois 65 niveaumax=oc->get_niveau_max();
463     cellule->feuille=oc->get_cellule(0)->get_feuille();
464 5 if (oc->get_cellule(0)->get_feuille()==0)
465     {
466 francois 65 cellule->fils[0]=cree_fils(cellule,oc->get_cellule(0)->get_fils(0),0);
467     cellule->fils[1]=cree_fils(cellule,oc->get_cellule(0)->get_fils(1),1);
468     cellule->fils[2]=cree_fils(cellule,oc->get_cellule(0)->get_fils(2),2);
469     cellule->fils[3]=cree_fils(cellule,oc->get_cellule(0)->get_fils(3),3);
470     cellule->fils[4]=cree_fils(cellule,oc->get_cellule(0)->get_fils(4),4);
471     cellule->fils[5]=cree_fils(cellule,oc->get_cellule(0)->get_fils(5),5);
472     cellule->fils[6]=cree_fils(cellule,oc->get_cellule(0)->get_fils(6),6);
473     cellule->fils[7]=cree_fils(cellule,oc->get_cellule(0)->get_fils(7),7);
474 5 }
475 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
476 5 };
477    
478    
479 francois 65 TPL_CELLULE_OCTREE<A,CONDITION>* cree_fils( TPL_CELLULE_OCTREE<A ,CONDITION>* cell,CELLULE_OCTREE_BASE *cellule_base,int st)
480 5 {
481     BOITE_3D boite=cellule_base->get_boite();
482     double xmin=boite.get_xmin();
483     double xmax=boite.get_xmax();
484     double ymin=boite.get_ymin();
485     double ymax=boite.get_ymax();
486     double zmin=boite.get_zmin();
487     double zmax=boite.get_zmax();
488 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmax,ymax,zmax,cellule_base->get_niveau(),st);
489 5 lst_entite_cellule.ajouter(cellule);
490 francois 65 if (niveaumax<cellule_base->get_niveau()) niveaumax=cellule_base->get_niveau();
491 5 if (cellule_base->get_feuille()==1)
492     {
493 francois 65 {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
494 5 }
495     else
496     {
497 francois 65 cellule->fils[0]=cree_fils(cellule,cellule_base->get_fils(0),0);
498     cellule->fils[1]=cree_fils(cellule,cellule_base->get_fils(1),1);
499     cellule->fils[2]=cree_fils(cellule,cellule_base->get_fils(2),2);
500     cellule->fils[3]=cree_fils(cellule,cellule_base->get_fils(3),3);
501     cellule->fils[4]=cree_fils(cellule,cellule_base->get_fils(4),4);
502     cellule->fils[5]=cree_fils(cellule,cellule_base->get_fils(5),5);
503     cellule->fils[6]=cree_fils(cellule,cellule_base->get_fils(6),6);
504     cellule->fils[7]=cree_fils(cellule,cellule_base->get_fils(7),7);
505 5 cellule->feuille=0;
506     }
507     return cellule;
508     };
509    
510 francois 65 virtual TPL_CELLULE_OCTREE<A ,CONDITION>* cree_fils(TPL_CELLULE_OCTREE<A ,CONDITION>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,int niv,int st)
511 5 {
512 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
513 5 lst_entite_cellule.ajouter(cellule);
514 francois 65 if (niveaumax<niv) niveaumax=niv;
515     for (int i=0;i<lst_entite->get_nb();i++)
516 5 {
517     CONDITION cond=lst_entite->get(i);
518     BOITE_3D boite_cond=cond->get_boite_3D();
519     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
520     }
521     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
522     {
523     cellule->feuille=0;
524 francois 65 cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
525     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,1);
526     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,2);
527     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,3);
528     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,4);
529     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,5);
530     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,6);
531     cellule->fils[7]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,7);
532 5 }
533 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
534 5 return cellule;
535     }
536    
537    
538     virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
539     {
540     if (boite*cellule->boite)
541     if (cellule->feuille==1)
542     {
543     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
544     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
545     }
546     else
547     {
548     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
549     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
550     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
551     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
552     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
553     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
554     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
555     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
556     }
557     };
558    
559    
560     virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > &liste_entite)
561     {
562     if (boite*cellule->boite)
563     if (cellule->feuille==1)
564     {
565     liste_entite.ajouter(cellule);
566     }
567     else
568     {
569     get_cellule(boite,cellule->fils[0],liste_entite);
570     get_cellule(boite,cellule->fils[1],liste_entite);
571     get_cellule(boite,cellule->fils[2],liste_entite);
572     get_cellule(boite,cellule->fils[3],liste_entite);
573     get_cellule(boite,cellule->fils[4],liste_entite);
574     get_cellule(boite,cellule->fils[5],liste_entite);
575     get_cellule(boite,cellule->fils[6],liste_entite);
576     get_cellule(boite,cellule->fils[7],liste_entite);
577     }
578     };
579    
580 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_adjacent(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
581     {
582     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
583     OUTIL_OCTREE outil;
584     if (cellule->pere==NULL) cellule2=NULL;
585     else if (outil.adjacent(direction,cellule->get_sontype())) cellule2=get_cellule_adjacent(cellule->pere,direction);
586     else if (outil.commonface(direction,cellule->get_sontype())!=-1) cellule2=get_cellule_voisin(cellule->pere,outil.commonface(direction,cellule->get_sontype()));
587     else cellule2=cellule->pere;
588     if (cellule2!=NULL)
589     if (cellule2->get_feuille()==0)
590     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
591     return cellule2;
592     }
593    
594     virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_voisin(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
595     {
596     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
597     OUTIL_OCTREE outil;
598     if ((!(cellule->pere==NULL)) && (outil.adjacent(direction,cellule->get_sontype())))
599     cellule2=get_cellule_voisin(cellule->pere,direction);
600     else
601     cellule2=cellule->pere;
602     if (cellule2!=NULL)
603     if (cellule2->feuille==0)
604     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
605     return cellule2;
606     }
607    
608    
609    
610    
611     virtual void get_feuille_voisins(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction,vector<TPL_CELLULE_OCTREE<A,CONDITION> *> *lst)
612     {
613     OUTIL_OCTREE outil;
614     lst->clear();
615     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2=get_cellule_voisin(cellule,direction);
616     if (cellule2!=NULL) lst->insert(lst->end(),cellule2);
617     int i=0;
618     while (i<lst->size())
619     {
620     TPL_CELLULE_OCTREE<A,CONDITION> *cell=(*lst)[i];
621     if (cell->feuille==0)
622     {
623     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,0)));
624     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,1)));
625     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,2)));
626     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,3)));
627     }
628     i++;
629     }
630 francois 102 typename vector<TPL_CELLULE_OCTREE<A,CONDITION> * >::iterator j=lst->end();
631 francois 65 while (j!=lst->begin())
632     {
633     j--;
634     TPL_CELLULE_OCTREE<A,CONDITION> *cell=*j;
635     if (cell->feuille==0)
636     lst->erase(j);
637    
638     }
639     }
640    
641 5 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule(double x,double y, double z)
642     {
643     BOITE_3D boite(x,y,z,x,y,z);
644     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
645     TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > liste_cellule;
646     get_cellule(boite,cellule,liste_cellule);
647     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
648     return NULL;
649     };
650    
651    
652 francois 65 virtual unsigned long get_cellule_keycode(int numcellule,int numsommet)
653     {
654     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
655     return get_keycode(cellule,numsommet);
656     }
657    
658     virtual unsigned long get_feuille_keycode(int numcellule,int numsommet)
659     {
660     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
661     return get_keycode(cellule,numsommet);
662     }
663    
664     virtual unsigned long get_keycode(TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,int numsommet)
665     {
666     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
667    
668     double x=cellule->boite.get_xmin();
669     double y=cellule->boite.get_ymin();
670     double z=cellule->boite.get_zmin();
671     double xx=cellule->boite.get_xmax();
672     double yy=cellule->boite.get_ymax();
673     double zz=cellule->boite.get_zmax();
674     double somx=x,somy=y,somz=z;
675     if (numsommet==1) somx=xx;
676     if (numsommet==2) {somx=xx;somy=yy;}
677     if (numsommet==3) somy=yy;
678     if (numsommet==4) somz=zz;
679     if (numsommet==5) {somx=xx;somz=zz;}
680     if (numsommet==6) {somx=xx;somy=yy;somz=zz;}
681     if (numsommet==7) {somy=yy;somz=zz;}
682     double nx=0.1+(somx-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
683     double ny=0.1+(somy-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
684     double nz=0.1+(somz-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
685     OUTIL_OCTREE outil;
686     return outil.determine_keycode(nx,ny,nz);
687     }
688    
689     virtual unsigned long get_keycode(double x,double y,double z)
690     {
691     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
692     double nx=0.1+(x-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
693     double ny=0.1+(y-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
694     double nz=0.1+(z-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
695     OUTIL_OCTREE outil;
696     return outil.determine_keycode(nx,ny,nz);
697     }
698    
699    
700    
701     virtual void get_xyzsommet_cellule(int numcellule,int numsommet,double &x,double &y,double &z)
702     {
703     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
704     x=cellule->boite.get_xmin();
705     y=cellule->boite.get_ymin();
706     z=cellule->boite.get_zmin();
707     double xx=cellule->boite.get_xmax();
708     double yy=cellule->boite.get_ymax();
709     double zz=cellule->boite.get_zmax();
710     if (numsommet==1) x=xx;
711     if (numsommet==2) {x=xx;y=yy;}
712     if (numsommet==3) y=yy;
713     if (numsommet==4) z=zz;
714     if (numsommet==5) {x=xx;z=zz;}
715     if (numsommet==6) {x=xx;y=yy;z=zz;}
716     if (numsommet==7) {y=yy;z=zz;}
717     }
718    
719     virtual void get_xyzsommet_feuille(int numcellule,int numsommet,double &x,double &y,double &z)
720     {
721     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
722     x=cellule->boite.get_xmin();
723     y=cellule->boite.get_ymin();
724     z=cellule->boite.get_zmin();
725     double xx=cellule->boite.get_xmax();
726     double yy=cellule->boite.get_ymax();
727     double zz=cellule->boite.get_zmax();
728     if (numsommet==1) x=xx;
729     if (numsommet==2) {x=xx;y=yy;}
730     if (numsommet==3) y=yy;
731     if (numsommet==4) z=zz;
732     if (numsommet==5) {x=xx;z=zz;}
733     if (numsommet==6) {x=xx;y=yy;z=zz;}
734     if (numsommet==7) {y=yy;z=zz;}
735     }
736    
737    
738    
739     virtual void equilibre(int niveauequilibre=1)
740     {
741     int ok=0;
742     do
743     {
744     int nbfeuilleavant=get_nb_feuille();
745     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstraf;
746     for (int i=0;i<lst_entite_feuille.get_nb();i++)
747     {
748     TPL_CELLULE_OCTREE<A,CONDITION> *feuille=lst_entite_feuille.get(i);
749     int niveaumaxvoisin=0;
750     for (int j=0;j<6;j++)
751     {
752     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstvoi;
753     get_feuille_voisins(feuille,j,&lstvoi);
754     int nb_feuille=lstvoi.size();
755     for (int k=0;k<nb_feuille;k++)
756     {
757     int niveau=lstvoi[k]->get_niveau();
758     if (niveau>niveaumaxvoisin) niveaumaxvoisin=niveau;
759     }
760    
761     }
762     if (niveaumaxvoisin-feuille->get_niveau()>niveauequilibre) {lstraf.insert(lstraf.end(),feuille);feuille->feuille=niveaumaxvoisin-niveauequilibre;}
763     }
764     int nbcelluleraffiner=lstraf.size();
765     for (int i=0;i<nbcelluleraffiner;i++)
766     {
767     TPL_CELLULE_OCTREE<A,CONDITION> *cell=lstraf[i];
768     lst_entite_feuille.supprimer(cell);
769     int niveauatteindre=cell->feuille;
770     int niveau=cell->niveau;
771     cell->feuille=0;
772     double xmin=cell->boite.get_xmin();
773     double ymin=cell->boite.get_ymin();
774     double zmin=cell->boite.get_zmin();
775     double dx=cell->boite.get_xmax()-cell->boite.get_xmin();
776     double dy=cell->boite.get_ymax()-cell->boite.get_ymin();
777     double dz=cell->boite.get_zmax()-cell->boite.get_zmin();
778    
779     cell->fils[0]=cree_fils(cell,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,0);
780     cell->fils[1]=cree_fils(cell,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,1);
781     cell->fils[2]=cree_fils(cell,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,2);
782     cell->fils[3]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,3);
783     cell->fils[4]=cree_fils(cell,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,4);
784     cell->fils[5]=cree_fils(cell,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,5);
785     cell->fils[6]=cree_fils(cell,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,6);
786     cell->fils[7]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,7);
787     }
788     int nbfeuilleapres=get_nb_feuille();
789     if (nbfeuilleapres==nbfeuilleavant) ok=1;
790     }
791     while (ok==0);
792    
793    
794     }
795    
796     virtual TPL_CELLULE_OCTREE<A ,CONDITION>* cree_fils(TPL_CELLULE_OCTREE<A ,CONDITION>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,int niv,int niveauatteindre,int st)
797     {
798     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
799     lst_entite_cellule.ajouter(cellule);
800     if (niveaumax<niv) niveaumax=niv;
801     if (cellule->get_niveau()!=niveauatteindre)
802     {
803     cellule->feuille=0;
804     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,0);
805     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,1);
806     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,2);
807     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,3);
808     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,4);
809     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,5);
810     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,6);
811     cellule->fils[7]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,7);
812     }
813     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
814     return cellule;
815     }
816    
817    
818 5 virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
819     {
820     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
821     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
822     rechercher(boite,liste_entite_trouve,cellule);
823     };
824    
825    
826    
827     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
828     {
829     if (boite*cellule->boite)
830     if (cellule->feuille==1)
831     {
832     cellule->lst_entite_A.ajouter(a);
833     }
834     else
835     {
836     inserer(boite,a,cellule->fils[0]);
837     inserer(boite,a,cellule->fils[1]);
838     inserer(boite,a,cellule->fils[2]);
839     inserer(boite,a,cellule->fils[3]);
840     inserer(boite,a,cellule->fils[4]);
841     inserer(boite,a,cellule->fils[5]);
842     inserer(boite,a,cellule->fils[6]);
843     inserer(boite,a,cellule->fils[7]);
844     }
845     };
846    
847     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
848     {
849     if (boite*cellule->boite)
850     if (cellule->feuille==1)
851     {
852     cellule->lst_entite_A.supprimer(a);
853     }
854     else
855     {
856     supprimer(boite,a,cellule->fils[0]);
857     supprimer(boite,a,cellule->fils[1]);
858     supprimer(boite,a,cellule->fils[2]);
859     supprimer(boite,a,cellule->fils[3]);
860     supprimer(boite,a,cellule->fils[4]);
861     supprimer(boite,a,cellule->fils[5]);
862     supprimer(boite,a,cellule->fils[6]);
863     supprimer(boite,a,cellule->fils[7]);
864     }
865     };
866    
867     virtual void inserer(A a)
868     {
869     BOITE_3D boite=a->get_boite_3D();
870     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
871     inserer(boite,a,cellule);
872     }
873    
874     virtual void supprimer(A a)
875     {
876     BOITE_3D boite=a->get_boite_3D();
877     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
878     supprimer(boite,a,cellule);
879     }
880    
881 francois 65 virtual int get_niveau_max(void)
882     {
883     return niveaumax;
884     }
885 5
886 francois 65
887    
888 francois 276 virtual void vide(void)
889     {
890     for (int i=0;i<lst_entite_feuille.get_nb();i++)
891     {
892     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(i);
893     cellule->vide();
894     }
895     }
896 francois 65
897     protected:
898 5 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_cellule;
899 francois 65 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_feuille;
900     int niveaumax;
901 5
902     };
903    
904 francois 65 template <class A,class B>
905     class TPL_OCTREE_FCT:public TPL_OCTREE<A,A>
906     {
907     private:
908     double coef;
909 5
910 francois 65 public:
911     TPL_OCTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
912     ~TPL_OCTREE_FCT() {}
913 5
914 francois 65
915 francois 102 virtual void change_coefficent_multiplicateur(double val) {coef=val;};
916 francois 65
917     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
918     {
919     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
920 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
921 francois 65 double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
922     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
923     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
924     double d=dx;
925     if (dy<d) d=dy;
926     if (dz<d) d=dz;
927     double xyz[3];
928     root_cellule->boite.get_centre(xyz);
929     double ecart[9];
930     fonction.evaluer(xyz,ecart);
931     double dcible=coef/sqrt(ecart[0]);
932     if (dcible<d)
933     {
934     root_cellule->feuille=0;
935     root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,0);
936     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,1);
937     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,2);
938     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,3);
939     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,4);
940     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,5);
941     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,6);
942     root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,7);
943     }
944 francois 102 else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
945 francois 65 }
946    
947     virtual TPL_CELLULE_OCTREE<A ,A>* cree_fils(TPL_CELLULE_OCTREE<A ,A>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,B &fonction,int niv,int st)
948     {
949     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
950 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
951     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
952 francois 65 double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
953     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
954     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
955     double d=dx;
956     if (ddy<d) d=ddy;
957     if (ddz<d) d=ddz;
958     double xyz[3];
959     cellule->boite.get_centre(xyz);
960     double ecart[9];
961     fonction.evaluer(xyz,ecart);
962     double dcible=coef/sqrt(ecart[0]);
963     if (dcible<d)
964     {
965     cellule->feuille=0;
966     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,0);
967     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,1);
968     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,2);
969     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,3);
970     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,4);
971     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,5);
972     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,6);
973     cellule->fils[7]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,7);
974     }
975 francois 102 else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
976 francois 65 return cellule;
977     }
978     };
979    
980    
981    
982 5 template <class A,class CONDITION,class B>
983     class TPL_OCTREE_INFO:public OCTREE_BASE
984     {
985     public:
986     TPL_OCTREE_INFO() {};
987     ~TPL_OCTREE_INFO()
988     {
989     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
990     {
991     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(i1);
992     delete cellule;
993     }
994     };
995    
996     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
997    
998     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
999    
1000     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
1001    
1002    
1003     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1004     {
1005     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1006     lst_entite_cellule.ajouter(root_cellule);
1007     for (int i=0;i<lst_entite->get_nb();i++)
1008     {
1009     CONDITION cond=lst_entite->get(i);
1010     BOITE_3D boite_cond=cond->get_boite_3D();
1011     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1012     }
1013     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1014     {
1015     root_cellule->feuille=0;
1016     double dx=xmax-xmin;
1017     double dy=ymax-ymin;
1018     double dz=zmax-zmin;
1019     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1020     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1021     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1022     root_cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1023     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1024     root_cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1025     root_cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1026     root_cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1027     }
1028     else root_cellule->feuille=1;
1029     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1030     {
1031     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1032     cellule->lst_entite_CONDITION.vide();
1033     }
1034     }
1035    
1036     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1037     {
1038     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1039     lst_entite_cellule.ajouter(root_cellule);
1040     for (int i=0;i<lst_entite->get_nb();i++)
1041     {
1042     CONDITION cond=lst_entite->get(i);
1043     BOITE_3D boite_cond=cond->get_boite_3D();
1044     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1045     }
1046     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1047     {
1048     root_cellule->feuille=0;
1049     double dx=xmax-xmin;
1050     double dy=ymax-ymin;
1051     double dz=zmax-zmin;
1052     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1053     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1054     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1055     root_cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1056     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1057     root_cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1058     root_cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1059     root_cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1060     }
1061     else root_cellule->feuille=1;
1062     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1063     {
1064     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1065     cellule->lst_entite_CONDITION.vide();
1066     }
1067     }
1068    
1069     virtual void initialiser(OCTREE_BASE* oc)
1070     {
1071     BOITE_3D boite=oc->get_cellule(0)->get_boite();
1072     double xmin=boite.get_xmin();
1073     double xmax=boite.get_xmax();
1074     double ymin=boite.get_ymin();
1075     double ymax=boite.get_ymax();
1076     double zmin=boite.get_zmin();
1077     double zmax=boite.get_zmax();
1078     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1079     lst_entite_cellule.ajouter(cellule);
1080     if (oc->get_cellule(0)->get_feuille()==0)
1081     {
1082     cellule->fils[0]=cree_fils(oc->get_cellule(0)->get_fils(0));
1083     cellule->fils[1]=cree_fils(oc->get_cellule(0)->get_fils(1));
1084     cellule->fils[2]=cree_fils(oc->get_cellule(0)->get_fils(2));
1085     cellule->fils[3]=cree_fils(oc->get_cellule(0)->get_fils(3));
1086     cellule->fils[4]=cree_fils(oc->get_cellule(0)->get_fils(4));
1087     cellule->fils[5]=cree_fils(oc->get_cellule(0)->get_fils(5));
1088     cellule->fils[6]=cree_fils(oc->get_cellule(0)->get_fils(6));
1089     cellule->fils[7]=cree_fils(oc->get_cellule(0)->get_fils(7));
1090     }
1091     cellule->feuille=oc->get_cellule(0)->get_feuille();
1092     };
1093    
1094    
1095     TPL_CELLULE_INFO<A,CONDITION,B>* cree_fils(CELLULE_OCTREE_BASE *cellule_base)
1096     {
1097     BOITE_3D boite=cellule_base->get_boite();
1098     double xmin=boite.get_xmin();
1099     double xmax=boite.get_xmax();
1100     double ymin=boite.get_ymin();
1101     double ymax=boite.get_ymax();
1102     double zmin=boite.get_zmin();
1103     double zmax=boite.get_zmax();
1104     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1105     lst_entite_cellule.ajouter(cellule);
1106     if (cellule_base->get_feuille()==1)
1107     {
1108     cellule->feuille=1;
1109     }
1110     else
1111     {
1112     cellule->fils[0]=cree_fils(cellule_base->get_fils(0));
1113     cellule->fils[1]=cree_fils(cellule_base->get_fils(1));
1114     cellule->fils[2]=cree_fils(cellule_base->get_fils(2));
1115     cellule->fils[3]=cree_fils(cellule_base->get_fils(3));
1116     cellule->fils[4]=cree_fils(cellule_base->get_fils(4));
1117     cellule->fils[5]=cree_fils(cellule_base->get_fils(5));
1118     cellule->fils[6]=cree_fils(cellule_base->get_fils(6));
1119     cellule->fils[7]=cree_fils(cellule_base->get_fils(7));
1120     cellule->feuille=0;
1121     }
1122     return cellule;
1123     };
1124    
1125     virtual TPL_CELLULE_INFO<A ,CONDITION,B>* cree_fils(double xmin,double ymin,double zmin,double dx,double dy,double dz,TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre)
1126     {
1127     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz);
1128     lst_entite_cellule.ajouter(cellule);
1129     for (int i=0;i<lst_entite->get_nb();i++)
1130     {
1131     CONDITION cond=lst_entite->get(i);
1132     BOITE_3D boite_cond=cond->get_boite_3D();
1133     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
1134     }
1135     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
1136     {
1137     cellule->feuille=0;
1138     cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1139     cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1140     cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1141     cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1142     cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1143     cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1144     cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1145     cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1146     }
1147     else cellule->feuille=1;
1148     return cellule;
1149     }
1150    
1151    
1152     virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1153     {
1154     if (boite*cellule->boite)
1155     if (cellule->feuille==1)
1156     {
1157     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
1158     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
1159     }
1160     else
1161     {
1162     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
1163     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
1164     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
1165     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
1166     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
1167     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
1168     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
1169     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
1170     }
1171     };
1172    
1173    
1174     virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > &liste_entite)
1175     {
1176     if (boite*cellule->boite)
1177     if (cellule->feuille==1)
1178     {
1179     liste_entite.ajouter(cellule);
1180     }
1181     else
1182     {
1183     get_cellule(boite,cellule->fils[0],liste_entite);
1184     get_cellule(boite,cellule->fils[1],liste_entite);
1185     get_cellule(boite,cellule->fils[2],liste_entite);
1186     get_cellule(boite,cellule->fils[3],liste_entite);
1187     get_cellule(boite,cellule->fils[4],liste_entite);
1188     get_cellule(boite,cellule->fils[5],liste_entite);
1189     get_cellule(boite,cellule->fils[6],liste_entite);
1190     get_cellule(boite,cellule->fils[7],liste_entite);
1191     }
1192     };
1193    
1194     virtual TPL_CELLULE_INFO<A,CONDITION,B> *get_cellule(double x,double y, double z)
1195     {
1196     BOITE_3D boite(x,y,z,x,y,z);
1197     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1198     TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > liste_cellule;
1199     get_cellule(boite,cellule,liste_cellule);
1200     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
1201     return NULL;
1202     };
1203    
1204    
1205     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
1206     {
1207     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
1208     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1209     rechercher(boite,liste_entite_trouve,cellule);
1210     };
1211    
1212    
1213    
1214     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1215     {
1216     if (boite*cellule->boite)
1217     if (cellule->feuille==1)
1218     {
1219     cellule->lst_entite_A.ajouter(a);
1220     }
1221     else
1222     {
1223     inserer(boite,a,cellule->fils[0]);
1224     inserer(boite,a,cellule->fils[1]);
1225     inserer(boite,a,cellule->fils[2]);
1226     inserer(boite,a,cellule->fils[3]);
1227     inserer(boite,a,cellule->fils[4]);
1228     inserer(boite,a,cellule->fils[5]);
1229     inserer(boite,a,cellule->fils[6]);
1230     inserer(boite,a,cellule->fils[7]);
1231     }
1232     };
1233    
1234     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1235     {
1236     if (boite*cellule->boite)
1237     if (cellule->feuille==1)
1238     {
1239     cellule->lst_entite_A.supprimer(a);
1240     }
1241     else
1242     {
1243     supprimer(boite,a,cellule->fils[0]);
1244     supprimer(boite,a,cellule->fils[1]);
1245     supprimer(boite,a,cellule->fils[2]);
1246     supprimer(boite,a,cellule->fils[3]);
1247     supprimer(boite,a,cellule->fils[4]);
1248     supprimer(boite,a,cellule->fils[5]);
1249     supprimer(boite,a,cellule->fils[6]);
1250     supprimer(boite,a,cellule->fils[7]);
1251     }
1252     };
1253    
1254     virtual void inserer(A a)
1255     {
1256     BOITE_3D boite=a->get_boite_3D();
1257     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1258     inserer(boite,a,cellule);
1259     }
1260    
1261     virtual void supprimer(A a)
1262     {
1263     BOITE_3D boite=a->get_boite_3D();
1264     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1265     supprimer(boite,a,cellule);
1266     }
1267    
1268    
1269     private:
1270     TPL_LISTE_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B>* > lst_entite_cellule;
1271    
1272     };
1273    
1274    
1275    
1276    
1277     #endif