void NodeDatabrick::split_data(int whichhalf) { kd_split(whichhalf); int leap[2]; leap[1] = m_bricksize/2; leap[0] = m_bricksize - leap[1]; m_bricksize = leap[whichhalf]; }
kd_t *kd_add_box_step(int axis, int canexpand, kd_t *kd, box_t *box) { //printf("%i %016llX %016llX\n", axis, kd, box); // check: do we even have a box? if(box == NULL) return kd; // check: do we need to create a new node? if(kd == NULL) { // yes. create a new kd node. kd = kd_new(axis, box->v0.a[axis], box->v1.a[axis], box, box, box); // check if we're at axis level 3. if(axis == 3) return kd; // nope. create an axis change child. kd->c[0] = kd_add_box_step(axis + 1, 1, NULL, box); kd->c[0]->p = kd; return kd; } // check: can we expand this? if(canexpand) { // check: do we exceed the -ve limit? if(box->v0.a[axis] < kd->v[0]) { // create parent, recurse down, and return. kd_t *pair = kd_new(axis, box->v0.a[axis], kd->v[1], box, box, kd->obox[1]); pair->c[0] = kd_add_box_step(axis, 0, NULL, box); pair->c[1] = kd_add_box_step(axis, 0, kd, box); pair->c[0]->p = pair; pair->c[1]->p = pair; return pair; } // check: do we exceed the +ve limit? if(box->v1.a[axis] > kd->v[1]) { // create parent, recurse down, and return. kd_t *pair = kd_new(axis, kd->v[0], box->v1.a[axis], box, kd->obox[0], box); pair->c[0] = kd_add_box_step(axis, 0, kd, box); pair->c[1] = kd_add_box_step(axis, 0, NULL, box); pair->c[0]->p = pair; pair->c[1]->p = pair; return pair; } } // check: do we not reach the -ve limit? if(box->v0.a[axis] > kd->v[0]) { // split this node and recurse. kd = kd_split(kd, box->v0.a[axis]); return kd_add_box_step(axis, 0, kd->c[1], box); } // check: do we not reach the +ve limit? if(box->v1.a[axis] < kd->v[1]) { // split this node and recurse. kd = kd_split(kd, box->v1.a[axis]); return kd_add_box_step(axis, 0, kd->c[0], box); } // check: is this a leaf? if(kd->c[0] == NULL) { // replace this node. kd_free_down(kd); return kd_add_box_step(axis, 0, NULL, box); } // then this is an axis switch. // step down. kd->c[0] = kd_add_box_step(axis + 1, 1, kd->c[0], box); kd->c[0]->p = kd; return kd; }