forked from alexgoussev/TrackProcessor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LowPass.cpp
127 lines (103 loc) · 4.13 KB
/
LowPass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//---------------------------------------------------------------------------
#include <vcl.h>
#include <System.IniFiles.hpp>
#pragma hdrstop
#include "SK42WGS84\\SK42WGS84.h"
#include "LowPass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TLowPassForm *LowPassForm;
//---------------------------------------------------------------------------
__fastcall TLowPassForm::TLowPassForm(TComponent* Owner)
: TForm(Owner)
{
TIniFile *pini = new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
Coordinates->Checked = pini->ReadBool("LowPass", "Coordinates", true);
Altitude->Checked = pini->ReadBool("LowPass", "Altitude", false);
Speed->Checked = pini->ReadBool("LowPass", "Speed", false);
double dSmooth = pini->ReadFloat("LowPass", "Smooth", 0.25);
delete pini;
Smoothing->Text = AnsiString(dSmooth);
}
//---------------------------------------------------------------------------
void __fastcall TLowPassForm::GoClick(TObject *Sender)
{
if(!Coordinates->Checked &&
!Altitude->Checked &&
!Speed->Checked)
MessageBox(Handle, TEXT("Nothing to do! Check at least one of Coordinates, Altitude or Speed"), TEXT("Warning"), MB_OK | MB_ICONSTOP);
else if(m_pCurrentTrack)
{
TCursor Save_Cursor = Screen->Cursor;
Screen->Cursor = crHourGlass;
PGPXTrack pOriginalTrack = new GPXTrack(m_pCurrentTrack);
double alpha = Smoothing->Text.ToDouble();
TIniFile *pini = new TIniFile(ChangeFileExt(Application->ExeName, ".ini"));
pini->WriteBool("LowPass", "Coordinates", Coordinates->Checked);
if(Altitude->Enabled) pini->WriteBool("LowPass", "Altitude", Altitude->Checked);
if(Speed->Enabled) pini->WriteBool("LowPass", "Speed", Speed->Checked);
pini->WriteFloat("LowPass", "Smooth", alpha);
delete pini;
ProgressBar->Max = pOriginalTrack->PointCount;
ProgressBar->Position = 0;
for(int i = 1; i < pOriginalTrack->PointCount; i++)
{
PGPXTrackPoint inP2 = pOriginalTrack->Points[i];
PGPXTrackPoint outP1 = m_pCurrentTrack->Points[i - 1];
PGPXTrackPoint outP2 = m_pCurrentTrack->Points[i];
if(Coordinates->Checked)
{
double inX2, inY2;
double outX1, outX2, outY1, outY2;
inP2->GetdProj(&inX2, &inY2);
outP1->GetdProj(&outX1, &outY1);
outX2 = outX1 + alpha * (inX2 - outX1);
outY2 = outY1 + alpha * (inY2 - outY1);
outP2->SetdProj(outX2, outY2);
}
if(Speed->Checked)
{
double dOutP1SpeedX, dOutP1SpeedY;
double dInP2SpeedX, dInP2SpeedY;
double dOutP2SpeedX, dOutP2SpeedY;
double dOutP2Speed, dOutP2Course;
DecomposeSpeed(outP1->m_dSpeed, outP1->m_dCourse, &dOutP1SpeedX, &dOutP1SpeedY);
DecomposeSpeed(inP2->m_dSpeed, inP2->m_dCourse, &dInP2SpeedX, &dInP2SpeedY);
dOutP2SpeedX = dOutP1SpeedX + alpha * (dInP2SpeedX - dOutP1SpeedX);
dOutP2SpeedY = dOutP1SpeedY + alpha * (dInP2SpeedY - dOutP1SpeedY);
//outP2->m_dSpeed = outP1->m_dSpeed + alpha * (inP2->m_dSpeed - outP1->m_dSpeed);
//outP2->m_dCourse = outP1->m_dCourse + alpha * (inP2->m_dCourse - outP1->m_dCourse);
ComposeSpeed(dOutP2SpeedX, dOutP2SpeedY, &dOutP2Speed, &dOutP2Course);
outP2->m_dSpeed = dOutP2Speed;
outP2->m_dCourse = dOutP2Course;
}
if(Altitude->Checked)
outP2->m_dAlt = outP1->m_dAlt + alpha * (inP2->m_dAlt - outP1->m_dAlt);
ProgressBar->Position = i;
Application->ProcessMessages();
}
m_pCurrentTrack->RecalcDistClimb();
delete pOriginalTrack;
Screen->Cursor = Save_Cursor;
}
}
//---------------------------------------------------------------------------
void __fastcall TLowPassForm::FormShow(TObject *Sender)
{
if(m_pCurrentTrack && !m_pCurrentTrack->m_bNoAlt)
Altitude->Enabled = true;
else
{
Altitude->Checked = false;
Altitude->Enabled = false;
}
if(m_pCurrentTrack && !m_pCurrentTrack->m_bNoTime)
Speed->Enabled = true;
else
{
Speed->Checked = false;
Speed->Enabled = false;
}
}
//---------------------------------------------------------------------------