ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_octree.h
Revision: 633
Committed: Thu Jan 15 20:44:44 2015 UTC (10 years, 4 months ago) by francois
Content type: text/plain
File size: 57885 byte(s)
Log Message:
Amélioration de la comparaison et projection de solution pour les calculs bidim triangulaires uniquement

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 francois 633 dz=dz*2;
563 francois 65 for (int i=0;i<lst_entite->get_nb();i++)
564 5 {
565     CONDITION cond=lst_entite->get(i);
566     BOITE_3D boite_cond=cond->get_boite_3D();
567     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
568     }
569     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
570     {
571     cellule->feuille=0;
572 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);
573     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);
574     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);
575     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);
576     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);
577     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);
578     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);
579     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);
580 5 }
581 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
582 5 return cellule;
583     }
584    
585 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)
586     {
587     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
588     lst_entite_cellule.ajouter(cellule);
589     if (niveaumax<niv) niveaumax=niv;
590     dz=dz*2;
591     for (int i=0;i<lst_entite->get_nb();i++)
592     {
593     CONDITION cond=lst_entite->get(i);
594     BOITE_3D boite_cond=cond->get_boite_3D();
595     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
596     }
597     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
598     {
599     cellule->feuille=0;
600     if (dimanepasdecouper==3)
601     {
602     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
603     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);
604     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);
605     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);
606     }
607     if (dimanepasdecouper==2)
608     {
609     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
610     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);
611     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);
612     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);
613     }
614     if (dimanepasdecouper==1)
615     {
616     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
617     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);
618     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);
619     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);
620     }
621     }
622     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
623     return cellule;
624     }
625 5
626 francois 633
627 5 virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
628     {
629 francois 632 if (cellule==NULL) return;
630 5 if (boite*cellule->boite)
631     if (cellule->feuille==1)
632     {
633     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
634     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
635     }
636     else
637     {
638     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
639     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
640     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
641     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
642     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
643     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
644     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
645     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
646     }
647     };
648    
649    
650     virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > &liste_entite)
651     {
652     if (boite*cellule->boite)
653     if (cellule->feuille==1)
654     {
655     liste_entite.ajouter(cellule);
656     }
657     else
658     {
659     get_cellule(boite,cellule->fils[0],liste_entite);
660     get_cellule(boite,cellule->fils[1],liste_entite);
661     get_cellule(boite,cellule->fils[2],liste_entite);
662     get_cellule(boite,cellule->fils[3],liste_entite);
663     get_cellule(boite,cellule->fils[4],liste_entite);
664     get_cellule(boite,cellule->fils[5],liste_entite);
665     get_cellule(boite,cellule->fils[6],liste_entite);
666     get_cellule(boite,cellule->fils[7],liste_entite);
667     }
668     };
669    
670 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_adjacent(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
671     {
672     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
673     OUTIL_OCTREE outil;
674     if (cellule->pere==NULL) cellule2=NULL;
675     else if (outil.adjacent(direction,cellule->get_sontype())) cellule2=get_cellule_adjacent(cellule->pere,direction);
676     else if (outil.commonface(direction,cellule->get_sontype())!=-1) cellule2=get_cellule_voisin(cellule->pere,outil.commonface(direction,cellule->get_sontype()));
677     else cellule2=cellule->pere;
678     if (cellule2!=NULL)
679     if (cellule2->get_feuille()==0)
680     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
681     return cellule2;
682     }
683    
684     virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_voisin(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
685     {
686     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
687     OUTIL_OCTREE outil;
688     if ((!(cellule->pere==NULL)) && (outil.adjacent(direction,cellule->get_sontype())))
689     cellule2=get_cellule_voisin(cellule->pere,direction);
690     else
691     cellule2=cellule->pere;
692     if (cellule2!=NULL)
693     if (cellule2->feuille==0)
694     return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
695     return cellule2;
696     }
697    
698    
699    
700    
701     virtual void get_feuille_voisins(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction,vector<TPL_CELLULE_OCTREE<A,CONDITION> *> *lst)
702     {
703     OUTIL_OCTREE outil;
704     lst->clear();
705     TPL_CELLULE_OCTREE<A,CONDITION> *cellule2=get_cellule_voisin(cellule,direction);
706     if (cellule2!=NULL) lst->insert(lst->end(),cellule2);
707     int i=0;
708     while (i<lst->size())
709     {
710     TPL_CELLULE_OCTREE<A,CONDITION> *cell=(*lst)[i];
711     if (cell->feuille==0)
712     {
713     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,0)));
714     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,1)));
715     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,2)));
716     lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,3)));
717     }
718     i++;
719     }
720 francois 102 typename vector<TPL_CELLULE_OCTREE<A,CONDITION> * >::iterator j=lst->end();
721 francois 65 while (j!=lst->begin())
722     {
723     j--;
724     TPL_CELLULE_OCTREE<A,CONDITION> *cell=*j;
725     if (cell->feuille==0)
726     lst->erase(j);
727    
728     }
729     }
730    
731 5 virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule(double x,double y, double z)
732     {
733     BOITE_3D boite(x,y,z,x,y,z);
734     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
735     TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > liste_cellule;
736     get_cellule(boite,cellule,liste_cellule);
737     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
738     return NULL;
739     };
740    
741    
742 francois 65 virtual unsigned long get_cellule_keycode(int numcellule,int numsommet)
743     {
744     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
745     return get_keycode(cellule,numsommet);
746     }
747    
748     virtual unsigned long get_feuille_keycode(int numcellule,int numsommet)
749     {
750     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
751     return get_keycode(cellule,numsommet);
752     }
753    
754     virtual unsigned long get_keycode(TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,int numsommet)
755     {
756     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
757    
758     double x=cellule->boite.get_xmin();
759     double y=cellule->boite.get_ymin();
760     double z=cellule->boite.get_zmin();
761     double xx=cellule->boite.get_xmax();
762     double yy=cellule->boite.get_ymax();
763     double zz=cellule->boite.get_zmax();
764     double somx=x,somy=y,somz=z;
765     if (numsommet==1) somx=xx;
766     if (numsommet==2) {somx=xx;somy=yy;}
767     if (numsommet==3) somy=yy;
768     if (numsommet==4) somz=zz;
769     if (numsommet==5) {somx=xx;somz=zz;}
770     if (numsommet==6) {somx=xx;somy=yy;somz=zz;}
771     if (numsommet==7) {somy=yy;somz=zz;}
772     double nx=0.1+(somx-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
773     double ny=0.1+(somy-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
774     double nz=0.1+(somz-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
775     OUTIL_OCTREE outil;
776     return outil.determine_keycode(nx,ny,nz);
777     }
778    
779     virtual unsigned long get_keycode(double x,double y,double z)
780     {
781     TPL_CELLULE_OCTREE<A ,CONDITION>* root=lst_entite_cellule.get(0);
782     double nx=0.1+(x-root->boite.get_xmin())/(root->boite.get_xmax()-root->boite.get_xmin())*(1<<get_niveau_max());
783     double ny=0.1+(y-root->boite.get_ymin())/(root->boite.get_ymax()-root->boite.get_ymin())*(1<<get_niveau_max());
784     double nz=0.1+(z-root->boite.get_zmin())/(root->boite.get_zmax()-root->boite.get_zmin())*(1<<get_niveau_max());
785     OUTIL_OCTREE outil;
786     return outil.determine_keycode(nx,ny,nz);
787     }
788    
789    
790    
791     virtual void get_xyzsommet_cellule(int numcellule,int numsommet,double &x,double &y,double &z)
792     {
793     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(numcellule);
794     x=cellule->boite.get_xmin();
795     y=cellule->boite.get_ymin();
796     z=cellule->boite.get_zmin();
797     double xx=cellule->boite.get_xmax();
798     double yy=cellule->boite.get_ymax();
799     double zz=cellule->boite.get_zmax();
800     if (numsommet==1) x=xx;
801     if (numsommet==2) {x=xx;y=yy;}
802     if (numsommet==3) y=yy;
803     if (numsommet==4) z=zz;
804     if (numsommet==5) {x=xx;z=zz;}
805     if (numsommet==6) {x=xx;y=yy;z=zz;}
806     if (numsommet==7) {y=yy;z=zz;}
807     }
808    
809     virtual void get_xyzsommet_feuille(int numcellule,int numsommet,double &x,double &y,double &z)
810     {
811     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(numcellule);
812     x=cellule->boite.get_xmin();
813     y=cellule->boite.get_ymin();
814     z=cellule->boite.get_zmin();
815     double xx=cellule->boite.get_xmax();
816     double yy=cellule->boite.get_ymax();
817     double zz=cellule->boite.get_zmax();
818     if (numsommet==1) x=xx;
819     if (numsommet==2) {x=xx;y=yy;}
820     if (numsommet==3) y=yy;
821     if (numsommet==4) z=zz;
822     if (numsommet==5) {x=xx;z=zz;}
823     if (numsommet==6) {x=xx;y=yy;z=zz;}
824     if (numsommet==7) {y=yy;z=zz;}
825     }
826    
827    
828    
829     virtual void equilibre(int niveauequilibre=1)
830     {
831     int ok=0;
832     do
833     {
834     int nbfeuilleavant=get_nb_feuille();
835     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstraf;
836     for (int i=0;i<lst_entite_feuille.get_nb();i++)
837     {
838     TPL_CELLULE_OCTREE<A,CONDITION> *feuille=lst_entite_feuille.get(i);
839     int niveaumaxvoisin=0;
840     for (int j=0;j<6;j++)
841     {
842     vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstvoi;
843     get_feuille_voisins(feuille,j,&lstvoi);
844     int nb_feuille=lstvoi.size();
845     for (int k=0;k<nb_feuille;k++)
846     {
847     int niveau=lstvoi[k]->get_niveau();
848     if (niveau>niveaumaxvoisin) niveaumaxvoisin=niveau;
849     }
850    
851     }
852     if (niveaumaxvoisin-feuille->get_niveau()>niveauequilibre) {lstraf.insert(lstraf.end(),feuille);feuille->feuille=niveaumaxvoisin-niveauequilibre;}
853     }
854     int nbcelluleraffiner=lstraf.size();
855     for (int i=0;i<nbcelluleraffiner;i++)
856     {
857     TPL_CELLULE_OCTREE<A,CONDITION> *cell=lstraf[i];
858     lst_entite_feuille.supprimer(cell);
859     int niveauatteindre=cell->feuille;
860     int niveau=cell->niveau;
861     cell->feuille=0;
862     double xmin=cell->boite.get_xmin();
863     double ymin=cell->boite.get_ymin();
864     double zmin=cell->boite.get_zmin();
865     double dx=cell->boite.get_xmax()-cell->boite.get_xmin();
866     double dy=cell->boite.get_ymax()-cell->boite.get_ymin();
867     double dz=cell->boite.get_zmax()-cell->boite.get_zmin();
868    
869     cell->fils[0]=cree_fils(cell,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,0);
870     cell->fils[1]=cree_fils(cell,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,1);
871     cell->fils[2]=cree_fils(cell,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,2);
872     cell->fils[3]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,3);
873     cell->fils[4]=cree_fils(cell,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,4);
874     cell->fils[5]=cree_fils(cell,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,5);
875     cell->fils[6]=cree_fils(cell,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,6);
876     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);
877     }
878     int nbfeuilleapres=get_nb_feuille();
879     if (nbfeuilleapres==nbfeuilleavant) ok=1;
880     }
881     while (ok==0);
882    
883    
884     }
885    
886     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)
887     {
888     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
889     lst_entite_cellule.ajouter(cellule);
890     if (niveaumax<niv) niveaumax=niv;
891     if (cellule->get_niveau()!=niveauatteindre)
892     {
893     cellule->feuille=0;
894     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,0);
895     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,1);
896     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,2);
897     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,3);
898     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,4);
899     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,5);
900     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,6);
901     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);
902     }
903     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
904     return cellule;
905     }
906    
907    
908 5 virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
909     {
910     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
911     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
912     rechercher(boite,liste_entite_trouve,cellule);
913     };
914    
915    
916    
917     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
918     {
919 francois 632 if (cellule==NULL) return;
920 5 if (boite*cellule->boite)
921     if (cellule->feuille==1)
922     {
923     cellule->lst_entite_A.ajouter(a);
924     }
925     else
926     {
927     inserer(boite,a,cellule->fils[0]);
928     inserer(boite,a,cellule->fils[1]);
929     inserer(boite,a,cellule->fils[2]);
930     inserer(boite,a,cellule->fils[3]);
931     inserer(boite,a,cellule->fils[4]);
932     inserer(boite,a,cellule->fils[5]);
933     inserer(boite,a,cellule->fils[6]);
934     inserer(boite,a,cellule->fils[7]);
935     }
936     };
937    
938     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
939     {
940 francois 632 if (cellule==NULL) return;
941 5 if (boite*cellule->boite)
942     if (cellule->feuille==1)
943     {
944     cellule->lst_entite_A.supprimer(a);
945     }
946     else
947     {
948     supprimer(boite,a,cellule->fils[0]);
949     supprimer(boite,a,cellule->fils[1]);
950     supprimer(boite,a,cellule->fils[2]);
951     supprimer(boite,a,cellule->fils[3]);
952     supprimer(boite,a,cellule->fils[4]);
953     supprimer(boite,a,cellule->fils[5]);
954     supprimer(boite,a,cellule->fils[6]);
955     supprimer(boite,a,cellule->fils[7]);
956     }
957     };
958    
959     virtual void inserer(A a)
960     {
961     BOITE_3D boite=a->get_boite_3D();
962     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
963     inserer(boite,a,cellule);
964     }
965    
966     virtual void supprimer(A a)
967     {
968     BOITE_3D boite=a->get_boite_3D();
969     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
970     supprimer(boite,a,cellule);
971     }
972    
973 francois 65 virtual int get_niveau_max(void)
974     {
975     return niveaumax;
976     }
977 5
978 francois 65
979    
980 francois 276 virtual void vide(void)
981     {
982     for (int i=0;i<lst_entite_feuille.get_nb();i++)
983     {
984     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(i);
985     cellule->vide();
986     }
987     }
988 francois 65
989 francois 507
990     virtual double get_dimension_caracteristique()
991     {
992     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
993     double x=cellule->boite.get_xmin();
994     double y=cellule->boite.get_ymin();
995     double z=cellule->boite.get_zmin();
996     double xx=cellule->boite.get_xmax();
997     double yy=cellule->boite.get_ymax();
998     double zz=cellule->boite.get_zmax();
999     return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y)+(zz-z)*(zz-z)) ;
1000     }
1001    
1002    
1003    
1004 francois 65 protected:
1005 5 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_cellule;
1006 francois 65 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_feuille;
1007     int niveaumax;
1008 5
1009     };
1010    
1011 francois 65 template <class A,class B>
1012     class TPL_OCTREE_FCT:public TPL_OCTREE<A,A>
1013     {
1014     private:
1015     double coef;
1016 5
1017 francois 65 public:
1018     TPL_OCTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1019     ~TPL_OCTREE_FCT() {}
1020 5
1021 francois 65
1022 francois 102 virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1023 francois 65
1024     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1025     {
1026     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1027 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1028 francois 65 double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1029     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1030     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1031     double d=dx;
1032 francois 584 if (dy>d) d=dy;
1033     if (dz>d) d=dz;
1034 francois 65 double xyz[3];
1035     root_cellule->boite.get_centre(xyz);
1036     double ecart[9];
1037     fonction.evaluer(xyz,ecart);
1038     double dcible=coef/sqrt(ecart[0]);
1039     if (dcible<d)
1040     {
1041     root_cellule->feuille=0;
1042     root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,0);
1043     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,1);
1044     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,2);
1045     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,3);
1046     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,4);
1047     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,5);
1048     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,6);
1049     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);
1050     }
1051 francois 102 else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1052 francois 65 }
1053    
1054     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)
1055     {
1056     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1057 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1058     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1059 francois 65 double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1060     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1061     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1062     double d=dx;
1063 francois 584 if (ddy>d) d=ddy;
1064     if (ddz>d) d=ddz;
1065 francois 65 double xyz[3];
1066     cellule->boite.get_centre(xyz);
1067     double ecart[9];
1068     fonction.evaluer(xyz,ecart);
1069     double dcible=coef/sqrt(ecart[0]);
1070     if (dcible<d)
1071     {
1072     cellule->feuille=0;
1073     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,0);
1074     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,1);
1075     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,2);
1076     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,3);
1077     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,4);
1078     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,5);
1079     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,6);
1080     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);
1081     }
1082 francois 102 else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1083 francois 65 return cellule;
1084     }
1085     };
1086    
1087    
1088 francois 632 template <class A,class B>
1089     class TPL_NTREE_FCT:public TPL_OCTREE<A,A>
1090     {
1091     private:
1092     double coef;
1093 francois 65
1094 francois 632 public:
1095     TPL_NTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1096     ~TPL_NTREE_FCT() {}
1097    
1098    
1099     virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1100    
1101     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1102     {
1103     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1104     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1105     double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1106     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1107     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1108     double xyz[3];
1109     root_cellule->boite.get_centre(xyz);
1110     double ecart[9];
1111     fonction.evaluer(xyz,ecart);
1112     double dcible=coef/sqrt(ecart[0]);
1113     int ndivx=2,ndivy=2,ndivz=2;
1114     if (dcible>dx) ndivx=1;
1115     if (dcible>dy) ndivy=1;
1116     if (dcible>dz) ndivz=1;
1117     if (ndivx*ndivy*ndivz!=1)
1118     {
1119     root_cellule->feuille=0;
1120     for (int i=0;i<ndivx;i++)
1121     for (int j=0;j<ndivy;j++)
1122     for (int k=0;k<ndivz;k++)
1123     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);
1124     }
1125     else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1126     }
1127    
1128     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)
1129     {
1130     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1131     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1132     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1133     double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1134     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1135     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1136     double xyz[3];
1137     cellule->boite.get_centre(xyz);
1138     double ecart[9];
1139     fonction.evaluer(xyz,ecart);
1140     double dcible=coef/sqrt(ecart[0]);
1141     int ndivx=2,ndivy=2,ndivz=2;
1142     if (dcible>dx) ndivx=1;
1143     if (dcible>dy) ndivy=1;
1144     if (dcible>dz) ndivz=1;
1145     if (ndivx*ndivy*ndivz!=1)
1146     {
1147     cellule->feuille=0;
1148     for (int i=0;i<ndivx;i++)
1149     for (int j=0;j<ndivy;j++)
1150     for (int k=0;k<ndivz;k++)
1151     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);
1152     }
1153     else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1154     return cellule;
1155     }
1156     };
1157    
1158    
1159    
1160    
1161    
1162    
1163    
1164    
1165    
1166 5 template <class A,class CONDITION,class B>
1167     class TPL_OCTREE_INFO:public OCTREE_BASE
1168     {
1169     public:
1170     TPL_OCTREE_INFO() {};
1171     ~TPL_OCTREE_INFO()
1172     {
1173     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
1174     {
1175     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(i1);
1176     delete cellule;
1177     }
1178     };
1179    
1180     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
1181    
1182     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
1183    
1184     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
1185    
1186    
1187     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1188     {
1189     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1190     lst_entite_cellule.ajouter(root_cellule);
1191     for (int i=0;i<lst_entite->get_nb();i++)
1192     {
1193     CONDITION cond=lst_entite->get(i);
1194     BOITE_3D boite_cond=cond->get_boite_3D();
1195     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1196     }
1197     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1198     {
1199     root_cellule->feuille=0;
1200     double dx=xmax-xmin;
1201     double dy=ymax-ymin;
1202     double dz=zmax-zmin;
1203     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1204     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1205     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1206     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);
1207     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1208     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);
1209     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);
1210     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);
1211     }
1212     else root_cellule->feuille=1;
1213     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1214     {
1215     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1216     cellule->lst_entite_CONDITION.vide();
1217     }
1218     }
1219    
1220     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1221     {
1222     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1223     lst_entite_cellule.ajouter(root_cellule);
1224     for (int i=0;i<lst_entite->get_nb();i++)
1225     {
1226     CONDITION cond=lst_entite->get(i);
1227     BOITE_3D boite_cond=cond->get_boite_3D();
1228     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1229     }
1230     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1231     {
1232     root_cellule->feuille=0;
1233     double dx=xmax-xmin;
1234     double dy=ymax-ymin;
1235     double dz=zmax-zmin;
1236     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1237     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1238     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1239     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);
1240     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1241     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);
1242     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);
1243     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);
1244     }
1245     else root_cellule->feuille=1;
1246     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1247     {
1248     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1249     cellule->lst_entite_CONDITION.vide();
1250     }
1251     }
1252    
1253     virtual void initialiser(OCTREE_BASE* oc)
1254     {
1255     BOITE_3D boite=oc->get_cellule(0)->get_boite();
1256     double xmin=boite.get_xmin();
1257     double xmax=boite.get_xmax();
1258     double ymin=boite.get_ymin();
1259     double ymax=boite.get_ymax();
1260     double zmin=boite.get_zmin();
1261     double zmax=boite.get_zmax();
1262     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1263     lst_entite_cellule.ajouter(cellule);
1264     if (oc->get_cellule(0)->get_feuille()==0)
1265     {
1266     cellule->fils[0]=cree_fils(oc->get_cellule(0)->get_fils(0));
1267     cellule->fils[1]=cree_fils(oc->get_cellule(0)->get_fils(1));
1268     cellule->fils[2]=cree_fils(oc->get_cellule(0)->get_fils(2));
1269     cellule->fils[3]=cree_fils(oc->get_cellule(0)->get_fils(3));
1270     cellule->fils[4]=cree_fils(oc->get_cellule(0)->get_fils(4));
1271     cellule->fils[5]=cree_fils(oc->get_cellule(0)->get_fils(5));
1272     cellule->fils[6]=cree_fils(oc->get_cellule(0)->get_fils(6));
1273     cellule->fils[7]=cree_fils(oc->get_cellule(0)->get_fils(7));
1274     }
1275     cellule->feuille=oc->get_cellule(0)->get_feuille();
1276     };
1277    
1278    
1279     TPL_CELLULE_INFO<A,CONDITION,B>* cree_fils(CELLULE_OCTREE_BASE *cellule_base)
1280     {
1281     BOITE_3D boite=cellule_base->get_boite();
1282     double xmin=boite.get_xmin();
1283     double xmax=boite.get_xmax();
1284     double ymin=boite.get_ymin();
1285     double ymax=boite.get_ymax();
1286     double zmin=boite.get_zmin();
1287     double zmax=boite.get_zmax();
1288     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1289     lst_entite_cellule.ajouter(cellule);
1290     if (cellule_base->get_feuille()==1)
1291     {
1292     cellule->feuille=1;
1293     }
1294     else
1295     {
1296     cellule->fils[0]=cree_fils(cellule_base->get_fils(0));
1297     cellule->fils[1]=cree_fils(cellule_base->get_fils(1));
1298     cellule->fils[2]=cree_fils(cellule_base->get_fils(2));
1299     cellule->fils[3]=cree_fils(cellule_base->get_fils(3));
1300     cellule->fils[4]=cree_fils(cellule_base->get_fils(4));
1301     cellule->fils[5]=cree_fils(cellule_base->get_fils(5));
1302     cellule->fils[6]=cree_fils(cellule_base->get_fils(6));
1303     cellule->fils[7]=cree_fils(cellule_base->get_fils(7));
1304     cellule->feuille=0;
1305     }
1306     return cellule;
1307     };
1308    
1309     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)
1310     {
1311     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz);
1312     lst_entite_cellule.ajouter(cellule);
1313     for (int i=0;i<lst_entite->get_nb();i++)
1314     {
1315     CONDITION cond=lst_entite->get(i);
1316     BOITE_3D boite_cond=cond->get_boite_3D();
1317     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
1318     }
1319     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
1320     {
1321     cellule->feuille=0;
1322     cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1323     cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1324     cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1325     cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1326     cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1327     cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1328     cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1329     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);
1330     }
1331     else cellule->feuille=1;
1332     return cellule;
1333     }
1334    
1335    
1336     virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1337     {
1338     if (boite*cellule->boite)
1339     if (cellule->feuille==1)
1340     {
1341     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
1342     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
1343     }
1344     else
1345     {
1346     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
1347     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
1348     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
1349     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
1350     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
1351     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
1352     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
1353     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
1354     }
1355     };
1356    
1357    
1358     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)
1359     {
1360     if (boite*cellule->boite)
1361     if (cellule->feuille==1)
1362     {
1363     liste_entite.ajouter(cellule);
1364     }
1365     else
1366     {
1367     get_cellule(boite,cellule->fils[0],liste_entite);
1368     get_cellule(boite,cellule->fils[1],liste_entite);
1369     get_cellule(boite,cellule->fils[2],liste_entite);
1370     get_cellule(boite,cellule->fils[3],liste_entite);
1371     get_cellule(boite,cellule->fils[4],liste_entite);
1372     get_cellule(boite,cellule->fils[5],liste_entite);
1373     get_cellule(boite,cellule->fils[6],liste_entite);
1374     get_cellule(boite,cellule->fils[7],liste_entite);
1375     }
1376     };
1377    
1378     virtual TPL_CELLULE_INFO<A,CONDITION,B> *get_cellule(double x,double y, double z)
1379     {
1380     BOITE_3D boite(x,y,z,x,y,z);
1381     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1382     TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > liste_cellule;
1383     get_cellule(boite,cellule,liste_cellule);
1384     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
1385     return NULL;
1386     };
1387    
1388    
1389     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
1390     {
1391     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
1392     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1393     rechercher(boite,liste_entite_trouve,cellule);
1394     };
1395    
1396    
1397    
1398     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1399     {
1400     if (boite*cellule->boite)
1401     if (cellule->feuille==1)
1402     {
1403     cellule->lst_entite_A.ajouter(a);
1404     }
1405     else
1406     {
1407     inserer(boite,a,cellule->fils[0]);
1408     inserer(boite,a,cellule->fils[1]);
1409     inserer(boite,a,cellule->fils[2]);
1410     inserer(boite,a,cellule->fils[3]);
1411     inserer(boite,a,cellule->fils[4]);
1412     inserer(boite,a,cellule->fils[5]);
1413     inserer(boite,a,cellule->fils[6]);
1414     inserer(boite,a,cellule->fils[7]);
1415     }
1416     };
1417    
1418     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1419     {
1420     if (boite*cellule->boite)
1421     if (cellule->feuille==1)
1422     {
1423     cellule->lst_entite_A.supprimer(a);
1424     }
1425     else
1426     {
1427     supprimer(boite,a,cellule->fils[0]);
1428     supprimer(boite,a,cellule->fils[1]);
1429     supprimer(boite,a,cellule->fils[2]);
1430     supprimer(boite,a,cellule->fils[3]);
1431     supprimer(boite,a,cellule->fils[4]);
1432     supprimer(boite,a,cellule->fils[5]);
1433     supprimer(boite,a,cellule->fils[6]);
1434     supprimer(boite,a,cellule->fils[7]);
1435     }
1436     };
1437    
1438     virtual void inserer(A a)
1439     {
1440     BOITE_3D boite=a->get_boite_3D();
1441     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1442     inserer(boite,a,cellule);
1443     }
1444    
1445     virtual void supprimer(A a)
1446     {
1447     BOITE_3D boite=a->get_boite_3D();
1448     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1449     supprimer(boite,a,cellule);
1450     }
1451    
1452    
1453     private:
1454     TPL_LISTE_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B>* > lst_entite_cellule;
1455    
1456     };
1457    
1458    
1459    
1460    
1461     #endif