#include "sym.h"
#include "map.h"
#include "graph.h"
+#include "simplify.h"
uns debug_dump_source, debug_dump_after_proj, debug_dump_after_scaling;
uns debug_dump_multipolygons, debug_dump_css, debug_dump_styling, debug_dump_symbols;
}
};
+#if 0
// FIXME: Make generic
static void draw_scale(struct svg *svg)
{
scale_text(svg, width, 5, osm_val_encode("1 km"));
svg_pop(svg);
}
+#endif
int main(int argc UNUSED, char **argv)
{
styles_init();
map_load_styles();
map_load_sources();
+ simplify();
graph_build();
map_set_scale();
map_generalize();
--- /dev/null
+/*
+ * Hic Est Leo -- Map Simplification
+ *
+ * (c) 2022 Martin Mares <mj@ucw.cz>
+ */
+
+#include "leo.h"
+
+#include <ucw/lib.h>
+#include <ucw/clists.h>
+#include <ucw/mempool.h>
+
+#include <stdio.h>
+#include <math.h>
+
+#include "osm.h"
+#include "map.h"
+#include "simplify.h"
+
+static struct mempool *simp_pool;
+
+struct coords {
+ double x, y;
+};
+
+struct simp_node_ref {
+ cnode n;
+ struct osm_node *to;
+};
+
+struct simp_way_ref {
+ cnode n;
+ struct osm_way *to;
+ bool is_end;
+};
+
+struct simp_node {
+ union {
+ struct coords c;
+ byte raw_coords[sizeof(struct coords)];
+ };
+ clist node_refs;
+ clist way_refs;
+ byte can_be_merged;
+};
+
+static void simp_hash_init_data(struct simp_node *s)
+{
+ clist_init(&s->node_refs);
+ clist_init(&s->way_refs);
+ s->can_be_merged = false;
+}
+
+#define HASH_NODE struct simp_node
+#define HASH_PREFIX(x) simp_hash_##x
+#define HASH_KEY_MEMORY raw_coords
+#define HASH_KEY_SIZE sizeof(struct coords)
+#define HASH_WANT_LOOKUP
+#define HASH_GIVE_INIT_DATA
+#define HASH_USE_POOL simp_pool
+#define HASH_TABLE_ALLOC
+#include <ucw/hashtable.h>
+
+static bool simp_can_be_merged(struct simp_node *s)
+{
+ uint num_nodes = clist_size(&s->node_refs);
+ uint num_ways = clist_size(&s->way_refs);
+
+ ASSERT(num_nodes);
+ if (num_nodes > 1)
+ {
+ msg(L_WARN, "Simplify: Multiple (%u) nodes at [%f, %f]", num_nodes, s->c.x, s->c.y);
+ return false;
+ }
+
+ if (num_ways > 2)
+ return false;
+
+ return false;
+}
+
+static void simplify_source(struct data_source *ds)
+{
+ msg(L_INFO, "Simplifying source %s", ds->file);
+ simp_pool = mp_new(65536);
+ simp_hash_init();
+ osm_this = ds->osm;
+
+ CLIST_FOR_EACH(struct osm_way *, w, osm_this->obj_list[OSM_TYPE_WAY])
+ {
+ struct osm_node *n_first = (struct osm_node *) osm_ref_head(&w->nodes);
+ struct osm_node *n_last = (struct osm_node *) osm_ref_tail(&w->nodes);
+
+ OSM_FOR_EACH_BEGIN(struct osm_node *, n, w->nodes)
+ {
+ struct coords c = { .x = n->x, .y = n->y };
+ struct simp_node *s = simp_hash_lookup((byte *) &c);
+
+ struct simp_node_ref *nref = mp_alloc(simp_pool, sizeof(*nref));
+ nref->to = n;
+ clist_add_tail(&s->node_refs, &nref->n);
+
+ struct simp_way_ref *wref = mp_alloc(simp_pool, sizeof(*wref));
+ wref->to = w;
+ wref->is_end = (n == n_first || n == n_last);
+ clist_add_tail(&s->way_refs, &wref->n);
+ }
+ OSM_FOR_EACH_END;
+ }
+
+ HASH_FOR_ALL(simp_hash, s)
+ {
+ s->can_be_merged = simp_can_be_merged(s);
+ }
+ HASH_END_FOR;
+
+ mp_delete(simp_pool);
+}
+
+void simplify(void)
+{
+ CLIST_FOR_EACH(struct data_source *, ds, map_sources)
+ simplify_source(ds);
+}