ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/template/src/tpl_octree.h
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
Content type: text/plain
File size: 47434 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

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