-
Notifications
You must be signed in to change notification settings - Fork 7
/
RealTimeRoute.cpp
196 lines (159 loc) · 5.4 KB
/
RealTimeRoute.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// RealTimeRoute.cpp : implementation file
#undef min
#undef max
#include "stdafx.h"
#include "DMSpec.h"
#include "RealTimeRoute.h"
#include "Spectrometer.h"
#include <algorithm>
// CRealTimeRoute dialog
using namespace Dialogs;
IMPLEMENT_DYNAMIC(CRealTimeRoute, CDialog)
CRealTimeRoute::CRealTimeRoute(CWnd* pParent /*=NULL*/)
: CDialog(CRealTimeRoute::IDD, pParent),
m_pointNum(0), fVisible(false), m_intensityLimit(400), m_legendWidth(0), m_spectrometer(nullptr), m_srcLat(0.0), m_srcLon(0.0)
{
// There is a maximum size to the dataset available, stick to that
m_lat.resize(65536);
m_lon.resize(65536);
m_col.resize(65536);
m_int.resize(65536);
}
CRealTimeRoute::~CRealTimeRoute()
{
}
void CRealTimeRoute::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC_REALTIME_PLOT, m_plotArea);
}
BEGIN_MESSAGE_MAP(CRealTimeRoute, CDialog)
ON_WM_SIZE()
ON_WM_CLOSE()
END_MESSAGE_MAP()
// CRealTimeRoute message handlers
BOOL CRealTimeRoute::OnInitDialog()
{
CDialog::OnInitDialog();
CRect dlgrect;
this->GetClientRect(&dlgrect);
CRect rect;
m_plotArea.GetClientRect(&rect);
m_legendWidth = dlgrect.right - rect.right;
m_range.maxLat = 10.0f;
m_range.maxLon = 10.0f;
m_range.minLat = -10.0f;
m_range.minLon = -10.0f;
m_gpsPlot.Create(WS_VISIBLE | WS_CHILD, rect, &m_plotArea);
m_gpsPlot.parentWnd = &m_plotArea;
m_gpsPlot.SetYUnits("Latitude");
m_gpsPlot.SetXUnits("Longitude");
m_gpsPlot.EnableGridLinesX(true);
m_gpsPlot.EnableGridLinesY(true);
m_gpsPlot.SetBackgroundColor(RGB(0, 0, 0));
m_gpsPlot.SetGridColor(RGB(255, 255, 255));
m_gpsPlot.SetAxisEqual(); // make sure that the latitude scale and the longitude scale are the same
m_gpsPlot.SetMarginSpace(0.01f); // Set some space around the graph
m_gpsPlot.SetRange(m_range.minLat, m_range.maxLat, 2, m_range.minLon, m_range.maxLon, 2);
DrawRouteGraph();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRealTimeRoute::DrawRouteGraph()
{
const int nofDecimals = 4;
// Read the data from the CSpectrometer class
ReadData();
// set range
m_gpsPlot.SetRange(m_range.minLat, m_range.maxLat, nofDecimals, m_range.minLon, m_range.maxLon, nofDecimals);
// Draw route plot
m_gpsPlot.DrawCircles(m_lon.data(), m_lat.data(), m_col.data(), m_pointNum);
// draw min/max col label
m_gpsPlot.SetPlotColor(RGB(255, 255, 255));
}
void CRealTimeRoute::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if (nType != SIZE_RESTORED)
return;
if (IsWindow(m_plotArea.m_hWnd))
{
int legendSpace = 70;
m_plotArea.MoveWindow(0, 0, cx - m_legendWidth, cy, FALSE);
m_gpsPlot.MoveWindow(0, 0, cx - m_legendWidth, cy, FALSE);
m_gpsPlot.CleanPlot();
}
DrawRouteGraph();
}
BOOL CRealTimeRoute::Create(UINT nID, CWnd* pParentWnd)
{
// TODO: Add your specialized code here and/or call the base class
fVisible = false;
this->m_spectrometer = 0;
return CDialog::Create(nID, pParentWnd);
}
void CRealTimeRoute::ReadData()
{
if (nullptr == m_spectrometer)
return;
long sum = std::min(65535L, m_spectrometer->GetColumnNumber()); // limit the number here since the vectors aren't long enough...
m_spectrometer->GetLatLongAlt(m_lat.data(), m_lon.data(), nullptr, sum);
m_spectrometer->GetColumns(m_col, sum);
m_spectrometer->GetIntensity(m_int, sum);
memset(&m_range, 0, sizeof(struct plotRange));
/* delete bad points (points without gps or dark points) */
for (int i = 0; i < sum; ++i)
{
if ((m_lat[i] == 0 && m_lon[i] == 0))
{
for (int j = i; j < sum; ++j)
{
m_lat[j] = m_lat[j + 1];
m_lon[j] = m_lon[j + 1];
m_col[j] = m_col[j + 1];
}
--i;
--sum;
}
}
if (sum == 0)
return;
m_pointNum = sum;
m_range.maxLat = m_lat[0];
m_range.maxLon = m_lon[0];
m_range.minLat = m_lat[0];
m_range.minLon = m_lon[0];
double maximumColumn = m_col[0];
double minimumColumn = m_col[0];
for (int i = 0; i < sum; i++)
{
m_range.maxLat = std::max(m_range.maxLat, m_lat[i]);
m_range.maxLon = std::max(m_range.maxLon, m_lon[i]);
m_range.minLat = std::min(m_range.minLat, m_lat[i]);
m_range.minLon = std::min(m_range.minLon, m_lon[i]);
if (m_col[i] > maximumColumn)
{
maximumColumn = m_col[i];
}
if (m_col[i] < minimumColumn)
{
minimumColumn = m_col[i];
}
}
// update legend max/min col
CString maxcol;
maxcol.Format("%.1f", maximumColumn);
this->SetDlgItemText(IDC_STATIC_MAXCOL, maxcol);
CString mincol;
mincol.Format("%.1f", minimumColumn);
this->SetDlgItemText(IDC_STATIC_MINCOL, mincol);
CString midcol;
midcol.Format("%.1f", (maximumColumn + minimumColumn) / 2);
this->SetDlgItemText(IDC_STATIC_MIDCOL, midcol);
}
void CRealTimeRoute::OnClose()
{
fVisible = false;
this->DestroyWindow();
CDialog::OnClose();
}