Debian Codegraph @

src/targetmotionanalysis.cpp

raw symbols SCIP
1 /***************************************************************************
2 targetmotionanalysis.cpp - description
3 -------------------
4 begin : Sat Mar 16 2002
5 copyright : (C) 2002 by Michael Bridak
6 email : [email protected]
7 $Id: targetmotionanalysis.cpp,v 1.7 2003/05/17 22:27:28 mbridak Exp $
8 ***************************************************************************/
9
10 /***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License. *
15 * . *
16 * *
17 ***************************************************************************/
18
19 #include "SDL/SDL.h"
20 #include "SDL/SDL_image.h"
21 #include "SDL/SDL_thread.h"
22 #include "targetmotionanalysis.h"cxx . . $ `<file>/src/targetmotionanalysis.h`/
23 #include "math.h"
24
25 TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#TargetMotionAnalysis(49f6e7a06ebc5aa8).(){
26 MutexLockcxx . . $ TargetMotionAnalysis#MutexLock. = SDL_CreateMutex();
27 plotscalecxx . . $ TargetMotionAnalysis#plotscale. = 1;
28 centerGeoPlotcxx . . $ TargetMotionAnalysis#centerGeoPlot. = true;
29 }
30
31 TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::~cxx . . $ TargetMotionAnalysis#`~TargetMotionAnalysis`(ced63f7c635d850d).TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#(){
32 SDL_DestroyMutex(MutexLockcxx . . $ TargetMotionAnalysis#MutexLock.);
33 }
34
35 /** Returns TRUE if tracker is in use */
36 bool TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::GetTrackerStatecxx . . $ TargetMotionAnalysis#GetTrackerState(4a668f6de69bf818).(int tracker) const{
37 return trackerstatecxx . . $ TargetMotionAnalysis#trackerstate.[tracker];
38 }
39
40 /** Frees a tracker to be used later. */
41 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::ClearTrackercxx . . $ TargetMotionAnalysis#ClearTracker(d4f767463ce0a6b3).(int tracker){
42 trackerstatecxx . . $ TargetMotionAnalysis#trackerstate.[tracker]=false;
43 }
44
45 /** Assign a tracker to a target */
46 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::AssignTrackercxx . . $ TargetMotionAnalysis#AssignTracker(3e454b8ccf442868).(int tracker, int target){
47 trackerstatecxx . . $ TargetMotionAnalysis#trackerstate.[tracker]=true;
48 }
49
50 /** Assign Target designation and Tracker to trace currently under
51 cursor on SONAR screen. */
52 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DesignateContactcxx . . $ TargetMotionAnalysis#DesignateContact(49f6e7a06ebc5aa8).(){
53 }
54
55 /** Display a GeoPlot for the designated contact based on the
56 position of the boat and the bearing history of the contact. */
57 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DisplayGeoPlotcxx . . $ TargetMotionAnalysis#DisplayGeoPlot(3e454b8ccf442868).(int xoffset, int yoffset){
58 ClearGeoPlotcxx . . $ TargetMotionAnalysis#ClearGeoPlot(49f6e7a06ebc5aa8).();
59 if(sizecxx . . $ BoatPositionLog#size. !=0){
60 PlotHistorycxx . . $ TargetMotionAnalysis#PlotHistory(b1146eedae1e1d0b).(plotscalecxx . . $ TargetMotionAnalysis#plotscale.,xoffset,yoffset);
61 }
62 SDL_Rect rectangle;
63 rectangle.x=0;
64 rectangle.y=0;
65 rectangle.h=500;
66 rectangle.w=500;
67 SDL_UpdateRects(GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen., 1, &rectangle);
68 }
69
70 /** Creates a speed ruler which we will use to drag around the
71 GeoPlot to test solutions.
72 Extend ruler backwards in time by plotting course using reciprocal
73 bearings. */
74 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::CreateSpeedRulercxx . . $ TargetMotionAnalysis#CreateSpeedRuler(49f6e7a06ebc5aa8).(){
75 }
76
77 /** Display the LOS Diagram*/
78 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DisplayLOScxx . . $ TargetMotionAnalysis#DisplayLOS(49f6e7a06ebc5aa8).(){
79
80 double bearing_to_target;
81 double relative_bearing;
82 double recipbearing;
83 double var1;//a place to hold a value so we don't have to calc it twice
84 double destinationx; //the dest x&y point for
85 double destinationy; //the drawn line.
86 double direction;
87 int x,y;
88
89 bearing_to_target = storagecxx . . $ BoatPositionLog#storage.[sizecxx . . $ BoatPositionLog#size.-1].bearingcxx . . $ BoatPositionLog#position#bearing.;
90 ClearGeoPlotcxx . . $ TargetMotionAnalysis#ClearGeoPlot(49f6e7a06ebc5aa8).();
91
92 //Draw LOS
93 DrawLinecxx . . $ TargetMotionAnalysis#DrawLine(6fb2c7d311165c4f).(250, 292, 250, 100, whitecxx . . $ TargetMotionAnalysis#white.);
94
95
96 //Draw our ships angle relative to the LOS
97 if(our_headingcxx . . $ TargetMotionAnalysis#our_heading. > bearing_to_target) bearing_to_target += 360;
98 relative_bearing = bearing_to_target - our_headingcxx . . $ TargetMotionAnalysis#our_heading.;
99
100 x=250;
101 y=292;
102 direction = 360 - relative_bearing;
103 our_speedcxx . . $ TargetMotionAnalysis#our_speed.=(our_speedcxx . . $ TargetMotionAnalysis#our_speed.*3);
104 var1 = direction * 0.017453; //convert degrees to radians.
105 destinationx = (sincxx . . $ sin(fee4f1d22bc8e617).(var1) * our_speedcxx . . $ TargetMotionAnalysis#our_speed.) + x;
106 destinationy = (-1) * (coscxx . . $ cos(fee4f1d22bc8e617).(var1) * our_speedcxx . . $ TargetMotionAnalysis#our_speed.) + y;
107 DrawLinecxx . . $ TargetMotionAnalysis#DrawLine(6fb2c7d311165c4f).(x, y, (int)destinationx, (int)destinationy, yellowcxx . . $ TargetMotionAnalysis#yellow.);
108
109 //Draw targets angle relative to the LOS
110 x=250;
111 y=100;
112 if (bearing_to_target >= 180){
113 recipbearing = bearing_to_target - 180;
114 }else{
115 recipbearing = bearing_to_target + 180;
116 }
117 direction = target_headingcxx . . $ TargetMotionAnalysis#target_heading. + (180 - recipbearing);
118 target_speedcxx . . $ TargetMotionAnalysis#target_speed.=(target_speedcxx . . $ TargetMotionAnalysis#target_speed.*3);
119 var1 = direction * 0.017453; //convert degrees to radians.
120 destinationx = (sincxx . . $ sin(fee4f1d22bc8e617).(var1) * target_speedcxx . . $ TargetMotionAnalysis#target_speed.) + x;
121 destinationy = (-1) * (coscxx . . $ cos(fee4f1d22bc8e617).(var1) * target_speedcxx . . $ TargetMotionAnalysis#target_speed.) + y;
122 DrawLinecxx . . $ TargetMotionAnalysis#DrawLine(6fb2c7d311165c4f).(x, y, (int)destinationx, (int)destinationy, redcxx . . $ TargetMotionAnalysis#red.);
123
124 SDL_Rect rectangle;
125 rectangle.x=0;
126 rectangle.y=0;
127 rectangle.h=500;
128 rectangle.w=500;
129 SDL_UpdateRects(GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen., 1, &rectangle);
130
131 }
132
133 /** Plots the amount of error from the expected bearing to target
134 and the actual bearing recieved. */
135 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::BearingDevitaionPlotcxx . . $ TargetMotionAnalysis#BearingDevitaionPlot(49f6e7a06ebc5aa8).(){
136 }
137
138 /** Record the boats current position*/
139 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::RecordBoatPositioncxx . . $ TargetMotionAnalysis#RecordBoatPosition(dcadd90aaa0f609).(float latitude, float longitude, double bearing, Uint32cxx . . $ Uint32# tick){
140 Lockcxx . . $ TargetMotionAnalysis#Lock(49f6e7a06ebc5aa8).();
141 positioncxx . . $ BoatPositionLog#position# temp;
142 temp.latcxx . . $ BoatPositionLog#position#lat. = latitude;
143 temp.loncxx . . $ BoatPositionLog#position#lon. = longitude;
144 temp.bearingcxx . . $ BoatPositionLog#position#bearing. = bearing;
145 temp.tickcxx . . $ BoatPositionLog#position#tick. = tick;
146 RecBoatPoscxx . . $ BoatPositionLog#RecBoatPos(6882ec15dc2018f0).(temp);
147 UnLockcxx . . $ TargetMotionAnalysis#UnLock(49f6e7a06ebc5aa8).();
148 }
149
150 /** Lock Mutex */
151 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::Lockcxx . . $ TargetMotionAnalysis#Lock(49f6e7a06ebc5aa8).(){
152 SDL_mutexP(MutexLockcxx . . $ TargetMotionAnalysis#MutexLock.);
153 }
154
155 /** Unlock Mutex */
156 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::UnLockcxx . . $ TargetMotionAnalysis#UnLock(49f6e7a06ebc5aa8).(){
157 SDL_mutexV(MutexLockcxx . . $ TargetMotionAnalysis#MutexLock.);
158 }
159
160 /** Initialize the graphics */
161 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::InitGraphicscxx . . $ TargetMotionAnalysis#InitGraphics(49f6e7a06ebc5aa8).(){
162 SDL_Surface *screen = SDL_GetVideoSurface();
163 SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACEcxx . . $ `<external>/3508485105195885937/SDL_video.h:229:9`!, 500, 500, 16,
164 screen->format->Rmask,
165 screen->format->Gmask,
166 screen->format->Bmask,
167 screen->format->Amask);
168 GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen.=SDL_DisplayFormat(temp);
169 SDL_FreeSurface(temp);
170 textcolorcxx . . $ TargetMotionAnalysis#textcolor. = SDL_MapRGB(screen->format, 192, 255, 6);
171 blackcxx . . $ TargetMotionAnalysis#black. = SDL_MapRGB(screen->format, 0, 0, 0);
172 whitecxx . . $ TargetMotionAnalysis#white. = SDL_MapRGB(screen->format, 255, 255, 255);
173 redcxx . . $ TargetMotionAnalysis#red. = SDL_MapRGB(screen->format, 255, 99, 20);
174 greencxx . . $ TargetMotionAnalysis#green. = SDL_MapRGB(screen->format, 0, 255, 0);
175 yellowcxx . . $ TargetMotionAnalysis#yellow. = SDL_MapRGB(screen->format, 216, 255, 0);
176 mapcolorcxx . . $ TargetMotionAnalysis#mapcolor. = SDL_MapRGB(screen->format, 130, 201, 225);
177 ClearGeoPlotcxx . . $ TargetMotionAnalysis#ClearGeoPlot(49f6e7a06ebc5aa8).();
178 }
179 /** No descriptions */
180 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::PlotPixelcxx . . $ TargetMotionAnalysis#PlotPixel(f59d17f8b9f2d3e1).(int x, int y, Uint32cxx . . $ Uint32# color){
181 if (x > 499 || x < 0 || y > 499 || y < 0) {
182 return;
183 }
184
185 //place the pixel on the screen
186 Uint16cxx . . $ Uint16# *pixel_location;
187 pixel_location = (Uint16cxx . . $ Uint16# *)GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen.->pixels + y*GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen.->pitch/2 + x;
188 *pixel_location = color;
189 }
190 /** erases the work screen */
191 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::ClearGeoPlotcxx . . $ TargetMotionAnalysis#ClearGeoPlot(49f6e7a06ebc5aa8).(){
192 SDL_Rect rectangle;
193 rectangle.x=0;
194 rectangle.y=0; //define a rectangle on the screen and make it black
195 rectangle.h=500;
196 rectangle.w=500;
197 SDL_FillRect(GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen., &rectangle, blackcxx . . $ TargetMotionAnalysis#black.);
198 SDL_UpdateRects(GeoPlotScreencxx . . $ TargetMotionAnalysis#GeoPlotScreen., 1, &rectangle);
199 }
200 /** Plot the boats history */
201 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::PlotHistorycxx . . $ TargetMotionAnalysis#PlotHistory(b1146eedae1e1d0b).(int scale, int change_scrollx, int change_scrolly){
202 //scale is in YDS per pixel
203 int x, y; //where to place the ships
204 int xoffset = 0; //offsets to move the ships to
205 int yoffset = 0; //the defined place on map screen
206 static int scrolloffsetx=0; //offset to center map
207 static int scrolloffsety=0;
208 double var1; //just a place to hold a value so we don't have to calc it twice.
209 double destinationx; //the dest X&Y point for
210 double destinationy; //the drawn line.
211 int length = 2000;
212
213 scale = scale * 5;
214 if(centerGeoPlotcxx . . $ TargetMotionAnalysis#centerGeoPlot.){ //center map onto our own ships location
215 scrolloffsetx = 250 - (int)(storagecxx . . $ BoatPositionLog#storage.[sizecxx . . $ BoatPositionLog#size.-1].latcxx . . $ BoatPositionLog#position#lat. / scale);
216 scrolloffsety = 250 - (int)(storagecxx . . $ BoatPositionLog#storage.[sizecxx . . $ BoatPositionLog#size.-1].loncxx . . $ BoatPositionLog#position#lon. / scale);
217 }else{
218 scrolloffsetx += change_scrollx;
219 scrolloffsety += change_scrolly;
220 }
221 for (int index = 0; index < sizecxx . . $ BoatPositionLog#size.; index ++){
222 x = 500 - (int)(storagecxx . . $ BoatPositionLog#storage.[index].latcxx . . $ BoatPositionLog#position#lat. / scale);
223 x = x - scrolloffsetx;
224 y = 500 - (int)(storagecxx . . $ BoatPositionLog#storage.[index].loncxx . . $ BoatPositionLog#position#lon. / scale);
225 y = y - scrolloffsety;
226 if (x>10 && x<490 && y>10 && y<490){
227 x = x + xoffset;
228 y = y + yoffset;
229 DrawDotcxx . . $ TargetMotionAnalysis#DrawDot(f59d17f8b9f2d3e1).(x, y, yellowcxx . . $ TargetMotionAnalysis#yellow.);
230 }
231 var1 = storagecxx . . $ BoatPositionLog#storage.[index].bearingcxx . . $ BoatPositionLog#position#bearing. * 0.017453; //convert degrees to radians.
232 destinationx = (sincxx . . $ sin(fee4f1d22bc8e617).(var1) * length) + x;
233 destinationy = (-1) * (coscxx . . $ cos(fee4f1d22bc8e617).(var1) * (length/.75)) + y; //adjust to account for 4:3 screen ratio.
234 DrawLinecxx . . $ TargetMotionAnalysis#DrawLine(6fb2c7d311165c4f).(x, y, (int)destinationx, (int)destinationy, whitecxx . . $ TargetMotionAnalysis#white.);
235 }
236
237 }
238 /** Draws a line....What were you expecting? */
239 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DrawLinecxx . . $ TargetMotionAnalysis#DrawLine(6fb2c7d311165c4f).(int X1,int Y1,int X2,int Y2,Uint32cxx . . $ Uint32# Color){
240 int dx,dy,sdx,sdy,py,px,x,y;
241 dx = X2 - X1;
242 dy = Y2 - Y1;
243 if (dx < 0) sdx = -1;
244 else sdx = 1;
245 if (dy < 0) sdy = -1;
246 else sdy = 1;
247 dx = sdx * dx + 1;
248 dy = sdy * dy + 1;
249 x = 0;
250 y = 0;
251 px = X1;
252 py = Y1;
253 if (dx >= dy){
254 for (int x = 0; x < dx; x++){
255 PlotPixelcxx . . $ TargetMotionAnalysis#PlotPixel(f59d17f8b9f2d3e1).(px, py, Color);
256 y = y + dy;
257 if (y >= dx){
258 y = y - dx;
259 py = py + sdy;
260 }
261 px = px + sdx;
262 }
263 }else{
264 for (int y = 0; y < dy; y++){
265 PlotPixelcxx . . $ TargetMotionAnalysis#PlotPixel(f59d17f8b9f2d3e1).(px, py, Color);
266 x = x + dx;
267 if (x >= dy){
268 x = x - dy;
269 px = px + sdx;
270 }
271 py = py + sdy;
272 }
273 }
274 }
275 /** No descriptions */
276 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DrawDotcxx . . $ TargetMotionAnalysis#DrawDot(f59d17f8b9f2d3e1).(int x, int y, Uint32cxx . . $ Uint32# color){
277 int xc, yc, radius;
278 int theta, theta1, theta2;
279 xc = x;
280 yc = y;
281 radius = 2;
282 theta1 = 0;
283 theta2 = 360;
284
285 for(theta=theta1;theta<=theta2;theta+=5) {
286 x = xc + int(radius*coscxx . . $ cos(fee4f1d22bc8e617).(theta*3.14/180.0));
287 y = yc - int(radius*sincxx . . $ sin(fee4f1d22bc8e617).(theta*3.14/180.0));
288 PlotPixelcxx . . $ TargetMotionAnalysis#PlotPixel(f59d17f8b9f2d3e1).(x, y, color);
289 }
290 }
291
292 /** Increments plotscale to zoom in on the GeoPlot */
293 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::IncreasePlotScalecxx . . $ TargetMotionAnalysis#IncreasePlotScale(49f6e7a06ebc5aa8).(){
294 plotscalecxx . . $ TargetMotionAnalysis#plotscale.++;
295 if(plotscalecxx . . $ TargetMotionAnalysis#plotscale. > 15){
296 plotscalecxx . . $ TargetMotionAnalysis#plotscale. = 15;
297 }
298 }
299 /** Decriment the plotscale to zoom out of GeoPlot */
300 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::DecreasePlotScalecxx . . $ TargetMotionAnalysis#DecreasePlotScale(49f6e7a06ebc5aa8).(){
301 plotscalecxx . . $ TargetMotionAnalysis#plotscale.--;
302 if(plotscalecxx . . $ TargetMotionAnalysis#plotscale. < 1){
303 plotscalecxx . . $ TargetMotionAnalysis#plotscale. = 1;
304 }
305 }
306 /** No descriptions */
307 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::ToggleGeoPlotCentercxx . . $ TargetMotionAnalysis#ToggleGeoPlotCenter(49f6e7a06ebc5aa8).(){
308 centerGeoPlotcxx . . $ TargetMotionAnalysis#centerGeoPlot. = !centerGeoPlotcxx . . $ TargetMotionAnalysis#centerGeoPlot.;
309 }
310 /** Fill in the initial values for the solution. */
311 void TargetMotionAnalysiscxx . . $ TargetMotionAnalysis#::InitializeSolutioncxx . . $ TargetMotionAnalysis#InitializeSolution(b89d05379985c7fc).(float LatYards, float LonYards, int Speed, int Heading){
312 Solutioncxx . . $ TargetMotionAnalysis#Solution.[0].Lat_TotalYardscxx . . $ Coord#Lat_TotalYards. = LatYards;
313 Solutioncxx . . $ TargetMotionAnalysis#Solution.[0].Lon_TotalYardscxx . . $ Coord#Lon_TotalYards. = LonYards;
314 Solutioncxx . . $ TargetMotionAnalysis#Solution.[0].Speedcxx . . $ Coord#Speed. = Speed;
315 Solutioncxx . . $ TargetMotionAnalysis#Solution.[0].Headingcxx . . $ Coord#Heading. = Heading;
316 }