src/bbox.c
void bbox_to_intv(const struct bbox *bb, uint64_t dim_virt, int bpd,
                  struct intv **intv, int *num_intv)
{
    // const int 1<<(bb->num_dims);
    struct bbox *bb_virt;
    struct bbox *b_tab; // the number of b_tab is 2^n
    struct queue q_can, q_good;
    struct intv *i_tab, *i_tmp;
    // int max;
    uint64_t max;
    int i, n;

    max = dim_virt; // n is the next power of 2 that includes the user's bbox
    bpd = compute_bits(max); // TODO

    bb_virt = malloc(sizeof(struct bbox));
    memset(bb_virt, 0, sizeof(struct bbox));
    bb_virt->num_dims = bb->num_dims;

    for(i = 0; i < bb->num_dims; i++) {
        bb_virt->ub.c[i] = max - 1;
    }

    queue_init(&q_can);
    queue_init(&q_good);

    n = 1 << (bb->num_dims); // number of b_tab
    b_tab = malloc(sizeof(struct bbox) * n);
    memset(b_tab, 0, sizeof(struct bbox) * n); // TODO sizeof???

    queue_enqueue(&q_can, bb_virt);
    while(!queue_is_empty(&q_can)) {

        bb_virt = (struct bbox *)queue_dequeue(&q_can);
        if(bbox_include(bb, bb_virt)) {
            i_tmp = malloc(sizeof(struct intv));
            bbox_flat(bb_virt, i_tmp, bpd);
            queue_enqueue(&q_good, i_tmp);
            free(bb_virt);
        } else if(bbox_does_intersect(bb, bb_virt)) {
            bbox_divide(bb_virt, b_tab);
            free(bb_virt);

            for(i = 0; i < n; i++) {
                bb_virt = malloc(sizeof(struct bbox));
                *bb_virt = b_tab[i];
                queue_enqueue(&q_can, bb_virt);
            }
        } else
            free(bb_virt);
    }
    free(b_tab);
    n = queue_size(&q_good);
    i_tab = malloc(n * sizeof(struct intv));

    n = 0;
    while(!queue_is_empty(&q_good)) {
        i_tmp = queue_dequeue(&q_good);
        i_tab[n++] = *i_tmp;
        free(i_tmp);
    }
    qsort(i_tab, n, sizeof(struct intv), &intv_compar);
    n = intv_compact(i_tab, n);

