25 int initial_buckets_num;
26 double tmp[3], error[3];
29 for(i = 0; i < 3; i++) error[i] = _size[i] * 0.01;
31 initial_buckets_num = (int)pow(8., p);
35 (*globalPara)->maxElements = _maxElem;
36 (*globalPara)->ptrToPrevElement =
nullptr;
38 for(i = 0; i < 3; i++) {
39 (*globalPara)->origin[i] = _orig[i];
40 (*globalPara)->size[i] = _size[i];
43 (*globalPara)->numBuckets = initial_buckets_num;
45 if(!(*buckets_head)) {
46 Msg::Error(
"Could not allocate octree buckets");
52 Msg::Error(
"Could not allocate octree buckets");
56 (*buckets_head)->next = buckets;
57 (*buckets_head)->
parent =
nullptr;
59 (*buckets_head)->lhead =
nullptr;
60 (*buckets_head)->precision = 0;
61 for(i = 0; i < 3; i++) {
62 (*buckets_head)->minPt[i] = _orig[i] - error[i];
63 (*buckets_head)->maxPt[i] = _size[i] + _orig[i] + error[i];
66 for(i = 0; i < (*globalPara)->numBuckets; i++) {
68 buckets[i].
lhead =
nullptr;
69 buckets[i].
next =
nullptr;
70 buckets[i].
parent = *buckets_head;
74 tmp1 = (int)(pow(2., p));
75 for(i = 0; i < 3; i++) {
76 tmp[i] = (double)(_size[i] + 2 * error[i]) / tmp1;
79 for(k = 0; k < tmp1; k++) {
80 for(j = 0; j < tmp1; j++) {
81 for(i = 0; i < tmp1; i++) {
82 buckets[i + j * tmp1 + k * tmp1 * tmp1].
minPt[0] =
83 (*buckets_head)->minPt[0] + tmp[0] * i;
84 buckets[i + j * tmp1 + k * tmp1 * tmp1].
minPt[1] =
85 (*buckets_head)->minPt[1] + tmp[1] * j;
86 buckets[i + j * tmp1 + k * tmp1 * tmp1].
minPt[2] =
87 (*buckets_head)->minPt[2] + tmp[2] * k;
88 buckets[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[0] =
89 (*buckets_head)->minPt[0] + tmp[0] * (i + 1);
90 buckets[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[1] =
91 (*buckets_head)->minPt[1] + tmp[1] * (j + 1);
92 buckets[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[2] =
93 (*buckets_head)->minPt[2] + tmp[2] * (k + 1);
99 for (i = 0; i < 8; i++) {
100 printf(
" bucket %d : min[0]=%f, min[1]=%f, min[2]=%f, max[0]= %f, max[1]=%f, max[3]=%f\n",
101 i,buckets[i].minPt[0],buckets[i].minPt[1],
102 buckets[i].minPt[2], buckets[i].maxPt[0], buckets[i].maxPt[1],
103 buckets[i].maxPt[2]);
104 printf(
"bucket elements link list: bucket->lhead = %d\n", buckets[i].lhead);
112 double *_maxBB,
double *_ele_centroid,
138 for(i = 0; i < 3; i++) {
139 ptr1->
minPt[i] = _minBB[i];
140 ptr1->
maxPt[i] = _maxBB[i];
141 ptr1->
centroid[i] = _ele_centroid[i];
145 _bucket->
lhead = ptr1;
149 printf(
"bucket element list: bucket->lhead = %d", _bucket->
lhead);
150 printf(
" numElements = %d\n",_bucket->
numElements);
151 printf(
"the element is add to this bucket: (%f, %f, %f) to (%f, %f, %f)\n",
167 ptr1 = _bucket->
lhead;
168 while(ptr1 !=
nullptr) {
172 if(ptrBucket ==
nullptr) {
177 ptrBucket->
lhead = ptr2;
181 _bucket->
lhead =
nullptr;
185 if(flag == 0) _bucket->
lhead =
nullptr;
197 for(ptr = _bucket->
lhead; ptr !=
nullptr; ptr = ptr->
next) {
199 if(ptr->
region == _element)
return 1;
216 while(tmpbucket !=
nullptr) {
217 for(i = 0; i < num; i++) {
218 for(j = 0; j < 3; j++) {
219 if(tmpbucket[i].minPt[j] > _pt[j] || tmpbucket[i].maxPt[j] < _pt[j])
223 prevbucket = tmpbucket + i;
224 tmpbucket = tmpbucket[i].
next;
248 Msg::Error(
"Could not allocate octree buckets");
255 for(i = 0; i < numBuck; i++) {
256 (_bucket->
next[i]).numElements = 0;
257 (_bucket->
next[i]).lhead =
nullptr;
258 (_bucket->
next[i]).next =
nullptr;
259 (_bucket->
next[i]).parent = _bucket;
264 for(i = 0; i < 3; i++) {
265 tmp[i] = ((double)(_bucket->
maxPt[i] - _bucket->
minPt[i])) / tmp1;
268 for(k = 0; k < tmp1; k++) {
269 for(j = 0; j < tmp1; j++) {
270 for(i = 0; i < tmp1; i++) {
271 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
minPt[0] =
272 _bucket->
minPt[0] + tmp[0] * i;
273 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
minPt[1] =
274 _bucket->
minPt[1] + tmp[1] * j;
275 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
minPt[2] =
276 _bucket->
minPt[2] + tmp[2] * k;
277 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[0] =
278 _bucket->
minPt[0] + tmp[0] * (i + 1);
279 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[1] =
280 _bucket->
minPt[1] + tmp[1] * (j + 1);
281 _bucket->
next[i + j * tmp1 + k * tmp1 * tmp1].
maxPt[2] =
282 _bucket->
minPt[2] + tmp[2] * (k + 1);
298 void *ptrToEle =
nullptr;
299 #pragma omp atomic read
304 if(flag == 1) flag = xyzInElement(ptrToEle, _pt);
305 if(flag == 1)
return ptrToEle;
309 if(ptrBucket ==
nullptr) {
316 ptr1 = ptrBucket->
lhead;
319 printf(
"point %lf %lf %lf has been found in bucket %lf %lf %fl -> %lf %lf %lf %p\n",
320 _pt[0],_pt[1],_pt[2], ptrBucket->
minPt[0],ptrBucket->
minPt[1],ptrBucket->
minPt[2],
322 if (ptr1 ==
nullptr) {
323 printf(
"empty element list for centroid list!?\n, possible!");
327 while(ptr1 !=
nullptr) {
329 if(flag == 1) flag = xyzInElement(ptr1->
region, _pt);
331 #pragma omp atomic write
338 for(
auto iter = (ptrBucket->
listBB).begin(); iter != (ptrBucket->
listBB).end();
341 if(flag == 1) flag = xyzInElement(*iter, _pt);
343 #pragma omp atomic write
362 (*_bbElement)(_region, minPt, maxPt);
364 for(i = 0; i < 3; i++) {
365 if(_xyz[i] > maxPt[i] || _xyz[i] < minPt[i])
return 0;
376 for(i = 0; i < 3; i++) {
377 if(_bucket->
minPt[i] > _maxPt[i] || _bucket->
maxPt[i] < _minPt[i])
return;
379 if(_bucket->
next ==
nullptr) {
380 ptr = _bucket->
lhead;
381 while(ptr !=
nullptr) {
382 if(ptr->
region == _region)
return;
387 _bucket->
listBB.push_back(_region);
391 for(i = 0; i < 8; i++)
399 std::vector<void *> *_elements)
405 if(ptrBucket ==
nullptr) {
406 Msg::Debug(
"Could not find point in octree (in search all elements)");
411 printf(
"point %lf %lf %lf has been found in bucket %lf %lf %fl -> %lf %lf %lf %p\n",
412 _pt[0],_pt[1],_pt[2], ptrBucket->
minPt[0],ptrBucket->
minPt[1],ptrBucket->
minPt[2],
415 if (ptr1 ==
nullptr) {
416 printf(
"empty element list for centroid list!?\n, possible!");
422 while(ptr1 !=
nullptr) {
424 if(flag == 1) flag = xyzInElement(ptr1->
region, _pt);
426 _elements->push_back(ptr1->
region);
432 for(
auto iter = (ptrBucket->
listBB).begin(); iter != (ptrBucket->
listBB).end();
435 if(flag == 1) flag = xyzInElement(*iter, _pt);
437 _elements->push_back(*iter);
442 if(flag1)
return (
void *)(_elements);