diff --git a/src/ref_oct.c b/src/ref_oct.c index 00663ba59..503e69de4 100644 --- a/src/ref_oct.c +++ b/src/ref_oct.c @@ -53,6 +53,80 @@ REF_FCN REF_STATUS ref_oct_free(REF_OCT ref_oct) { return REF_SUCCESS; } +REF_FCN REF_STATUS ref_oct_child_bbox(REF_DBL *bbox, REF_INT child_index, + REF_DBL *box) { + switch (child_index) { + case 0: + box[0] = bbox[0]; + box[1] = 0.5 * (bbox[0] + bbox[1]); + box[2] = bbox[2]; + box[3] = 0.5 * (bbox[2] + bbox[3]); + box[4] = bbox[4]; + box[5] = 0.5 * (bbox[4] + bbox[5]); + break; + case 1: + box[0] = 0.5 * (bbox[0] + bbox[1]); + box[1] = bbox[1]; + box[2] = bbox[2]; + box[3] = 0.5 * (bbox[2] + bbox[3]); + box[4] = bbox[4]; + box[5] = 0.5 * (bbox[4] + bbox[5]); + break; + case 2: + box[0] = 0.5 * (bbox[0] + bbox[1]); + box[1] = bbox[1]; + box[2] = 0.5 * (bbox[2] + bbox[3]); + box[3] = bbox[3]; + box[4] = bbox[4]; + box[5] = 0.5 * (bbox[4] + bbox[5]); + break; + case 3: + box[0] = bbox[0]; + box[1] = 0.5 * (bbox[0] + bbox[1]); + box[2] = 0.5 * (bbox[2] + bbox[3]); + box[3] = bbox[3]; + box[4] = bbox[4]; + box[5] = 0.5 * (bbox[4] + bbox[5]); + break; + case 4: + box[0] = bbox[0]; + box[1] = 0.5 * (bbox[0] + bbox[1]); + box[2] = bbox[2]; + box[3] = 0.5 * (bbox[2] + bbox[3]); + box[4] = 0.5 * (bbox[4] + bbox[5]); + box[5] = bbox[5]; + break; + case 5: + box[0] = 0.5 * (bbox[0] + bbox[1]); + box[1] = bbox[1]; + box[2] = bbox[2]; + box[3] = 0.5 * (bbox[2] + bbox[3]); + box[4] = 0.5 * (bbox[4] + bbox[5]); + box[5] = bbox[5]; + break; + case 6: + box[0] = 0.5 * (bbox[0] + bbox[1]); + box[1] = bbox[1]; + box[2] = 0.5 * (bbox[2] + bbox[3]); + box[3] = bbox[3]; + box[4] = 0.5 * (bbox[4] + bbox[5]); + box[5] = bbox[5]; + break; + case 7: + box[0] = bbox[0]; + box[1] = 0.5 * (bbox[0] + bbox[1]); + box[2] = 0.5 * (bbox[2] + bbox[3]); + box[3] = bbox[3]; + box[4] = 0.5 * (bbox[4] + bbox[5]); + box[5] = bbox[5]; + break; + default: + THROW("not 2^3"); + } + + return REF_SUCCESS; +} + REF_FCN REF_STATUS ref_oct_split(REF_OCT ref_oct, REF_INT node) { REF_INT i; for (i = 0; i < 8; i++) { diff --git a/src/ref_oct.h b/src/ref_oct.h index f07345ace..665451c56 100644 --- a/src/ref_oct.h +++ b/src/ref_oct.h @@ -38,6 +38,9 @@ REF_FCN REF_STATUS ref_oct_create(REF_OCT *ref_oct); REF_FCN REF_STATUS ref_oct_free(REF_OCT ref_oct); +REF_FCN REF_STATUS ref_oct_child_bbox(REF_DBL *parent_bbox, REF_INT child_index, + REF_DBL *child_bbox); + REF_FCN REF_STATUS ref_oct_split(REF_OCT ref_oct, REF_INT node); REF_FCN REF_STATUS ref_oct_contains(REF_OCT ref_oct, REF_DBL *xyz, diff --git a/src/ref_oct_test.c b/src/ref_oct_test.c index 60d18bb9e..355643500 100644 --- a/src/ref_oct_test.c +++ b/src/ref_oct_test.c @@ -58,6 +58,20 @@ int main(int argc, char *argv[]) { RSS(ref_oct_free(ref_oct), "free oct"); } + { /* child's bbox */ + REF_DBL parent_bbox[6], child_bbox[6]; + REF_INT child_index = 0; + REF_DBL tol = -1.0; + parent_bbox[0] = 0.0; + parent_bbox[1] = 1.0; + parent_bbox[2] = 0.0; + parent_bbox[3] = 1.0; + parent_bbox[4] = 0.0; + parent_bbox[5] = 1.0; + RSS(ref_oct_child_bbox(parent_bbox, child_index, child_bbox), "bbox"); + RWDS(0.0, child_bbox[0], tol, "not zero"); + } + { /* split root */ REF_OCT ref_oct; REF_DBL xyz[] = {0.1, 0.1, 0.1};