|
|
|
|
@ -34,6 +34,7 @@
|
|
|
|
|
#include "map.h"
|
|
|
|
|
#include "system.h"
|
|
|
|
|
#include "memoryleak.h"
|
|
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
@ -190,6 +191,7 @@ void osm_waynodes_checknode (struct s_osm_hashnodes *nhash, struct osm_node *nod
|
|
|
|
|
|
|
|
|
|
void osm_marea_new (struct s_osmmarea *a, int max);
|
|
|
|
|
void osm_area_save (struct osm_way *oway, struct s_osmmarea *marea);
|
|
|
|
|
int osm_area_split_add (struct s_osmmarea *marea);
|
|
|
|
|
|
|
|
|
|
void osm_nodedetail_save (struct osm_nodedetail *onoded, struct osm_node *node);
|
|
|
|
|
|
|
|
|
|
@ -696,7 +698,8 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
|
|
|
|
|
do {
|
|
|
|
|
lseek (hnodes->nodes_fd, wpos, SEEK_SET);
|
|
|
|
|
if (read (hnodes->nodes_fd, &wn, sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__,
|
|
|
|
|
hnodes->fnnodes, hash.pos);
|
|
|
|
|
errorexit (-1);
|
|
|
|
|
}
|
|
|
|
|
wpos = wn.next;
|
|
|
|
|
@ -707,7 +710,8 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
|
|
|
|
|
pos = 0 - (long long int)sizeof (struct osm_waynode);
|
|
|
|
|
lseek (hnodes->nodes_fd, pos, SEEK_CUR);
|
|
|
|
|
if (write (hnodes->nodes_fd, &wn, sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
|
|
|
|
|
d_printf ("%s:%d could not write data to file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
|
|
|
|
|
d_printf ("%s:%d could not write data to file:%s pos:%d", __FILE__, __LINE__,
|
|
|
|
|
hnodes->fnnodes, hash.pos);
|
|
|
|
|
errorexit (-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -719,7 +723,6 @@ void osm_waynode_add (struct osm_node *node, long long int nodepos, unsigned lon
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, hnodes->fnnodes, hash.pos);
|
|
|
|
|
errorexit (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -741,7 +744,8 @@ void osm_waynodes_check () {
|
|
|
|
|
/* read node */
|
|
|
|
|
lseek (ohash->nodes_fd, ohash->hash[i].pos, SEEK_SET);
|
|
|
|
|
if (read (ohash->nodes_fd, &node, sizeof (struct osm_node)) < sizeof (struct osm_node)) {
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, ohash->fnnodes, ohash->hash[i].pos);
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__,
|
|
|
|
|
ohash->fnnodes, ohash->hash[i].pos);
|
|
|
|
|
errorexit (-1);
|
|
|
|
|
}
|
|
|
|
|
osm_waynodes_checknode (ohash, &node);
|
|
|
|
|
@ -777,7 +781,8 @@ void osm_waynodes_checknode (struct s_osm_hashnodes *ohash, struct osm_node *nod
|
|
|
|
|
do {
|
|
|
|
|
/* read waynode */
|
|
|
|
|
if (read (ohash->nodes_fd, &osm_wnode[wncnt], sizeof (struct osm_waynode)) < sizeof (struct osm_waynode)) {
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d", __FILE__, __LINE__, ohash->fnnodes, osm_wnode[wncnt].next);
|
|
|
|
|
d_printf ("%s:%d could not read data from file:%s pos:%d",
|
|
|
|
|
__FILE__, __LINE__, ohash->fnnodes, osm_wnode[wncnt].next);
|
|
|
|
|
errorexit (-1);
|
|
|
|
|
}
|
|
|
|
|
lseek (ohash->nodes_fd, osm_wnode[wncnt].next, SEEK_SET);
|
|
|
|
|
@ -1036,6 +1041,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
|
|
|
|
|
static int nodestat_alloc = 0; // size of the struct
|
|
|
|
|
struct map_pos pos, p1; // current hash, pos
|
|
|
|
|
struct osm_node curnode, node; // current node, node
|
|
|
|
|
int sid = 0;
|
|
|
|
|
|
|
|
|
|
/* check if we just need to free all data */
|
|
|
|
|
if (oway == NULL) {
|
|
|
|
|
@ -1105,6 +1111,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
|
|
|
|
|
|
|
|
|
|
/* save first node */
|
|
|
|
|
area->marea->id = oway->wid;
|
|
|
|
|
area->marea->subid = sid;
|
|
|
|
|
area->marea->type = oway->type;
|
|
|
|
|
area->marea->p_cnt = 1;
|
|
|
|
|
area->marea->p = (struct map_pos *) area->marea->data;
|
|
|
|
|
@ -1120,7 +1127,8 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
|
|
|
|
|
if (++nd >= oway->ncnt) nd = 0; /* count +1, check for overrun */
|
|
|
|
|
while (nd != ndfirst) {
|
|
|
|
|
if (osm_node_load (&node, oway->nid[nd]) == -1) {
|
|
|
|
|
d_printf ("%s:%d osm_area_save count not find node number: %lld", __FILE__, __LINE__, oway->nid[nd]);
|
|
|
|
|
d_printf ("%s:%d osm_area_save count not find node number: %lld",
|
|
|
|
|
__FILE__, __LINE__, oway->nid[nd]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pos.lon = node.lon;
|
|
|
|
|
@ -1150,7 +1158,7 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
|
|
|
|
|
}
|
|
|
|
|
if (++nd >= oway->ncnt) nd = 0; /* count +1, check for overrun */
|
|
|
|
|
}
|
|
|
|
|
map_area_add (area->marea, MHLOAD_RELOAD);
|
|
|
|
|
osm_area_split_add (area);
|
|
|
|
|
}
|
|
|
|
|
} while (ndfirst < oway->ncnt);
|
|
|
|
|
|
|
|
|
|
@ -1158,6 +1166,196 @@ void osm_area_save (struct osm_way *oway, struct s_osmmarea *area ) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* convert area into a polygon without angles above 180°
|
|
|
|
|
* it saves time late in drawing on slow devices.
|
|
|
|
|
* only needed because of GL_TRIANGLE_STRIP and return
|
|
|
|
|
* last subid saved.
|
|
|
|
|
*/
|
|
|
|
|
struct s_osmareapnt {
|
|
|
|
|
int pnr;
|
|
|
|
|
fPoint km;
|
|
|
|
|
float angle;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int osm_area_split_add (struct s_osmmarea *marea) {
|
|
|
|
|
/* allocate enought memory */
|
|
|
|
|
struct map_area *a = NULL;
|
|
|
|
|
struct s_osmareapnt *pall = ml_malloc (sizeof (struct s_osmareapnt) * marea->marea->p_cnt);
|
|
|
|
|
int pall_cnt = marea->marea->p_cnt;
|
|
|
|
|
int i, j, c, k, smaller;
|
|
|
|
|
int _debug = 0;
|
|
|
|
|
|
|
|
|
|
// if (marea->marea->id == 29225778) _debug = 1;
|
|
|
|
|
// else return 1;
|
|
|
|
|
// d_printf ("marea: %lld cnt:%d", marea->marea->id, marea->marea->p_cnt);
|
|
|
|
|
// map_area_add (marea->marea, MHLOAD_RELOAD);
|
|
|
|
|
// return 1;
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("area:%lld:%d", marea->marea->id, marea->marea->subid);
|
|
|
|
|
a = ml_malloc (map_area_getsize (marea->marea));
|
|
|
|
|
map_area_copy (a, marea->marea);
|
|
|
|
|
|
|
|
|
|
/* calculate all klon, klat and prepare start struct, also
|
|
|
|
|
* ignore double entrys */
|
|
|
|
|
for (c = 0, i = 0; i < marea->marea->p_cnt; i++) {
|
|
|
|
|
if (i == 0) j = marea->marea->p_cnt-1;
|
|
|
|
|
else j = i-1;
|
|
|
|
|
|
|
|
|
|
if (marea->marea->p[i].lon == marea->marea->p[j].lon
|
|
|
|
|
&& marea->marea->p[i].lat == marea->marea->p[j].lat) continue;
|
|
|
|
|
|
|
|
|
|
pall[c].pnr = i;
|
|
|
|
|
pall[c].km.x = map_lon2km (marea->marea->p[i].lon, marea->marea->p[i].lat);
|
|
|
|
|
pall[c].km.y = map_lat2km (marea->marea->p[i].lat);
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
pall_cnt = c;
|
|
|
|
|
|
|
|
|
|
while (pall[0].pnr >= 0 && pall_cnt > 2) {
|
|
|
|
|
/* j - will keep first ptr to start checking polygon
|
|
|
|
|
* c - counter how many angles > 180° */
|
|
|
|
|
// d_printf ("**************** subid:%d pallcnt:%d", a->subid, pall_cnt);
|
|
|
|
|
for (smaller = 0, j = -1, c = 0, i = 0; i < pall_cnt; i++) {
|
|
|
|
|
if (i == pall_cnt-1) pall[i].angle = point_angle (pall[i-1].km, pall[i].km, pall[0].km);
|
|
|
|
|
else if (i == 0) pall[i].angle = point_angle (pall[pall_cnt-1].km, pall[i].km, pall[i+1].km);
|
|
|
|
|
else pall[i].angle = point_angle (pall[i-1].km, pall[i].km, pall[i+1].km);
|
|
|
|
|
if (pall[i].angle > M_PI) {
|
|
|
|
|
if (j == -1 ||j+1 == i) j = i;
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
else smaller = 1;
|
|
|
|
|
// if (_debug) d_printf ("i:%-2d pnr:%-2d angle:%f",i, pall[i].pnr, pall[i].angle);
|
|
|
|
|
}
|
|
|
|
|
// if (_debug) d_printf ("c:%d pall_cnt:%d j:%d",c, pall_cnt, j);
|
|
|
|
|
|
|
|
|
|
/* if all angles are abover 180° turn rotation around */
|
|
|
|
|
if (smaller == 0) {
|
|
|
|
|
struct s_osmareapnt *pall_ = ml_malloc (sizeof (struct s_osmareapnt) * pall_cnt);
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("change rotation ...");
|
|
|
|
|
for (i = 0; i < pall_cnt; i++) pall_[pall_cnt - i - 1] = pall[i];
|
|
|
|
|
ml_free (pall);
|
|
|
|
|
pall = pall_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if c==0 save last areapart */
|
|
|
|
|
else if (c == 0) {
|
|
|
|
|
for (i = 0; i < pall_cnt; i++) {
|
|
|
|
|
// if (_debug) d_printf ("0: added %d pnr:%d", k, pall[i].pnr);
|
|
|
|
|
a->p[i] = marea->marea->p[pall[i].pnr];
|
|
|
|
|
pall[i].pnr = -1;
|
|
|
|
|
}
|
|
|
|
|
a->p_cnt = pall_cnt;
|
|
|
|
|
map_area_add (a, MHLOAD_RELOAD);
|
|
|
|
|
a->subid++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* if c==1 select j as 0 then quit, if GL_TRIANGLE_STRIP gets kicked out of
|
|
|
|
|
* openGL we need to change this */
|
|
|
|
|
else if (c == 1) {
|
|
|
|
|
for (k = 0, i = j; k < pall_cnt;) {
|
|
|
|
|
// if (_debug) d_printf ("1: added %d pnr:%d", k, pall[i].pnr);
|
|
|
|
|
a->p[k++] = marea->marea->p[pall[i].pnr];
|
|
|
|
|
pall[i].pnr = -1;
|
|
|
|
|
|
|
|
|
|
if (i < pall_cnt-1) i++;
|
|
|
|
|
else i = 0;
|
|
|
|
|
}
|
|
|
|
|
a->p_cnt = pall_cnt;
|
|
|
|
|
map_area_add (a, MHLOAD_RELOAD);
|
|
|
|
|
a->subid++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* check again for the part to split the area. */
|
|
|
|
|
else {
|
|
|
|
|
float angle;
|
|
|
|
|
int s; /* second point */
|
|
|
|
|
float angle_old; /* old value */
|
|
|
|
|
int i_old;
|
|
|
|
|
int pnr_old;
|
|
|
|
|
|
|
|
|
|
k = 0;
|
|
|
|
|
i = j;
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("added %d pnr:%d", k, pall[i].pnr);
|
|
|
|
|
a->p[k++] = marea->marea->p[pall[i].pnr]; /* copy first point */
|
|
|
|
|
if (i < pall_cnt-1) i++; /* increase */
|
|
|
|
|
else i = 0;
|
|
|
|
|
|
|
|
|
|
i_old = s = i;
|
|
|
|
|
angle_old = angle = 0.0;
|
|
|
|
|
if (_debug) d_printf ("pall_cnt:%d c:%d s:%d j:%d", pall_cnt, c, s, j);
|
|
|
|
|
|
|
|
|
|
/* loop as long as angle is increasing and below 180° */
|
|
|
|
|
for (; i != j && angle_old <= angle && angle <= M_PI;) {
|
|
|
|
|
angle_old = angle; /* save old values */
|
|
|
|
|
i_old = i;
|
|
|
|
|
pnr_old = pall[i].pnr;
|
|
|
|
|
// if (_debug) d_printf ("added %d pnr:%d", k, pall[i].pnr);
|
|
|
|
|
a->p[k++] = marea->marea->p[pall[i].pnr]; /* copy point */
|
|
|
|
|
pall[i].pnr = -1;
|
|
|
|
|
|
|
|
|
|
if (i < pall_cnt-1) i++; /* increase */
|
|
|
|
|
else i = 0;
|
|
|
|
|
angle = point_angle (pall[i].km, pall[j].km, pall[s].km);
|
|
|
|
|
// if (_debug) d_printf ("k:%d next angle:%f angle_old:%f pall[%d].angle:%f nr:%d", k, angle, angle_old, i, pall[i].angle, pall[i].pnr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("j:%d i:%d s:%d k:%d angle:%f angle_old:%f pall[i].angle:%f",
|
|
|
|
|
// j, i, s, k, angle, angle_old, pall[i].angle);
|
|
|
|
|
|
|
|
|
|
// /* last visible point */
|
|
|
|
|
// if (pall[i].angle > M_PI) {
|
|
|
|
|
// if (_debug) d_printf ("added %d pnr:%d", k, pall[i].pnr);
|
|
|
|
|
// a->p[k++] = marea->marea->p[pall[i].pnr]; /* copy point */
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
if (angle_old > angle) {
|
|
|
|
|
pall[i_old].pnr = pnr_old;
|
|
|
|
|
}
|
|
|
|
|
else if (angle > M_PI) {
|
|
|
|
|
pall[i_old].pnr = pnr_old;
|
|
|
|
|
}
|
|
|
|
|
else if (i == j) {
|
|
|
|
|
d_printf ("%s:%d i(%d) == j(%d) finished?", __FILE__, __LINE__, i, j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("j:%d i:%d s:%d k:%d angle:%f angle_old:%f pall[i].angle:%f",
|
|
|
|
|
// j, i, s, k, angle, angle_old, pall[i].angle);
|
|
|
|
|
|
|
|
|
|
/* add element */
|
|
|
|
|
a->p_cnt = k;
|
|
|
|
|
map_area_add (a, MHLOAD_RELOAD);
|
|
|
|
|
a->subid++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* recreate pall list, delete unneeded elements (pnr == -1) */
|
|
|
|
|
for (k = 0, i = 0; i < pall_cnt; i++)
|
|
|
|
|
if (pall[i].pnr != -1) {
|
|
|
|
|
pall[k++] = pall[i];
|
|
|
|
|
// if (_debug) d_printf (" old:%-2d new:%-2d pnr:%d", i, k, pall[i].pnr);
|
|
|
|
|
}
|
|
|
|
|
pall_cnt = k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (_debug) d_printf ("j:%d c:%d", j, c);
|
|
|
|
|
if (pall[0].pnr >= 0 && pall_cnt > 0) {
|
|
|
|
|
d_printf ("%s:%d osm_area_split_add: something went very wrong", __FILE__, __LINE__);
|
|
|
|
|
d_printf (" marea->id: %lld:%d", marea->marea->id, marea->marea->subid);
|
|
|
|
|
d_printf (" pall[0].pnr:%d pall_cnt: %d", pall[0].pnr, pall_cnt);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* free unneeded memory and return to caller */
|
|
|
|
|
ml_free (a);
|
|
|
|
|
ml_free (pall);
|
|
|
|
|
|
|
|
|
|
return a->subid;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
|
* save detail information of the node. This will also create the
|
|
|
|
|
|