-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRadarCalculation.hpp
More file actions
249 lines (227 loc) · 10.8 KB
/
RadarCalculation.hpp
File metadata and controls
249 lines (227 loc) · 10.8 KB
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* Bridge Command 5.0 Ship Simulator
Copyright (C) 2014 James Packer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY Or FITNESS For A PARTICULAR PURPOSE. See the
GNU General Public License For more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
#ifndef __RADARCALCULATION_HPP_INCLUDED__
#define __RADARCALCULATION_HPP_INCLUDED__
#include "irrlicht.h"
#include <vector>
#include <string>
#include <stdint.h> //for uint64_t
#include <ctime> //To check time elapsed between changing EBL when button held down
class Terrain;
class OwnShip;
class Buoys;
class OtherShips;
struct RadarData;
enum ARPA_CONTACT_TYPE {
CONTACT_NONE,
CONTACT_NORMAL,
CONTACT_MANUAL
};
struct ARPAScan {
//ARPA scan information based on the assumption that the own ship position is well known
irr::f32 x; //Absolute metres
irr::f32 z; //Absolute metres
uint64_t timeStamp; //Timestamp in seconds
//irr::f32 estimatedRCS; //Estimated radar cross section
irr::f32 rangeNm; //Reference only
irr::f32 bearingDeg; //For reference only
ARPAScan() {
x = 0;
z = 0;
timeStamp = 0;
rangeNm = 0;
bearingDeg = 0;
}
};
struct ARPAEstimatedState {
irr::u32 displayID; //User displayed ID
bool stationary; // E.g. if detected as static and a small RCS or a buoy.
irr::f32 absVectorX; //Estimated X speed (m/s)
irr::f32 absVectorZ; //Estimated Z speed (m/s)
irr::f32 absHeading; //Estimated heading (deg)
irr::f32 relVectorX; //Estimated X speed (m/s)
irr::f32 relVectorZ; //Estimated Z speed (m/s)
irr::f32 relHeading; //Estimated heading (deg)
irr::f32 range; //Estimated current range from own ship (Nm)
irr::f32 bearing; //Estimated current bearing from own ship (deg)
irr::f32 speed; //Estimated current speed (Kts)
bool lost; //True if we last scanned more than a defined time ago.
irr::f32 cpa; //Closest point of approach in Nm
irr::f32 tcpa; //Time to closest point of approach (mins)
ARPA_CONTACT_TYPE contactType; //Duplicate of what's in the parent, but useful to pass to the GUI
ARPAEstimatedState() {
displayID = 0;
stationary = false;
absVectorX = 0;
absVectorZ = 0;
absHeading = 0;
relVectorX = 0;
relVectorZ = 0;
relHeading = 0;
range = 0;
bearing = 0;
speed = 0;
lost = false;
cpa = 0;
tcpa = 0;
contactType = CONTACT_NONE;
}
};
struct ARPAContact {
std::vector<ARPAScan> scans;
irr::f32 totalXMovementEst; //Estimates of total movement (sum of absolutes) in X and Z, to help detect stationary contacts
irr::f32 totalZMovementEst;
ARPA_CONTACT_TYPE contactType;
void* contact;
//irr::u32 displayID;
ARPAEstimatedState estimate;
ARPAContact() {
totalXMovementEst = 0;
totalZMovementEst = 0;
contactType = CONTACT_NONE;
contact = 0;
}
};
class RadarCalculation
{
public:
RadarCalculation();
virtual ~RadarCalculation();
void load(std::string radarConfigFile, irr::IrrlichtDevice* dev);
void increaseRange();
void decreaseRange();
irr::f32 getRangeNm() const;
void setGain(irr::f32 value);
void setClutter(irr::f32 value);
void setRainClutter(irr::f32 value);
void increaseClutter(irr::f32 value);
void decreaseClutter(irr::f32 value);
void increaseRainClutter(irr::f32 value);
void decreaseRainClutter(irr::f32 value);
void increaseGain(irr::f32 value);
void decreaseGain(irr::f32 value);
irr::f32 getGain() const;
irr::f32 getClutter() const;
irr::f32 getRainClutter() const;
irr::f32 getEBLRangeNm() const;
irr::f32 getEBLBrg() const;
irr::f32 getCursorRangeNm() const;
irr::f32 getCursorBrg() const;
void setPIData(irr::s32 PIid, irr::f32 PIbearing, irr::f32 PIrange);
irr::f32 getPIbearing(irr::s32 PIid) const;
irr::f32 getPIrange(irr::s32 PIid) const;
void increaseCursorRangeXNm();
void decreaseCursorRangeXNm();
void increaseCursorRangeYNm();
void decreaseCursorRangeYNm();
void increaseEBLRange();
void decreaseEBLRange();
void increaseEBLBrg();
void decreaseEBLBrg();
void setNorthUp();
void setCourseUp();
void setHeadUp();
bool getHeadUp() const; //Head or course up
bool getStabilised() const;
void toggleRadarOn();
bool isRadarOn() const;
int getArpaMode() const;
void setArpaMode(int mode);
void setRadarARPARel();
void setRadarARPATrue();
void setArpaListSelection(irr::s32 selection);
irr::s32 getArpaListSelection() const;
void setRadarARPAVectors(irr::f32 vectorMinutes);
void setRadarDisplayRadius(irr::u32 radiusPx);
void changeRadarColourChoice();
irr::u32 getARPATracksSize() const;
int getARPAContactIDFromTrackIndex(irr::u32 trackIndex) const;
ARPAContact getARPAContactFromTrackIndex(irr::u32 trackIndex) const;
void addManualPoint(bool newContact, irr::core::vector3d<int64_t> offsetPosition, const OwnShip& ownShip, uint64_t absoluteTime);
void clearManualPoints();
void trackTargetFromCursor();
void clearTargetFromCursor();
irr::video::SColor getRadarForegroundColour() const;
irr::video::SColor getRadarBackgroundColour() const;
irr::video::SColor getRadarSurroundColour() const;
irr::f32 getBrilliance() const;
void setBrilliance(irr::f32 brilliance);
void update(irr::video::IImage * radarImage, irr::video::IImage * radarImageOverlaid, irr::core::vector3d<int64_t> offsetPosition, const Terrain& terrain, const OwnShip& ownShip, const Buoys& buoys, const OtherShips& otherShips, irr::f32 weather, irr::f32 rain, irr::f32 tideHeight, irr::f32 deltaTime, uint64_t absoluteTime, irr::f32 scenarioTime, irr::core::vector2di mouseRelPosition, bool isMouseDown);
private:
irr::IrrlichtDevice* device;
std::vector<std::vector<irr::f32> > scanArray;
std::vector<std::vector<irr::f32> > scanArrayAmplified;
std::vector<std::vector<irr::f32> > scanArrayToPlot;
std::vector<std::vector<irr::f32> > scanArrayToPlotPrevious;
std::vector<bool> toReplot;
std::vector<ARPAContact> arpaContacts;
std::vector<irr::u32> arpaTracks;
bool radarOn;
int arpaMode; // 0: Off/Manual, 1: MARPA, 2: ARPA
irr::s32 arpaListSelection;
irr::f32 radarGain;
irr::f32 radarRainClutterReduction;
irr::f32 radarSeaClutterReduction;
irr::f32 currentScanAngle;
irr::f32 scanAngleStep;
irr::u32 currentScanLine; //Note that this MUST be an integer, as the scanline number is used to look up values in radar scan arrays
irr::u32 rangeResolution;
irr::u32 angularResolution;
irr::f32 rangeSensitivity; //Used for ARPA contacts - in metres
irr::u32 radarRangeIndex;
irr::f32 radarScannerHeight;
//parameters for noise behaviour
irr::f32 radarNoiseLevel;
irr::f32 radarSeaClutter;
irr::f32 radarRainClutter;
//Parameters for parallel index
std::vector<irr::f32> piBearings;
std::vector<irr::f32> piRanges;
//Parameters for EBL
irr::f32 EBLRangeNm;
irr::f32 EBLBrg;
clock_t radarCursorsLastUpdated;
//Parameters for radar cursor
irr::f32 cursorRangeXNm;
irr::f32 cursorRangeYNm;
irr::f32 CursorRangeNm;
irr::f32 CursorBrg;
//Radar config
bool headUp;
bool stabilised;
irr::u32 radarRadiusPx;
bool radarScreenStale;
bool trueVectors;
irr::f32 vectorLengthMinutes;
//colours
std::vector<irr::video::SColor> radarBackgroundColours;
std::vector<irr::video::SColor> radarForegroundColours;
std::vector<irr::video::SColor> radarSurroundColours;
irr::u32 currentRadarColourChoice;
irr::f32 brilliance;
std::vector<irr::f32> radarRangeNm;
void scan(irr::core::vector3d<int64_t> offsetPosition, const Terrain& terrain, const OwnShip& ownShip, const Buoys& buoys, const OtherShips& otherShips, irr::f32 weather, irr::f32 rain, irr::f32 tideHeight, irr::f32 deltaTime, uint64_t absoluteTime, irr::f32 scenarioTime);
void addRaconString(irr::f32 raconEchoStrength, irr::f32 cellLength, irr::f32 contactRange, std::string raconCode);
void addRaconReturn(irr::f32 raconEchoStrength, irr::f32 cellLength, irr::f32 raconEchoLength, irr::f32 raconSpaceLength, irr::f32& raconEchoStart);
void updateARPA(irr::core::vector3d<int64_t> offsetPosition, const OwnShip& ownShip, uint64_t absoluteTime);
void updateArpaEstimate(ARPAContact& thisArpaContact, int contactID, const OwnShip& ownShip, irr::core::vector3d<int64_t> absolutePosition, uint64_t absoluteTime);
irr::f32 radarNoise(irr::f32 radarNoiseLevel, irr::f32 radarSeaClutter, irr::f32 radarRainClutter, irr::f32 weather, irr::f32 radarRange,irr::f32 radarBrgDeg, irr::f32 windDirectionDeg, irr::f32 radarInclinationAngle, irr::f32 rainIntensity);
void render(irr::video::IImage * radarImage, irr::video::IImage * radarImageOverlaid, irr::f32 ownShipHeading, irr::f32 ownShipSpeed);
irr::f32 rangeAtAngle(irr::f32 checkAngle,irr::f32 centreX, irr::f32 centreZ, irr::f32 heading);
void drawSector(irr::video::IImage * radarImage,irr::f32 centreX, irr::f32 centreY, irr::f32 innerRadius, irr::f32 outerRadius, irr::f32 startAngle, irr::f32 endAngle, irr::video::SColor colour, irr::f32 ownShipHeading);
void drawLine(irr::video::IImage * radarImage, irr::f32 startX, irr::f32 startY, irr::f32 endX, irr::f32 endY, irr::video::SColor colour);//Try with f32 as inputs so we can do interpolation based on the theoretical start and end
void drawCircle(irr::video::IImage * radarImage, irr::f32 centreX, irr::f32 centreY, irr::f32 radius, irr::video::SColor colour);//Try with f32 as inputs so we can do interpolation based on the theoretical start and end
bool isPointInEllipse(irr::f32 pointX, irr::f32 pointZ, irr::f32 centreX, irr::f32 centreZ, irr::f32 width, irr::f32 length, irr::f32 angle);
irr::video::SColor brill(irr::video::SColor originalColour, irr::f32 brilliance) const;
};
#endif