#include "leo.h"
#include "sym.h"
+#include "map.h"
#include "labeller.h"
#include "lab-bitmaps.h"
#include "lab-utils.h"
static struct map_part **get_map_parts(struct placement *p);
static struct placement **get_overlapping(struct placement *p);
+double bitmap_granularity = 1;
+
+int page_width_gran, page_height_gran;
+
void make_bitmap(struct variant *v, struct symbol *sym)
{
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; i<page_height_int; i++)
- for (int j=0; j<page_width_int; j++)
- bitmap[i*page_width_int + j] = 0;
+ bool *bitmap = xmalloc(page_width_gran * page_height_gran * sizeof(bool));
+ printf("Bitmap size is %d\n", page_width_gran * page_height_gran);
+ for (int i=0; i<page_height_gran; i++)
+ for (int j=0; j<page_width_gran; j++)
+ bitmap[i*page_width_gran + j] = 0;
int total = 0;
for (uns i=0; i<GARY_SIZE(individual->placements); i++)
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])
{
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; i<page_height_int; i++)
+ fprintf(fd_dump, "%d %d\n", page_width_gran, page_height_gran);
+ for (int i=0; i<page_height_gran; i++)
{
- for (int j=0; j<page_width_int; j++)
+ for (int j=0; j<page_width_gran; j++)
{
- fprintf(fd_dump, "%d", bitmap[(int) (i*page_width_int + j)] ? 1 : 0);
+ fprintf(fd_dump, "%d", bitmap[(int) (i*page_width_int*bitmap_granularity + j)] ? 1 : 0);
}
fprintf(fd_dump, "\n");
}
int x_min = max2(0, p->x) / 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);
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)); y<min2(page_height_int, min2(p1y+v1->height, p2y+v2->height)); y++)
- for (int x=max2(0, max2(p1x, p2x)); x<min2(page_width_int, min2(p1x+v1->width, 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; j<max_iter_y; j++, y1++, y2++) {
+ for (int i=0; i<max_iter_x; i++, x1++, x2++) {
+ if (v1->bitmap[y1*v1->width + x1] && v2->bitmap[y2*v2->width + x2])
overlap++;
}
+ }
return overlap;
}
//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;
}
#include <stdio.h>
#include <math.h>
#include <ucw/lib.h>
+#include <ucw/conf.h>
#include "leo.h"
#include "sym.h"
uns num_map_parts_col = 0;
uns num_map_parts = 0;
+static struct cf_section labelling_cf = {
+ CF_ITEMS {
+ CF_DOUBLE("MaxSectionLenght", &conf_max_section_length),
+ CF_DOUBLE("MaxSectionOverlay", &conf_max_section_overlay),
+ CF_DOUBLE("BitmapGranularity", &bitmap_granularity),
+ CF_END
+ }
+};
+
static void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t zindex);
static void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t zindex);
page_width_int = floor(page_width);
page_height_int = floor(page_height);
+ page_width_gran = page_width * bitmap_granularity;
+ page_height_gran = page_height * bitmap_granularity;
+
num_map_parts_row = (page_width_int + conf_map_part_width) / conf_map_part_width;
num_map_parts_col = (page_height_int + conf_map_part_height) / conf_map_part_height;
num_map_parts = num_map_parts_row * num_map_parts_col;
void labeller_conf(void)
{
+ cf_declare_section("Labelling", &labelling_cf, 0);
evolution_conf();
- lines_conf();
}
void labeller_init(void)