    i_tab = realloc(i_tab, n * sizeof(struct intv));
    *intv = i_tab;
    *num_intv = n;
}
/*
  Find the equivalence in 1d index space using a SFC for a bounding
  box bb.
*/
Find the equivalence in 1d index space using a SFC for a bounding
box bb.
Find the equivalence in 1d index space using a SFC for a bounding box bb .
void bbox_to_intv(const struct bbox *bb, uint64_t dim_virt, int bpd,
                  struct intv **intv, int *num_intv)
{
    struct bbox *bb_virt;
    struct bbox *b_tab; 
    struct queue q_can, q_good;
    struct intv *i_tab, *i_tmp;
    uint64_t max;
    int i, n;
    max = dim_virt; 
    bpd = compute_bits(max); 
    bb_virt = malloc(sizeof(struct bbox));
    memset(bb_virt, 0, sizeof(struct bbox));
    bb_virt->num_dims = bb->num_dims;
    for(i = 0; i < bb->num_dims; i++) {
        bb_virt->ub.c[i] = max - 1;
    }
    queue_init(&q_can);
    queue_init(&q_good);
    n = 1 << (bb->num_dims); 
    b_tab = malloc(sizeof(struct bbox) * n);
    memset(b_tab, 0, sizeof(struct bbox) * n);  sizeof???
    queue_enqueue(&q_can, bb_virt);
    while(!queue_is_empty(&q_can)) {
        bb_virt = (struct bbox *)queue_dequeue(&q_can);
        if(bbox_include(bb, bb_virt)) {
            i_tmp = malloc(sizeof(struct intv));
            bbox_flat(bb_virt, i_tmp, bpd);
            queue_enqueue(&q_good, i_tmp);
            free(bb_virt);
        } else if(bbox_does_intersect(bb, bb_virt)) {
            bbox_divide(bb_virt, b_tab);
            free(bb_virt);
            for(i = 0; i < n; i++) {
                bb_virt = malloc(sizeof(struct bbox));
                *bb_virt = b_tab[i];
                queue_enqueue(&q_can, bb_virt);
            }
        } else
            free(bb_virt);
    }
    free(b_tab);
    n = queue_size(&q_good);
    i_tab = malloc(n * sizeof(struct intv));
    n = 0;
    while(!queue_is_empty(&q_good)) {
        i_tmp = queue_dequeue(&q_good);
        i_tab[n++] = *i_tmp;
        free(i_tmp);
    }
    qsort(i_tab, n, sizeof(struct intv), &intv_compar);
    n = intv_compact(i_tab, n);
    i_tab = realloc(i_tab, n * sizeof(struct intv));
    *intv = i_tab;
    *num_intv = n;
}
void bbox_to_intv ( const struct bbox * bb , uint64_t dim_virt , int bpd , struct intv * * intv , int * num_intv ) { struct bbox * bb_virt ; struct bbox * b_tab ; struct queue q_can , q_good ; struct intv * i_tab , * i_tmp ; uint64_t max ; int i , n ; max = dim_virt ; bpd = compute_bits ( max ) ; bb_virt = malloc ( sizeof ( struct bbox ) ) ; memset ( bb_virt , 0 , sizeof ( struct bbox ) ) ; bb_virt -> num_dims = bb -> num_dims ; for ( i = 0 ; i < bb -> num_dims ; i ++ ) { bb_virt -> ub . c [ i ] = max - 1 ; } queue_init ( & q_can ) ; queue_init ( & q_good ) ; n = 1 << ( bb -> num_dims ) ; b_tab = malloc ( sizeof ( struct bbox ) * n ) ; memset ( b_tab , 0 , sizeof ( struct bbox ) * n ) ; queue_enqueue ( & q_can , bb_virt ) ; while ( ! queue_is_empty ( & q_can ) ) { bb_virt = ( struct bbox * ) queue_dequeue ( & q_can ) ; if ( bbox_include ( bb , bb_virt ) ) { i_tmp = malloc ( sizeof ( struct intv ) ) ; bbox_flat ( bb_virt , i_tmp , bpd ) ; queue_enqueue ( & q_good , i_tmp ) ; free ( bb_virt ) ; } else if ( bbox_does_intersect ( bb , bb_virt ) ) { bbox_divide ( bb_virt , b_tab ) ; free ( bb_virt ) ; for ( i = 0 ; i < n ; i ++ ) { bb_virt = malloc ( sizeof ( struct bbox ) ) ; * bb_virt = b_tab [ i ] ; queue_enqueue ( & q_can , bb_virt ) ; } } else free ( bb_virt ) ; } free ( b_tab ) ; n = queue_size ( & q_good ) ; i_tab = malloc ( n * sizeof ( struct intv ) ) ; n = 0 ; while ( ! queue_is_empty ( & q_good ) ) { i_tmp = queue_dequeue ( & q_good ) ; i_tab [ n ++ ] = * i_tmp ; free ( i_tmp ) ; } qsort ( i_tab , n , sizeof ( struct intv ) , & intv_compar ) ; n = intv_compact ( i_tab , n ) ; i_tab = realloc ( i_tab , n * sizeof ( struct intv ) ) ; * intv = i_tab ; * num_intv = n ; }
Find the equivalence in 1d index space using a SFC for a bounding
box bb.
Find the equivalence in 1d index space using a SFC for a bounding box bb .
// const int 1<<(bb->num_dims); // the number of b_tab is 2^n // int max; // n is the next power of 2 that includes the user's bbox // TODO // number of b_tab // TODO sizeof???