ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/outil/src/tpl_octree.h
Revision: 1019
Committed: Tue Jun 4 21:16:50 2019 UTC (6 years ago) by francois
Content type: text/plain
File size: 58290 byte(s)
Log Message:
restructuration de magic
outil est sorti de lib pour pouvoir etre utiliser en dehors de lib
template est merge avec outil
poly_occ et un sous projet de magic qui utilise le nouveau outil

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 francois 904 /*
32 couturad 906 // #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 francois 904 */
51 francois 65
52     class OUTIL_OCTREE
53     {
54     public:
55     OUTIL_OCTREE()
56     {
57     };
58     ~OUTIL_OCTREE()
59     {
60     };
61    
62     unsigned long determine_keycode(int nx,int ny,int nz)
63     {
64 couturad 951 std::vector<int> bits;
65 francois 65 int ok=0,i=0;
66     do
67     {
68     int nnz=nz>>i;
69     int nny=ny>>i;
70     int nnx=nx>>i;
71     int bit1= nnz & 1;
72     int bit2= nny & 1;
73     int bit3= nnx & 1;
74     if ((nnz==0) && (nny==0) && (nnx==0)) ok=1;
75     bits.insert(bits.end(),bit1);
76     bits.insert(bits.end(),bit2);
77     bits.insert(bits.end(),bit3);
78     i++;
79     }
80     while (ok==0);
81     unsigned long keycode=0;
82     for (int i=0;i<bits.size();i++)
83     keycode=keycode+bits[i]*(1<<i);
84     return keycode;
85     }
86    
87    
88     bool adjacent(int direction,int octant)
89     {
90     bool tabadj[18][8]=
91     {
92     {true, true, true, true, false, false, false, false},
93     {true, true, false, false, true, true, false, false},
94     {false, true, false, true, false, true, false, true},
95     {false, false, true, true, false, false, true, true},
96     {true, false, true, false, true, false, true, false},
97     {false, false, false, false, true, true, true, true},
98     {true, true, false, false, false, false, false, false},
99     {true, false, true, false, false, false, false, false},
100     {true, false, false, false, true, false, false, false},
101     {false, true, false, true, false, false, false, false},
102     {false, true, false, false, false, true, false, false},
103     {false, false, true, true, false, false, false, false},
104     {false, false, false, true, false, false, false, true},
105     {false, false, true, false, false, false, true, false},
106     {false, false, false, false, true, true, false, false},
107     {false, false, false, false, true, false, true, false},
108     {false, false, false, false, false, true, false, true},
109     {false, false, false, false, false, false, true, true},
110    
111     };
112    
113     return tabadj[direction][octant];
114     }
115    
116    
117     int reflect(int direction,int octant)
118     {
119     int tabreflect[18][8]=
120     {
121     {4, 5, 6, 7, 0, 1, 2, 3},
122     {2, 3, 0, 1, 6, 7, 4, 5},
123     {1, 0, 3, 2, 5, 4, 7, 6},
124     {2, 3, 0, 1, 6, 7, 4, 5},
125     {1, 0, 3, 2, 5, 4, 7, 6},
126     {4, 5, 6, 7, 0, 1, 2, 3},
127     {6, 7, 4, 5, 2, 3, 0, 1},
128     {5, 4, 7, 6, 1, 0, 3, 2},
129     {3, 2, 1, 0, 7, 6, 5, 4},
130     {5, 4, 7, 6, 1, 0, 3, 2},
131     {3, 2, 1, 0, 7, 6, 5, 4},
132     {6, 7, 4, 5, 2, 3, 0, 1},
133     {3, 2, 1, 0, 7, 6, 5, 4},
134     {3, 2, 1, 0, 7, 6, 5, 4},
135     {6, 7, 4, 5, 2, 3, 0, 1},
136     {5, 4, 7, 6, 1, 0, 3, 2},
137     {5, 4, 7, 6, 1, 0, 3, 2},
138     {6, 7, 4, 5, 2, 3, 0, 1}
139    
140     };
141    
142     return tabreflect[direction][octant];
143     }
144    
145    
146    
147     int commonface(int direction,int octant)
148     {
149     int tabcommonface[12][8]=
150     {
151     {-1, -1, 0, 0, 1, 1, -1, -1},
152     {-1, 0, -1, 0, 4, -1, 4, -1},
153     {-1, 1, 4, -1, -1, 1, 4, -1},
154     {0, -1, 0, -1, -1, 2, -1, 2},
155     {1, -1, -1, 2, 1, -1, -1, 2},
156     {0, 0, -1, -1, -1, -1, 3, 3},
157     {-1, 2, 3, -1, -1, 2, 3, -1},
158     {4, -1, -1, 3, 4, -1, -1, 3},
159     {1, 1, -1, -1, -1, -1, 5, 5},
160     {4, -1, 4, -1, -1, 5, -1, 5},
161     {-1, 2, -1, 2, 5, -1, 5, -1},
162     {-1, -1, 3, 3, 5, 5, -1, -1},
163     } ;
164     return tabcommonface[direction-6][octant];
165    
166     }
167    
168     int filsvoisin(int direction,int numvoisin)
169     {
170     int tab[6][4]=
171     {
172     {4, 5, 6, 7},
173     {2, 3, 6, 7},
174     {0, 2, 4, 6},
175     {0, 1, 4, 5},
176     {1, 3, 5, 7},
177     {0, 1, 2, 3}
178     };
179     return tab[direction][numvoisin];
180     }
181    
182     int sommetface(int numface,int numsommet)
183     {
184     int tab[6][4]=
185     {
186     {0,1,2,3},
187     {0,1,5,4},
188     {1,2,6,5},
189     {3,2,6,7},
190     {0,3,7,4},
191     {4,5,6,7},
192     };
193     return tab[numface][numsommet];
194     }
195    
196     int sommetarete(int numarete,int numsommet)
197     {
198     int tab[12][2]=
199     {
200     {0,1},
201     {0,3},
202     {0,4},
203     {1,2},
204     {1,5},
205     {3,2},
206     {2,6},
207     {3,7},
208     {4,5},
209     {4,7},
210     {5,6},
211     {7,6},
212     };
213     return tab[numarete-6][numsommet];
214     }
215    
216    
217    
218    
219    
220     int areteface(int numface,int numarete)
221     {
222     int tab[6][4]=
223     {
224     {6,9,11,7},
225     {6,10,14,8},
226     {9,12,16,10},
227     {11,12,17,13},
228     {7,13,15,8},
229     {14,16,17,15},
230     };
231     return tab[numface][numarete];
232     }
233    
234     int faceadjacente(int numface,int numarete)
235     {
236     int tab[6][4]=
237     {
238     {1,2,3,4},
239     {0,2,5,4},
240     {0,3,5,1},
241     {0,2,5,4},
242     {0,3,5,1},
243     {1,2,3,4},
244     };
245     return tab[numface][numarete];
246     }
247    
248    
249    
250     };
251    
252    
253 5 class CELLULE_OCTREE_BASE
254     {
255     public:
256     CELLULE_OCTREE_BASE()
257     {
258     static unsigned long idmax=0;
259     id=idmax;
260     idmax++;
261     };
262    
263     virtual ~CELLULE_OCTREE_BASE() {};
264     virtual BOITE_3D get_boite(void)=0;
265     virtual CELLULE_OCTREE_BASE* get_fils(int num)=0;
266     virtual int get_feuille(void)=0;
267 francois 65 virtual int get_niveau(void)=0;
268     virtual int get_sontype(void)=0;
269 5 virtual unsigned long get_id() {return id;};
270     unsigned long id;
271     };
272    
273    
274     class OCTREE_BASE
275     {
276     public:
277     OCTREE_BASE() {};
278     virtual ~OCTREE_BASE() {};
279     virtual int get_nb_cellule(void)=0;
280     virtual CELLULE_OCTREE_BASE* get_cellule(int num)=0;
281 francois 65 virtual int get_niveau_max(void)=0;
282 5 };
283    
284    
285     template <class A,class CONDITION>
286     class TPL_CELLULE_OCTREE:public CELLULE_OCTREE_BASE
287     {
288     public:
289 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)
290 5 {
291 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;
292     };
293 5 virtual ~TPL_CELLULE_OCTREE() {};
294     BOITE_3D get_boite(void) {return boite;};
295 francois 65 int get_niveau(void) {return niveau;};
296 5 BOITE_3D boite;
297     int feuille;
298     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
299     TPL_LISTE_ENTITE<A> lst_entite_A;
300     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_fils(int num) {return fils[num];};
301 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_pere(void) {return pere;};
302 5 virtual int get_feuille(void) {return feuille;};
303 francois 276
304     virtual void vide(void)
305     {
306     lst_entite_A.vide();
307     }
308    
309 francois 65 int get_sontype(void)
310     {
311     return sontype;
312     }
313 5 int get_nb_entite(void)
314     {
315     return lst_entite_A.get_nb();
316     };
317     A get_entite(int num)
318     {
319     return lst_entite_A.get(num);
320     };
321 francois 65 TPL_CELLULE_OCTREE< A ,CONDITION> *fils[8];
322     TPL_CELLULE_OCTREE< A ,CONDITION> *pere;
323 5
324 francois 65
325     int niveau;
326     int sontype;
327 5 };
328    
329     template <class A,class CONDITION,class B>
330     class TPL_CELLULE_INFO:public CELLULE_OCTREE_BASE
331     {
332     public:
333     TPL_CELLULE_INFO(double xmin,double ymin,double zmin,double xmax,double ymax,double zmax):CELLULE_OCTREE_BASE(),boite(xmin,ymin,zmin,xmax,ymax,zmax)
334     {
335     };
336     virtual ~TPL_CELLULE_INFO() {};
337     BOITE_3D get_boite(void) {return boite;};
338     BOITE_3D boite;
339     int feuille;
340     TPL_CELLULE_INFO< A ,CONDITION,B> *fils[8];
341     TPL_LISTE_ENTITE<CONDITION> lst_entite_CONDITION;
342     TPL_LISTE_ENTITE<A> lst_entite_A;
343     B tab[8];
344     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_fils(int num) {return fils[num];};
345     virtual int get_feuille(void) {return feuille;};
346     int get_nb_entite(void)
347     {
348     return lst_entite_A.get_nb();
349     };
350     A get_entite(int num)
351     {
352     return lst_entite_A.get(num);
353     };
354    
355     B get_info(int num) {return tab[num];};
356     void change_info(int num,B val) {tab[num]=val;};
357    
358     };
359    
360    
361    
362     template <class A,class CONDITION>
363     class TPL_OCTREE:public OCTREE_BASE
364     {
365     public:
366 francois 1019 TPL_OCTREE():niveaumax(0),niveaumaxlim(10000) {};
367 francois 1008 virtual ~TPL_OCTREE()
368 5 {
369     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
370     {
371     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(i1);
372     delete cellule;
373     }
374     };
375    
376     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
377 francois 65 virtual int get_nb_feuille(void) {return lst_entite_feuille.get_nb();};
378 5
379     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
380    
381     virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_cellule(int num) {return lst_entite_cellule.get(num); };
382 francois 65 virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_feuille(int num) {return lst_entite_feuille.get(num); };
383 5
384    
385     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
386     {
387 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
388 5 lst_entite_cellule.ajouter(root_cellule);
389     for (int i=0;i<lst_entite->get_nb();i++)
390     {
391     CONDITION cond=lst_entite->get(i);
392     BOITE_3D boite_cond=cond->get_boite_3D();
393     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
394     }
395     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
396     {
397     root_cellule->feuille=0;
398     double dx=xmax-xmin;
399     double dy=ymax-ymin;
400     double dz=zmax-zmin;
401 francois 65 root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
402     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
403     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
404     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,3);
405     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
406     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,5);
407     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,6);
408     root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,7);
409 5 }
410     else root_cellule->feuille=1;
411     for (int j=0;j<lst_entite_cellule.get_nb();j++)
412     {
413     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
414     cellule->lst_entite_CONDITION.vide();
415     }
416     }
417    
418     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
419     {
420 francois 65 TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
421 5 lst_entite_cellule.ajouter(root_cellule);
422 francois 276 typename TPL_MAP_ENTITE<CONDITION>::ITERATEUR it;
423     for (CONDITION cond=lst_entite->get_premier(it);cond!=NULL;cond=lst_entite->get_suivant(it))
424 5 {
425     BOITE_3D boite_cond=cond->get_boite_3D();
426     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
427     }
428     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
429     {
430     root_cellule->feuille=0;
431     double dx=xmax-xmin;
432     double dy=ymax-ymin;
433     double dz=zmax-zmin;
434 francois 65 root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,0);
435     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,1);
436     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,2);
437     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,3);
438     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,4);
439     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,5);
440     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,6);
441     root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre,1,7);
442 5 }
443     else root_cellule->feuille=1;
444     for (int j=0;j<lst_entite_cellule.get_nb();j++)
445     {
446     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
447     cellule->lst_entite_CONDITION.vide();
448     }
449     }
450    
451 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)
452     {
453     TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
454     lst_entite_cellule.ajouter(root_cellule);
455     for (int i=0;i<lst_entite->get_nb();i++)
456     {
457     CONDITION cond=lst_entite->get(i);
458     BOITE_3D boite_cond=cond->get_boite_3D();
459     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
460     }
461     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
462     {
463     root_cellule->feuille=0;
464     double dx=xmax-xmin;
465     double dy=ymax-ymin;
466     double dz=zmax-zmin;
467     if (dimanepasdecouper==3)
468     {
469     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);
470     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);
471     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);
472     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);
473     }
474     if (dimanepasdecouper==2)
475     {
476     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);
477     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);
478     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);
479     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);
480     }
481     if (dimanepasdecouper==1)
482     {
483     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);
484     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);
485     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);
486     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);
487     }
488     }
489     else root_cellule->feuille=1;
490     for (int j=0;j<lst_entite_cellule.get_nb();j++)
491     {
492     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
493     cellule->lst_entite_CONDITION.vide();
494     }
495     }
496    
497 5 virtual void initialiser(OCTREE_BASE* oc)
498     {
499     BOITE_3D boite=oc->get_cellule(0)->get_boite();
500     double xmin=boite.get_xmin();
501     double xmax=boite.get_xmax();
502     double ymin=boite.get_ymin();
503     double ymax=boite.get_ymax();
504     double zmin=boite.get_zmin();
505     double zmax=boite.get_zmax();
506 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());
507 5 lst_entite_cellule.ajouter(cellule);
508 francois 65 niveaumax=oc->get_niveau_max();
509     cellule->feuille=oc->get_cellule(0)->get_feuille();
510 5 if (oc->get_cellule(0)->get_feuille()==0)
511     {
512 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);
513     if (oc->get_cellule(0)->get_fils(1)!=NULL) cellule->fils[1]=cree_fils(cellule,oc->get_cellule(0)->get_fils(1),1);
514     if (oc->get_cellule(0)->get_fils(2)!=NULL) cellule->fils[2]=cree_fils(cellule,oc->get_cellule(0)->get_fils(2),2);
515     if (oc->get_cellule(0)->get_fils(3)!=NULL) cellule->fils[3]=cree_fils(cellule,oc->get_cellule(0)->get_fils(3),3);
516     if (oc->get_cellule(0)->get_fils(4)!=NULL) cellule->fils[4]=cree_fils(cellule,oc->get_cellule(0)->get_fils(4),4);
517     if (oc->get_cellule(0)->get_fils(5)!=NULL) cellule->fils[5]=cree_fils(cellule,oc->get_cellule(0)->get_fils(5),5);
518     if (oc->get_cellule(0)->get_fils(6)!=NULL) cellule->fils[6]=cree_fils(cellule,oc->get_cellule(0)->get_fils(6),6);
519     if (oc->get_cellule(0)->get_fils(7)!=NULL) cellule->fils[7]=cree_fils(cellule,oc->get_cellule(0)->get_fils(7),7);
520 5 }
521 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
522 5 };
523    
524    
525 francois 65 TPL_CELLULE_OCTREE<A,CONDITION>* cree_fils( TPL_CELLULE_OCTREE<A ,CONDITION>* cell,CELLULE_OCTREE_BASE *cellule_base,int st)
526 5 {
527     BOITE_3D boite=cellule_base->get_boite();
528     double xmin=boite.get_xmin();
529     double xmax=boite.get_xmax();
530     double ymin=boite.get_ymin();
531     double ymax=boite.get_ymax();
532     double zmin=boite.get_zmin();
533     double zmax=boite.get_zmax();
534 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);
535 5 lst_entite_cellule.ajouter(cellule);
536 francois 65 if (niveaumax<cellule_base->get_niveau()) niveaumax=cellule_base->get_niveau();
537 5 if (cellule_base->get_feuille()==1)
538     {
539 francois 65 {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
540 5 }
541     else
542     {
543 francois 632 if (cellule_base->get_fils(0)!=NULL) cellule->fils[0]=cree_fils(cellule,cellule_base->get_fils(0),0);
544     if (cellule_base->get_fils(1)!=NULL) cellule->fils[1]=cree_fils(cellule,cellule_base->get_fils(1),1);
545     if (cellule_base->get_fils(2)!=NULL) cellule->fils[2]=cree_fils(cellule,cellule_base->get_fils(2),2);
546     if (cellule_base->get_fils(3)!=NULL) cellule->fils[3]=cree_fils(cellule,cellule_base->get_fils(3),3);
547     if (cellule_base->get_fils(4)!=NULL) cellule->fils[4]=cree_fils(cellule,cellule_base->get_fils(4),4);
548     if (cellule_base->get_fils(5)!=NULL) cellule->fils[5]=cree_fils(cellule,cellule_base->get_fils(5),5);
549     if (cellule_base->get_fils(6)!=NULL) cellule->fils[6]=cree_fils(cellule,cellule_base->get_fils(6),6);
550     if (cellule_base->get_fils(7)!=NULL) cellule->fils[7]=cree_fils(cellule,cellule_base->get_fils(7),7);
551     cellule->feuille=cellule_base->get_feuille();
552 5 }
553     return cellule;
554     };
555    
556 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)
557 5 {
558 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);
559 5 lst_entite_cellule.ajouter(cellule);
560 francois 65 if (niveaumax<niv) niveaumax=niv;
561     for (int i=0;i<lst_entite->get_nb();i++)
562 5 {
563     CONDITION cond=lst_entite->get(i);
564     BOITE_3D boite_cond=cond->get_boite_3D();
565     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
566     }
567 francois 1019 if ((cellule->lst_entite_CONDITION.get_nb()>nombre) && (niveaumax<niveaumaxlim))
568 5 {
569     cellule->feuille=0;
570 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);
571     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);
572     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);
573     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);
574     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);
575     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);
576     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);
577     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);
578 5 }
579 francois 65 else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
580 5 return cellule;
581     }
582    
583 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)
584     {
585     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
586     lst_entite_cellule.ajouter(cellule);
587     if (niveaumax<niv) niveaumax=niv;
588     dz=dz*2;
589     for (int i=0;i<lst_entite->get_nb();i++)
590     {
591     CONDITION cond=lst_entite->get(i);
592     BOITE_3D boite_cond=cond->get_boite_3D();
593     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
594     }
595     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
596     {
597     cellule->feuille=0;
598     if (dimanepasdecouper==3)
599     {
600     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
601     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);
602     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);
603     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);
604     }
605     if (dimanepasdecouper==2)
606     {
607     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx/2.,dy,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
608     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);
609     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);
610     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);
611     }
612     if (dimanepasdecouper==1)
613     {
614     cellule->fils[0]=cree_fils2D(dimanepasdecouper,cellule,xmin,ymin,zmin,dx,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre,niv+1,0);
615     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);
616     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);
617     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);
618     }
619     }
620     else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
621     return cellule;
622     }
623 5
624 francois 633
625 5 virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
626     {
627 francois 632 if (cellule==NULL) return;
628 5 if (boite*cellule->boite)
629     if (cellule->feuille==1)
630     {
631     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
632 francois 945 if (boite*cellule->lst_entite_A.get(i)->get_boite_3D())
633 5 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 couturad 951 virtual void get_feuille_voisins(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction,std::vector<TPL_CELLULE_OCTREE<A,CONDITION> *> *lst)
701 francois 65 {
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 couturad 951 typename std::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 couturad 951 std::vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstraf;
835 francois 65 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 couturad 951 std::vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstvoi;
842 francois 65 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 1019 virtual int get_niveau_max_lim(void)
978     {
979     return niveaumaxlim;
980     }
981 francois 65
982    
983 francois 1019 void change_niveau_max_lim(int num)
984     {
985     niveaumaxlim=num;
986     }
987    
988 francois 276 virtual void vide(void)
989     {
990     for (int i=0;i<lst_entite_feuille.get_nb();i++)
991     {
992     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(i);
993     cellule->vide();
994     }
995     }
996 francois 65
997 francois 507
998     virtual double get_dimension_caracteristique()
999     {
1000     TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
1001     double x=cellule->boite.get_xmin();
1002     double y=cellule->boite.get_ymin();
1003     double z=cellule->boite.get_zmin();
1004     double xx=cellule->boite.get_xmax();
1005     double yy=cellule->boite.get_ymax();
1006     double zz=cellule->boite.get_zmax();
1007     return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y)+(zz-z)*(zz-z)) ;
1008     }
1009    
1010    
1011    
1012 francois 65 protected:
1013 5 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_cellule;
1014 francois 65 TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_feuille;
1015     int niveaumax;
1016 francois 1019 int niveaumaxlim;
1017 5
1018     };
1019    
1020 francois 65 template <class A,class B>
1021     class TPL_OCTREE_FCT:public TPL_OCTREE<A,A>
1022     {
1023     private:
1024     double coef;
1025 5
1026 francois 65 public:
1027     TPL_OCTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1028 francois 1008 virtual ~TPL_OCTREE_FCT() {}
1029 5
1030 francois 65
1031 francois 102 virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1032 francois 65
1033     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1034     {
1035     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1036 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1037 francois 65 double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1038     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1039     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1040     double d=dx;
1041 francois 584 if (dy>d) d=dy;
1042     if (dz>d) d=dz;
1043 francois 65 double xyz[3];
1044     root_cellule->boite.get_centre(xyz);
1045     double ecart[9];
1046     fonction.evaluer(xyz,ecart);
1047     double dcible=coef/sqrt(ecart[0]);
1048     if (dcible<d)
1049     {
1050     root_cellule->feuille=0;
1051     root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,0);
1052     root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,1);
1053     root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,2);
1054     root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,3);
1055     root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,4);
1056     root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,5);
1057     root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,6);
1058     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);
1059     }
1060 francois 102 else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1061 francois 65 }
1062    
1063     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)
1064     {
1065     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1066 francois 102 TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1067     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1068 francois 65 double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1069     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1070     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1071     double d=dx;
1072 francois 584 if (ddy>d) d=ddy;
1073     if (ddz>d) d=ddz;
1074 francois 65 double xyz[3];
1075     cellule->boite.get_centre(xyz);
1076     double ecart[9];
1077     fonction.evaluer(xyz,ecart);
1078     double dcible=coef/sqrt(ecart[0]);
1079     if (dcible<d)
1080     {
1081     cellule->feuille=0;
1082     cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,0);
1083     cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,1);
1084     cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,2);
1085     cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,3);
1086     cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,4);
1087     cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,5);
1088     cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,6);
1089     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);
1090     }
1091 francois 102 else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1092 francois 65 return cellule;
1093     }
1094     };
1095    
1096    
1097 francois 632 template <class A,class B>
1098     class TPL_NTREE_FCT:public TPL_OCTREE<A,A>
1099     {
1100     private:
1101     double coef;
1102 francois 65
1103 francois 632 public:
1104     TPL_NTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
1105 francois 1008 virtual ~TPL_NTREE_FCT() {}
1106 francois 632
1107    
1108     virtual void change_coefficent_multiplicateur(double val) {coef=val;};
1109    
1110     virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1111     {
1112     TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
1113     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
1114     double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
1115     double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
1116     double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
1117     double xyz[3];
1118     root_cellule->boite.get_centre(xyz);
1119     double ecart[9];
1120     fonction.evaluer(xyz,ecart);
1121     double dcible=coef/sqrt(ecart[0]);
1122     int ndivx=2,ndivy=2,ndivz=2;
1123     if (dcible>dx) ndivx=1;
1124     if (dcible>dy) ndivy=1;
1125     if (dcible>dz) ndivz=1;
1126     if (ndivx*ndivy*ndivz!=1)
1127     {
1128     root_cellule->feuille=0;
1129     for (int i=0;i<ndivx;i++)
1130     for (int j=0;j<ndivy;j++)
1131     for (int k=0;k<ndivz;k++)
1132     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);
1133     }
1134     else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
1135     }
1136    
1137     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)
1138     {
1139     TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
1140     TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
1141     if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
1142     double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
1143     double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
1144     double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
1145     double xyz[3];
1146     cellule->boite.get_centre(xyz);
1147     double ecart[9];
1148     fonction.evaluer(xyz,ecart);
1149     double dcible=coef/sqrt(ecart[0]);
1150     int ndivx=2,ndivy=2,ndivz=2;
1151     if (dcible>dx) ndivx=1;
1152     if (dcible>dy) ndivy=1;
1153     if (dcible>dz) ndivz=1;
1154     if (ndivx*ndivy*ndivz!=1)
1155     {
1156     cellule->feuille=0;
1157     for (int i=0;i<ndivx;i++)
1158     for (int j=0;j<ndivy;j++)
1159     for (int k=0;k<ndivz;k++)
1160     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);
1161     }
1162     else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
1163     return cellule;
1164     }
1165     };
1166    
1167    
1168    
1169    
1170    
1171    
1172    
1173    
1174    
1175 5 template <class A,class CONDITION,class B>
1176     class TPL_OCTREE_INFO:public OCTREE_BASE
1177     {
1178     public:
1179     TPL_OCTREE_INFO() {};
1180 francois 1008 virtual ~TPL_OCTREE_INFO()
1181 5 {
1182     for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
1183     {
1184     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(i1);
1185     delete cellule;
1186     }
1187     };
1188    
1189     virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
1190    
1191     virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
1192    
1193     virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
1194    
1195    
1196     virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1197     {
1198     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1199     lst_entite_cellule.ajouter(root_cellule);
1200     for (int i=0;i<lst_entite->get_nb();i++)
1201     {
1202     CONDITION cond=lst_entite->get(i);
1203     BOITE_3D boite_cond=cond->get_boite_3D();
1204     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1205     }
1206     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1207     {
1208     root_cellule->feuille=0;
1209     double dx=xmax-xmin;
1210     double dy=ymax-ymin;
1211     double dz=zmax-zmin;
1212     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1213     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1214     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1215     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);
1216     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1217     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);
1218     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);
1219     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);
1220     }
1221     else root_cellule->feuille=1;
1222     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1223     {
1224     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1225     cellule->lst_entite_CONDITION.vide();
1226     }
1227     }
1228    
1229     virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
1230     {
1231     TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1232     lst_entite_cellule.ajouter(root_cellule);
1233     for (int i=0;i<lst_entite->get_nb();i++)
1234     {
1235     CONDITION cond=lst_entite->get(i);
1236     BOITE_3D boite_cond=cond->get_boite_3D();
1237     if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
1238     }
1239     if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
1240     {
1241     root_cellule->feuille=0;
1242     double dx=xmax-xmin;
1243     double dy=ymax-ymin;
1244     double dz=zmax-zmin;
1245     root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1246     root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1247     root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1248     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);
1249     root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
1250     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);
1251     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);
1252     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);
1253     }
1254     else root_cellule->feuille=1;
1255     for (int j=0;j<lst_entite_cellule.get_nb();j++)
1256     {
1257     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
1258     cellule->lst_entite_CONDITION.vide();
1259     }
1260     }
1261    
1262     virtual void initialiser(OCTREE_BASE* oc)
1263     {
1264     BOITE_3D boite=oc->get_cellule(0)->get_boite();
1265     double xmin=boite.get_xmin();
1266     double xmax=boite.get_xmax();
1267     double ymin=boite.get_ymin();
1268     double ymax=boite.get_ymax();
1269     double zmin=boite.get_zmin();
1270     double zmax=boite.get_zmax();
1271     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1272     lst_entite_cellule.ajouter(cellule);
1273     if (oc->get_cellule(0)->get_feuille()==0)
1274     {
1275     cellule->fils[0]=cree_fils(oc->get_cellule(0)->get_fils(0));
1276     cellule->fils[1]=cree_fils(oc->get_cellule(0)->get_fils(1));
1277     cellule->fils[2]=cree_fils(oc->get_cellule(0)->get_fils(2));
1278     cellule->fils[3]=cree_fils(oc->get_cellule(0)->get_fils(3));
1279     cellule->fils[4]=cree_fils(oc->get_cellule(0)->get_fils(4));
1280     cellule->fils[5]=cree_fils(oc->get_cellule(0)->get_fils(5));
1281     cellule->fils[6]=cree_fils(oc->get_cellule(0)->get_fils(6));
1282     cellule->fils[7]=cree_fils(oc->get_cellule(0)->get_fils(7));
1283     }
1284     cellule->feuille=oc->get_cellule(0)->get_feuille();
1285     };
1286    
1287    
1288     TPL_CELLULE_INFO<A,CONDITION,B>* cree_fils(CELLULE_OCTREE_BASE *cellule_base)
1289     {
1290     BOITE_3D boite=cellule_base->get_boite();
1291     double xmin=boite.get_xmin();
1292     double xmax=boite.get_xmax();
1293     double ymin=boite.get_ymin();
1294     double ymax=boite.get_ymax();
1295     double zmin=boite.get_zmin();
1296     double zmax=boite.get_zmax();
1297     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
1298     lst_entite_cellule.ajouter(cellule);
1299     if (cellule_base->get_feuille()==1)
1300     {
1301     cellule->feuille=1;
1302     }
1303     else
1304     {
1305     cellule->fils[0]=cree_fils(cellule_base->get_fils(0));
1306     cellule->fils[1]=cree_fils(cellule_base->get_fils(1));
1307     cellule->fils[2]=cree_fils(cellule_base->get_fils(2));
1308     cellule->fils[3]=cree_fils(cellule_base->get_fils(3));
1309     cellule->fils[4]=cree_fils(cellule_base->get_fils(4));
1310     cellule->fils[5]=cree_fils(cellule_base->get_fils(5));
1311     cellule->fils[6]=cree_fils(cellule_base->get_fils(6));
1312     cellule->fils[7]=cree_fils(cellule_base->get_fils(7));
1313     cellule->feuille=0;
1314     }
1315     return cellule;
1316     };
1317    
1318     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)
1319     {
1320     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz);
1321     lst_entite_cellule.ajouter(cellule);
1322     for (int i=0;i<lst_entite->get_nb();i++)
1323     {
1324     CONDITION cond=lst_entite->get(i);
1325     BOITE_3D boite_cond=cond->get_boite_3D();
1326     if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
1327     }
1328     if (cellule->lst_entite_CONDITION.get_nb()>nombre)
1329     {
1330     cellule->feuille=0;
1331     cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1332     cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1333     cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1334     cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1335     cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1336     cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1337     cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
1338     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);
1339     }
1340     else cellule->feuille=1;
1341     return cellule;
1342     }
1343    
1344    
1345     virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1346     {
1347     if (boite*cellule->boite)
1348     if (cellule->feuille==1)
1349     {
1350     for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
1351 francois 945 if (boite*cellule->lst_entite_A.get(i)->get_boite_3D())
1352     liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
1353 5 }
1354     else
1355     {
1356     rechercher(boite,liste_entite_trouve,cellule->fils[0]);
1357     rechercher(boite,liste_entite_trouve,cellule->fils[1]);
1358     rechercher(boite,liste_entite_trouve,cellule->fils[2]);
1359     rechercher(boite,liste_entite_trouve,cellule->fils[3]);
1360     rechercher(boite,liste_entite_trouve,cellule->fils[4]);
1361     rechercher(boite,liste_entite_trouve,cellule->fils[5]);
1362     rechercher(boite,liste_entite_trouve,cellule->fils[6]);
1363     rechercher(boite,liste_entite_trouve,cellule->fils[7]);
1364     }
1365     };
1366    
1367    
1368     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)
1369     {
1370     if (boite*cellule->boite)
1371     if (cellule->feuille==1)
1372     {
1373     liste_entite.ajouter(cellule);
1374     }
1375     else
1376     {
1377     get_cellule(boite,cellule->fils[0],liste_entite);
1378     get_cellule(boite,cellule->fils[1],liste_entite);
1379     get_cellule(boite,cellule->fils[2],liste_entite);
1380     get_cellule(boite,cellule->fils[3],liste_entite);
1381     get_cellule(boite,cellule->fils[4],liste_entite);
1382     get_cellule(boite,cellule->fils[5],liste_entite);
1383     get_cellule(boite,cellule->fils[6],liste_entite);
1384     get_cellule(boite,cellule->fils[7],liste_entite);
1385     }
1386     };
1387    
1388     virtual TPL_CELLULE_INFO<A,CONDITION,B> *get_cellule(double x,double y, double z)
1389     {
1390     BOITE_3D boite(x,y,z,x,y,z);
1391     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1392     TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > liste_cellule;
1393     get_cellule(boite,cellule,liste_cellule);
1394     if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
1395     return NULL;
1396     };
1397    
1398    
1399     virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
1400     {
1401     BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
1402     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1403     rechercher(boite,liste_entite_trouve,cellule);
1404     };
1405    
1406    
1407    
1408     virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1409     {
1410     if (boite*cellule->boite)
1411     if (cellule->feuille==1)
1412     {
1413     cellule->lst_entite_A.ajouter(a);
1414     }
1415     else
1416     {
1417     inserer(boite,a,cellule->fils[0]);
1418     inserer(boite,a,cellule->fils[1]);
1419     inserer(boite,a,cellule->fils[2]);
1420     inserer(boite,a,cellule->fils[3]);
1421     inserer(boite,a,cellule->fils[4]);
1422     inserer(boite,a,cellule->fils[5]);
1423     inserer(boite,a,cellule->fils[6]);
1424     inserer(boite,a,cellule->fils[7]);
1425     }
1426     };
1427    
1428     virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
1429     {
1430     if (boite*cellule->boite)
1431     if (cellule->feuille==1)
1432     {
1433     cellule->lst_entite_A.supprimer(a);
1434     }
1435     else
1436     {
1437     supprimer(boite,a,cellule->fils[0]);
1438     supprimer(boite,a,cellule->fils[1]);
1439     supprimer(boite,a,cellule->fils[2]);
1440     supprimer(boite,a,cellule->fils[3]);
1441     supprimer(boite,a,cellule->fils[4]);
1442     supprimer(boite,a,cellule->fils[5]);
1443     supprimer(boite,a,cellule->fils[6]);
1444     supprimer(boite,a,cellule->fils[7]);
1445     }
1446     };
1447    
1448     virtual void inserer(A a)
1449     {
1450     BOITE_3D boite=a->get_boite_3D();
1451     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1452     inserer(boite,a,cellule);
1453     }
1454    
1455     virtual void supprimer(A a)
1456     {
1457     BOITE_3D boite=a->get_boite_3D();
1458     TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
1459     supprimer(boite,a,cellule);
1460     }
1461    
1462    
1463     private:
1464     TPL_LISTE_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B>* > lst_entite_cellule;
1465    
1466     };
1467    
1468    
1469    
1470    
1471     #endif