X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lab-bitmaps.c;h=51d1da847623d12f17944dae19e0b098ccfa5ddf;hb=refs%2Fheads%2Flabelling;hp=0769d34d54cce3745eb8e13dd27e0131c0d4f6f2;hpb=1b17564442494d9827c24abbdfd24dc2848bb107;p=leo.git diff --git a/lab-bitmaps.c b/lab-bitmaps.c index 0769d34..51d1da8 100644 --- a/lab-bitmaps.c +++ b/lab-bitmaps.c @@ -8,9 +8,11 @@ #include "leo.h" #include "sym.h" +#include "map.h" #include "labeller.h" #include "lab-bitmaps.h" #include "lab-utils.h" +#include "lab-evolution.h" static void make_bitmap_icon(struct variant *v, struct sym_icon *si); static void make_bitmap_point(struct variant *v, struct sym_point *sp); @@ -19,7 +21,11 @@ static void make_bitmap_label(struct variant *v, struct sym_text *text); static int overlaps(struct placement *p1, struct placement *p2); static struct map_part **get_map_parts(struct placement *p); -static struct placement **get_overlapping(struct placement *p); +static struct placement **get_overlapping_in(struct placement *p, struct individual *individual); + +double bitmap_granularity = 1; + +int page_width_gran, page_height_gran; void make_bitmap(struct variant *v, struct symbol *sym) @@ -103,11 +109,11 @@ static void make_bitmap_label(struct variant *v, struct sym_text *text) void dump_bitmaps(struct individual *individual) { - bool *bitmap = xmalloc(page_width_int * page_height_int * sizeof(bool)); - printf("Bitmap size is %d\n", page_width_int * page_height_int); - for (int i=0; iplacements); i++) @@ -129,10 +135,18 @@ void dump_bitmaps(struct individual *individual) continue; } - int base_x = p->x; int base_y = p->y; - for (int dr = max2(0, 0-p->y); dr < v->height; dr++) + // FIXME: + // if e.g. granularity is 2, p->x = 2.4 and v->width = 4 + // then <2, 2.5> will be marked as occupied while <4, 4.5> won't be, + // though the variant occupies <2.4, 4,4> and therefore occupies much + // more of <4, 4.5> than of <2, 2.5> + int base_x = p->x * bitmap_granularity; + int base_y = p->y * bitmap_granularity; + int max_dr = min2(v->height - 1, (page_height - p->y) * bitmap_granularity); + int max_dc = min2(v->width - 1, (page_width - p->x) * bitmap_granularity); + for (int dr = max2(0, 0-p->y); dr < max_dr; dr++) { - for (int dc = max2(0, 0-p->x); dc < v->width; dc++) + for (int dc = max2(0, 0-p->x); dc < max_dc; dc++) { if (v->bitmap[dr * v->width + dc]) { @@ -146,12 +160,12 @@ void dump_bitmaps(struct individual *individual) FILE *fd_dump = fopen("dump.pbm", "w"); fprintf(fd_dump, "P1\n"); - fprintf(fd_dump, "%d %d\n", page_width_int, page_height_int); - for (int i=0; ix) / conf_map_part_width; // CHECK ME: Is rounding needed? - int x_max = min2(page_width_int, (p->x + v.width)) / conf_map_part_width; + int x_max = min2(page_width_int, (p->x + v.width / bitmap_granularity)) / conf_map_part_width; int y_min = max2(0, p->y) / conf_map_part_height; // CHECK ME: Is rounding needed? - int y_max = min2(page_height_int, (p->y + v.height)) / conf_map_part_height; + int y_max = min2(page_height_int, (p->y + v.height / bitmap_granularity)) / conf_map_part_height; DEBUG(dbg_map_parts, VERBOSITY_PLACEMENT, "Cells between [%d; %d] and [%d; %d] generated\n", x_min, y_min, x_max, y_max); @@ -252,7 +266,7 @@ void update_map_parts(struct placement *p) update_map_parts_create(p); } -struct placement **get_closure(struct placement *placement) +struct placement **get_closure(struct placement *placement, struct individual *other) { struct placement **closure; GARY_INIT(closure, 0); @@ -266,7 +280,7 @@ struct placement **get_closure(struct placement *placement) while (first < GARY_SIZE(closure)) { DEBUG(dbg_breeding, VERBOSITY_ALL, "Iterating, first is %u of current %zu\n", first, GARY_SIZE(closure)); - struct placement **overlapping = get_overlapping(placement); + struct placement **overlapping = get_overlapping_in(closure[first], other); if (! overlapping) { first++; continue; } struct placement **filtered = filter(overlapping, &chosen); @@ -279,7 +293,8 @@ struct placement **get_closure(struct placement *placement) { if (overlaps(*p, overlapping[j])) { - p = GARY_PUSH(closure); *p = overlapping[j]; + p = GARY_PUSH(closure); + *p = &(placement->individual->placements[overlapping[j]->request->ind]); DEBUG(dbg_breeding, VERBOSITY_ALL, "Adding placement of request %d (in fact at [%.2f; %.2f] of size %d x %d)\n", overlapping[j]->request->ind, overlapping[j]->x, overlapping[j]->y, overlapping[j]->request->variants[overlapping[j]->variant_used].width, overlapping[j]->request->variants[overlapping[j]->variant_used].height); chosen[overlapping[j]->request->ind] = 1; } @@ -294,7 +309,7 @@ struct placement **get_closure(struct placement *placement) return closure; } -static struct placement **get_overlapping(struct placement *p) +static struct placement **get_overlapping_in(struct placement *p, struct individual *individual) { struct placement **buffer; GARY_INIT(buffer, 0); @@ -304,7 +319,7 @@ static struct placement **get_overlapping(struct placement *p) for (uns i=0; iplacement->next_in_map; + struct map_placement *mp = individual->map[parts[i]->ind]->placement->next_in_map; while (mp) { if (p->variant_used >= 0) @@ -342,18 +357,42 @@ static int overlaps(struct placement *p1, struct placement *p2) v1 = &(p1->request->variants[p1->variant_used]); v2 = &(p2->request->variants[p2->variant_used]); - // FIXME: This doesn't fully respect offset which it probably should - int p1x = p1->x; int p1y = p1->y; - int p2x = p2->x; int p2y = p2->y; + int x1, x2; + // FIXME: CHECK ME: Is rounding working all right here? + if (p1->x > p2->x) + { + x1 = 0; + x2 = (p1->x - p2->y) * bitmap_granularity; + } + else + { + x1 = (p2->x - p1->x) * bitmap_granularity; + x2 = 0; + } + + int max_iter_x = min2(v1->width-1-x1, v2->width-1-x2); + + int y1, y2; + if (p1->y > p2->y) + { + y1 = 0; + y2 = (p1->y - p2->y) * bitmap_granularity; + } + else + { + y1 = (p2->y - p1->y) * bitmap_granularity; + y2 = 0; + } + + int max_iter_y = min2(v1->width-1-y1, v2->width-1-y2); int overlap = 0; - for (int y=max2(0, max2(p1y, p2y)); yheight, p2y+v2->height)); y++) - for (int x=max2(0, max2(p1x, p2x)); xwidth, p2x+v2->width)); x++) - { - if (v1->bitmap[(y-p1y)*v1->width + (x-p1x)] && - v2->bitmap[(y-p2y)*v2->width + (x-p2x)]) + for (int j=0; jbitmap[y1*v1->width + x1] && v2->bitmap[y2*v2->width + x2]) overlap++; } + } return overlap; } @@ -409,13 +448,13 @@ int get_overlap(struct placement *p, int **planned_ptr, int iteration) //dump_placement_links(p); } - if (p->x < 0) overlap += 0 - p->x; - if (p->x + p->request->variants[p->variant_used].width > page_width_int) - overlap += p->x + p->request->variants[p->variant_used].width - page_width_int; + if (p->x < 0) overlap += (0 - p->x) * bitmap_granularity; + if (p->x + p->request->variants[p->variant_used].width * bitmap_granularity > page_width) + overlap += p->x + p->request->variants[p->variant_used].width * bitmap_granularity - page_width; - if (p->y < 0) overlap += 0 - p->y; - if (p->y + p->request->variants[p->variant_used].height > page_height_int) - overlap += p->y + p->request->variants[p->variant_used].height - page_height_int; + if (p->y < 0) overlap += (0 - p->y) * bitmap_granularity; + if (p->y + p->request->variants[p->variant_used].height * bitmap_granularity > page_height) + overlap += p->y + p->request->variants[p->variant_used].height * bitmap_granularity - page_height; return overlap; }