1 |
francois |
1009 |
//------------------------------------------------------------
|
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 |
|
|
#include <math.h>
|
31 |
|
|
/*
|
32 |
|
|
// #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 |
|
|
|
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 |
|
|
std::vector<int> bits;
|
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 |
|
|
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 |
|
|
virtual int get_niveau(void)=0;
|
268 |
|
|
virtual int get_sontype(void)=0;
|
269 |
|
|
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 |
|
|
virtual int get_niveau_max(void)=0;
|
282 |
|
|
};
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
template <class A,class CONDITION>
|
286 |
|
|
class TPL_CELLULE_OCTREE:public CELLULE_OCTREE_BASE
|
287 |
|
|
{
|
288 |
|
|
public:
|
289 |
|
|
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 |
|
|
{
|
291 |
|
|
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 |
|
|
virtual ~TPL_CELLULE_OCTREE() {};
|
294 |
|
|
BOITE_3D get_boite(void) {return boite;};
|
295 |
|
|
int get_niveau(void) {return niveau;};
|
296 |
|
|
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 |
|
|
virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_pere(void) {return pere;};
|
302 |
|
|
virtual int get_feuille(void) {return feuille;};
|
303 |
|
|
|
304 |
|
|
virtual void vide(void)
|
305 |
|
|
{
|
306 |
|
|
lst_entite_A.vide();
|
307 |
|
|
}
|
308 |
|
|
|
309 |
|
|
int get_sontype(void)
|
310 |
|
|
{
|
311 |
|
|
return sontype;
|
312 |
|
|
}
|
313 |
|
|
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 |
|
|
TPL_CELLULE_OCTREE< A ,CONDITION> *fils[8];
|
322 |
|
|
TPL_CELLULE_OCTREE< A ,CONDITION> *pere;
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
int niveau;
|
326 |
|
|
int sontype;
|
327 |
|
|
};
|
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 |
|
|
TPL_OCTREE():niveaumax(0) {};
|
367 |
|
|
~TPL_OCTREE()
|
368 |
|
|
{
|
369 |
|
|
for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
|
370 |
|
|
{
|
371 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(i1);
|
372 |
|
|
delete cellule;
|
373 |
|
|
}
|
374 |
|
|
};
|
375 |
|
|
|
376 |
|
|
virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
|
377 |
|
|
virtual int get_nb_feuille(void) {return lst_entite_feuille.get_nb();};
|
378 |
|
|
|
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 |
|
|
virtual TPL_CELLULE_OCTREE<A,CONDITION>* get_feuille(int num) {return lst_entite_feuille.get(num); };
|
383 |
|
|
|
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 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
|
388 |
|
|
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 |
|
|
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 |
|
|
}
|
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 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* root_cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
|
421 |
|
|
lst_entite_cellule.ajouter(root_cellule);
|
422 |
|
|
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 |
|
|
{
|
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 |
|
|
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 |
|
|
}
|
443 |
|
|
else root_cellule->feuille=1;
|
444 |
|
|
for (int j=0;j<lst_entite_cellule.get_nb();j++)
|
445 |
|
|
{
|
446 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(j);
|
447 |
|
|
cellule->lst_entite_CONDITION.vide();
|
448 |
|
|
}
|
449 |
|
|
}
|
450 |
|
|
|
451 |
|
|
virtual void 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 |
|
|
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 |
|
|
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 |
|
|
lst_entite_cellule.ajouter(cellule);
|
508 |
|
|
niveaumax=oc->get_niveau_max();
|
509 |
|
|
cellule->feuille=oc->get_cellule(0)->get_feuille();
|
510 |
|
|
if (oc->get_cellule(0)->get_feuille()==0)
|
511 |
|
|
{
|
512 |
|
|
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 |
|
|
}
|
521 |
|
|
else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
|
522 |
|
|
};
|
523 |
|
|
|
524 |
|
|
|
525 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION>* cree_fils( TPL_CELLULE_OCTREE<A ,CONDITION>* cell,CELLULE_OCTREE_BASE *cellule_base,int st)
|
526 |
|
|
{
|
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 |
|
|
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 |
|
|
lst_entite_cellule.ajouter(cellule);
|
536 |
|
|
if (niveaumax<cellule_base->get_niveau()) niveaumax=cellule_base->get_niveau();
|
537 |
|
|
if (cellule_base->get_feuille()==1)
|
538 |
|
|
{
|
539 |
|
|
{cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
|
540 |
|
|
}
|
541 |
|
|
else
|
542 |
|
|
{
|
543 |
|
|
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 |
|
|
}
|
553 |
|
|
return cellule;
|
554 |
|
|
};
|
555 |
|
|
|
556 |
|
|
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 |
|
|
{
|
558 |
|
|
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 |
|
|
lst_entite_cellule.ajouter(cellule);
|
560 |
|
|
if (niveaumax<niv) niveaumax=niv;
|
561 |
|
|
for (int i=0;i<lst_entite->get_nb();i++)
|
562 |
|
|
{
|
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 |
|
|
if (cellule->lst_entite_CONDITION.get_nb()>nombre)
|
568 |
|
|
{
|
569 |
|
|
cellule->feuille=0;
|
570 |
|
|
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 |
|
|
}
|
579 |
|
|
else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
|
580 |
|
|
return cellule;
|
581 |
|
|
}
|
582 |
|
|
|
583 |
|
|
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 |
|
|
|
624 |
|
|
|
625 |
|
|
virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule)
|
626 |
|
|
{
|
627 |
|
|
if (cellule==NULL) return;
|
628 |
|
|
if (boite*cellule->boite)
|
629 |
|
|
if (cellule->feuille==1)
|
630 |
|
|
{
|
631 |
|
|
for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
|
632 |
|
|
if (boite*cellule->lst_entite_A.get(i)->get_boite_3D())
|
633 |
|
|
liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
|
634 |
|
|
}
|
635 |
|
|
else
|
636 |
|
|
{
|
637 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[0]);
|
638 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[1]);
|
639 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[2]);
|
640 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[3]);
|
641 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[4]);
|
642 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[5]);
|
643 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[6]);
|
644 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[7]);
|
645 |
|
|
}
|
646 |
|
|
};
|
647 |
|
|
|
648 |
|
|
|
649 |
|
|
virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_OCTREE<A ,CONDITION>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION> * > &liste_entite)
|
650 |
|
|
{
|
651 |
|
|
if (boite*cellule->boite)
|
652 |
|
|
if (cellule->feuille==1)
|
653 |
|
|
{
|
654 |
|
|
liste_entite.ajouter(cellule);
|
655 |
|
|
}
|
656 |
|
|
else
|
657 |
|
|
{
|
658 |
|
|
get_cellule(boite,cellule->fils[0],liste_entite);
|
659 |
|
|
get_cellule(boite,cellule->fils[1],liste_entite);
|
660 |
|
|
get_cellule(boite,cellule->fils[2],liste_entite);
|
661 |
|
|
get_cellule(boite,cellule->fils[3],liste_entite);
|
662 |
|
|
get_cellule(boite,cellule->fils[4],liste_entite);
|
663 |
|
|
get_cellule(boite,cellule->fils[5],liste_entite);
|
664 |
|
|
get_cellule(boite,cellule->fils[6],liste_entite);
|
665 |
|
|
get_cellule(boite,cellule->fils[7],liste_entite);
|
666 |
|
|
}
|
667 |
|
|
};
|
668 |
|
|
|
669 |
|
|
virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_adjacent(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
|
670 |
|
|
{
|
671 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
|
672 |
|
|
OUTIL_OCTREE outil;
|
673 |
|
|
if (cellule->pere==NULL) cellule2=NULL;
|
674 |
|
|
else if (outil.adjacent(direction,cellule->get_sontype())) cellule2=get_cellule_adjacent(cellule->pere,direction);
|
675 |
|
|
else if (outil.commonface(direction,cellule->get_sontype())!=-1) cellule2=get_cellule_voisin(cellule->pere,outil.commonface(direction,cellule->get_sontype()));
|
676 |
|
|
else cellule2=cellule->pere;
|
677 |
|
|
if (cellule2!=NULL)
|
678 |
|
|
if (cellule2->get_feuille()==0)
|
679 |
|
|
return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
|
680 |
|
|
return cellule2;
|
681 |
|
|
}
|
682 |
|
|
|
683 |
|
|
virtual TPL_CELLULE_OCTREE<A,CONDITION> *get_cellule_voisin(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction)
|
684 |
|
|
{
|
685 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *cellule2;
|
686 |
|
|
OUTIL_OCTREE outil;
|
687 |
|
|
if ((!(cellule->pere==NULL)) && (outil.adjacent(direction,cellule->get_sontype())))
|
688 |
|
|
cellule2=get_cellule_voisin(cellule->pere,direction);
|
689 |
|
|
else
|
690 |
|
|
cellule2=cellule->pere;
|
691 |
|
|
if (cellule2!=NULL)
|
692 |
|
|
if (cellule2->feuille==0)
|
693 |
|
|
return cellule2->get_fils(outil.reflect(direction,cellule->get_sontype()));
|
694 |
|
|
return cellule2;
|
695 |
|
|
}
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
|
699 |
|
|
|
700 |
|
|
virtual void get_feuille_voisins(TPL_CELLULE_OCTREE<A,CONDITION> * cellule,int direction,std::vector<TPL_CELLULE_OCTREE<A,CONDITION> *> *lst)
|
701 |
|
|
{
|
702 |
|
|
OUTIL_OCTREE outil;
|
703 |
|
|
lst->clear();
|
704 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *cellule2=get_cellule_voisin(cellule,direction);
|
705 |
|
|
if (cellule2!=NULL) lst->insert(lst->end(),cellule2);
|
706 |
|
|
int i=0;
|
707 |
|
|
while (i<lst->size())
|
708 |
|
|
{
|
709 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *cell=(*lst)[i];
|
710 |
|
|
if (cell->feuille==0)
|
711 |
|
|
{
|
712 |
|
|
lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,0)));
|
713 |
|
|
lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,1)));
|
714 |
|
|
lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,2)));
|
715 |
|
|
lst->insert(lst->end(),cell->get_fils(outil.filsvoisin(direction,3)));
|
716 |
|
|
}
|
717 |
|
|
i++;
|
718 |
|
|
}
|
719 |
|
|
typename std::vector<TPL_CELLULE_OCTREE<A,CONDITION> * >::iterator j=lst->end();
|
720 |
|
|
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 |
|
|
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 |
|
|
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 |
|
|
std::vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstraf;
|
835 |
|
|
for (int i=0;i<lst_entite_feuille.get_nb();i++)
|
836 |
|
|
{
|
837 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *feuille=lst_entite_feuille.get(i);
|
838 |
|
|
int niveaumaxvoisin=0;
|
839 |
|
|
for (int j=0;j<6;j++)
|
840 |
|
|
{
|
841 |
|
|
std::vector< TPL_CELLULE_OCTREE<A,CONDITION> *> lstvoi;
|
842 |
|
|
get_feuille_voisins(feuille,j,&lstvoi);
|
843 |
|
|
int nb_feuille=lstvoi.size();
|
844 |
|
|
for (int k=0;k<nb_feuille;k++)
|
845 |
|
|
{
|
846 |
|
|
int niveau=lstvoi[k]->get_niveau();
|
847 |
|
|
if (niveau>niveaumaxvoisin) niveaumaxvoisin=niveau;
|
848 |
|
|
}
|
849 |
|
|
|
850 |
|
|
}
|
851 |
|
|
if (niveaumaxvoisin-feuille->get_niveau()>niveauequilibre) {lstraf.insert(lstraf.end(),feuille);feuille->feuille=niveaumaxvoisin-niveauequilibre;}
|
852 |
|
|
}
|
853 |
|
|
int nbcelluleraffiner=lstraf.size();
|
854 |
|
|
for (int i=0;i<nbcelluleraffiner;i++)
|
855 |
|
|
{
|
856 |
|
|
TPL_CELLULE_OCTREE<A,CONDITION> *cell=lstraf[i];
|
857 |
|
|
lst_entite_feuille.supprimer(cell);
|
858 |
|
|
int niveauatteindre=cell->feuille;
|
859 |
|
|
int niveau=cell->niveau;
|
860 |
|
|
cell->feuille=0;
|
861 |
|
|
double xmin=cell->boite.get_xmin();
|
862 |
|
|
double ymin=cell->boite.get_ymin();
|
863 |
|
|
double zmin=cell->boite.get_zmin();
|
864 |
|
|
double dx=cell->boite.get_xmax()-cell->boite.get_xmin();
|
865 |
|
|
double dy=cell->boite.get_ymax()-cell->boite.get_ymin();
|
866 |
|
|
double dz=cell->boite.get_zmax()-cell->boite.get_zmin();
|
867 |
|
|
|
868 |
|
|
cell->fils[0]=cree_fils(cell,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,0);
|
869 |
|
|
cell->fils[1]=cree_fils(cell,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,1);
|
870 |
|
|
cell->fils[2]=cree_fils(cell,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,2);
|
871 |
|
|
cell->fils[3]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,3);
|
872 |
|
|
cell->fils[4]=cree_fils(cell,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,4);
|
873 |
|
|
cell->fils[5]=cree_fils(cell,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,5);
|
874 |
|
|
cell->fils[6]=cree_fils(cell,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,6);
|
875 |
|
|
cell->fils[7]=cree_fils(cell,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niveau+1,niveauatteindre,7);
|
876 |
|
|
}
|
877 |
|
|
int nbfeuilleapres=get_nb_feuille();
|
878 |
|
|
if (nbfeuilleapres==nbfeuilleavant) ok=1;
|
879 |
|
|
}
|
880 |
|
|
while (ok==0);
|
881 |
|
|
|
882 |
|
|
|
883 |
|
|
}
|
884 |
|
|
|
885 |
|
|
virtual TPL_CELLULE_OCTREE<A ,CONDITION>* cree_fils(TPL_CELLULE_OCTREE<A ,CONDITION>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,int niv,int niveauatteindre,int st)
|
886 |
|
|
{
|
887 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=new TPL_CELLULE_OCTREE<A ,CONDITION>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
|
888 |
|
|
lst_entite_cellule.ajouter(cellule);
|
889 |
|
|
if (niveaumax<niv) niveaumax=niv;
|
890 |
|
|
if (cellule->get_niveau()!=niveauatteindre)
|
891 |
|
|
{
|
892 |
|
|
cellule->feuille=0;
|
893 |
|
|
cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,0);
|
894 |
|
|
cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,1);
|
895 |
|
|
cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,2);
|
896 |
|
|
cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,3);
|
897 |
|
|
cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,4);
|
898 |
|
|
cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,5);
|
899 |
|
|
cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,6);
|
900 |
|
|
cellule->fils[7]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,niv+1,niveauatteindre,7);
|
901 |
|
|
}
|
902 |
|
|
else {cellule->feuille=1;lst_entite_feuille.ajouter(cellule);}
|
903 |
|
|
return cellule;
|
904 |
|
|
}
|
905 |
|
|
|
906 |
|
|
|
907 |
|
|
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 |
|
|
if (cellule==NULL) return;
|
919 |
|
|
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 |
|
|
if (cellule==NULL) return;
|
940 |
|
|
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 |
|
|
virtual int get_niveau_max(void)
|
973 |
|
|
{
|
974 |
|
|
return niveaumax;
|
975 |
|
|
}
|
976 |
|
|
|
977 |
|
|
|
978 |
|
|
|
979 |
|
|
virtual void vide(void)
|
980 |
|
|
{
|
981 |
|
|
for (int i=0;i<lst_entite_feuille.get_nb();i++)
|
982 |
|
|
{
|
983 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_feuille.get(i);
|
984 |
|
|
cellule->vide();
|
985 |
|
|
}
|
986 |
|
|
}
|
987 |
|
|
|
988 |
|
|
|
989 |
|
|
virtual double get_dimension_caracteristique()
|
990 |
|
|
{
|
991 |
|
|
TPL_CELLULE_OCTREE<A ,CONDITION>* cellule=lst_entite_cellule.get(0);
|
992 |
|
|
double x=cellule->boite.get_xmin();
|
993 |
|
|
double y=cellule->boite.get_ymin();
|
994 |
|
|
double z=cellule->boite.get_zmin();
|
995 |
|
|
double xx=cellule->boite.get_xmax();
|
996 |
|
|
double yy=cellule->boite.get_ymax();
|
997 |
|
|
double zz=cellule->boite.get_zmax();
|
998 |
|
|
return sqrt((xx-x)*(xx-x)+(yy-y)*(yy-y)+(zz-z)*(zz-z)) ;
|
999 |
|
|
}
|
1000 |
|
|
|
1001 |
|
|
|
1002 |
|
|
|
1003 |
|
|
protected:
|
1004 |
|
|
TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_cellule;
|
1005 |
|
|
TPL_LISTE_ENTITE<TPL_CELLULE_OCTREE<A ,CONDITION>* > lst_entite_feuille;
|
1006 |
|
|
int niveaumax;
|
1007 |
|
|
|
1008 |
|
|
};
|
1009 |
|
|
|
1010 |
|
|
template <class A,class B>
|
1011 |
|
|
class TPL_OCTREE_FCT:public TPL_OCTREE<A,A>
|
1012 |
|
|
{
|
1013 |
|
|
private:
|
1014 |
|
|
double coef;
|
1015 |
|
|
|
1016 |
|
|
public:
|
1017 |
|
|
TPL_OCTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
|
1018 |
|
|
~TPL_OCTREE_FCT() {}
|
1019 |
|
|
|
1020 |
|
|
|
1021 |
|
|
virtual void change_coefficent_multiplicateur(double val) {coef=val;};
|
1022 |
|
|
|
1023 |
|
|
virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
|
1024 |
|
|
{
|
1025 |
|
|
TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
|
1026 |
|
|
TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
|
1027 |
|
|
double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
|
1028 |
|
|
double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
|
1029 |
|
|
double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
|
1030 |
|
|
double d=dx;
|
1031 |
|
|
if (dy>d) d=dy;
|
1032 |
|
|
if (dz>d) d=dz;
|
1033 |
|
|
double xyz[3];
|
1034 |
|
|
root_cellule->boite.get_centre(xyz);
|
1035 |
|
|
double ecart[9];
|
1036 |
|
|
fonction.evaluer(xyz,ecart);
|
1037 |
|
|
double dcible=coef/sqrt(ecart[0]);
|
1038 |
|
|
if (dcible<d)
|
1039 |
|
|
{
|
1040 |
|
|
root_cellule->feuille=0;
|
1041 |
|
|
root_cellule->fils[0]=cree_fils(root_cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,0);
|
1042 |
|
|
root_cellule->fils[1]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,1,1);
|
1043 |
|
|
root_cellule->fils[2]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,2);
|
1044 |
|
|
root_cellule->fils[3]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,1,3);
|
1045 |
|
|
root_cellule->fils[4]=cree_fils(root_cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,4);
|
1046 |
|
|
root_cellule->fils[5]=cree_fils(root_cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,5);
|
1047 |
|
|
root_cellule->fils[6]=cree_fils(root_cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,6);
|
1048 |
|
|
root_cellule->fils[7]=cree_fils(root_cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,1,7);
|
1049 |
|
|
}
|
1050 |
|
|
else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
|
1051 |
|
|
}
|
1052 |
|
|
|
1053 |
|
|
virtual TPL_CELLULE_OCTREE<A ,A>* cree_fils(TPL_CELLULE_OCTREE<A ,A>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,B &fonction,int niv,int st)
|
1054 |
|
|
{
|
1055 |
|
|
TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
|
1056 |
|
|
TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
|
1057 |
|
|
if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
|
1058 |
|
|
double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
|
1059 |
|
|
double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
|
1060 |
|
|
double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
|
1061 |
|
|
double d=dx;
|
1062 |
|
|
if (ddy>d) d=ddy;
|
1063 |
|
|
if (ddz>d) d=ddz;
|
1064 |
|
|
double xyz[3];
|
1065 |
|
|
cellule->boite.get_centre(xyz);
|
1066 |
|
|
double ecart[9];
|
1067 |
|
|
fonction.evaluer(xyz,ecart);
|
1068 |
|
|
double dcible=coef/sqrt(ecart[0]);
|
1069 |
|
|
if (dcible<d)
|
1070 |
|
|
{
|
1071 |
|
|
cellule->feuille=0;
|
1072 |
|
|
cellule->fils[0]=cree_fils(cellule,xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,0);
|
1073 |
|
|
cellule->fils[1]=cree_fils(cellule,xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,1);
|
1074 |
|
|
cellule->fils[2]=cree_fils(cellule,xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,2);
|
1075 |
|
|
cellule->fils[3]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,fonction,niv+1,3);
|
1076 |
|
|
cellule->fils[4]=cree_fils(cellule,xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,4);
|
1077 |
|
|
cellule->fils[5]=cree_fils(cellule,xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,5);
|
1078 |
|
|
cellule->fils[6]=cree_fils(cellule,xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,6);
|
1079 |
|
|
cellule->fils[7]=cree_fils(cellule,xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,fonction,niv+1,7);
|
1080 |
|
|
}
|
1081 |
|
|
else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
|
1082 |
|
|
return cellule;
|
1083 |
|
|
}
|
1084 |
|
|
};
|
1085 |
|
|
|
1086 |
|
|
|
1087 |
|
|
template <class A,class B>
|
1088 |
|
|
class TPL_NTREE_FCT:public TPL_OCTREE<A,A>
|
1089 |
|
|
{
|
1090 |
|
|
private:
|
1091 |
|
|
double coef;
|
1092 |
|
|
|
1093 |
|
|
public:
|
1094 |
|
|
TPL_NTREE_FCT():TPL_OCTREE<A,A>(),coef(1.) {};
|
1095 |
|
|
~TPL_NTREE_FCT() {}
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
|
|
virtual void change_coefficent_multiplicateur(double val) {coef=val;};
|
1099 |
|
|
|
1100 |
|
|
virtual void initialiser(B &fonction,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
|
1101 |
|
|
{
|
1102 |
|
|
TPL_CELLULE_OCTREE<A ,A>* root_cellule=new TPL_CELLULE_OCTREE<A ,A>(NULL,xmin,ymin,zmin,xmax,ymax,zmax,0,-1);
|
1103 |
|
|
TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(root_cellule);
|
1104 |
|
|
double dx=root_cellule->boite.get_xmax()-root_cellule->boite.get_xmin();
|
1105 |
|
|
double dy=root_cellule->boite.get_ymax()-root_cellule->boite.get_ymin();
|
1106 |
|
|
double dz=root_cellule->boite.get_zmax()-root_cellule->boite.get_zmin();
|
1107 |
|
|
double xyz[3];
|
1108 |
|
|
root_cellule->boite.get_centre(xyz);
|
1109 |
|
|
double ecart[9];
|
1110 |
|
|
fonction.evaluer(xyz,ecart);
|
1111 |
|
|
double dcible=coef/sqrt(ecart[0]);
|
1112 |
|
|
int ndivx=2,ndivy=2,ndivz=2;
|
1113 |
|
|
if (dcible>dx) ndivx=1;
|
1114 |
|
|
if (dcible>dy) ndivy=1;
|
1115 |
|
|
if (dcible>dz) ndivz=1;
|
1116 |
|
|
if (ndivx*ndivy*ndivz!=1)
|
1117 |
|
|
{
|
1118 |
|
|
root_cellule->feuille=0;
|
1119 |
|
|
for (int i=0;i<ndivx;i++)
|
1120 |
|
|
for (int j=0;j<ndivy;j++)
|
1121 |
|
|
for (int k=0;k<ndivz;k++)
|
1122 |
|
|
root_cellule->fils[((i*ndivx)+j)*ndivy+k]=cree_fils(root_cellule,xmin+i*1.0/ndivx*dx,ymin+j*1.0/ndivy*dy,zmin+k*1.0/ndivz*dz,dx*1./ndivx,dy*1./ndivy,dz*1./ndivz,fonction,1,0);
|
1123 |
|
|
}
|
1124 |
|
|
else {root_cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(root_cellule);}
|
1125 |
|
|
}
|
1126 |
|
|
|
1127 |
|
|
virtual TPL_CELLULE_OCTREE<A ,A>* cree_fils(TPL_CELLULE_OCTREE<A ,A>* cell,double xmin,double ymin,double zmin,double dx,double dy,double dz,B &fonction,int niv,int st)
|
1128 |
|
|
{
|
1129 |
|
|
TPL_CELLULE_OCTREE<A ,A>* cellule=new TPL_CELLULE_OCTREE<A ,A>(cell,xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz,niv,st);
|
1130 |
|
|
TPL_OCTREE<A,A>::lst_entite_cellule.ajouter(cellule);
|
1131 |
|
|
if (TPL_OCTREE<A,A>::niveaumax<niv) TPL_OCTREE<A,A>::niveaumax=niv;
|
1132 |
|
|
double ddx=cellule->boite.get_xmax()-cellule->boite.get_xmin();
|
1133 |
|
|
double ddy=cellule->boite.get_ymax()-cellule->boite.get_ymin();
|
1134 |
|
|
double ddz=cellule->boite.get_zmax()-cellule->boite.get_zmin();
|
1135 |
|
|
double xyz[3];
|
1136 |
|
|
cellule->boite.get_centre(xyz);
|
1137 |
|
|
double ecart[9];
|
1138 |
|
|
fonction.evaluer(xyz,ecart);
|
1139 |
|
|
double dcible=coef/sqrt(ecart[0]);
|
1140 |
|
|
int ndivx=2,ndivy=2,ndivz=2;
|
1141 |
|
|
if (dcible>dx) ndivx=1;
|
1142 |
|
|
if (dcible>dy) ndivy=1;
|
1143 |
|
|
if (dcible>dz) ndivz=1;
|
1144 |
|
|
if (ndivx*ndivy*ndivz!=1)
|
1145 |
|
|
{
|
1146 |
|
|
cellule->feuille=0;
|
1147 |
|
|
for (int i=0;i<ndivx;i++)
|
1148 |
|
|
for (int j=0;j<ndivy;j++)
|
1149 |
|
|
for (int k=0;k<ndivz;k++)
|
1150 |
|
|
cellule->fils[((i*ndivx)+j)*ndivy+k]=cree_fils(cellule,xmin+i*1.0/ndivx*dx,ymin+j*1.0/ndivy*dy,zmin+k*1.0/ndivz*dz,dx*1./ndivx,dy*1./ndivy,dz*1./ndivz,fonction,1,0);
|
1151 |
|
|
}
|
1152 |
|
|
else {cellule->feuille=1;TPL_OCTREE<A,A>::lst_entite_feuille.ajouter(cellule);}
|
1153 |
|
|
return cellule;
|
1154 |
|
|
}
|
1155 |
|
|
};
|
1156 |
|
|
|
1157 |
|
|
|
1158 |
|
|
|
1159 |
|
|
|
1160 |
|
|
|
1161 |
|
|
|
1162 |
|
|
|
1163 |
|
|
|
1164 |
|
|
|
1165 |
|
|
template <class A,class CONDITION,class B>
|
1166 |
|
|
class TPL_OCTREE_INFO:public OCTREE_BASE
|
1167 |
|
|
{
|
1168 |
|
|
public:
|
1169 |
|
|
TPL_OCTREE_INFO() {};
|
1170 |
|
|
~TPL_OCTREE_INFO()
|
1171 |
|
|
{
|
1172 |
|
|
for (int i1=0;i1<lst_entite_cellule.get_nb();i1++)
|
1173 |
|
|
{
|
1174 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(i1);
|
1175 |
|
|
delete cellule;
|
1176 |
|
|
}
|
1177 |
|
|
};
|
1178 |
|
|
|
1179 |
|
|
virtual int get_nb_cellule(void) {return lst_entite_cellule.get_nb();};
|
1180 |
|
|
|
1181 |
|
|
virtual BOITE_3D get_boite_de_base(void) {return lst_entite_cellule.get(0)->get_boite();};
|
1182 |
|
|
|
1183 |
|
|
virtual TPL_CELLULE_INFO<A,CONDITION,B>* get_cellule(int num) {return lst_entite_cellule.get(num); };
|
1184 |
|
|
|
1185 |
|
|
|
1186 |
|
|
virtual void initialiser(TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
|
1187 |
|
|
{
|
1188 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
|
1189 |
|
|
lst_entite_cellule.ajouter(root_cellule);
|
1190 |
|
|
for (int i=0;i<lst_entite->get_nb();i++)
|
1191 |
|
|
{
|
1192 |
|
|
CONDITION cond=lst_entite->get(i);
|
1193 |
|
|
BOITE_3D boite_cond=cond->get_boite_3D();
|
1194 |
|
|
if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
|
1195 |
|
|
}
|
1196 |
|
|
if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
|
1197 |
|
|
{
|
1198 |
|
|
root_cellule->feuille=0;
|
1199 |
|
|
double dx=xmax-xmin;
|
1200 |
|
|
double dy=ymax-ymin;
|
1201 |
|
|
double dz=zmax-zmin;
|
1202 |
|
|
root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1203 |
|
|
root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1204 |
|
|
root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1205 |
|
|
root_cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1206 |
|
|
root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1207 |
|
|
root_cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1208 |
|
|
root_cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1209 |
|
|
root_cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1210 |
|
|
}
|
1211 |
|
|
else root_cellule->feuille=1;
|
1212 |
|
|
for (int j=0;j<lst_entite_cellule.get_nb();j++)
|
1213 |
|
|
{
|
1214 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
|
1215 |
|
|
cellule->lst_entite_CONDITION.vide();
|
1216 |
|
|
}
|
1217 |
|
|
}
|
1218 |
|
|
|
1219 |
|
|
virtual void initialiser(TPL_MAP_ENTITE<CONDITION>* lst_entite,int nombre,double xmin,double ymin,double zmin,double xmax,double ymax,double zmax)
|
1220 |
|
|
{
|
1221 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* root_cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
|
1222 |
|
|
lst_entite_cellule.ajouter(root_cellule);
|
1223 |
|
|
for (int i=0;i<lst_entite->get_nb();i++)
|
1224 |
|
|
{
|
1225 |
|
|
CONDITION cond=lst_entite->get(i);
|
1226 |
|
|
BOITE_3D boite_cond=cond->get_boite_3D();
|
1227 |
|
|
if (boite_cond*root_cellule->boite) root_cellule->lst_entite_CONDITION.ajouter(cond);
|
1228 |
|
|
}
|
1229 |
|
|
if (root_cellule->lst_entite_CONDITION.get_nb()>nombre)
|
1230 |
|
|
{
|
1231 |
|
|
root_cellule->feuille=0;
|
1232 |
|
|
double dx=xmax-xmin;
|
1233 |
|
|
double dy=ymax-ymin;
|
1234 |
|
|
double dz=zmax-zmin;
|
1235 |
|
|
root_cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1236 |
|
|
root_cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1237 |
|
|
root_cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1238 |
|
|
root_cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1239 |
|
|
root_cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1240 |
|
|
root_cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1241 |
|
|
root_cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1242 |
|
|
root_cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(root_cellule->lst_entite_CONDITION),nombre);
|
1243 |
|
|
}
|
1244 |
|
|
else root_cellule->feuille=1;
|
1245 |
|
|
for (int j=0;j<lst_entite_cellule.get_nb();j++)
|
1246 |
|
|
{
|
1247 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(j);
|
1248 |
|
|
cellule->lst_entite_CONDITION.vide();
|
1249 |
|
|
}
|
1250 |
|
|
}
|
1251 |
|
|
|
1252 |
|
|
virtual void initialiser(OCTREE_BASE* oc)
|
1253 |
|
|
{
|
1254 |
|
|
BOITE_3D boite=oc->get_cellule(0)->get_boite();
|
1255 |
|
|
double xmin=boite.get_xmin();
|
1256 |
|
|
double xmax=boite.get_xmax();
|
1257 |
|
|
double ymin=boite.get_ymin();
|
1258 |
|
|
double ymax=boite.get_ymax();
|
1259 |
|
|
double zmin=boite.get_zmin();
|
1260 |
|
|
double zmax=boite.get_zmax();
|
1261 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
|
1262 |
|
|
lst_entite_cellule.ajouter(cellule);
|
1263 |
|
|
if (oc->get_cellule(0)->get_feuille()==0)
|
1264 |
|
|
{
|
1265 |
|
|
cellule->fils[0]=cree_fils(oc->get_cellule(0)->get_fils(0));
|
1266 |
|
|
cellule->fils[1]=cree_fils(oc->get_cellule(0)->get_fils(1));
|
1267 |
|
|
cellule->fils[2]=cree_fils(oc->get_cellule(0)->get_fils(2));
|
1268 |
|
|
cellule->fils[3]=cree_fils(oc->get_cellule(0)->get_fils(3));
|
1269 |
|
|
cellule->fils[4]=cree_fils(oc->get_cellule(0)->get_fils(4));
|
1270 |
|
|
cellule->fils[5]=cree_fils(oc->get_cellule(0)->get_fils(5));
|
1271 |
|
|
cellule->fils[6]=cree_fils(oc->get_cellule(0)->get_fils(6));
|
1272 |
|
|
cellule->fils[7]=cree_fils(oc->get_cellule(0)->get_fils(7));
|
1273 |
|
|
}
|
1274 |
|
|
cellule->feuille=oc->get_cellule(0)->get_feuille();
|
1275 |
|
|
};
|
1276 |
|
|
|
1277 |
|
|
|
1278 |
|
|
TPL_CELLULE_INFO<A,CONDITION,B>* cree_fils(CELLULE_OCTREE_BASE *cellule_base)
|
1279 |
|
|
{
|
1280 |
|
|
BOITE_3D boite=cellule_base->get_boite();
|
1281 |
|
|
double xmin=boite.get_xmin();
|
1282 |
|
|
double xmax=boite.get_xmax();
|
1283 |
|
|
double ymin=boite.get_ymin();
|
1284 |
|
|
double ymax=boite.get_ymax();
|
1285 |
|
|
double zmin=boite.get_zmin();
|
1286 |
|
|
double zmax=boite.get_zmax();
|
1287 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmax,ymax,zmax);
|
1288 |
|
|
lst_entite_cellule.ajouter(cellule);
|
1289 |
|
|
if (cellule_base->get_feuille()==1)
|
1290 |
|
|
{
|
1291 |
|
|
cellule->feuille=1;
|
1292 |
|
|
}
|
1293 |
|
|
else
|
1294 |
|
|
{
|
1295 |
|
|
cellule->fils[0]=cree_fils(cellule_base->get_fils(0));
|
1296 |
|
|
cellule->fils[1]=cree_fils(cellule_base->get_fils(1));
|
1297 |
|
|
cellule->fils[2]=cree_fils(cellule_base->get_fils(2));
|
1298 |
|
|
cellule->fils[3]=cree_fils(cellule_base->get_fils(3));
|
1299 |
|
|
cellule->fils[4]=cree_fils(cellule_base->get_fils(4));
|
1300 |
|
|
cellule->fils[5]=cree_fils(cellule_base->get_fils(5));
|
1301 |
|
|
cellule->fils[6]=cree_fils(cellule_base->get_fils(6));
|
1302 |
|
|
cellule->fils[7]=cree_fils(cellule_base->get_fils(7));
|
1303 |
|
|
cellule->feuille=0;
|
1304 |
|
|
}
|
1305 |
|
|
return cellule;
|
1306 |
|
|
};
|
1307 |
|
|
|
1308 |
|
|
virtual TPL_CELLULE_INFO<A ,CONDITION,B>* cree_fils(double xmin,double ymin,double zmin,double dx,double dy,double dz,TPL_LISTE_ENTITE<CONDITION>* lst_entite,int nombre)
|
1309 |
|
|
{
|
1310 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=new TPL_CELLULE_INFO<A ,CONDITION,B>(xmin,ymin,zmin,xmin+dx,ymin+dy,zmin+dz);
|
1311 |
|
|
lst_entite_cellule.ajouter(cellule);
|
1312 |
|
|
for (int i=0;i<lst_entite->get_nb();i++)
|
1313 |
|
|
{
|
1314 |
|
|
CONDITION cond=lst_entite->get(i);
|
1315 |
|
|
BOITE_3D boite_cond=cond->get_boite_3D();
|
1316 |
|
|
if (boite_cond*cellule->boite) cellule->lst_entite_CONDITION.ajouter(cond);
|
1317 |
|
|
}
|
1318 |
|
|
if (cellule->lst_entite_CONDITION.get_nb()>nombre)
|
1319 |
|
|
{
|
1320 |
|
|
cellule->feuille=0;
|
1321 |
|
|
cellule->fils[0]=cree_fils(xmin,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1322 |
|
|
cellule->fils[1]=cree_fils(xmin+dx/2.,ymin,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1323 |
|
|
cellule->fils[2]=cree_fils(xmin,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1324 |
|
|
cellule->fils[3]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1325 |
|
|
cellule->fils[4]=cree_fils(xmin,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1326 |
|
|
cellule->fils[5]=cree_fils(xmin+dx/2.,ymin,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1327 |
|
|
cellule->fils[6]=cree_fils(xmin,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1328 |
|
|
cellule->fils[7]=cree_fils(xmin+dx/2.,ymin+dy/2.,zmin+dz/2.,dx/2.,dy/2.,dz/2.,&(cellule->lst_entite_CONDITION),nombre);
|
1329 |
|
|
}
|
1330 |
|
|
else cellule->feuille=1;
|
1331 |
|
|
return cellule;
|
1332 |
|
|
}
|
1333 |
|
|
|
1334 |
|
|
|
1335 |
|
|
virtual void rechercher(BOITE_3D& boite,TPL_MAP_ENTITE<A>& liste_entite_trouve,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
|
1336 |
|
|
{
|
1337 |
|
|
if (boite*cellule->boite)
|
1338 |
|
|
if (cellule->feuille==1)
|
1339 |
|
|
{
|
1340 |
|
|
for (int i=0;i<cellule->lst_entite_A.get_nb();i++)
|
1341 |
|
|
if (boite*cellule->lst_entite_A.get(i)->get_boite_3D())
|
1342 |
|
|
liste_entite_trouve.ajouter(cellule->lst_entite_A.get(i));
|
1343 |
|
|
}
|
1344 |
|
|
else
|
1345 |
|
|
{
|
1346 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[0]);
|
1347 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[1]);
|
1348 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[2]);
|
1349 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[3]);
|
1350 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[4]);
|
1351 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[5]);
|
1352 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[6]);
|
1353 |
|
|
rechercher(boite,liste_entite_trouve,cellule->fils[7]);
|
1354 |
|
|
}
|
1355 |
|
|
};
|
1356 |
|
|
|
1357 |
|
|
|
1358 |
|
|
virtual void get_cellule(BOITE_3D& boite,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule,TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > &liste_entite)
|
1359 |
|
|
{
|
1360 |
|
|
if (boite*cellule->boite)
|
1361 |
|
|
if (cellule->feuille==1)
|
1362 |
|
|
{
|
1363 |
|
|
liste_entite.ajouter(cellule);
|
1364 |
|
|
}
|
1365 |
|
|
else
|
1366 |
|
|
{
|
1367 |
|
|
get_cellule(boite,cellule->fils[0],liste_entite);
|
1368 |
|
|
get_cellule(boite,cellule->fils[1],liste_entite);
|
1369 |
|
|
get_cellule(boite,cellule->fils[2],liste_entite);
|
1370 |
|
|
get_cellule(boite,cellule->fils[3],liste_entite);
|
1371 |
|
|
get_cellule(boite,cellule->fils[4],liste_entite);
|
1372 |
|
|
get_cellule(boite,cellule->fils[5],liste_entite);
|
1373 |
|
|
get_cellule(boite,cellule->fils[6],liste_entite);
|
1374 |
|
|
get_cellule(boite,cellule->fils[7],liste_entite);
|
1375 |
|
|
}
|
1376 |
|
|
};
|
1377 |
|
|
|
1378 |
|
|
virtual TPL_CELLULE_INFO<A,CONDITION,B> *get_cellule(double x,double y, double z)
|
1379 |
|
|
{
|
1380 |
|
|
BOITE_3D boite(x,y,z,x,y,z);
|
1381 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
|
1382 |
|
|
TPL_MAP_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B> * > liste_cellule;
|
1383 |
|
|
get_cellule(boite,cellule,liste_cellule);
|
1384 |
|
|
if (liste_cellule.get_nb()==1) return liste_cellule.get(0);
|
1385 |
|
|
return NULL;
|
1386 |
|
|
};
|
1387 |
|
|
|
1388 |
|
|
|
1389 |
|
|
virtual void rechercher(double xcentre,double ycentre,double zcentre,double rayon_recherche,TPL_MAP_ENTITE<A>& liste_entite_trouve)
|
1390 |
|
|
{
|
1391 |
|
|
BOITE_3D boite(xcentre-rayon_recherche,ycentre-rayon_recherche,zcentre-rayon_recherche,xcentre+rayon_recherche,ycentre+rayon_recherche,zcentre+rayon_recherche);
|
1392 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
|
1393 |
|
|
rechercher(boite,liste_entite_trouve,cellule);
|
1394 |
|
|
};
|
1395 |
|
|
|
1396 |
|
|
|
1397 |
|
|
|
1398 |
|
|
virtual void inserer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
|
1399 |
|
|
{
|
1400 |
|
|
if (boite*cellule->boite)
|
1401 |
|
|
if (cellule->feuille==1)
|
1402 |
|
|
{
|
1403 |
|
|
cellule->lst_entite_A.ajouter(a);
|
1404 |
|
|
}
|
1405 |
|
|
else
|
1406 |
|
|
{
|
1407 |
|
|
inserer(boite,a,cellule->fils[0]);
|
1408 |
|
|
inserer(boite,a,cellule->fils[1]);
|
1409 |
|
|
inserer(boite,a,cellule->fils[2]);
|
1410 |
|
|
inserer(boite,a,cellule->fils[3]);
|
1411 |
|
|
inserer(boite,a,cellule->fils[4]);
|
1412 |
|
|
inserer(boite,a,cellule->fils[5]);
|
1413 |
|
|
inserer(boite,a,cellule->fils[6]);
|
1414 |
|
|
inserer(boite,a,cellule->fils[7]);
|
1415 |
|
|
}
|
1416 |
|
|
};
|
1417 |
|
|
|
1418 |
|
|
virtual void supprimer(BOITE_3D& boite,A a,TPL_CELLULE_INFO<A ,CONDITION,B>* cellule)
|
1419 |
|
|
{
|
1420 |
|
|
if (boite*cellule->boite)
|
1421 |
|
|
if (cellule->feuille==1)
|
1422 |
|
|
{
|
1423 |
|
|
cellule->lst_entite_A.supprimer(a);
|
1424 |
|
|
}
|
1425 |
|
|
else
|
1426 |
|
|
{
|
1427 |
|
|
supprimer(boite,a,cellule->fils[0]);
|
1428 |
|
|
supprimer(boite,a,cellule->fils[1]);
|
1429 |
|
|
supprimer(boite,a,cellule->fils[2]);
|
1430 |
|
|
supprimer(boite,a,cellule->fils[3]);
|
1431 |
|
|
supprimer(boite,a,cellule->fils[4]);
|
1432 |
|
|
supprimer(boite,a,cellule->fils[5]);
|
1433 |
|
|
supprimer(boite,a,cellule->fils[6]);
|
1434 |
|
|
supprimer(boite,a,cellule->fils[7]);
|
1435 |
|
|
}
|
1436 |
|
|
};
|
1437 |
|
|
|
1438 |
|
|
virtual void inserer(A a)
|
1439 |
|
|
{
|
1440 |
|
|
BOITE_3D boite=a->get_boite_3D();
|
1441 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
|
1442 |
|
|
inserer(boite,a,cellule);
|
1443 |
|
|
}
|
1444 |
|
|
|
1445 |
|
|
virtual void supprimer(A a)
|
1446 |
|
|
{
|
1447 |
|
|
BOITE_3D boite=a->get_boite_3D();
|
1448 |
|
|
TPL_CELLULE_INFO<A ,CONDITION,B>* cellule=lst_entite_cellule.get(0);
|
1449 |
|
|
supprimer(boite,a,cellule);
|
1450 |
|
|
}
|
1451 |
|
|
|
1452 |
|
|
|
1453 |
|
|
private:
|
1454 |
|
|
TPL_LISTE_ENTITE<TPL_CELLULE_INFO<A ,CONDITION,B>* > lst_entite_cellule;
|
1455 |
|
|
|
1456 |
|
|
};
|
1457 |
|
|
|
1458 |
|
|
|
1459 |
|
|
|
1460 |
|
|
|
1461 |
|
|
#endif
|