X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=labeller.h;h=3bd13e5f1e7204e2ac52fd9932d6a3b0d887c6b2;hb=refs%2Fheads%2Flabelling;hp=8f1b0fad9637b17c5176176878c087422e8a9bd0;hpb=2dda46b6d1cebc5205f7f98b4db4dcae40c11e55;p=leo.git diff --git a/labeller.h b/labeller.h index 8f1b0fa..3bd13e5 100644 --- a/labeller.h +++ b/labeller.h @@ -1,211 +1,178 @@ #ifndef _LEO_LABELLER_H #define _LEO_LABELLER_H -enum label_type -{ - LABEL_POINT, - LABEL_LINE, - LABEL_AREA, -}; +#include "lab-utils.h" + +/* +* Requests for point refer directly to point symbols that should be placed. +* Line and area requests are in fact requests for labels (either symbols or +* textual labels) of such objects. +* Area requests are taken quite as-is, +* line requests are broken into section and segment requests -- each line +* is broken into sections of maximal length and each section is made of segments +* which correspond to OSM ways. +* For each line, exactly one segment of each section is labelled in the output. +*/ enum request_type { + REQUEST_INVALID, REQUEST_POINT, - REQUEST_AREALABEL, - REQUEST_LINELABEL, + REQUEST_AREA, + REQUEST_LINE, + REQUEST_SECTION, REQUEST_SEGMENT, }; -enum term_cond +struct variant { - TERM_COND_PENALTY, - TERM_COND_STAGNATION, - TERM_COND_ITERATIONS, -}; - -struct sym_placement -{ - double x; - double y; - int variant; - struct request *request; + int width; + int height; + int offset_x; // Desired offset of top-left corner with respect to + int offset_y; // actual coordinates of corresponding object + bool *bitmap; // Mask having 1s where the variant is not blank; used for overlap check }; struct request { enum request_type type; - int ind; -}; - -struct point_variant -{ - double width; - double height; - bool *bitmap; -}; - -struct line_variant -{ - bool *masks; + int ind; // Index used whenever request indexing is needed + struct variant *variants; // Growing array of all variants usable for this request }; struct request_point { struct request request; struct symbol *sym; - struct osm_object *object; // FIXME: Linked also by sym - z_index_t zindex; + z_index_t zindex; // Needed when planning symbol double x; double y; - double offset_x; - double offset_y; - int num_variants; - struct point_variant *variants; }; struct request_segment { struct request request; - double x1; + struct symbol *label; + double x1; // Start and end of segment double y1; double x2; double y2; - double k; - struct sym_line *sym; - struct point_variant *variant; - struct sym_text *text; - z_index_t zindex; + double slope; // Used to calculate label rotation + z_index_t zindex; // Needed when planning symbol +}; + +struct request_section +{ + struct request request; + struct request_segment *segments; // Growing array }; struct request_line { struct request request; - struct symbol *sym; - int num_variants; - int num_segments; - struct line_variant *variants; - struct request_segment *segments; + struct symbol *line; + struct request_section *sections; // Growing array }; struct request_area { struct request request; struct osm_multipolygon *o; - struct sym_text *sym; - struct point_variant *text_variant; + struct symbol *label; z_index_t zindex; + double cx, cy; // Area center (coordinates average), used as reference coordinates }; +// Buffer for lines (osm_ways) added via labeller_notify_line, +// used to make graph and join lines which should be labelled as one object struct buffer_line { struct sym_line *line; - z_index_t zindex; }; +// Buffer for line labes, +// used to label graph -- join logical lines with their labels struct buffer_linelabel { struct osm_way *way; - struct sym_text *text; + struct symbol *label; z_index_t zindex; }; -struct graph_node -{ - osm_id_t id; - struct osm_node *o; - struct graph_edge **edges; -}; - -struct graph_edge -{ - osm_id_t id; - double length; - color_t color; - bool visited; - struct graph_edge *prev; - struct graph_edge *next; - struct graph_node *n1; - struct graph_node *n2; - uns longline; - struct sym_text *text; - struct sym_line *sym; - z_index_t zindex; -}; - -struct longline -{ - uns id; - struct graph_edge *first; -}; - struct placement { - double x; - double y; - int variant_used; - bool processed; struct request *request; + struct individual *individual;// FIXME: Is it needed? + double x; // Coordinates of variant top-left corner placement + double y; + int variant_used; // Variant chosen for request in this placement + int ind; // Index used whenever placement indexing is needed + bool processed; // FIXME: Is it needed? + // FIXME: Replace with clist? + struct map_placement *map_links; }; -struct map_part +struct map_placement { + struct placement *placement; + struct map_part *part; + struct map_placement *next_in_map; + struct map_placement *prev_in_map; + struct map_placement *next_in_placement; + struct map_placement *prev_in_placement; }; -struct individual +struct map_part { - struct placement *placements; - struct map_part **map; - int penalty; + // FIXME: Replace with clist? + struct map_placement *placement; + int ind; }; +void labeller_conf(void); void labeller_init(void); -void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex); -void labeller_add_line(struct symbol *sym, z_index_t zindex); -void labeller_label(void); -void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t zindex); -void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t zindex); - -void make_bitmap_icon(struct point_variant *v, struct sym_icon *si); -void make_bitmap_point(struct point_variant *v, struct sym_point *sp); -void make_bitmap_label(struct point_variant *v, struct sym_text *text); - -void make_graph(void); -void label_graph(void); -void join_edge(struct graph_edge *e, int dir); -void bfs(void); -void make_segments(void); - -void make_population(void); -bool shall_terminate(void); -void breed(void); -void mutate(void); -void elite(void); -void rank_population(void); - -struct individual **perform_crossover(struct individual *parent1, struct individual *parent2); -void perform_mutation(struct individual *individual); +void labeller_cleanup(void); -void init_placement(struct placement *p, struct request *r); -void init_individual(struct individual *i); -void gen_coords_point(struct placement *p); -void gen_coords(struct placement *p); -struct map_part **get_parts(struct placement *symbol, struct individual *individual); - -int randint(int min, int max); - -struct placement **get_closure(struct placement *placement, struct individual *parent1, struct individual *parent2); -void copy_symbols(struct placement **closure, struct individual *parent, struct individual *child); -void move_symbol(struct placement *p); -void move_symbol_point(struct placement *p); - -struct placement **get_overlapping(struct placement *p); -void filter(struct placement **list, bool *pred); - -int flip(int a, int b); -double randdouble(void); +void labeller_label(void); -void cleanup(void); +void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex); +void labeller_notify_line(struct symbol *sym, z_index_t zindex); +void labeller_add_label(struct symbol *sym, struct osm_object *o, z_index_t zindex); + +extern struct request_point *requests_point; +extern struct request_line *requests_line; +extern struct request_area *requests_area; + +extern struct longline *longlines; +extern struct buffer_line *buffer_line; +extern struct buffer_linelabel *buffer_linelabel; + +extern int dbg_segments; +extern int dbg_plan; +extern int dbg_requests; +extern int dbg_graph; +extern int dbg_bfs; +extern int dbg_map_parts; +extern int dbg_movement; +extern int dbg_init; +extern int dbg_overlaps; +extern int dbg_rank; +extern int dbg_evolution; +extern int dbg_mutation; +extern int dbg_breeding; + +extern int page_width_int; +extern int page_height_int; + +extern int num_requests; +extern int num_placements; + +extern int conf_map_part_width; +extern int conf_map_part_height; + +extern uns num_map_parts_row; +extern uns num_map_parts_col; +extern uns num_map_parts; -void copy_individual(struct individual *src, struct individual *dest); #endif