ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_octree.h
Revision: 634
Committed: Thu Jan 15 22:48:07 2015 UTC (10 years, 4 months ago) by francois
Content type: text/plain
File size: 57871 byte(s)
Log Message:
ostie que je fais des erreurs connes de commit des fois.

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 francois 632 fils[0]=NULL;fils[1]=NULL;fils[2]=NULL;fils[3]=NULL;fils[4]=NULL;fils[5]=NULL;fils[6]=NULL;fils[7]=NULL;
293     };
294 5 virtual ~TPL_CELLULE_OCTREE() {};
295     BOITE_3D get_boite(void) {return boite;};
296 francois 65 int get_niveau(void) {return niveau;};
297 5 BOITE_3D boite;
298     int feuille;
299     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
300     TPL_LISTE_ENTITE<A> lst_entite_A;
301     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_fils(int num) {return fils[num];};
302 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_pere(void) {return pere;};
303 5 virtual int get_feuille(void) {return feuille;};
304 francois 276
305     virtual void vide(void)
306     {
307     lst_entite_A.vide();
308     }
309    
310 francois 65 int get_sontype(void)
311     {
312     return sontype;
313     }
314 5 int get_nb_entite(void)
315     {
316     return lst_entite_A.get_nb();
317     };
318     A get_entite(int num)
319     {
320     return lst_entite_A.get(num);
321     };
322 francois 65 TPL_CELLULE_OCTREE< A ,CONDITION> *fils[8];
323     TPL_CELLULE_OCTREE< A ,CONDITION> *pere;
324 5
325 francois 65
326     int niveau;
327     int sontype;
328 5 };
329    
330     template <class A,class CONDITION,class B>
331     class TPL_CELLULE_INFO:public CELLULE_OCTREE_BASE
332     {
333     public:
334     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)
335     {
336     };
337     virtual ~TPL_CELLULE_INFO() {};
338     BOITE_3D get_boite(void) {return boite;};
339     BOITE_3D boite;
340     int feuille;
341     TPL_CELLULE_INFO< A ,CONDITION,B> *fils[8];
342     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
343     TPL_LISTE_ENTITE<A> lst_entite_A;
344     B tab[8];
345     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_fils(int num) {return fils[num];};
346     virtual int get_feuille(void) {return feuille;};
347     int get_nb_entite(void)
348     {
349     return lst_entite_A.get_nb();
350     };
351     A get_entite(int num)
352     {
353     return lst_entite_A.get(num);
354     };
355    
356     B get_info(int num) {return tab[num];};
357     void change_info(int num,B val) {tab[num]=val;};
358    
359     };
360    
361    
362    
363     template <class A,class CONDITION>
364     class TPL_OCTREE:public OCTREE_BASE
365     {
366     public:
367 francois 65 TPL_OCTREE():niveaumax(0) {};
368 5 ~TPL_OCTREE()
369     {
370     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
371     {
372     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(i1);
373     delete cellule;
374     }
375     };
376    
377     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
378 francois 65 virtual int get_nb_feuille(void) {return lst_entite_feuille.get_nb();};
379 5
380     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
381    
382     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_cellule(int num) {return lst_entite_cellule.get(num); };
383 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_feuille(int num) {return lst_entite_feuille.get(num); };
384 5
385    
386     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
387     {
388 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
389 5 lst_entite_cellule.ajouter(root_cellule);
390     for (int i=0;i<lst_entite->get_nb();i++)
391     {
392     CONDITION cond=lst_entite->get(i);
393     BOITE_3D boite_cond=cond->get_boite_3D();
394     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
395     }
396     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
397     {
398     root_cellule->feuille=0;
399     double dx=xmax-xmin;
400     double dy=ymax-ymin;
401     double dz=zmax-zmin;
402 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);
403     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);
404     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);
405     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);
406     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);
407     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);
408     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);
409     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);
410 5 }
411     else root_cellule->feuille=1;
412     for (int j=0;j<lst_entite_cellule.get_nb();j++)
413     {
414     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
415     cellule->lst_entite_CONDITION.vide();
416     }
417     }
418    
419     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
420     {
421 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
422 5 lst_entite_cellule.ajouter(root_cellule);
423 francois 276 typename TPL_MAP_ENTITE<CONDITION>::ITERATEUR it;
424     for (CONDITION cond=lst_entite->get_premier(it);cond!=NULL;cond=lst_entite->get_suivant(it))
425 5 {
426     BOITE_3D boite_cond=cond->get_boite_3D();
427     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
428     }
429     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
430     {
431     root_cellule->feuille=0;
432     double dx=xmax-xmin;
433     double dy=ymax-ymin;
434     double dz=zmax-zmin;
435 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);
436     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);
437     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);
438     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);
439     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);
440     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);
441     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);
442     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);
443 5 }
444     else root_cellule->feuille=1;
445     for (int j=0;j<lst_entite_cellule.get_nb();j++)
446     {
447     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
448     cellule->lst_entite_CONDITION.vide();
449     }
450     }
451    
452 francois 633 virtual void initialiser2D(int dimanepasdecouper,TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
453     {
454     TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
455     lst_entite_cellule.ajouter(root_cellule);
456     for (int i=0;i<lst_entite->get_nb();i++)
457     {
458     CONDITION cond=lst_entite->get(i);
459     BOITE_3D boite_cond=cond->get_boite_3D();
460     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
461     }
462     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
463     {
464     root_cellule->feuille=0;
465     double dx=xmax-xmin;
466     double dy=ymax-ymin;
467     double dz=zmax-zmin;
468     if (dimanepasdecouper==3)
469     {
470     root_cellule->fils[0]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
471     root_cellule->fils[1]=cree_fils2D(dimanepasdecouper,root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
472     root_cellule->fils[2]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
473     root_cellule->fils[3]=cree_fils2D(dimanepasdecouper,root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz,&(root_cellule->lst_entite_CONDITION),nombre,1,3);
474     }
475     if (dimanepasdecouper==2)
476     {
477     root_cellule->fils[0]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin,zmin,dx/2.,dy,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
478     root_cellule->fils[1]=cree_fils2D(dimanepasdecouper,root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
479     root_cellule->fils[4]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
480     root_cellule->fils[5]=cree_fils2D(dimanepasdecouper,root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,5);
481     }
482     if (dimanepasdecouper==1)
483     {
484     root_cellule->fils[0]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin,zmin,dx,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
485     root_cellule->fils[2]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin+dy/2.,zmin,dx,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
486     root_cellule->fils[4]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin,zmin+dz/2.,dx,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
487     root_cellule->fils[6]=cree_fils2D(dimanepasdecouper,root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,6);
488     }
489     }
490     else root_cellule->feuille=1;
491     for (int j=0;j<lst_entite_cellule.get_nb();j++)
492     {
493     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
494     cellule->lst_entite_CONDITION.vide();
495     }
496     }
497    
498 5 virtual void initialiser(OCTREE_BASE* oc)
499     {
500     BOITE_3D boite=oc->get_cellule(0)->get_boite();
501     double xmin=boite.get_xmin();
502     double xmax=boite.get_xmax();
503     double ymin=boite.get_ymin();
504     double ymax=boite.get_ymax();
505     double zmin=boite.get_zmin();
506     double zmax=boite.get_zmax();
507 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());
508 5 lst_entite_cellule.ajouter(cellule);
509 francois 65 niveaumax=oc->get_niveau_max();
510     cellule->feuille=oc->get_cellule(0)->get_feuille();
511 5 if (oc->get_cellule(0)->get_feuille()==0)
512     {
513 francois 632 if (oc->get_cellule(0)->get_fils(0)!=NULL) cellule->fils[0]=cree_fils(cellule,oc->get_cellule(0)->get_fils(0),0);
514     if (oc->get_cellule(0)->get_fils(1)!=NULL) cellule->fils[1]=cree_fils(cellule,oc->get_cellule(0)->get_fils(1),1);
515     if (oc->get_cellule(0)->get_fils(2)!=NULL) cellule->fils[2]=cree_fils(cellule,oc->get_cellule(0)->get_fils(2),2);
516     if (oc->get_cellule(0)->get_fils(3)!=NULL) cellule->fils[3]=cree_fils(cellule,oc->get_cellule(0)->get_fils(3),3);
517     if (oc->get_cellule(0)->get_fils(4)!=NULL) cellule->fils[4]=cree_fils(cellule,oc->get_cellule(0)->get_fils(4),4);
518     if (oc->get_cellule(0)->get_fils(5)!=NULL) cellule->fils[5]=cree_fils(cellule,oc->get_cellule(0)->get_fils(5),5);
519     if (oc->get_cellule(0)->get_fils(6)!=NULL) cellule->fils[6]=cree_fils(cellule,oc->get_cellule(0)->get_fils(6),6);
520     if (oc->get_cellule(0)->get_fils(7)!=NULL) cellule->fils[7]=cree_fils(cellule,oc->get_cellule(0)->get_fils(7),7);
521 5 }
522 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
523 5 };
524    
525    
526 francois 65 TPL_CELLULE_OCTREE<A,CONDITION>* cree_fils( TPL_CELLULE_OCTREE<A ,CONDITION>* cell,CELLULE_OCTREE_BASE *cellule_base,int st)
527 5 {
528     BOITE_3D boite=cellule_base->get_boite();
529     double xmin=boite.get_xmin();
530     double xmax=boite.get_xmax();
531     double ymin=boite.get_ymin();
532     double ymax=boite.get_ymax();
533     double zmin=boite.get_zmin();
534     double zmax=boite.get_zmax();
535 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);
536 5 lst_entite_cellule.ajouter(cellule);
537 francois 65 if (niveaumax<cellule_base->get_niveau()) niveaumax=cellule_base->get_niveau();
538 5 if (cellule_base->get_feuille()==1)
539     {
540 francois 65 {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
541 5 }
542     else
543     {
544 francois 632 if (cellule_base->get_fils(0)!=NULL) cellule->fils[0]=cree_fils(cellule,cellule_base->get_fils(0),0);
545     if (cellule_base->get_fils(1)!=NULL) cellule->fils[1]=cree_fils(cellule,cellule_base->get_fils(1),1);
546     if (cellule_base->get_fils(2)!=NULL) cellule->fils[2]=cree_fils(cellule,cellule_base->get_fils(2),2);
547     if (cellule_base->get_fils(3)!=NULL) cellule->fils[3]=cree_fils(cellule,cellule_base->get_fils(3),3);
548     if (cellule_base->get_fils(4)!=NULL) cellule->fils[4]=cree_fils(cellule,cellule_base->get_fils(4),4);
549     if (cellule_base->get_fils(5)!=NULL) cellule->fils[5]=cree_fils(cellule,cellule_base->get_fils(5),5);
550     if (cellule_base->get_fils(6)!=NULL) cellule->fils[6]=cree_fils(cellule,cellule_base->get_fils(6),6);
551     if (cellule_base->get_fils(7)!=NULL) cellule->fils[7]=cree_fils(cellule,cellule_base->get_fils(7),7);
552     cellule->feuille=cellule_base->get_feuille();
553 5 }
554     return cellule;
555     };
556    
557 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)
558 5 {
559 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);
560 5 lst_entite_cellule.ajouter(cellule);
561 francois 65 if (niveaumax<niv) niveaumax=niv;
562     for (int i=0;i<lst_entite->get_nb();i++)
563 5 {
564     CONDITION cond=lst_entite->get(i);
565     BOITE_3D boite_cond=cond->get_boite_3D();
566     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
567     }
568     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
569     {
570     cellule->feuille=0;
571 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);
572     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);
573     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);
574     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);
575     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);
576     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);
577     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);
578     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);
579 5 }
580 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
581 5 return cellule;
582     }
583    
584 francois 633 virtual TPL_CELLULE_OCTREE<A ,CONDITION>* cree_fils2D(int dimanepasdecouper,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)
585     {
586     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
587     lst_entite_cellule.ajouter(cellule);
588     if (niveaumax<niv) niveaumax=niv;
589     dz=dz*2;
590     for (int i=0;i<lst_entite->get_nb();i++)
591     {
592     CONDITION cond=lst_entite->get(i);
593     BOITE_3D boite_cond=cond->get_boite_3D();
594     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
595     }
596     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
597     {
598     cellule->feuille=0;
599     if (dimanepasdecouper==3)
600     {
601     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
602     cellule->fils[1]=cree_fils2D(dimanepasdecouper,cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,1);
603     cellule->fils[2]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,2);
604     cellule->fils[3]=cree_fils2D(dimanepasdecouper,cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,3);
605     }
606     if (dimanepasdecouper==2)
607     {
608     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
609     cellule->fils[1]=cree_fils2D(dimanepasdecouper,cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,1);
610     cellule->fils[4]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,4);
611     cellule->fils[5]=cree_fils2D(dimanepasdecouper,cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,5);
612     }
613     if (dimanepasdecouper==1)
614     {
615     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
616     cellule->fils[2]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin+dy/2.,zmin,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,2);
617     cellule->fils[4]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin+dz/2.,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,4);
618     cellule->fils[6]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,6);
619     }
620     }
621     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
622     return cellule;
623     }
624 5
625 francois 633
626 5 virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
627     {
628 francois 632 if (cellule==NULL) return;
629 5 if (boite*cellule->boite)
630     if (cellule->feuille==1)
631     {
632     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
633     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
634     }
635     else
636     {
637     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
638     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
639     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
640     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
641     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
642     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
643     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
644     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
645     }
646     };
647    
648    
649     virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > &liste_entite)
650     {
651     if (boite*cellule->boite)
652     if (cellule->feuille==1)
653     {
654     liste_entite.ajouter(cellule);
655     }
656     else
657     {
658     get_cellule(boite,cellule->fils[0],liste_entite);
659     get_cellule(boite,cellule->fils[1],liste_entite);
660     get_cellule(boite,cellule->fils[2],liste_entite);
661     get_cellule(boite,cellule->fils[3],liste_entite);
662     get_cellule(boite,cellule->fils[4],liste_entite);
663     get_cellule(boite,cellule->fils[5],liste_entite);
664     get_cellule(boite,cellule->fils[6],liste_entite);
665     get_cellule(boite,cellule->fils[7],liste_entite);
666     }
667     };
668    
669 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_adjacent(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
670     {
671     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
672     OUTIL_OCTREE outil;
673     if (cellule->pere==NULL) cellule2=NULL;
674     else if (outil.adjacent(direction,cellule->get_sontype())) cellule2=get_cellule_adjacent(cellule->pere,direction);
675     else if (outil.commonface(direction,cellule->get_sontype())!=-1) cellule2=get_cellule_voisin(cellule->pere,outil.commonface(direction,cellule->get_sontype()));
676     else cellule2=cellule->pere;
677     if (cellule2!=NULL)
678     if (cellule2->get_feuille()==0)
679     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
680     return cellule2;
681     }
682    
683     virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_voisin(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
684     {
685     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
686     OUTIL_OCTREE outil;
687     if ((!(cellule->pere==NULL)) && (outil.adjacent(direction,cellule->get_sontype())))
688     cellule2=get_cellule_voisin(cellule->pere,direction);
689     else
690     cellule2=cellule->pere;
691     if (cellule2!=NULL)
692     if (cellule2->feuille==0)
693     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
694     return cellule2;
695     }
696    
697    
698    
699    
700     virtual void get_feuille_voisins(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction,vector<TPL_CELLULE_OCTREE<A,CONDITION> *> *lst)
701     {
702     OUTIL_OCTREE outil;
703     lst->clear();
704     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2=get_cellule_voisin(cellule,direction);
705     if (cellule2!=NULL) lst->insert(lst->end(),cellule2);
706     int i=0;
707     while (i<lst->size())
708     {
709     TPL_CELLULE_OCTREE<A,CONDITION> *cell=(*lst)[i];
710     if (cell->feuille==0)
711     {
712     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,0)));
713     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,1)));
714     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,2)));
715     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,3)));
716     }
717     i++;
718     }
719 francois 102 typename vector<TPL_CELLULE_OCTREE<A,CONDITION> * >::iterator j=lst->end();
720 francois 65 while (j!=lst->begin())
721     {
722     j--;
723     TPL_CELLULE_OCTREE<A,CONDITION> *cell=*j;
724     if (cell->feuille==0)
725     lst->erase(j);
726    
727     }
728     }
729    
730 5 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule(double x,double y, double z)
731     {
732     BOITE_3D boite(x,y,z,x,y,z);
733     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
734     TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > liste_cellule;
735     get_cellule(boite,cellule,liste_cellule);
736     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
737     return NULL;
738     };
739    
740    
741 francois 65 virtual unsigned long get_cellule_keycode(int numcellule,int numsommet)
742     {
743     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
744     return get_keycode(cellule,numsommet);
745     }
746    
747     virtual unsigned long get_feuille_keycode(int numcellule,int numsommet)
748     {
749     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
750     return get_keycode(cellule,numsommet);
751     }
752    
753     virtual unsigned long get_keycode(TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,int numsommet)
754     {
755     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
756    
757     double x=cellule->boite.get_xmin();
758     double y=cellule->boite.get_ymin();
759     double z=cellule->boite.get_zmin();
760     double xx=cellule->boite.get_xmax();
761     double yy=cellule->boite.get_ymax();
762     double zz=cellule->boite.get_zmax();
763     double somx=x,somy=y,somz=z;
764     if (numsommet==1) somx=xx;
765     if (numsommet==2) {somx=xx;somy=yy;}
766     if (numsommet==3) somy=yy;
767     if (numsommet==4) somz=zz;
768     if (numsommet==5) {somx=xx;somz=zz;}
769     if (numsommet==6) {somx=xx;somy=yy;somz=zz;}
770     if (numsommet==7) {somy=yy;somz=zz;}
771     double nx=0.1+(somx-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
772     double ny=0.1+(somy-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
773     double nz=0.1+(somz-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
774     OUTIL_OCTREE outil;
775     return outil.determine_keycode(nx,ny,nz);
776     }
777    
778     virtual unsigned long get_keycode(double x,double y,double z)
779     {
780     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
781     double nx=0.1+(x-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
782     double ny=0.1+(y-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
783     double nz=0.1+(z-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
784     OUTIL_OCTREE outil;
785     return outil.determine_keycode(nx,ny,nz);
786     }
787    
788    
789    
790     virtual void get_xyzsommet_cellule(int numcellule,int numsommet,double &x,double &y,double &z)
791     {
792     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
793     x=cellule->boite.get_xmin();
794     y=cellule->boite.get_ymin();
795     z=cellule->boite.get_zmin();
796     double xx=cellule->boite.get_xmax();
797     double yy=cellule->boite.get_ymax();
798     double zz=cellule->boite.get_zmax();
799     if (numsommet==1) x=xx;
800     if (numsommet==2) {x=xx;y=yy;}
801     if (numsommet==3) y=yy;
802     if (numsommet==4) z=zz;
803     if (numsommet==5) {x=xx;z=zz;}
804     if (numsommet==6) {x=xx;y=yy;z=zz;}
805     if (numsommet==7) {y=yy;z=zz;}
806     }
807    
808     virtual void get_xyzsommet_feuille(int numcellule,int numsommet,double &x,double &y,double &z)
809     {
810     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
811     x=cellule->boite.get_xmin();
812     y=cellule->boite.get_ymin();
813     z=cellule->boite.get_zmin();
814     double xx=cellule->boite.get_xmax();
815     double yy=cellule->boite.get_ymax();
816     double zz=cellule->boite.get_zmax();
817     if (numsommet==1) x=xx;
818     if (numsommet==2) {x=xx;y=yy;}
819     if (numsommet==3) y=yy;
820     if (numsommet==4) z=zz;
821     if (numsommet==5) {x=xx;z=zz;}
822     if (numsommet==6) {x=xx;y=yy;z=zz;}
823     if (numsommet==7) {y=yy;z=zz;}
824     }
825    
826    
827    
828     virtual void equilibre(int niveauequilibre=1)
829     {
830     int ok=0;
831     do
832     {
833     int nbfeuilleavant=get_nb_feuille();
834     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstraf;
835     for (int i=0;i<lst_entite_feuille.get_nb();i++)
836     {
837     TPL_CELLULE_OCTREE<A,CONDITION> *feuille=lst_entite_feuille.get(i);
838     int niveaumaxvoisin=0;
839     for (int j=0;j<6;j++)
840     {
841     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstvoi;
842     get_feuille_voisins(feuille,j,&lstvoi);
843     int nb_feuille=lstvoi.size();
844     for (int k=0;k<nb_feuille;k++)
845     {
846     int niveau=lstvoi[k]->get_niveau();
847     if (niveau>niveaumaxvoisin) niveaumaxvoisin=niveau;
848     }
849    
850     }
851     if (niveaumaxvoisin-feuille->get_niveau()>niveauequilibre) {lstraf.insert(lstraf.end(),feuille);feuille->feuille=niveaumaxvoisin-niveauequilibre;}
852     }
853     int nbcelluleraffiner=lstraf.size();
854     for (int i=0;i<nbcelluleraffiner;i++)
855     {
856     TPL_CELLULE_OCTREE<A,CONDITION> *cell=lstraf[i];
857     lst_entite_feuille.supprimer(cell);
858     int niveauatteindre=cell->feuille;
859     int niveau=cell->niveau;
860     cell->feuille=0;
861     double xmin=cell->boite.get_xmin();
862     double ymin=cell->boite.get_ymin();
863     double zmin=cell->boite.get_zmin();
864     double dx=cell->boite.get_xmax()-cell->boite.get_xmin();
865     double dy=cell->boite.get_ymax()-cell->boite.get_ymin();
866     double dz=cell->boite.get_zmax()-cell->boite.get_zmin();
867    
868     cell->fils[0]=cree_fils(cell,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,0);
869     cell->fils[1]=cree_fils(cell,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,1);
870     cell->fils[2]=cree_fils(cell,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,2);
871     cell->fils[3]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,3);
872     cell->fils[4]=cree_fils(cell,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,4);
873     cell->fils[5]=cree_fils(cell,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,5);
874     cell->fils[6]=cree_fils(cell,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,6);
875     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);
876     }
877     int nbfeuilleapres=get_nb_feuille();
878     if (nbfeuilleapres==nbfeuilleavant) ok=1;
879     }
880     while (ok==0);
881    
882    
883     }
884    
885     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)
886     {
887     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
888     lst_entite_cellule.ajouter(cellule);
889     if (niveaumax<niv) niveaumax=niv;
890     if (cellule->get_niveau()!=niveauatteindre)
891     {
892     cellule->feuille=0;
893     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,0);
894     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,1);
895     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,2);
896     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,3);
897     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,4);
898     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,5);
899     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,6);
900     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);
901     }
902     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
903     return cellule;
904     }
905    
906    
907 5 virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
908     {
909     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
910     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
911     rechercher(boite,liste_entite_trouve,cellule);
912     };
913    
914    
915    
916     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
917     {
918 francois 632 if (cellule==NULL) return;
919 5 if (boite*cellule->boite)
920     if (cellule->feuille==1)
921     {
922     cellule->lst_entite_A.ajouter(a);
923     }
924     else
925     {
926     inserer(boite,a,cellule->fils[0]);
927     inserer(boite,a,cellule->fils[1]);
928     inserer(boite,a,cellule->fils[2]);
929     inserer(boite,a,cellule->fils[3]);
930     inserer(boite,a,cellule->fils[4]);
931     inserer(boite,a,cellule->fils[5]);
932     inserer(boite,a,cellule->fils[6]);
933     inserer(boite,a,cellule->fils[7]);
934     }
935     };
936    
937     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
938     {
939 francois 632 if (cellule==NULL) return;
940 5 if (boite*cellule->boite)
941     if (cellule->feuille==1)
942     {
943     cellule->lst_entite_A.supprimer(a);
944     }
945     else
946     {
947     supprimer(boite,a,cellule->fils[0]);
948     supprimer(boite,a,cellule->fils[1]);
949     supprimer(boite,a,cellule->fils[2]);
950     supprimer(boite,a,cellule->fils[3]);
951     supprimer(boite,a,cellule->fils[4]);
952     supprimer(boite,a,cellule->fils[5]);
953     supprimer(boite,a,cellule->fils[6]);
954     supprimer(boite,a,cellule->fils[7]);
955     }
956     };
957    
958     virtual void inserer(A a)
959     {
960     BOITE_3D boite=a->get_boite_3D();
961     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
962     inserer(boite,a,cellule);
963     }
964    
965     virtual void supprimer(A a)
966     {
967     BOITE_3D boite=a->get_boite_3D();
968     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
969     supprimer(boite,a,cellule);
970     }
971    
972 francois 65 virtual int get_niveau_max(void)
973     {
974     return niveaumax;
975     }
976 5
977 francois 65
978    
979 francois 276 virtual void vide(void)
980     {
981     for (int i=0;i<lst_entite_feuille.get_nb();i++)
982     {
983     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(i);
984     cellule->vide();
985     }
986     }
987 francois 65
988 francois 507
989     virtual double get_dimension_caracteristique()
990     {
991     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
992     double x=cellule->boite.get_xmin();
993     double y=cellule->boite.get_ymin();
994     double z=cellule->boite.get_zmin();
995     double xx=cellule->boite.get_xmax();
996     double yy=cellule->boite.get_ymax();
997     double zz=cellule->boite.get_zmax();
998     return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y)+(zz-z)*(zz-z)) ;
999     }
1000    
1001    
1002    
1003 francois 65 protected:
1004 5 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_cellule;
1005 francois 65 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_feuille;
1006     int niveaumax;
1007 5
1008     };
1009    
1010 francois 65 template <class A,class B>
1011     class TPL_OCTREE_FCT:public TPL_OCTREE<A,A>
1012     {
1013     private:
1014     double coef;
1015 5
1016 francois 65 public:
1017     TPL_OCTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1018     ~TPL_OCTREE_FCT() {}
1019 5
1020 francois 65
1021 francois 102 virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1022 francois 65
1023     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1024     {
1025     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1026 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1027 francois 65 double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1028     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1029     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1030     double d=dx;
1031 francois 584 if (dy>d) d=dy;
1032     if (dz>d) d=dz;
1033 francois 65 double xyz[3];
1034     root_cellule->boite.get_centre(xyz);
1035     double ecart[9];
1036     fonction.evaluer(xyz,ecart);
1037     double dcible=coef/sqrt(ecart[0]);
1038     if (dcible<d)
1039     {
1040     root_cellule->feuille=0;
1041     root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,0);
1042     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,1);
1043     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,2);
1044     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,3);
1045     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,4);
1046     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,5);
1047     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,6);
1048     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);
1049     }
1050 francois 102 else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1051 francois 65 }
1052    
1053     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)
1054     {
1055     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1056 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1057     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1058 francois 65 double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1059     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1060     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1061     double d=dx;
1062 francois 584 if (ddy>d) d=ddy;
1063     if (ddz>d) d=ddz;
1064 francois 65 double xyz[3];
1065     cellule->boite.get_centre(xyz);
1066     double ecart[9];
1067     fonction.evaluer(xyz,ecart);
1068     double dcible=coef/sqrt(ecart[0]);
1069     if (dcible<d)
1070     {
1071     cellule->feuille=0;
1072     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,0);
1073     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,1);
1074     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,2);
1075     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,3);
1076     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,4);
1077     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,5);
1078     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,6);
1079     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);
1080     }
1081 francois 102 else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1082 francois 65 return cellule;
1083     }
1084     };
1085    
1086    
1087 francois 632 template <class A,class B>
1088     class TPL_NTREE_FCT:public TPL_OCTREE<A,A>
1089     {
1090     private:
1091     double coef;
1092 francois 65
1093 francois 632 public:
1094     TPL_NTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1095     ~TPL_NTREE_FCT() {}
1096    
1097    
1098     virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1099    
1100     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1101     {
1102     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1103     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1104     double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1105     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1106     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1107     double xyz[3];
1108     root_cellule->boite.get_centre(xyz);
1109     double ecart[9];
1110     fonction.evaluer(xyz,ecart);
1111     double dcible=coef/sqrt(ecart[0]);
1112     int ndivx=2,ndivy=2,ndivz=2;
1113     if (dcible>dx) ndivx=1;
1114     if (dcible>dy) ndivy=1;
1115     if (dcible>dz) ndivz=1;
1116     if (ndivx*ndivy*ndivz!=1)
1117     {
1118     root_cellule->feuille=0;
1119     for (int i=0;i<ndivx;i++)
1120     for (int j=0;j<ndivy;j++)
1121     for (int k=0;k<ndivz;k++)
1122     root_cellule->fils[((i*ndivx)+j)*ndivy+k]=cree_fils(root_cellule,xmin+i*1.0/ndivx*dx,ymin+j*1.0/ndivy*dy,zmin+k*1.0/ndivz*dz,dx*1./ndivx,dy*1./ndivy,dz*1./ndivz,fonction,1,0);
1123     }
1124     else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1125     }
1126    
1127     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)
1128     {
1129     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1130     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1131     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1132     double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1133     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1134     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1135     double xyz[3];
1136     cellule->boite.get_centre(xyz);
1137     double ecart[9];
1138     fonction.evaluer(xyz,ecart);
1139     double dcible=coef/sqrt(ecart[0]);
1140     int ndivx=2,ndivy=2,ndivz=2;
1141     if (dcible>dx) ndivx=1;
1142     if (dcible>dy) ndivy=1;
1143     if (dcible>dz) ndivz=1;
1144     if (ndivx*ndivy*ndivz!=1)
1145     {
1146     cellule->feuille=0;
1147     for (int i=0;i<ndivx;i++)
1148     for (int j=0;j<ndivy;j++)
1149     for (int k=0;k<ndivz;k++)
1150     cellule->fils[((i*ndivx)+j)*ndivy+k]=cree_fils(cellule,xmin+i*1.0/ndivx*dx,ymin+j*1.0/ndivy*dy,zmin+k*1.0/ndivz*dz,dx*1./ndivx,dy*1./ndivy,dz*1./ndivz,fonction,1,0);
1151     }
1152     else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1153     return cellule;
1154     }
1155     };
1156    
1157    
1158    
1159    
1160    
1161    
1162    
1163    
1164    
1165 5 template <class A,class CONDITION,class B>
1166     class TPL_OCTREE_INFO:public OCTREE_BASE
1167     {
1168     public:
1169     TPL_OCTREE_INFO() {};
1170     ~TPL_OCTREE_INFO()
1171     {
1172     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
1173     {
1174     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(i1);
1175     delete cellule;
1176     }
1177     };
1178    
1179     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
1180    
1181     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
1182    
1183     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
1184    
1185    
1186     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1187     {
1188     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1189     lst_entite_cellule.ajouter(root_cellule);
1190     for (int i=0;i<lst_entite->get_nb();i++)
1191     {
1192     CONDITION cond=lst_entite->get(i);
1193     BOITE_3D boite_cond=cond->get_boite_3D();
1194     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1195     }
1196     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1197     {
1198     root_cellule->feuille=0;
1199     double dx=xmax-xmin;
1200     double dy=ymax-ymin;
1201     double dz=zmax-zmin;
1202     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1203     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1204     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1205     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);
1206     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1207     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);
1208     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);
1209     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);
1210     }
1211     else root_cellule->feuille=1;
1212     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1213     {
1214     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1215     cellule->lst_entite_CONDITION.vide();
1216     }
1217     }
1218    
1219     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1220     {
1221     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1222     lst_entite_cellule.ajouter(root_cellule);
1223     for (int i=0;i<lst_entite->get_nb();i++)
1224     {
1225     CONDITION cond=lst_entite->get(i);
1226     BOITE_3D boite_cond=cond->get_boite_3D();
1227     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1228     }
1229     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1230     {
1231     root_cellule->feuille=0;
1232     double dx=xmax-xmin;
1233     double dy=ymax-ymin;
1234     double dz=zmax-zmin;
1235     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1236     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1237     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1238     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);
1239     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1240     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);
1241     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);
1242     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);
1243     }
1244     else root_cellule->feuille=1;
1245     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1246     {
1247     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1248     cellule->lst_entite_CONDITION.vide();
1249     }
1250     }
1251    
1252     virtual void initialiser(OCTREE_BASE* oc)
1253     {
1254     BOITE_3D boite=oc->get_cellule(0)->get_boite();
1255     double xmin=boite.get_xmin();
1256     double xmax=boite.get_xmax();
1257     double ymin=boite.get_ymin();
1258     double ymax=boite.get_ymax();
1259     double zmin=boite.get_zmin();
1260     double zmax=boite.get_zmax();
1261     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1262     lst_entite_cellule.ajouter(cellule);
1263     if (oc->get_cellule(0)->get_feuille()==0)
1264     {
1265     cellule->fils[0]=cree_fils(oc->get_cellule(0)->get_fils(0));
1266     cellule->fils[1]=cree_fils(oc->get_cellule(0)->get_fils(1));
1267     cellule->fils[2]=cree_fils(oc->get_cellule(0)->get_fils(2));
1268     cellule->fils[3]=cree_fils(oc->get_cellule(0)->get_fils(3));
1269     cellule->fils[4]=cree_fils(oc->get_cellule(0)->get_fils(4));
1270     cellule->fils[5]=cree_fils(oc->get_cellule(0)->get_fils(5));
1271     cellule->fils[6]=cree_fils(oc->get_cellule(0)->get_fils(6));
1272     cellule->fils[7]=cree_fils(oc->get_cellule(0)->get_fils(7));
1273     }
1274     cellule->feuille=oc->get_cellule(0)->get_feuille();
1275     };
1276    
1277    
1278     TPL_CELLULE_INFO<A,CONDITION,B>* cree_fils(CELLULE_OCTREE_BASE *cellule_base)
1279     {
1280     BOITE_3D boite=cellule_base->get_boite();
1281     double xmin=boite.get_xmin();
1282     double xmax=boite.get_xmax();
1283     double ymin=boite.get_ymin();
1284     double ymax=boite.get_ymax();
1285     double zmin=boite.get_zmin();
1286     double zmax=boite.get_zmax();
1287     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1288     lst_entite_cellule.ajouter(cellule);
1289     if (cellule_base->get_feuille()==1)
1290     {
1291     cellule->feuille=1;
1292     }
1293     else
1294     {
1295     cellule->fils[0]=cree_fils(cellule_base->get_fils(0));
1296     cellule->fils[1]=cree_fils(cellule_base->get_fils(1));
1297     cellule->fils[2]=cree_fils(cellule_base->get_fils(2));
1298     cellule->fils[3]=cree_fils(cellule_base->get_fils(3));
1299     cellule->fils[4]=cree_fils(cellule_base->get_fils(4));
1300     cellule->fils[5]=cree_fils(cellule_base->get_fils(5));
1301     cellule->fils[6]=cree_fils(cellule_base->get_fils(6));
1302     cellule->fils[7]=cree_fils(cellule_base->get_fils(7));
1303     cellule->feuille=0;
1304     }
1305     return cellule;
1306     };
1307    
1308     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)
1309     {
1310     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz);
1311     lst_entite_cellule.ajouter(cellule);
1312     for (int i=0;i<lst_entite->get_nb();i++)
1313     {
1314     CONDITION cond=lst_entite->get(i);
1315     BOITE_3D boite_cond=cond->get_boite_3D();
1316     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
1317     }
1318     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
1319     {
1320     cellule->feuille=0;
1321     cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1322     cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1323     cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1324     cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1325     cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1326     cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1327     cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1328     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);
1329     }
1330     else cellule->feuille=1;
1331     return cellule;
1332     }
1333    
1334    
1335     virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1336     {
1337     if (boite*cellule->boite)
1338     if (cellule->feuille==1)
1339     {
1340     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
1341     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
1342     }
1343     else
1344     {
1345     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
1346     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
1347     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
1348     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
1349     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
1350     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
1351     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
1352     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
1353     }
1354     };
1355    
1356    
1357     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)
1358     {
1359     if (boite*cellule->boite)
1360     if (cellule->feuille==1)
1361     {
1362     liste_entite.ajouter(cellule);
1363     }
1364     else
1365     {
1366     get_cellule(boite,cellule->fils[0],liste_entite);
1367     get_cellule(boite,cellule->fils[1],liste_entite);
1368     get_cellule(boite,cellule->fils[2],liste_entite);
1369     get_cellule(boite,cellule->fils[3],liste_entite);
1370     get_cellule(boite,cellule->fils[4],liste_entite);
1371     get_cellule(boite,cellule->fils[5],liste_entite);
1372     get_cellule(boite,cellule->fils[6],liste_entite);
1373     get_cellule(boite,cellule->fils[7],liste_entite);
1374     }
1375     };
1376    
1377     virtual TPL_CELLULE_INFO<A,CONDITION,B> *get_cellule(double x,double y, double z)
1378     {
1379     BOITE_3D boite(x,y,z,x,y,z);
1380     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1381     TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > liste_cellule;
1382     get_cellule(boite,cellule,liste_cellule);
1383     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
1384     return NULL;
1385     };
1386    
1387    
1388     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
1389     {
1390     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
1391     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1392     rechercher(boite,liste_entite_trouve,cellule);
1393     };
1394    
1395    
1396    
1397     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1398     {
1399     if (boite*cellule->boite)
1400     if (cellule->feuille==1)
1401     {
1402     cellule->lst_entite_A.ajouter(a);
1403     }
1404     else
1405     {
1406     inserer(boite,a,cellule->fils[0]);
1407     inserer(boite,a,cellule->fils[1]);
1408     inserer(boite,a,cellule->fils[2]);
1409     inserer(boite,a,cellule->fils[3]);
1410     inserer(boite,a,cellule->fils[4]);
1411     inserer(boite,a,cellule->fils[5]);
1412     inserer(boite,a,cellule->fils[6]);
1413     inserer(boite,a,cellule->fils[7]);
1414     }
1415     };
1416    
1417     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1418     {
1419     if (boite*cellule->boite)
1420     if (cellule->feuille==1)
1421     {
1422     cellule->lst_entite_A.supprimer(a);
1423     }
1424     else
1425     {
1426     supprimer(boite,a,cellule->fils[0]);
1427     supprimer(boite,a,cellule->fils[1]);
1428     supprimer(boite,a,cellule->fils[2]);
1429     supprimer(boite,a,cellule->fils[3]);
1430     supprimer(boite,a,cellule->fils[4]);
1431     supprimer(boite,a,cellule->fils[5]);
1432     supprimer(boite,a,cellule->fils[6]);
1433     supprimer(boite,a,cellule->fils[7]);
1434     }
1435     };
1436    
1437     virtual void inserer(A a)
1438     {
1439     BOITE_3D boite=a->get_boite_3D();
1440     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1441     inserer(boite,a,cellule);
1442     }
1443    
1444     virtual void supprimer(A a)
1445     {
1446     BOITE_3D boite=a->get_boite_3D();
1447     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1448     supprimer(boite,a,cellule);
1449     }
1450    
1451    
1452     private:
1453     TPL_LISTE_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B>* > lst_entite_cellule;
1454    
1455     };
1456    
1457    
1458    
1459    
1460     #endif