100,6 → 100,7 |
weight = cfg->readNumEntry("weight", 70); |
sampleTime = cfg->readNumEntry("seconds", 15); |
Serial = cfg->readBoolEntry("Serial", false); |
Contour = cfg->readBoolEntry("Contour", false); |
Device = cfg->readEntry("Device", "/dev/ttyUSB0"); |
Data = cfg->readEntry("Data", QDir::home().absPath() + "/.sportwatcher"); |
HRM = cfg->readEntry("HRM", QDir::home().absPath() + "/polar"); |
2436,14 → 2437,89 |
x1 = x2 = y1 = y2 = 0; |
int hy1, hy2, hx1, hx2; |
hy1 = hy2 = hx1 = hx2 = 0; |
int hEc = 20; |
double avgHeight[20]; |
int hEven = -1; |
int hEc = 0; |
i = 0; |
AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0; |
|
for (i = 0; i < hEc; i++) |
avgHeight[i] = 0.0; |
// To even the surface lines, we store every altitude in the |
// memory, by building a chain. Then, if the user has set in the |
// settings (Contour == true), we will even the line by calculating |
// the average of 10 messure points and setting every value to the |
// average, who is up or down more than 2 meters from the average. |
while ((point = ds.getPoint(i)) != 0) |
{ |
if (point->alt > 20000.0 || point->alt < -1000.0) |
{ |
i++; |
continue; |
} |
|
if (!avgHeight) |
{ |
avgHeight = new AVGHEIGHT; |
avgHeight->alt = point->alt; |
avgHeight->pos = hEc; |
avgHeight->prev = 0; |
avgHeight->next = 0; |
avgHakt = avgHeight; |
avgHfirst = avgHeight; |
} |
else |
{ |
avgHakt = new AVGHEIGHT; |
avgHakt->alt = point->alt; |
avgHakt->pos = hEc; |
avgHakt->next = 0; |
avgHakt->prev = avgHeight; |
avgHeight->next = avgHakt; |
avgHeight = avgHakt; |
} |
|
// FIXME: Currently we can not draw below 0 meters, because the |
// base line is always 0! |
if (avgHakt->alt < 0.0) |
avgHakt->alt = 0.0; |
|
hEc++; |
i++; |
} |
|
avgHlast = avgHeight; |
// If wanted, even the lines |
if (Contour) |
{ |
double alt[10], avg, step; |
int a; |
|
for (i = 0; i < (hEc + 10); i += 10) |
{ |
avg = 0.0; |
|
for (a = 0; a < 10; a++) |
{ |
alt[a] = getAvgAlt(avgHfirst, i + a); |
avg += alt[a]; |
} |
|
if ((i + 10) >= hEc) |
avg /= (double)(hEc - i) + 1.0; |
else |
avg /= 10.0; |
|
for (a = 0; a < 10; a++) |
{ |
if ((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0) |
{ |
if ((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2) |
avgHakt->alt = avg; |
} |
} |
} |
} |
|
// plot the altitude |
i = 0; |
int j = 0; |
|
while ((point = ds.getPoint(i)) != 0) |
{ |
2462,63 → 2538,16 |
|
if (point->alt < 20000.0 && point->alt > -1000.0) |
{ |
double aH; |
double alt = getAvgAlt(avgHfirst, j); |
|
/* Polynominterpolation zum glätten der Höhenlinien (Kurvenglätten) |
FIXME: following formulas are to be done! |
j++; |
|
For i = 1 To n |
For j = n To i + 1 Step -1 |
y(j) = (y(j) - y(j-1)) / (x(j) - x(j-i)) |
Next j |
Next i |
|
y_Wert = 0 |
For i = n To 1 Step -1 |
y_Wert = y_Wert * (x_Wert - x(i)) + y(i) |
Next i |
*/ |
|
if (Contour) |
{ |
if (hEven == -1) |
{ |
aH = point->alt; |
hEven = 0; |
} |
|
if (hEven > (hEc - 1)) |
{ |
aH = 0.0; |
|
for (hEven = 0; hEven < hEc; hEven++) |
aH += avgHeight[hEven]; |
|
aH /= (double)hEc; |
hEven = 0; |
} |
|
if (point->alt < 0.0) |
avgHeight[hEven] = 0.0; |
else |
avgHeight[hEven] = point->alt; |
|
hEven++; |
} |
else |
{ |
if (point->alt < 0.0) |
aH = 0.0; |
else |
aH = point->alt; |
} |
|
if (meter) |
y2 = (double)rh - (aH - minHeight) * h_tick; |
y2 = (double)rh - (alt - minHeight) * h_tick; |
else |
{ |
double hrscale = rh / (maxHeight - minHeight); |
y2 = (double)rh - (aH - minHeight) * hrscale; |
y2 = (double)rh - (alt - minHeight) * hrscale; |
} |
|
if (y1 == 0) |
2555,10 → 2584,54 |
paint.end(); |
imgProfile->setPixmap(pmProfile); |
|
// free the chain of altitudes |
avgHakt = avgHfirst; |
|
while (avgHakt) |
{ |
avgHeight = avgHakt->next; |
delete avgHakt; |
avgHakt = avgHeight; |
} |
|
// if (bProfile) |
// bitBlt(imgProfile, 0, 0, &pmProfile); |
} |
|
double sportwatcherWidget::getAvgAlt(AVGHEIGHT *avgHeight, int pos) |
{ |
AVGHEIGHT *akt; |
|
akt = avgHeight; |
|
while (akt) |
{ |
if (akt->pos == pos) |
return akt->alt; |
|
akt = akt->next; |
} |
|
return 0.0; |
} |
|
AVGHEIGHT *sportwatcherWidget::getAvgPtr(AVGHEIGHT *avgHeight, int pos) |
{ |
AVGHEIGHT *akt; |
|
akt = avgHeight; |
|
while (akt) |
{ |
if (akt->pos == pos) |
return akt; |
|
akt = akt->next; |
} |
|
return 0; |
} |
|
void sportwatcherWidget::resizeEvent(QResizeEvent */* *e */) |
{ |
showTrack(zfactor); |