\( \def\bold#1{\bf #1} \newcommand{\d}{\mathrm{d}} \) BTP: Manual and Source Code Documentation

Power Uphill

bike mass [kg]
body mass [kg]
altitude gain [m]
climb length [km]
gradient [%]
time [s]
speed [km/h]
power [W]
power/mass [W/kg]
climbrate [m/min]

average power on climb stage

BTP  3.0
Routing/ClimbAnalysis/PowerCalculation
webdata.cpp
1 #include "webdata.h"
2 
3 
5  this->w = w;
6 }
7 
8 void WebData::run(){
9  switch(w.mode){
10  case CreateHTML:
12  break;
13  case ReadOSM:
14  read_osm();
15  break;
16  case CreateTiles:
17  generate_map();
18  break;
19  case CreateTilesBTP:
21  break;
22  case SplitEurope:
23  split_europe();
24  break;
25  case CreateSTRONGLayers:
27  break;
28  }
29 }
30 
31 void WebData::exit(){}
33  QDir maind(w.dest);
34  QDir zdir(QString(w.dest).append(QString("\\%1").arg(w.z)));
35  QDir ydir(QString(w.dest).append(QString("\\%1\\%2").arg(w.z).arg(w.y)));
36  if(!zdir.exists()) maind.mkdir(zdir.dirName());
37  if(!ydir.exists()) zdir.mkdir(ydir.dirName());
38  HeightData hd;
40  MAP mt(&hd,w.osm);
41  mt.settings(&(w.c->MS));
42  mt.resize(w.width,w.height);
43  mt.set_borders(yztolat(w.y+1,w.z),yztolat(w.y,w.z),xztolon(w.x,w.z),xztolon(w.x+1,w.z));
44  mt.calc_borders();
45  mt.draw_map(NULL,NULL,NULL,0);
46  mt.get_Map()->save(ydir.absoluteFilePath(QString("%1.png").arg(w.x)),"PNG");
47 }
49  double dd = 0.15;
50  QString filename = QString("D:\\ClimbProject\\pbf-Data\\%1-%2-%3.pbf").arg(w.z).arg(w.x).arg(w.y);
51  QFileInfo fi = QFileInfo(filename);
52  qint64 fs = fi.size();
53  if(fi.exists()){
54  if((w.z < 9 || fi.size() > 400e6) && fs > 250)
55  for(int jx = 0; jx < 2; jx++)
56  for(int jy = 0; jy < 2; jy++){
57  webdatacmd* wt = new webdatacmd;
58  wt->z = w.z + 1;
59  wt->x = w.x*2 + jx;
60  wt->y = w.y*2 + jy;
61  wt->mode = SplitEurope;
62  double minlat = qMax( -90.,yztolat(wt->y+1,wt->z) - dd);
63  double maxlat = qMin( 90.,yztolat(wt->y,wt->z) + dd);
64  double minlon = qMax(-180.,xztolon(wt->x,wt->z) - dd);
65  double maxlon = qMin( 180.,xztolon(wt->x+1,wt->z) + dd);
66  QString newfile = QString("D:\\ClimbProject\\pbf-Data\\%1-%2-%3.pbf").arg(wt->z).arg(wt->x).arg(wt->y);
67  QString cmdline = QString("D:\\ClimbProject\\pbf-Data\\osmconvert.exe");
68  QStringList arguments;
69  arguments << filename;
70  arguments << QString("-b=%1,%2,%3,%4").arg(minlon)
71  .arg(minlat)
72  .arg(maxlon)
73  .arg(maxlat);
74  arguments << QString("-o=").append(newfile);
75  //QString cmdline = QString("C:\\Users\\User\c++\\BTP3\\Release\\BTP3.exe");
76  //QStringList arguments;
77  //arguments << "close";
78  QProcess System_Call;
79  System_Call.start(cmdline,arguments);
80  System_Call.waitForFinished(-1);
81  emit add(wt);
82  }
83  }
84 }
85 double WebData::xztolon(int x, int z){
86  double step = 360. / pow(2.,z);
87  return x*step - 180.;
88 }
89 double WebData::yztolat(int y, int z){
90  double step = 360. / pow(2.,z);
91  return mercatortolat(180-y*step);
92 }
94  QFileInfo fi = QFileInfo(w.src);
95  qint64 fs = fi.size();
96  if(fi.exists() && fs > 250){
97  QString osmout(w.dest);
98  osmout.append(".osm");
99  QString cmdline = QString("D:\\ClimbProject\\pbf-Data\\osmconvert.exe");
100  QStringList arguments;
101  arguments << w.src;
102  arguments << QString("-o=").append(osmout);
103  QProcess System_Call;
104  System_Call.start(cmdline,arguments);
105  System_Call.waitForFinished(-1);
106  cmdline = QString("C:\\Users\\User\\c++\\BTP3\\release\\BTP3.exe");
107  QStringList argumentBTP;
108  argumentBTP << QString("-r=").append(osmout);
109  argumentBTP << QString("-d=").append(w.dest);
110  argumentBTP << QString("close");
111  System_Call.start(cmdline,argumentBTP);
112  System_Call.waitForFinished(-1);
113  QFile(osmout).remove();
114  }
115 }
117  QDir di(w.dest);
118  QString dirname = di.dirName();
119  if(!di.exists()){
120  // create directory as it does not exist
121  di.cdUp();
122  di.mkdir(dirname);
123  }
124  QString srcfilename = QString(w.dest).append("\\")
125  .append(dirname)
126  .append("-BinaryList.src");
127  FILE* srcfile = fopen(srcfilename.toLocal8Bit().data(),"wb");
128  int zero = 0;
129  fwrite(&zero,4,1,srcfile);
130  fclose(srcfile);
131  srcfilename = QString(w.dest).append("\\")
132  .append(dirname)
133  .append("-names.txt");
134  srcfile = fopen(srcfilename.toLocal8Bit().data(),"w");
135  fclose(srcfile);
136  QFileInfo fi = QFileInfo(w.src);
137  qint64 fs = fi.size();
138  if(fi.exists() && fs > 108){
139  QString dummyfile = QString(w.dest).append(".dmy");
140  FILE* dmy = fopen(dummyfile.toLocal8Bit().data(),"w");
141  fclose(dmy);
142  double minlat = qMax( -90.,yztolat(w.y+1,w.z));
143  double maxlat = qMin( 90.,yztolat(w.y,w.z) );
144  double minlon = qMax(-180.,xztolon(w.x,w.z) );
145  double maxlon = qMin( 180.,xztolon(w.x+1,w.z));
146  QString cmdline = QString("C:\\Users\\User\\c++\\BTP3\\release\\BTP3.exe");
147  QStringList arguments;
148  arguments << w.src;
149  arguments << QString("-b=%1,%2,%3,%4").arg(minlon)
150  .arg(minlat)
151  .arg(maxlon)
152  .arg(maxlat);
153  arguments << QString("-a=").append(w.dest);
154  arguments << QString("close");
155  QProcess System_Call;
156  System_Call.start(cmdline,arguments);
157  System_Call.waitForFinished(-1);
158  QFile fi2(dummyfile);
159  if(fi2.exists()) fi2.remove();
160  }
161 }
163  QDir maind(w.dest);
164  HeightData hd;
166  OSM osm;
167  for(int dx = -1; dx < 2; dx++)
168  for(int dy = -1; dy < 2; dy++)
169  osm.load(QString("%1%4-%2-%3.btp").arg(w.src).arg(w.x+dx)
170  .arg(w.y+dy).arg(9)
171  .toLocal8Bit().data());
172 
173  MAP mt(&hd,&osm);
174  mt.settings(&(w.c->MS));
175 
176  //first zoomlevel 9 .. 11
177  for(int z = 9; z < 12; z++){
178  QDir zdir(QString(w.dest).append(QString("\\%1").arg(z)));
179  if(!zdir.exists()) maind.mkdir(zdir.dirName());
180  // generate the map
181  int m = pow(2,z-w.z);
182  mt.resize(w.width*3*m,w.height*3*m);
183  mt.set_borders(yztolat(w.y+2,w.z),yztolat(w.y-1,w.z),
184  xztolon(w.x-1,w.z),xztolon(w.x+2,w.z));
185  mt.calc_borders();
186  mt.draw_map(NULL,NULL,NULL,1);
187  // extract all tiles from it
188  for(int y = 0; y < m; y++){
189  QDir ydir(QString(w.dest).append(QString("\\%1\\%2").arg(z).arg(w.y*m+y)));
190  if(!ydir.exists()) zdir.mkdir(ydir.dirName());
191  for(int x = 0; x < m; x++){
192  QPixmap pt = mt.get_Map()->copy((m+x)*256,(m+y)*256,256,256);
193  QString filename = QString("%1%2\\%3\\%4.png").arg(w.dest)
194  .arg(z)
195  .arg(w.y*m+y)
196  .arg(w.x*m+x);
197  pt.save(filename,"PNG");
198  }
199  }
200  }
201  //then zoomlevel 12 .. 14
202  webdatacmd wt = w;
203  wt.z = 12;
204  for(wt.x = w.x*8; wt.x < (w.x+1)*8; wt.x++)
205  for(wt.y = w.y*8; wt.y < (w.y+1)*8; wt.y++)
206  for(int z = 12; z < 15; z++){
207  QDir zdir(QString(w.dest).append(QString("\\%1").arg(z)));
208  if(!zdir.exists()) maind.mkdir(zdir.dirName());
209  // generate the map
210  int m = pow(2,z-wt.z);
211  mt.resize(wt.width*3*m,wt.height*3*m);
212  mt.set_borders(yztolat(wt.y+2,wt.z),yztolat(wt.y-1,wt.z),
213  xztolon(wt.x-1,wt.z),xztolon(wt.x+2,wt.z));
214  mt.calc_borders();
215  mt.draw_map(NULL,NULL,NULL,1);
216  // extract all tiles from it
217  for(int y = 0; y < m; y++){
218  QDir ydir(QString(w.dest).append(QString("\\%1\\%2").arg(z).arg(wt.y*m+y)));
219  if(!ydir.exists()) zdir.mkdir(ydir.dirName());
220  for(int x = 0; x < m; x++){
221  QPixmap pt = mt.get_Map()->copy((m+x)*256,(m+y)*256,256,256);
222  QString filename = QString("%1%2\\%3\\%4.png").arg(wt.dest)
223  .arg(z)
224  .arg(wt.y*m+y)
225  .arg(wt.x*m+x);
226  pt.save(filename,"PNG");
227  }
228  }
229  }
230 }
232  QDir maind(w.dest);
233  HeightData hd;
235  OSM osm;
236  osm.load(QString("%1%4-%2-%3.btp").arg(w.src).arg(w.x).arg(w.y).arg(9).toLocal8Bit().data());
237  //osm.normalize_Hm(osm.get_first_KOO());
238  osm.invert_Hm(osm.get_first_KOO());
239  int N;
240  Track** t;
241  //STRONGcalc s(&osm,NULL,NULL,w.c->maxtype,w.c->mintype,&(w.c->sconfig),&t,&N,true);
242  STRONGcalc s(&osm,NULL,NULL,w.c->maxtype,w.c->mintype,&(w.c->cconfig),&t,&N,false);
243  s.start();
244  s.wait();
245  int Nmax = 0;
246  for(int i = 0; i < N; i++)
247  if(t[i] != NULL){
248  Nmax = i;
249  delete t[i];
250  }
251  delete t;
252  Routing r(&osm);
253  if(Nmax > 0){
254  STRONGlayer* SL = r.STRONGlayer_create(Nmax);
255  QString SLfile = QString("%1%4-%2-%3.bsl").arg(w.dest).arg(w.y).arg(w.x).arg(9);
256  r.STRONGlayer_save(SLfile.toLocal8Bit().data(),SL);
257 
258  MAP mt(&hd,&osm);
259  mt.settings(&(w.c->MS));
260 
261  //first zoomlevel 9 .. 11
262  for(int z = 9; z < 12; z++){
263  QDir zdir(QString(w.dest).append(QString("\\%1").arg(z)));
264  if(!zdir.exists()) maind.mkdir(zdir.dirName());
265  // generate the map
266  int m = pow(2,z-w.z);
267  mt.resize(w.width*3*m,w.height*3*m);
268  mt.set_borders(yztolat(w.y+2,w.z),yztolat(w.y-1,w.z),
269  xztolon(w.x-1,w.z),xztolon(w.x+2,w.z));
270  mt.calc_borders();
271  QImage image(mt.getwidth(),mt.getheight(),QImage::Format_ARGB32);
272  image.fill(qRgba(0,0,0,0));
273  QPainter p(&image);
274  p.setRenderHint(QPainter::Antialiasing);
275  mt.STRONGlayer_to_Map(&p,SL);
276  // extract all tiles from it
277  for(int y = 0; y < m; y++){
278  QDir ydir(QString(w.dest).append(QString("\\%1\\%2").arg(z).arg(w.y*m+y)));
279  if(!ydir.exists()) zdir.mkdir(ydir.dirName());
280  for(int x = 0; x < m; x++){
281  QImage it = image.copy((m+x)*256,(m+y)*256,256,256);
282  QString filename = QString("%1%2\\%3\\%4.png").arg(w.dest)
283  .arg(z)
284  .arg(w.y*m+y)
285  .arg(w.x*m+x);
286  it.save(filename,"PNG");
287  }
288  }
289  }
290  //then zoomlevel 12 .. 14
291  webdatacmd wt = w;
292  wt.z = 12;
293  for(wt.x = w.x*8; wt.x < (w.x+1)*8; wt.x++)
294  for(wt.y = w.y*8; wt.y < (w.y+1)*8; wt.y++)
295  for(int z = 12; z < 15; z++){
296  QDir zdir(QString(w.dest).append(QString("\\%1").arg(z)));
297  if(!zdir.exists()) maind.mkdir(zdir.dirName());
298  // generate the map
299  int m = pow(2,z-wt.z);
300  mt.resize(wt.width*3*m,wt.height*3*m);
301  mt.set_borders(yztolat(wt.y+2,wt.z),yztolat(wt.y-1,wt.z),
302  xztolon(wt.x-1,wt.z),xztolon(wt.x+2,wt.z));
303  mt.calc_borders();
304  QImage image(mt.getwidth(),mt.getheight(),QImage::Format_ARGB32);
305  image.fill(qRgba(0,0,0,0));
306  QPainter p(&image);
307  p.setRenderHint(QPainter::Antialiasing);
308  mt.STRONGlayer_to_Map(&p,SL);
309  // extract all tiles from it
310  for(int y = 0; y < m; y++){
311  QDir ydir(QString(w.dest).append(QString("\\%1\\%2").arg(z).arg(wt.y*m+y)));
312  if(!ydir.exists()) zdir.mkdir(ydir.dirName());
313  for(int x = 0; x < m; x++){
314  QImage it = image.copy((m+x)*256,(m+y)*256,256,256);
315  QString filename = QString("%1%2\\%3\\%4.png").arg(wt.dest)
316  .arg(z)
317  .arg(wt.y*m+y)
318  .arg(wt.x*m+x);
319  it.save(filename,"PNG");
320  }
321  }
322  }
323  delete SL->data;
324  delete SL;
325  }
326 }
void settings(MapSettings *MS)
assigns new settings
Definition: MAP.cpp:122
void load(char *filename)
load btp to dataset
Definition: osm.cpp:2049
void STRONGlayer_save(char *filename, STRONGlayer *SL)
saves STRONGlayer to file
Definition: Routing.cpp:398
double xztolon(int x, int z)
longitude of tile x in zoom z
Definition: webdata.cpp:85
void STRONGlayer_to_Map(QPainter *p, STRONGlayer *SL)
draws STRONG calculation network
Definition: MAP.cpp:1250
void generate_map()
Definition: webdata.cpp:32
list elements to handle multiple STRONGlayers
Definition: DataTyps.h:349
KOO * get_first_KOO()
returns root of node-AVL tree
Definition: osm.cpp:1692
int y
Definition: webdata.h:29
void generate_STRONG()
Definition: webdata.cpp:231
label algorithm to solve multicriteria shortes path problem
Definition: strongcalc.h:28
WebData(webdatacmd w)
contructor to create png tiles of bounding rect
Definition: webdata.cpp:4
RunModeWebData mode
Definition: webdata.h:17
int width
rendering image size
Definition: webdata.h:22
int x
Definition: webdata.h:29
double yztolat(int y, int z)
lattitude of tile y in zoom z
Definition: webdata.cpp:89
int z
Definition: webdata.h:29
config * c
BTP configuration to be used.
Definition: webdata.h:24
char SRTM3folder[260]
SRTM3 data folder.
Definition: DataTyps.h:330
char maxtype
way restrictions
Definition: DataTyps.h:326
void analyse_climbs()
analyses climbs on btp files and saves html data
Definition: webdata.cpp:116
holds digital elevation model extracted from SRTM3 data
Definition: HeightData.h:26
official representation of Track in BTP3
Definition: track.h:14
QString src
source file name
Definition: webdata.h:31
void resize(int width, int height)
adapts size, recalculate borders from desired borders
Definition: MAP.cpp:126
QString dest
destination file name
Definition: webdata.h:25
OSM * osm
Definition: webdata.h:26
void set_borders(double latmin0, double latmax0, double lonmin0, double lonmax0)
sets desired borders, recalculate bordes due to window size
Definition: MAP.cpp:132
void split_europe()
Definition: webdata.cpp:48
int height
rendering image size
Definition: webdata.h:23
multithreading working command, defines the task to be executed
Definition: webdata.h:16
class to perform routing routines on osm data sets
Definition: Routing.h:18
void set_SRTM3_folder(char *folder)
specifies the folder where hgt-files of SRTM3 data are searched
Definition: HeightData.cpp:324
STRONGsetting cconfig
STRONGAlgo setting, climb mode.
Definition: DataTyps.h:329
QPixmap * get_Map()
return pixmap of the last generated map
Definition: MAP.cpp:139
void generate_map_BTP()
Definition: webdata.cpp:162
void calc_borders()
desired borders to real borders
Definition: MAP.cpp:142
void draw_map(STRONGlayer *SL, climblayer *cl, Track *ct, int fastmode)
universal high quality drawing
Definition: MAP.cpp:1410
STRONGlayer * STRONGlayer_create(STRONGlayer *SL, int N)
creates STRONGlayer from a unfinalized STRONG network
Definition: Routing.cpp:312
BTP3 database, created from OpenStreetMap data.
Definition: osm.h:34
void invert_Hm(KOO *k)
switches descenting and ascenting vertical meters in Neighbour relation
Definition: osm.cpp:2691
void read_osm()
creats *.osm file from pbf and reads in with external BTP process
Definition: webdata.cpp:93
generating maps
Definition: MAP.h:24