1 #define _USE_MATH_DEFINES
38 double minlat = lat[0], maxlat = lat[0], minlon = lon[0], maxlon = lon[0];
39 KOO* nodes =
new KOO[count];
40 KOO** node =
new KOO*[count];
41 for(
int i = 0; i < count; i++){
42 if(minlat > lat[i]) minlat = lat[i];
43 if(maxlat < lat[i]) maxlat = lat[i];
44 if(minlon > lon[i]) minlon = lon[i];
45 if(maxlon < lon[i]) maxlon = lon[i];
46 nodes[i].
lat = lat[i];
47 nodes[i].lon = lon[i];
51 node[i] = &(nodes[i]);
53 for(
int i = 1; i < count; i++)
54 nodes[i-1].r = &(nodes[i]);
55 nodes[count-1].r = NULL;
72 node[0]->r = node[count-1];
77 h->
reset_t(minlat,maxlat,minlon,maxlon);
85 WayHeight::~WayHeight(){}
97 for(
int i = 1; i<w->
nodec-1 ;i++)
113 k->cd->
s->
from = NULL;
114 k->cd->
s->
via = NULL;
127 for(
int i = 1; i < w->
nodec; i++){
128 d = d + distance(w->
node[i] ->
lat,w->
node[i] ->lon,
133 w->
node[i ],w,d,i-iold+1,fw);
135 w->
node[iold],w,d,i-iold+1,bw);
137 if(n1 != NULL && n2 != NULL){
143 if(n1 != NULL) n1->
brthr = n1;
144 if(n2 != NULL) n2->
brthr = n2;
145 if((n1 != NULL || n2 != NULL)&&w->
node[i] != w->
node[iold])
146 QMessageBox(QMessageBox::NoIcon,
148 "Neighbour add failure").exec();
160 double latmin = 90, latmax = -90, lonmin = 180, lonmax = -180;
166 h->
reset_t(latmin,latmax,lonmin,lonmax);
169 double* lonmin,
double* lonmax){
172 if(w->maxlat > *latmax) *latmax = w->maxlat;
174 if(w->minlat < *latmin) *latmin = w->minlat;
175 if(w->minlon < *lonmin) *lonmin = w->minlon;
188 double t[3] = {0,0,0}, dstep = 0;
190 N = qMax(
long(2),
long(1+ceil(nb->
d/
dstep0)));
192 double d0 = 0, dlon, dlat, di, lon, lat;
193 dstep = nb->
d / (N-1);
196 for(
int i = 0; i < nb->
nodec-1; i++){
201 dlon = (nb->
node[i+1]->lon-nb->
node[i]->lon)/(di/dstep);
203 t[2] = dlon * cos(M_PI/180.*k->
lat);
204 t[1] = dlat / sqrt(t[2]*t[2]+dlat*dlat);
205 t[2] = t[2] / sqrt(t[2]*t[2]+dlat*dlat);
209 dN = (n*dstep-d0)/dstep;
210 lon = nb->
node[i]->lon + dN*dlon;
211 lat = nb->
node[i]->
lat + dN*dlat;
213 while(n < N && n*dstep < d0+di){
217 nb->
tp[N+n].d = float(n*dstep);
219 nb->
tp[ n].d = float(t[0]);
234 nb->
tp[N-2].d = float(t[0]);
241 nb->
tp[2*N-1].d = float((N-1)*dstep);
242 nb->
tp[N-1].d = float(t[0]);
273 for(
long i = 1; i < nb->
tpc-1; i++){
274 nb->
tp[i-1].h = nb->
tp[i-1].h + nb->
tp[i].d + nb->
tp[i-1].d;
275 nb->
tp[i+1].h = nb->
tp[i+1].h + nb->
tp[i].d + nb->
tp[i+1].d;
277 nb->
tp[1 ].h = nb->
tp[1].h
281 + nb->
tp[nb->
tpc-1].d
282 + nb->
tp[nb->
tpc-2].d;
296 for(
int i = 0; i < pi->Pcount; i++)
297 pi->PI[i].dest->h =
float( pi->PI[i].dest->h
298 + pi->src->d*pi->PI[i].cos);
299 pi->src->h = pi->src->h + pi->src->d;
321 double* phi = (
double*)malloc(nbcount*
sizeof(
double)),dlon,dlat;
327 dlon = nb->
node[1]->lon-nb->
node[0]->lon;
329 tp[nbcount] = &(nb->
tp[0]);
334 tp[nbcount] = &(nb->
tp[nb->
tpc-1]);
336 dlon = dlon * cos(nb->
node[0]->
lat/180*M_PI);
337 phi[nbcount] = atan2(dlat,dlon);
344 for(
int i = 0; i < nbcount; i++){
347 p->Pcount = nbcount-1;
354 for(
int j = 0; j < nbcount; j++)
356 p->PI[q].dest = tp[j];
357 p->PI[q].cos = -(cos(phi[i]-phi[j]));
358 if(p->PI[q].cos < 0) p->PI[q].cos = 0;
359 p->SumCos = p->SumCos + p->PI[q].cos;
365 k->cd->
s->
from = pic.next;
396 for(
long i = 1; i < nb->
tpc-1; i++){
397 nb->
tp[i].d = float(nb->
tp[i].h / 4.);
406 pic->src->d = float(pic->src->h / (3 + pic->SumCos));
422 for(
long i = 0; i < nb->
tpc; i++){
423 nb->
tp[i].h = nb->
tp[nb->
tpc+i].h;
424 nb->
tp[i].d = nb->
tp[nb->
tpc+i].d;
440 for(
long i = 0; i < nb->
tpc; i++){
441 nb->
tp[i].h = nb->
tp[i].d;
442 nb->
tp[i].d = nb->
tp[nb->
tpc+i].d;
459 if((n->
rd == fw && n->
tp[0].d > rl)
460 ||(n->
rd == bw && n->
tp[n->
tpc-1].d > rl)){
466 rl = n->
tp[n->
tpc-1].d;
476 double latcorr = cos(k->
lat/180.*M_PI);
478 double dlat = - cos(phi) * 0.08/111./10.;
479 double dlon = - sin(phi)/latcorr * 0.08/111./10.;
484 double grad20 = dxt*dxt + dyt*dyt*latcorr*latcorr,
487 for(
int i = 1; i < 10; i++){
489 dxt = h->
height_t(k->lon+dlon*i,k->
lat+dlat*i,NULL,1);
490 dyt = h->
height_t(k->lon+dlon*i,k->
lat+dlat*i,NULL,2);
491 if( dxt*dxt + dyt*dyt*latcorr*latcorr < grad2*0.9){
494 grad2 = dxt*dxt + dyt*dyt*latcorr*latcorr;
504 h->
height_t(k->lon+irl*dlon,k->
lat+irl*dlat,NULL,0)
505 - h->
height_t(k->lon+10*dlon,k->
lat+irl*dlat,NULL,0) < 5
509 double newheight = h->
height_t(k->lon+dlon*irl,
510 k->
lat+dlat*irl,NULL,0);
511 double dh = h->
height_t(k->lon,k->
lat,NULL,0) - newheight;
516 for(
long i = n->
tpc; i < 2*n->tpc -1; i++){
517 n->
tp[i].h = float(n->
tp[i].h
518 - (n->
d - n->
tp[i].d)/n->
d * dh);
522 for(
long i = n->
tpc; i < 2*n->tpc; i++){
523 n->
tp[i].h = float(n->
tp[i].h
524 - ( n->
tp[i].d)/n->
d * dh);
529 if(n->
rd == fw)n->
tp[0].h = float(newheight);
530 else n->
tp[n->
tpc-1].h = float(newheight);
559 double d0 = n->
tp[n->
tpc + s].d, d1 = n->
tp[n->
tpc + e].d;
562 double h0 = n->
tp[n->
tpc + s].h, h1 = n->
tp[n->
tpc + e].h;
565 long max= 0, min = 0, maxur = 0, minur = 0;
566 double maxh = 0, minh = 0, maxhur = 0, minhur = 0;
568 for(
long i = s + 1; i < e - 1; i++){
570 dh = n->
tp[n->
tpc + i].h - (h0 + (n->
tp[n->
tpc + i].d-d0)*grd);
574 if(dh > maxh){ maxh = dh; max = i;}
575 if(dh < minh && n->tp[i].d <
rlimit){ minh = dh; min = i;}
580 if(dh > maxhur){ maxhur = dh; maxur = i;}
581 if(dh < minhur){ minhur = dh; minur = i;}
586 if( min > 0 && max > 0){
587 long first = qMin(min,max);
588 long second = qMax(min,max);
609 if( min == 0 && max == 0 && (minur != 0 || maxur != 0)){
610 if( minhur + maxhur <= 0
611 && n->
tp[n->
tpc + minur].h > qMin(h0,h1)
612 && n->
tp[n->
tpc + minur].h < qMax(h0,h1)){
618 && n->
tp[n->
tpc + maxur].h > qMin(h0,h1)
619 && n->
tp[n->
tpc + maxur].h < qMax(h0,h1)){
630 for(
long i = n->
tpc + s + 1; i < n->tpc + e; i++){
638 for(
long i = n->
tpc; i < 2*n->tpc; i++){
646 for(
long i = n->
tpc; i < 2*n->tpc; i++)
662 float hmup = 0, hmdown = 0;
663 for(
long i = 0; i < n->
tpc-1; i++)
664 if(n->
tp[i].h < n->
tp[i+1].h) hmup = hmup
665 + (n->
tp[i+1].h - n->
tp[i].h);
667 + (n->
tp[i].h - n->
tp[i+1].h);
679 if(n->
tp[n->
tpc].d != 0)
709 for(
int i = 1; i < w->
nodec; i++){
710 d = d + distance(w->
node[i] ->
lat,w->
node[i] ->lon,
715 w->
node[i ],w,d,i-iold+1,fw);
717 w->
node[iold],w,d,i-iold+1,bw);
719 if(n1 != NULL && n2 != NULL){
725 if(n1 != NULL) n1->
brthr = n1;
726 if(n2 != NULL) n2->
brthr = n2;
727 if((n1 != NULL || n2 != NULL)&&w->
node[i] != w->
node[iold])
728 QMessageBox(QMessageBox::NoIcon,
"Error",
729 "Neighbour add failure").exec();
753 KOOlist kl1; kl1.next = NULL; kl1.
k = &kfake;
761 nb->
tp[0].h = nb->
tp[0].h + tt->t.h * 1. / tt->t.d;
762 srho = srho + 1. / tt->t.d;
766 nb->
tp[0].h = tt->t.h;
772 nb->
tp[0].h = nb->
tp[0].h / srho;
774 KOOlist kl2; kl2.next = NULL; kl2.
k = &kfake;
782 nb->
tp[1].h = nb->
tp[1].h + tt->t.h * 1. / tt->t.d;
783 srho = srho + 1. / tt->t.d;
787 nb->
tp[1].h = tt->t.h;
793 nb->
tp[1].h = nb->
tp[1].h / srho;
798 while(kbuf1 != NULL){
799 kbuf2 = kbuf1; kbuf1 = kbuf1->next; free(kbuf2);
802 while(kbuf1 != NULL){
803 kbuf2 = kbuf1; kbuf1 = kbuf1->next; free(kbuf2);
806 while(tbuf1 != NULL){
807 tbuf2 = tbuf1; tbuf1 = tbuf1->next; free(tbuf2);
810 while(tbuf1 != NULL){
811 tbuf2 = tbuf1; tbuf1 = tbuf1->next; free(tbuf2);
825 ktnew->next = kl->next;
830 while(nb != NULL && nb->
way->
type > 9)
835 tlnew->next = tl->next;
837 if(nb->
rd == fw) tlnew->t = nb->
tp[0];
838 else tlnew->t = nb->
tp[nb->
tpc-1];
int KOO_already_used(KOO *k, KOOlist *kl)
help function of trace_to_HeightData()
void calc_crossheight(KOO *k)
determines the common crossheight fromthe domiciled Neighbour
Neighbour * via
connection to reach this STRONG
void check_brect(Way *w, double *latmin, double *latmax, double *lonmin, double *lonmax)
adapt bounding rect to cover whole data set
double height_t(double lon, double lat, void *hc, short mode)
returns height data operating at the precalculated data grid
void trace_to_HeightData(float d, KOO *k, KOOlist *kl, trackpointlist *tl)
work function of add_NoHeights_HeightData()
double rlimit
maximum accepted mistrust index
void portion_divide(KOO *k)
normalize the distributes mistrust index
void alloc_neighbours(Way *w)
search allong way for neighbouring cross, link them with Neighbour data
Way * way
Neighbour lives uses this Way.
double dminur
minimum section length to cross
void portion_way(KOO *k)
smearing out the mistrust index within the Neighbour data
void mark_NoHeights()
if a Way is tunnel or bridge height must be interpolated lineary
void delete_PortionInstructions(KOO *k)
delete the angular relation of Neighbour at a cross
float maxlon
bounding rect, for rendering
KOO * get_first_KOO()
returns root of node-AVL tree
container struct to hold data of a coordinate
double dstep0
interpolation step size in km
KOO ** node
reference to KOO (of way)
char status
state of the KOO when used by different classes
int glacerate
how many times is glazed
void alloc_NoHeights_neighbours()
create Neighbour data (end & start only) for members of osm::NoHeight
void add_NoHeights_HeightData(KOO *k)
determine the heights of tunnels and bridges at start and end
routing container struct, connects cross via Way with each other
Neighbour * next
next Neighbour, set to NULL if last
main container list climbanalyse
int nodec
count of used KOO in way
short check0(KOO *k)
returns zero if a zero distance Neighbour was found
STRONG * s
memory for routing algorithms
Neighbour * add_Neighbour(KOO *k, KOO **node, KOO *nb, Way *w, float d, int KOOc, readdirection rd)
add Neighbour cross to k
double flach2
move cross to place with (grad^2)
holds digital elevation model extracted from SRTM3 data
void reset_t(double minlat, double maxlat, double minlon, double maxlon)
generates the data grid being
container for line geodata
void dismark_NoHeights()
reduces Way::type by 10 if member of osm::NoHeight data
void * from
< pointer to STRONG or FibunacciHeap
void reduce_data(KOO *k)
run select_heights() and finalize_data() on every Neighbour
WayHeight(HeightData *H, OSM *O)
constructor runs the whole calculation
KOO ** node
array KOO pointers
void glaze()
smear out gaussian the mistrust index over several hundred meter
void finalize_data(Neighbour *n)
keep selected data and delete unused data
void portion_cross(KOO *k)
smearing out at the borders of the Neighbour data, i.g. at the cross
void add_raw_HeightData(KOO *k)
assign raw height data to all Neighbour datasets
int tpc
count of trackpoint
Neighbour * neighbours
neigbours to link to other cross
BTP3 database, created from OpenStreetMap data.
void generate_PortionInstructions(KOO *k)
generate the angular relation of Neighbour at a cross
void select_heights(Neighbour *n, long s, long e)
select the most charakteristicand trustful heighdata of a Neighbour
double dmin
minimum section length in km
KOO * k
reference to KOO data
container struct to hold data of a cross
void reset_cross_markers(KOO *k)
set status of every KOO zero
container struct for Track to hold distance and height data
float hm
total height meter, for routing
trackpoint * tp
heighdata of this Neighbour
main container for Track, WayHeight and ClimbAnalyse
osm data container list for line like data (roads, rivers)
void show_d_confidence(KOO *k)
Way * get_first_Way()
returns root of Way-AVL tree
Way * way
reference element of this list
void alloc_crossdata(KOO *k)
allocs crossdata if KOO was marked as cross
Neighbour * brthr
related Neighbour with opposite read direction supposed to store brthr
void show_d_h(KOO *k)
visualization for developers
main struct for routing purpose