1 | #include "MStarguider.h"
|
---|
2 |
|
---|
3 | #include <fstream.h> // ifstream
|
---|
4 | #include <iostream.h> // cout
|
---|
5 | #include <iomanip.h> // cout
|
---|
6 |
|
---|
7 | #include <TH2F.h>
|
---|
8 | #include <TGraph.h>
|
---|
9 | #include <TTimer.h>
|
---|
10 | #include <TSystem.h>
|
---|
11 |
|
---|
12 | #include <TGMenu.h>
|
---|
13 | #include <TGLabel.h>
|
---|
14 | #include <TGButton.h>
|
---|
15 | #include <TGSplitter.h> // TGHorizontal3DLine
|
---|
16 | #include <TGTextEntry.h>
|
---|
17 |
|
---|
18 | #include "MString.h"
|
---|
19 |
|
---|
20 | #include "MCosy.h"
|
---|
21 | #include "MCaos.h"
|
---|
22 |
|
---|
23 | #include "MGImage.h"
|
---|
24 | #include "MGCoordinates.h"
|
---|
25 |
|
---|
26 | #include "coord.h"
|
---|
27 |
|
---|
28 | #include "Camera.h"
|
---|
29 | #include "PngReader.h"
|
---|
30 |
|
---|
31 | #include "Led.h"
|
---|
32 | #include "Writer.h"
|
---|
33 | #include "FilterLed.h"
|
---|
34 | #include "MStarList.h"
|
---|
35 | #include "CaosFilter.h"
|
---|
36 | #include "StarCatalog.h"
|
---|
37 | #include "MGeomCamMagic.h"
|
---|
38 | #include "MAstroCamera.h"
|
---|
39 |
|
---|
40 | #include "MGMenu.h"
|
---|
41 | #include "MGCosy.h"
|
---|
42 |
|
---|
43 | ClassImp(MStarguider);
|
---|
44 |
|
---|
45 | enum {
|
---|
46 | IDM_kFilter,
|
---|
47 | IDM_kFindStar,
|
---|
48 | IDM_kCaosFilter,
|
---|
49 | IDM_kCatalog,
|
---|
50 | IDM_kStarguider,
|
---|
51 | IDM_kStart,
|
---|
52 | IDM_kStop,
|
---|
53 | IDM_kFileType,
|
---|
54 | IDM_kPPM,
|
---|
55 | IDM_kPNG,
|
---|
56 | IDM_kOnce,
|
---|
57 | IDM_kStretch,
|
---|
58 | IDM_kInput,
|
---|
59 | IDM_kChannel1,
|
---|
60 | IDM_kChannel2,
|
---|
61 | IDM_kContinous,
|
---|
62 | IDM_kRate25ps,
|
---|
63 | IDM_kRate5ps,
|
---|
64 | IDM_kRate1s,
|
---|
65 | IDM_kRate5s,
|
---|
66 | IDM_kRate30s,
|
---|
67 | IDM_kRate1m,
|
---|
68 | IDM_kRate5m,
|
---|
69 | IDM_kSetup,
|
---|
70 | IDM_kLimMag3,
|
---|
71 | IDM_kLimMag4,
|
---|
72 | IDM_kLimMag5,
|
---|
73 | IDM_kLimMag6,
|
---|
74 | IDM_kLimMag7,
|
---|
75 | IDM_kLimMag8,
|
---|
76 | IDM_kLimMag9,
|
---|
77 | IDM_kPixSize,
|
---|
78 | IDM_kAngle,
|
---|
79 | IDM_kInterpol250,
|
---|
80 | IDM_kInterpol125,
|
---|
81 | IDM_kInterpol50,
|
---|
82 | IDM_kInterpol25,
|
---|
83 | IDM_kInterpol10,
|
---|
84 | IDM_kInterpol5,
|
---|
85 | IDM_kInterpol2,
|
---|
86 | IDM_kInterpol1,
|
---|
87 | IDM_kCaosPrintRings,
|
---|
88 | IDM_kCaosPrintLeds,
|
---|
89 | IDM_kCaosAnalStart,
|
---|
90 | IDM_kCaosAnalStop,
|
---|
91 | IDM_kCaosWriteStart,
|
---|
92 | IDM_kCaosWriteStop,
|
---|
93 | IDM_kResetHistograms
|
---|
94 | };
|
---|
95 |
|
---|
96 | Bool_t MStarguider::HandleTimer(TTimer *t)
|
---|
97 | {
|
---|
98 | if (IsMapped())
|
---|
99 | {
|
---|
100 | fImage->DoRedraw();
|
---|
101 | fZoomImage->DoRedraw();
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (fCosy && fCosy->GetWin()->IsMapped())
|
---|
105 | fCosy->GetWin()->GetImage()->DoRedraw();
|
---|
106 |
|
---|
107 | return kTRUE;
|
---|
108 | }
|
---|
109 |
|
---|
110 | #define kZOOM 96
|
---|
111 |
|
---|
112 | XY MStarguider::GetCoordinates() const
|
---|
113 | {
|
---|
114 | return fPZdAz->GetCoordinates();
|
---|
115 | }
|
---|
116 |
|
---|
117 | void MStarguider::InitGui(Int_t channel)
|
---|
118 | {
|
---|
119 | fList = new MGList;
|
---|
120 |
|
---|
121 | const TGWindow *p=gClient->GetRoot();
|
---|
122 |
|
---|
123 | fChannel = new MGPopupMenu(p);
|
---|
124 | fChannel->AddEntry("Channel #1", IDM_kChannel1);
|
---|
125 | fChannel->AddEntry("Channel #2", IDM_kChannel2);
|
---|
126 | fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2);
|
---|
127 | fChannel->Associate(this);
|
---|
128 | fList->Add(fChannel);
|
---|
129 |
|
---|
130 | //
|
---|
131 | // Create Menu for MStarguider Display
|
---|
132 | //
|
---|
133 | fDisplay = new MGPopupMenu(p);
|
---|
134 | fDisplay->AddEntry("&Filter", IDM_kFilter);
|
---|
135 | fDisplay->AddEntry("Find &Star", IDM_kFindStar);
|
---|
136 | fDisplay->AddEntry("C&aosFilter", IDM_kCaosFilter);
|
---|
137 | fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
|
---|
138 | fDisplay->AddEntry("Starguider", IDM_kStarguider);
|
---|
139 | fDisplay->AddEntry("Stretch", IDM_kStretch);
|
---|
140 | if (channel>=0)
|
---|
141 | fDisplay->AddPopup("&Input", fChannel);
|
---|
142 | fDisplay->DisableEntry(IDM_kStarguider);
|
---|
143 | fDisplay->CheckEntry(IDM_kStretch);
|
---|
144 | fDisplay->Associate(this);
|
---|
145 | fList->Add(fDisplay);
|
---|
146 |
|
---|
147 | fFileType = new MGPopupMenu(p);
|
---|
148 | fFileType->AddEntry("PP&M", IDM_kPPM);
|
---|
149 | fFileType->AddEntry("&PNG", IDM_kPNG);
|
---|
150 | fFileType->CheckEntry(IDM_kPNG);
|
---|
151 | fFileType->Associate(this);
|
---|
152 | fList->Add(fFileType);
|
---|
153 |
|
---|
154 | fWriteType = new MGPopupMenu(p);
|
---|
155 | fWriteType->AddEntry("&Once", IDM_kOnce);
|
---|
156 | fWriteType->AddEntry("&Continous", IDM_kContinous);
|
---|
157 | fWriteType->CheckEntry(IDM_kOnce);
|
---|
158 | fWriteType->Associate(this);
|
---|
159 | fList->Add(fWriteType);
|
---|
160 |
|
---|
161 | fWriteRate = new MGPopupMenu(p);
|
---|
162 | fWriteRate->AddEntry("25/s", IDM_kRate25ps);
|
---|
163 | fWriteRate->AddEntry("5/s", IDM_kRate5ps);
|
---|
164 | fWriteRate->AddEntry("1s", IDM_kRate1s);
|
---|
165 | fWriteRate->AddEntry("5s", IDM_kRate5s);
|
---|
166 | fWriteRate->AddEntry("30s", IDM_kRate30s);
|
---|
167 | fWriteRate->AddEntry("1min", IDM_kRate1m);
|
---|
168 | fWriteRate->AddEntry("5min", IDM_kRate5m);
|
---|
169 | fWriteRate->CheckEntry(IDM_kRate1m);
|
---|
170 | fWriteRate->Associate(this);
|
---|
171 | fList->Add(fWriteRate);
|
---|
172 |
|
---|
173 | fWrtRate = 25*60;
|
---|
174 |
|
---|
175 | fWritePictures = new MGPopupMenu(p);
|
---|
176 | fWritePictures->AddEntry("&Start", IDM_kStart);
|
---|
177 | fWritePictures->AddEntry("Sto&p", IDM_kStop);
|
---|
178 | fWritePictures->AddSeparator();
|
---|
179 | fWritePictures->AddPopup("File &Type", fFileType);
|
---|
180 | fWritePictures->AddPopup("&Write Type", fWriteType);
|
---|
181 | fWritePictures->AddPopup("Write &Rate", fWriteRate);
|
---|
182 | fWritePictures->DisableEntry(IDM_kStop);
|
---|
183 | fWritePictures->Associate(this);
|
---|
184 | fList->Add(fWritePictures);
|
---|
185 |
|
---|
186 | fLimMag = new MGPopupMenu(p);
|
---|
187 | fLimMag->AddEntry("3", IDM_kLimMag3);
|
---|
188 | fLimMag->AddEntry("4", IDM_kLimMag4);
|
---|
189 | fLimMag->AddEntry("5", IDM_kLimMag5);
|
---|
190 | fLimMag->AddEntry("6", IDM_kLimMag6);
|
---|
191 | fLimMag->AddEntry("7", IDM_kLimMag7);
|
---|
192 | fLimMag->AddEntry("8", IDM_kLimMag8);
|
---|
193 | fLimMag->AddEntry("9", IDM_kLimMag9);
|
---|
194 | fLimMag->CheckEntry(IDM_kLimMag8);
|
---|
195 | fLimMag->Associate(this);
|
---|
196 | fList->Add(fLimMag);
|
---|
197 |
|
---|
198 | fSao->SetLimitMag(7.0);
|
---|
199 |
|
---|
200 | fInterpol = new MGPopupMenu(p);
|
---|
201 | fInterpol->AddEntry("250", IDM_kInterpol250);
|
---|
202 | fInterpol->AddEntry("125", IDM_kInterpol125);
|
---|
203 | fInterpol->AddEntry("50", IDM_kInterpol50);
|
---|
204 | fInterpol->AddEntry("25", IDM_kInterpol25);
|
---|
205 | fInterpol->AddEntry("10", IDM_kInterpol10);
|
---|
206 | fInterpol->AddEntry("5", IDM_kInterpol5);
|
---|
207 | fInterpol->AddEntry("2", IDM_kInterpol2);
|
---|
208 | fInterpol->AddEntry("Off", IDM_kInterpol1);
|
---|
209 | fInterpol->Associate(this);
|
---|
210 | fList->Add(fInterpol);
|
---|
211 |
|
---|
212 | TString disp=gVirtualX->DisplayName();
|
---|
213 | cout << "Display: " << disp << endl;
|
---|
214 | if (disp.First(':')>=0)
|
---|
215 | disp=disp(0, disp.First(':'));
|
---|
216 |
|
---|
217 | if (disp.IsNull() || disp==(TString)"localhost")
|
---|
218 | {
|
---|
219 | fInterpol->CheckEntry(IDM_kInterpol5);
|
---|
220 | fIntRate = 5;
|
---|
221 | }
|
---|
222 | else
|
---|
223 | {
|
---|
224 | fInterpol->CheckEntry(IDM_kInterpol125);
|
---|
225 | fIntRate = 125;
|
---|
226 | }
|
---|
227 |
|
---|
228 | fSetup = new MGPopupMenu(p);
|
---|
229 | fSetup->AddPopup("Lim. &Magnitude", fLimMag);
|
---|
230 | fSetup->AddPopup("Disp. &Interpolation", fInterpol);
|
---|
231 | //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
|
---|
232 | fSetup->Associate(this);
|
---|
233 | fList->Add(fSetup);
|
---|
234 |
|
---|
235 | fCaosPrint = new MGPopupMenu(p);
|
---|
236 | fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds);
|
---|
237 | fCaosPrint->AddEntry("&Rings", IDM_kCaosPrintRings);
|
---|
238 | fCaosPrint->Associate(this);
|
---|
239 | fList->Add(fCaosPrint);
|
---|
240 |
|
---|
241 | fCaosWrite = new MGPopupMenu(p);
|
---|
242 | fCaosWrite->AddEntry("&Start", IDM_kCaosWriteStart);
|
---|
243 | fCaosWrite->AddEntry("Sto&p", IDM_kCaosWriteStop);
|
---|
244 | fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
|
---|
245 | fCaosWrite->Associate(this);
|
---|
246 | fList->Add(fCaosWrite);
|
---|
247 |
|
---|
248 | fCaosAnalyse = new MGPopupMenu(p);
|
---|
249 | fCaosAnalyse->AddEntry("S&tart Analyse", IDM_kCaosAnalStart);
|
---|
250 | fCaosAnalyse->AddEntry("St&opp Analyse", IDM_kCaosAnalStop);
|
---|
251 | fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
|
---|
252 | // fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
|
---|
253 | // fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
|
---|
254 | fCaosAnalyse->Associate(this);
|
---|
255 | fList->Add(fCaosAnalyse);
|
---|
256 |
|
---|
257 | fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
|
---|
258 | fMenu->AddPopup("&Display", fDisplay, NULL);
|
---|
259 | fMenu->AddPopup("&WritePics", fWritePictures, NULL);
|
---|
260 | fMenu->AddPopup("&Setup", fSetup, NULL);
|
---|
261 | fMenu->Resize(fMenu->GetDefaultSize());
|
---|
262 | fMenu->BindKeys(this);
|
---|
263 | AddFrame(fMenu);
|
---|
264 | fList->Add(fMenu);
|
---|
265 |
|
---|
266 | fCaOs = new MGPopupMenu(p);
|
---|
267 | fCaOs->AddPopup("&Write", fCaosWrite);
|
---|
268 | fCaOs->AddPopup("&Print", fCaosPrint);
|
---|
269 | fCaOs->AddPopup("&Analyse", fCaosAnalyse);
|
---|
270 | fCaOs->Associate(this);
|
---|
271 | fCaOs->BindKeys(fMenu, this);
|
---|
272 | fList->Add(fCaOs);
|
---|
273 |
|
---|
274 | fCRaDec = new MGCoordinates(this, kETypeRaDec);
|
---|
275 | fCRaDec->Move(4, fMenu->GetDefaultHeight()+584);
|
---|
276 | AddFrame(fCRaDec);
|
---|
277 | fList->Add(fCRaDec);
|
---|
278 |
|
---|
279 | fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
|
---|
280 | fCZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+584);
|
---|
281 | AddFrame(fCZdAz);
|
---|
282 | fList->Add(fCZdAz);
|
---|
283 |
|
---|
284 | fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
|
---|
285 | fPZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+630);
|
---|
286 | AddFrame(fPZdAz);
|
---|
287 | fList->Add(fPZdAz);
|
---|
288 |
|
---|
289 | fTPoint = new TGTextButton(this, "TPoint");
|
---|
290 | fTPoint->Move(4, fMenu->GetDefaultHeight()+665);
|
---|
291 | fTPoint->AllowStayDown(kTRUE);
|
---|
292 | AddFrame(fTPoint);
|
---|
293 | fList->Add(fTPoint);
|
---|
294 |
|
---|
295 | fFps = new TGLabel(this, "---fps");
|
---|
296 | fFps->SetTextJustify(kTextRight);
|
---|
297 | fFps->Move(633, fMenu->GetDefaultHeight()+578);
|
---|
298 | AddFrame(fFps);
|
---|
299 | fList->Add(fFps);
|
---|
300 |
|
---|
301 | fPosZoom = new TGLabel(this, "----.--d/----.--d (----, ----)");
|
---|
302 | fPosZoom->SetTextJustify(kTextRight);
|
---|
303 | fPosZoom->Move(620, fMenu->GetDefaultHeight()+678);
|
---|
304 | AddFrame(fPosZoom);
|
---|
305 | fList->Add(fPosZoom);
|
---|
306 |
|
---|
307 | TGLabel *l = new TGLabel(this, "Arb.-Sky Pos");
|
---|
308 | l->SetTextJustify(kTextLeft);
|
---|
309 | l->Move(480+32, fMenu->GetDefaultHeight()+590);
|
---|
310 | AddFrame(l);
|
---|
311 | fList->Add(l);
|
---|
312 |
|
---|
313 | l = new TGLabel(this, "arcsec/pix");
|
---|
314 | l->SetTextJustify(kTextLeft);
|
---|
315 | l->Move(605, fMenu->GetDefaultHeight()+619+13);
|
---|
316 | AddFrame(l);
|
---|
317 | fList->Add(l);
|
---|
318 |
|
---|
319 | l = new TGLabel(this, "deg");
|
---|
320 | l->SetTextJustify(kTextLeft);
|
---|
321 | l->Move(605, fMenu->GetDefaultHeight()+619-10);
|
---|
322 | AddFrame(l);
|
---|
323 | fList->Add(l);
|
---|
324 |
|
---|
325 | l = new TGLabel(this, "Pointing Pos");
|
---|
326 | l->SetTextJustify(kTextLeft);
|
---|
327 | l->Move(480+32, fMenu->GetDefaultHeight()+655);
|
---|
328 | AddFrame(l);
|
---|
329 | fList->Add(l);
|
---|
330 |
|
---|
331 | const Double_t pixsize = 23.4;
|
---|
332 |
|
---|
333 | fSao->SetPixSize(pixsize);
|
---|
334 | fSao->SetRotationAngle(0);
|
---|
335 |
|
---|
336 | TString txt;
|
---|
337 | txt += pixsize;
|
---|
338 |
|
---|
339 | fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
|
---|
340 | fPixSize->SetAlignment(kTextCenterX);
|
---|
341 | fPixSize->Move(547, fMenu->GetDefaultHeight()+617+13);
|
---|
342 | AddFrame(fPixSize);
|
---|
343 | fList->Add(fPixSize);
|
---|
344 |
|
---|
345 | fAngle = new TGTextEntry(this, " 0", IDM_kAngle);
|
---|
346 | fAngle->SetAlignment(kTextCenterX);
|
---|
347 | fAngle->Move(547, fMenu->GetDefaultHeight()+617-10);
|
---|
348 | AddFrame(fAngle);
|
---|
349 | fList->Add(fAngle);
|
---|
350 |
|
---|
351 | // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
|
---|
352 | // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
|
---|
353 | // fList->Add(fLineSep);
|
---|
354 |
|
---|
355 | //
|
---|
356 | // Create Image Display
|
---|
357 | //
|
---|
358 | fZoomImage = new MGImage(this, kZOOM, kZOOM);
|
---|
359 | fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
|
---|
360 | AddFrame(fZoomImage);
|
---|
361 | fList->Add(fZoomImage);
|
---|
362 |
|
---|
363 | fImage = new MGImage(this, 768, 576);
|
---|
364 | fImage->Move(0, fMenu->GetDefaultHeight());
|
---|
365 | AddFrame(fImage);
|
---|
366 | fList->Add(fImage);
|
---|
367 |
|
---|
368 | //
|
---|
369 | // Make everything visible
|
---|
370 | //
|
---|
371 | SetWindowName("MStarguider Main Window");
|
---|
372 | SetIconName("MStarguider");
|
---|
373 |
|
---|
374 | MapSubwindows();
|
---|
375 | fTPoint->UnmapWindow();
|
---|
376 | MapWindow();
|
---|
377 |
|
---|
378 | IconifyWindow();
|
---|
379 |
|
---|
380 | //------------------------------------------------------------
|
---|
381 | // XY xy(3.819444, 24.05333);
|
---|
382 | // fCRaDec->SetCoordinates(xy);
|
---|
383 | // fRaDec->Set(xy.X()*360/24, xy.Y());
|
---|
384 | //------------------------------------------------------------
|
---|
385 | }
|
---|
386 |
|
---|
387 | MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel)
|
---|
388 | : TGMainFrame(gClient->GetRoot(), 768, 740), fCosy(NULL), fOutTp(0), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
|
---|
389 | {
|
---|
390 | cout << " #### FIXME: Make MCaos Thread safe!" << endl;
|
---|
391 |
|
---|
392 | fSao = new StarCatalog(obs);
|
---|
393 | fRaDec = new RaDec(180, 40);
|
---|
394 |
|
---|
395 | fCaos = new MCaos;
|
---|
396 | fCaos->ReadResources();
|
---|
397 |
|
---|
398 | InitGui(channel);
|
---|
399 |
|
---|
400 | fTimer=new TTimer(this, 1000/25); // 40ms
|
---|
401 | fTimer->TurnOn();
|
---|
402 |
|
---|
403 | fTime.Now();
|
---|
404 |
|
---|
405 | gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
|
---|
406 |
|
---|
407 | if (channel<0)
|
---|
408 | fGetter=new PngReader(*this);
|
---|
409 | else
|
---|
410 | {
|
---|
411 | fGetter = new Camera(*this, channel);
|
---|
412 | ((Camera*)fGetter)->Loop(0);
|
---|
413 | }
|
---|
414 | }
|
---|
415 |
|
---|
416 | MStarguider::~MStarguider()
|
---|
417 | {
|
---|
418 | fGetter->ExitLoop();
|
---|
419 | delete fGetter;
|
---|
420 |
|
---|
421 | gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
|
---|
422 |
|
---|
423 | fTimer->TurnOff();
|
---|
424 | delete fTimer;
|
---|
425 |
|
---|
426 | delete fList;
|
---|
427 |
|
---|
428 | delete fCaos;
|
---|
429 | delete fSao;
|
---|
430 | delete fRaDec;
|
---|
431 |
|
---|
432 | if (fOutTp)
|
---|
433 | delete fOutTp;
|
---|
434 |
|
---|
435 | cout << "Camera Display destroyed." << endl;
|
---|
436 | }
|
---|
437 |
|
---|
438 | void MStarguider::Layout()
|
---|
439 | {
|
---|
440 | // Resize(GetDefaultSize());
|
---|
441 | }
|
---|
442 |
|
---|
443 | void MStarguider::CloseWindow()
|
---|
444 | {
|
---|
445 | cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
|
---|
446 |
|
---|
447 | //fClient.ExitLoop();
|
---|
448 | // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
|
---|
449 | gSystem->ExitLoop();
|
---|
450 | }
|
---|
451 |
|
---|
452 | void MStarguider::Toggle(MGPopupMenu *p, UInt_t id)
|
---|
453 | {
|
---|
454 | if (p->IsEntryChecked(id))
|
---|
455 | p->UnCheckEntry(id);
|
---|
456 | else
|
---|
457 | p->CheckEntry(id);
|
---|
458 | }
|
---|
459 |
|
---|
460 | Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
|
---|
461 | {
|
---|
462 | switch (GET_MSG(msg))
|
---|
463 | {
|
---|
464 | case kC_TEXTENTRY:
|
---|
465 | if (GET_SUBMSG(msg)==kTE_ENTER)
|
---|
466 | switch (mp1)
|
---|
467 | {
|
---|
468 | case IDM_kPixSize:
|
---|
469 | {
|
---|
470 | const Float_t pixsize = atof(fPixSize->GetText());
|
---|
471 | cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
|
---|
472 | fSao->SetPixSize(pixsize);
|
---|
473 | return kTRUE;
|
---|
474 | }
|
---|
475 | case IDM_kAngle:
|
---|
476 | {
|
---|
477 | const Float_t angle = atof(fAngle->GetText());
|
---|
478 | cout << "Rotation Angle changed to " << angle << "deg" << endl;
|
---|
479 | fSao->SetRotationAngle(angle);
|
---|
480 | return kTRUE;
|
---|
481 | }
|
---|
482 | }
|
---|
483 | return kTRUE;
|
---|
484 |
|
---|
485 | case kC_COMMAND:
|
---|
486 | switch (GET_SUBMSG(msg))
|
---|
487 | {
|
---|
488 | case kCM_MENU:
|
---|
489 | switch (mp1)
|
---|
490 | {
|
---|
491 | case IDM_kCatalog:
|
---|
492 | Toggle(fDisplay, IDM_kCatalog);
|
---|
493 | if (fDisplay->IsEntryChecked(IDM_kCatalog))
|
---|
494 | fDisplay->EnableEntry(IDM_kStarguider);
|
---|
495 | else
|
---|
496 | {
|
---|
497 | fDisplay->UnCheckEntry(IDM_kStarguider);
|
---|
498 | fDisplay->DisableEntry(IDM_kStarguider);
|
---|
499 | }
|
---|
500 | return kTRUE;
|
---|
501 |
|
---|
502 | case IDM_kStarguider:
|
---|
503 | Toggle(fDisplay, IDM_kStarguider);
|
---|
504 | gSystem->Unlink("tracking_error.txt");
|
---|
505 | return kTRUE;
|
---|
506 |
|
---|
507 | case IDM_kFilter:
|
---|
508 | Toggle(fDisplay, IDM_kFilter);
|
---|
509 | if (fDisplay->IsEntryChecked(IDM_kFilter))
|
---|
510 | fDisplay->EnableEntry(IDM_kStarguider);
|
---|
511 | else
|
---|
512 | {
|
---|
513 | fDisplay->UnCheckEntry(IDM_kStarguider);
|
---|
514 | fDisplay->DisableEntry(IDM_kStarguider);
|
---|
515 | }
|
---|
516 | return kTRUE;
|
---|
517 |
|
---|
518 | case IDM_kFindStar:
|
---|
519 | Toggle(fDisplay, IDM_kFindStar);
|
---|
520 | if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy)
|
---|
521 | fTPoint->MapWindow();
|
---|
522 | else
|
---|
523 | {
|
---|
524 | fTPoint->UnmapWindow();
|
---|
525 | fTPoint->SetDown(kFALSE);
|
---|
526 | }
|
---|
527 | return kTRUE;
|
---|
528 |
|
---|
529 | case IDM_kStretch:
|
---|
530 | Toggle(fDisplay, IDM_kStretch);
|
---|
531 | return kTRUE;
|
---|
532 |
|
---|
533 | case IDM_kCaosFilter:
|
---|
534 | //if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
|
---|
535 | // fCaos->OpenFile();
|
---|
536 | Toggle(fDisplay, IDM_kCaosFilter);
|
---|
537 | if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
|
---|
538 | fMenu->AddPopup("&CaOs", fCaOs, NULL);
|
---|
539 | else
|
---|
540 | {
|
---|
541 | if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
|
---|
542 | fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
|
---|
543 | if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
|
---|
544 | fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
|
---|
545 | if(fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
|
---|
546 | {
|
---|
547 | fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
|
---|
548 | fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
|
---|
549 | fCaos->DeleteHistograms();
|
---|
550 | }
|
---|
551 | if(fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
|
---|
552 | {
|
---|
553 | fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
|
---|
554 | fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
|
---|
555 | fCaos->CloseFile();
|
---|
556 | }
|
---|
557 | fMenu->RemovePopup("CaOs");
|
---|
558 | }
|
---|
559 | fMenu->Resize(fMenu->GetDefaultSize());
|
---|
560 | MapSubwindows();
|
---|
561 | MapWindow();
|
---|
562 | return kTRUE;
|
---|
563 |
|
---|
564 | case IDM_kCaosPrintLeds:
|
---|
565 | case IDM_kCaosPrintRings:
|
---|
566 | Toggle(fCaosPrint, mp1);
|
---|
567 | return kTRUE;
|
---|
568 |
|
---|
569 | case IDM_kCaosAnalStart:
|
---|
570 | fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart);
|
---|
571 | fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop);
|
---|
572 | fCaos->InitHistograms();
|
---|
573 | return kTRUE;
|
---|
574 |
|
---|
575 | case IDM_kCaosAnalStop:
|
---|
576 | fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
|
---|
577 | fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
|
---|
578 | fCaos->ShowHistograms();
|
---|
579 | fCaos->DeleteHistograms();
|
---|
580 | return kTRUE;
|
---|
581 |
|
---|
582 | case IDM_kCaosWriteStart:
|
---|
583 | fCaosWrite->DisableEntry(IDM_kCaosWriteStart);
|
---|
584 | fCaosWrite->EnableEntry(IDM_kCaosWriteStop);
|
---|
585 | fCaos->OpenFile();
|
---|
586 | return kTRUE;
|
---|
587 |
|
---|
588 | case IDM_kCaosWriteStop:
|
---|
589 | fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
|
---|
590 | fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
|
---|
591 | fCaos->CloseFile();
|
---|
592 | return kTRUE;
|
---|
593 |
|
---|
594 | case IDM_kStart:
|
---|
595 | fWritePictures->DisableEntry(IDM_kStart);
|
---|
596 | fWritePictures->EnableEntry(IDM_kStop);
|
---|
597 | return kTRUE;
|
---|
598 |
|
---|
599 | case IDM_kStop:
|
---|
600 | fWritePictures->DisableEntry(IDM_kStop);
|
---|
601 | fWritePictures->EnableEntry(IDM_kStart);
|
---|
602 | return kTRUE;
|
---|
603 |
|
---|
604 | case IDM_kPNG:
|
---|
605 | fFileType->CheckEntry(IDM_kPNG);
|
---|
606 | fFileType->UnCheckEntry(IDM_kPPM);
|
---|
607 | return kTRUE;
|
---|
608 |
|
---|
609 | case IDM_kPPM:
|
---|
610 | fFileType->CheckEntry(IDM_kPPM);
|
---|
611 | fFileType->UnCheckEntry(IDM_kPNG);
|
---|
612 | return kTRUE;
|
---|
613 |
|
---|
614 | case IDM_kOnce:
|
---|
615 | fWriteType->CheckEntry(IDM_kOnce);
|
---|
616 | fWriteType->UnCheckEntry(IDM_kContinous);
|
---|
617 | return kTRUE;
|
---|
618 |
|
---|
619 | case IDM_kContinous:
|
---|
620 | fWriteType->CheckEntry(IDM_kContinous);
|
---|
621 | fWriteType->UnCheckEntry(IDM_kOnce);
|
---|
622 | return kTRUE;
|
---|
623 |
|
---|
624 | case IDM_kRate25ps:
|
---|
625 | case IDM_kRate5ps:
|
---|
626 | case IDM_kRate1s:
|
---|
627 | case IDM_kRate5s:
|
---|
628 | case IDM_kRate30s:
|
---|
629 | case IDM_kRate1m:
|
---|
630 | case IDM_kRate5m:
|
---|
631 | for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
|
---|
632 | if (mp1==i)
|
---|
633 | fWriteRate->CheckEntry(i);
|
---|
634 | else
|
---|
635 | fWriteRate->UnCheckEntry(i);
|
---|
636 | switch (mp1)
|
---|
637 | {
|
---|
638 | case IDM_kRate25ps:
|
---|
639 | fWrtRate = 1;
|
---|
640 | return kTRUE;
|
---|
641 | case IDM_kRate5ps:
|
---|
642 | fWrtRate = 5;
|
---|
643 | return kTRUE;
|
---|
644 | case IDM_kRate1s:
|
---|
645 | fWrtRate = 25;
|
---|
646 | return kTRUE;
|
---|
647 | case IDM_kRate5s:
|
---|
648 | fWrtRate = 5*25;
|
---|
649 | return kTRUE;
|
---|
650 | case IDM_kRate30s:
|
---|
651 | fWrtRate = 30*25;
|
---|
652 | return kTRUE;
|
---|
653 | case IDM_kRate1m:
|
---|
654 | fWrtRate = 60*25;
|
---|
655 | return kTRUE;
|
---|
656 | case IDM_kRate5m:
|
---|
657 | fWrtRate = 5*60*25;
|
---|
658 | return kTRUE;
|
---|
659 | }
|
---|
660 | return kTRUE;
|
---|
661 |
|
---|
662 | case IDM_kChannel1:
|
---|
663 | case IDM_kChannel2:
|
---|
664 | {
|
---|
665 | const Int_t ch0 = fChannel->IsEntryChecked(IDM_kChannel1) ? 0 : 1;
|
---|
666 | const Int_t ch1 = mp1==IDM_kChannel1 ? 0 : 1;
|
---|
667 | if (ch0==ch1)
|
---|
668 | return kTRUE;
|
---|
669 |
|
---|
670 | fChannel->CheckEntry (ch1==0?IDM_kChannel1:IDM_kChannel2);
|
---|
671 | fChannel->UnCheckEntry(ch1==1?IDM_kChannel1:IDM_kChannel2);
|
---|
672 | delete fGetter;
|
---|
673 | usleep(150000); // FIX: Device or resource busy.
|
---|
674 | fGetter = new Camera(*this, ch1);
|
---|
675 | ((Camera*)fGetter)->Loop(0);
|
---|
676 | }
|
---|
677 | return kTRUE;
|
---|
678 |
|
---|
679 | case IDM_kInterpol250:
|
---|
680 | case IDM_kInterpol125:
|
---|
681 | case IDM_kInterpol50:
|
---|
682 | case IDM_kInterpol25:
|
---|
683 | case IDM_kInterpol10:
|
---|
684 | case IDM_kInterpol5:
|
---|
685 | case IDM_kInterpol2:
|
---|
686 | case IDM_kInterpol1:
|
---|
687 | for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++)
|
---|
688 | if (mp1==i)
|
---|
689 | fInterpol->CheckEntry(i);
|
---|
690 | else
|
---|
691 | fInterpol->UnCheckEntry(i);
|
---|
692 | switch (mp1)
|
---|
693 | {
|
---|
694 | case IDM_kInterpol1:
|
---|
695 | fIntRate = 1;
|
---|
696 | return kTRUE;
|
---|
697 | case IDM_kInterpol2:
|
---|
698 | fIntRate = 2;
|
---|
699 | return kTRUE;
|
---|
700 | case IDM_kInterpol5:
|
---|
701 | fIntRate = 5;
|
---|
702 | return kTRUE;
|
---|
703 | case IDM_kInterpol10:
|
---|
704 | fIntRate = 10;
|
---|
705 | return kTRUE;
|
---|
706 | case IDM_kInterpol25:
|
---|
707 | fIntRate = 25;
|
---|
708 | return kTRUE;
|
---|
709 | case IDM_kInterpol50:
|
---|
710 | fIntRate = 50;
|
---|
711 | return kTRUE;
|
---|
712 | case IDM_kInterpol125:
|
---|
713 | fIntRate = 125;
|
---|
714 | return kTRUE;
|
---|
715 | case IDM_kInterpol250:
|
---|
716 | fIntRate = 250;
|
---|
717 | return kTRUE;
|
---|
718 | }
|
---|
719 | return kTRUE;
|
---|
720 |
|
---|
721 | case IDM_kLimMag3:
|
---|
722 | case IDM_kLimMag4:
|
---|
723 | case IDM_kLimMag5:
|
---|
724 | case IDM_kLimMag6:
|
---|
725 | case IDM_kLimMag7:
|
---|
726 | case IDM_kLimMag8:
|
---|
727 | case IDM_kLimMag9:
|
---|
728 | for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
|
---|
729 | if (mp1==i)
|
---|
730 | fLimMag->CheckEntry(i);
|
---|
731 | else
|
---|
732 | fLimMag->UnCheckEntry(i);
|
---|
733 |
|
---|
734 | fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
|
---|
735 | return kTRUE;
|
---|
736 | }
|
---|
737 | break;
|
---|
738 | }
|
---|
739 | break;
|
---|
740 | }
|
---|
741 |
|
---|
742 | return kTRUE;
|
---|
743 | }
|
---|
744 |
|
---|
745 | void MStarguider::SetPointingPosition(RaDec rd)
|
---|
746 | {
|
---|
747 | rd.Ra(rd.Ra()*24/360);
|
---|
748 | fCRaDec->SetCoordinates(rd);
|
---|
749 | }
|
---|
750 |
|
---|
751 | ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
|
---|
752 | {
|
---|
753 | //
|
---|
754 | // Viewable area (FIXME: AZ)
|
---|
755 | //
|
---|
756 | TH2F h("Hist", "dX/dY", 77, -768/2-.5, 768/2+.5, 58, -576/2-.5, 576/2+.5); // 3
|
---|
757 |
|
---|
758 | /*
|
---|
759 | TH1F hmag("HistMag", "Mag", 19, 0, 100);
|
---|
760 | for (int i=0; i<mag.GetSize(); i++)
|
---|
761 | hmag.Fill(mag[i]);
|
---|
762 | */
|
---|
763 |
|
---|
764 | //
|
---|
765 | // Search for matching Magnitudes
|
---|
766 | //
|
---|
767 | for (int i=0; i<mag.GetSize(); i++)
|
---|
768 | {
|
---|
769 | if (mag[i]>48-15 && mag[i]<48+15)
|
---|
770 | h.Fill(x[i], y[i]);
|
---|
771 | }
|
---|
772 |
|
---|
773 | //
|
---|
774 | // Serach for an excess in the histogram
|
---|
775 | //
|
---|
776 | Int_t mx, my, dummy;
|
---|
777 | h.GetMaximumBin(mx, my, dummy);
|
---|
778 |
|
---|
779 | const double xmax = h.GetXaxis()->GetBinCenter(mx);
|
---|
780 | const double dx = h.GetXaxis()->GetBinWidth(mx);
|
---|
781 |
|
---|
782 | const double ymax = h.GetYaxis()->GetBinCenter(my);
|
---|
783 | const double dy = h.GetYaxis()->GetBinWidth(my);
|
---|
784 |
|
---|
785 | cout << setprecision(3);
|
---|
786 | cout << "Cut-XY: " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
|
---|
787 |
|
---|
788 | TGraph g;
|
---|
789 | for (int i=0; i<mag.GetSize(); i++)
|
---|
790 | {
|
---|
791 | if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
|
---|
792 | y[i]>ymax-dy && y[i]<ymax+dy &&
|
---|
793 | mag[i]>48-15 && mag[i]<48+15))
|
---|
794 | continue;
|
---|
795 |
|
---|
796 | g.SetPoint(g.GetN(), x[i], y[i]);
|
---|
797 | }
|
---|
798 |
|
---|
799 | cout << "Offset-XY: " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
|
---|
800 | cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
|
---|
801 |
|
---|
802 | AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
|
---|
803 | AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
|
---|
804 |
|
---|
805 | ofstream fout1("pointingpos.txt");
|
---|
806 | fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
|
---|
807 | if (fCosy)
|
---|
808 | fout1 << fCosy->GetPointingPos() << " ";
|
---|
809 | fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
|
---|
810 |
|
---|
811 | pos1 -= pos0;
|
---|
812 |
|
---|
813 | ofstream fout2("tracking_error.txt", ios::app);
|
---|
814 | fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
|
---|
815 | if (fCosy)
|
---|
816 | fout2 << fCosy->GetPointingPos() << " ";
|
---|
817 | fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
|
---|
818 |
|
---|
819 | return ZdAz(-pos1.Alt(), pos1.Az());
|
---|
820 | }
|
---|
821 |
|
---|
822 | void MStarguider::CalcTrackingError(Leds &leds, MStarList &stars)
|
---|
823 | {
|
---|
824 | const Int_t max = leds.GetEntries();
|
---|
825 |
|
---|
826 | if (stars.GetRealEntries() < 3)
|
---|
827 | {
|
---|
828 | cout << "Sorry, less than 3 stars in FOV!" << endl;
|
---|
829 | return;
|
---|
830 | }
|
---|
831 |
|
---|
832 | if (max < 1)
|
---|
833 | {
|
---|
834 | cout << "Sorry, less than 1 detected spot in FOV!" << endl;
|
---|
835 | return;
|
---|
836 | }
|
---|
837 |
|
---|
838 | stars.Sort(); // Sort by magnitude
|
---|
839 |
|
---|
840 | TString str = "data/tracking_";
|
---|
841 | str += fSao->GetMjd()-52000;
|
---|
842 | str += ".txt";
|
---|
843 |
|
---|
844 | ofstream fout(str);
|
---|
845 |
|
---|
846 | TArrayF x, y, mag;
|
---|
847 |
|
---|
848 | Int_t num = 0;
|
---|
849 |
|
---|
850 | // FIXME: Is predifined value 3 a good idea?
|
---|
851 |
|
---|
852 | MStar *star;
|
---|
853 | MStarListIter NextStar(&stars);
|
---|
854 | while ((star=NextStar()) && num++<max+3)
|
---|
855 | {
|
---|
856 | TIter NextSp(&leds);
|
---|
857 | Led *spot=NULL;
|
---|
858 | while ((spot=(Led*)NextSp()))
|
---|
859 | {
|
---|
860 | const XY dpos(spot->GetX()-star->GetX(), spot->GetY()-star->GetY());
|
---|
861 |
|
---|
862 | const Int_t idx = x.GetSize();
|
---|
863 |
|
---|
864 | x.Set(idx+1);
|
---|
865 | y.Set(idx+1);
|
---|
866 | mag.Set(idx+1);
|
---|
867 |
|
---|
868 | x.AddAt(dpos.X(), idx);
|
---|
869 | y.AddAt(dpos.Y(), idx);
|
---|
870 | mag.AddAt(spot->GetMag()/star->GetMag(), idx);
|
---|
871 |
|
---|
872 | if (fout)
|
---|
873 | fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
|
---|
874 | }
|
---|
875 | }
|
---|
876 |
|
---|
877 | ZdAz d = TrackingError(x, y, mag);
|
---|
878 |
|
---|
879 | //
|
---|
880 | // Calculated offsets
|
---|
881 | //
|
---|
882 |
|
---|
883 | // round= floor(x+.5)
|
---|
884 | cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
|
---|
885 | cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
|
---|
886 |
|
---|
887 | //
|
---|
888 | // Current Pointing position
|
---|
889 | //
|
---|
890 | ZdAz cpos = fSao->GetZdAz()-d;
|
---|
891 | fPZdAz->SetCoordinates(cpos);
|
---|
892 | }
|
---|
893 |
|
---|
894 | void MStarguider::FindStar(FilterLed &f, FilterLed &f2, Ring ¢er, MTime &t)
|
---|
895 | {
|
---|
896 | // Set search Paremeters (FIXME: Get them from user input!)
|
---|
897 | f.SetCut(3.5);
|
---|
898 | f.SetBox(70);
|
---|
899 |
|
---|
900 | // Try to find Led in this area
|
---|
901 | Leds leds;
|
---|
902 | f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY());
|
---|
903 |
|
---|
904 | // Check wheter star found
|
---|
905 | Led *star = (Led*)leds.At(0);
|
---|
906 | if (!star || leds.GetEntries()<1)
|
---|
907 | return;
|
---|
908 |
|
---|
909 | cout << "Found star @ " << flush;
|
---|
910 | star->Print();
|
---|
911 | f2.MarkPoint(star->GetX(), star->GetY(), 2<<2);
|
---|
912 |
|
---|
913 | // Initialize Star Catalog on th camera plane
|
---|
914 | MGeomCamMagic geom;
|
---|
915 | MAstroCamera ac;
|
---|
916 | ac.SetGeom(geom);
|
---|
917 | ac.SetRadiusFOV(3);
|
---|
918 | ac.SetObservatory(*fSao);
|
---|
919 | ac.SetTime(t);
|
---|
920 |
|
---|
921 | // Get tracking coordinates
|
---|
922 | const XY xy = fCRaDec->GetCoordinates();
|
---|
923 | const RaDec rd(xy.X()*TMath::DegToRad()*15, xy.Y()*TMath::DegToRad());
|
---|
924 |
|
---|
925 | ac.SetRaDec(rd.Ra(), rd.Dec());
|
---|
926 |
|
---|
927 | // Adapt coordinate system (GUIs and humans are counting Y in different directions)
|
---|
928 | Double_t x = star->GetX()-center.GetX();
|
---|
929 | Double_t y = center.GetY()-star->GetY();
|
---|
930 |
|
---|
931 | cout << "STAR-Offset: " << MTime(-1) << " dx=" << x << "pix dy=" << y << "pix" << endl;
|
---|
932 |
|
---|
933 | // Convert from Pixel to millimeter (1pix=2.9mm)
|
---|
934 | x *= 2.58427;
|
---|
935 | y *= 2.58427;
|
---|
936 |
|
---|
937 | // Correct for abberation.
|
---|
938 | x /= 1.0713;
|
---|
939 | y /= 1.0713;
|
---|
940 |
|
---|
941 | // Calculate Offset
|
---|
942 | Double_t dzd, daz;
|
---|
943 | ac.GetDiffZdAz(x, y, dzd, daz);
|
---|
944 |
|
---|
945 | cout << "STAR-Offset: " << MTime(-1) << " dZd=" << dzd << "d dAz=" << daz << "d" << endl;
|
---|
946 |
|
---|
947 | // Check TPoint data set request
|
---|
948 | if (!fTPoint->IsDown())
|
---|
949 | return;
|
---|
950 | fTPoint->SetDown(kFALSE);
|
---|
951 |
|
---|
952 | // If no file open: open new file
|
---|
953 | if (!fOutTp)
|
---|
954 | {
|
---|
955 | //
|
---|
956 | // open tpoint file
|
---|
957 | //
|
---|
958 | const TString name = MCosy::GetFileName("tpoint/starg_%s.txt");
|
---|
959 | cout << "TPoint-Starg File ********* " << name << " ********** " << endl;
|
---|
960 |
|
---|
961 | fOutTp = new ofstream(name);
|
---|
962 | *fOutTp << "Magic Model TPOINT data file" << endl;
|
---|
963 | *fOutTp << ": ALTAZ" << endl;
|
---|
964 | *fOutTp << "49 48 0 ";
|
---|
965 | *fOutTp << t << endl;
|
---|
966 | // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m)
|
---|
967 | }
|
---|
968 |
|
---|
969 | // Output Ra/Dec the drive system thinks that it is currently tracking
|
---|
970 | cout << "TPoint Star: " << xy.X() << "h " << xy.Y() << "°" << endl;
|
---|
971 |
|
---|
972 | // From the star position in the camera we calculate the Alt/Az
|
---|
973 | // position we are currently tracking (real pointing position)
|
---|
974 | fSao->SetMjd(t.GetMjd());
|
---|
975 | AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg;
|
---|
976 |
|
---|
977 | //ZdAz za0 = fSao->GetZdAz();
|
---|
978 | za0 -= AltAz(-dzd, daz);
|
---|
979 |
|
---|
980 | // From the Shaftencoders we get the current 'pointing' position
|
---|
981 | // as it is seen by the drive system (system pointing position)
|
---|
982 | const ZdAz za1 = fCosy->GetTrackingPosRaw();
|
---|
983 |
|
---|
984 | // Write real pointing position
|
---|
985 | cout << " Alt/Az: " << za0.Alt() << "° " << za0.Az() << "°" << endl;
|
---|
986 | *fOutTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " ";
|
---|
987 |
|
---|
988 | // Write system pointing position
|
---|
989 | cout << " SE-Pos: " << 90-za1.Zd() << "° " << za1.Az() << "°" << endl;
|
---|
990 | *fOutTp << fmod(za1.Az()+360, 360) << " " << 90-za1.Zd();
|
---|
991 |
|
---|
992 | *fOutTp << " " << xy.X() << " " << xy.Y();
|
---|
993 | *fOutTp << " " << -dzd << " " << -daz;
|
---|
994 | *fOutTp << " " << setprecision(11) << t.GetMjd();
|
---|
995 | *fOutTp << " " << setprecision(4) << center.GetMag();
|
---|
996 | *fOutTp << " " << star->GetMag();
|
---|
997 | *fOutTp << endl;
|
---|
998 |
|
---|
999 | MLog &outrep = *fCosy->GetOutRep();
|
---|
1000 | if (outrep.Lock("MStarguider::FindStar"))
|
---|
1001 | {
|
---|
1002 | outrep << "FINDSTAR-REPORT " << MTime(-1) << " " << setprecision(7);
|
---|
1003 | outrep << 90-za0.Alt() << " " << za0.Az() << " ";
|
---|
1004 | outrep << za1.Zd() << " " << za1.Az() << " ";
|
---|
1005 | outrep << xy.X() << " " << xy.Y() << " ";
|
---|
1006 | outrep << -dzd << " " << -daz << " ";
|
---|
1007 | outrep << star->GetX() << " " << star->GetY() << " ";
|
---|
1008 | outrep << center.GetX() << " " << center.GetY() << " ";
|
---|
1009 | outrep << x*1.0713/2.58427 << " " << y*1.0713/2.58427 << " " << star->GetMag();
|
---|
1010 | outrep << setprecision(11) << t.GetMjd() << endl;
|
---|
1011 | outrep.UnLock("MStarguider::FindStar");
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 |
|
---|
1015 | bool MStarguider::Interpolate(const unsigned long n, byte *img) const
|
---|
1016 | {
|
---|
1017 | if (fIntRate<=1)
|
---|
1018 | return true;
|
---|
1019 |
|
---|
1020 | static unsigned short myimg[768*576];
|
---|
1021 |
|
---|
1022 | unsigned short *f = myimg;
|
---|
1023 | byte *i = img;
|
---|
1024 | byte *e = img+768*576;
|
---|
1025 |
|
---|
1026 | while (i<e)
|
---|
1027 | *f++ += *i++;
|
---|
1028 |
|
---|
1029 | if (n%fIntRate)
|
---|
1030 | return false;
|
---|
1031 |
|
---|
1032 | f = myimg;
|
---|
1033 | i = img;
|
---|
1034 | e = img+768*576;
|
---|
1035 |
|
---|
1036 | while (i<e)
|
---|
1037 | *i++ = (byte)(*f++/fIntRate);
|
---|
1038 |
|
---|
1039 | memset(myimg, 0, sizeof(myimg));
|
---|
1040 |
|
---|
1041 | return true;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | void MStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
|
---|
1045 | {
|
---|
1046 | static unsigned long n0 = n;
|
---|
1047 |
|
---|
1048 | MTime t(*tm);
|
---|
1049 |
|
---|
1050 | const Double_t d = t-fTime;
|
---|
1051 | if (d>1)
|
---|
1052 | {
|
---|
1053 | MString txt;
|
---|
1054 | txt.Print("%dfps", (int)((n-n0)/d+.5));
|
---|
1055 | fFps->SetText(txt);
|
---|
1056 | fTime = t;
|
---|
1057 | n0 = n;
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | if (!Interpolate(n, img))
|
---|
1061 | return;
|
---|
1062 |
|
---|
1063 | byte cimg[768*576];
|
---|
1064 | memset(cimg, 0, 768*576);
|
---|
1065 |
|
---|
1066 | FilterLed f(img, 768, 576, 2.5); // 2.5
|
---|
1067 | FilterLed f2(cimg, 768, 576); // former color 0xb0
|
---|
1068 |
|
---|
1069 | if (fDisplay->IsEntryChecked(IDM_kStretch))
|
---|
1070 | f.Stretch();
|
---|
1071 |
|
---|
1072 | if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
|
---|
1073 | (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
|
---|
1074 | {
|
---|
1075 | if (fFileType->IsEntryChecked(IDM_kPNG))
|
---|
1076 | Writer::Png("pix/file", img, tm);
|
---|
1077 |
|
---|
1078 | if (fFileType->IsEntryChecked(IDM_kPPM))
|
---|
1079 | Writer::Ppm("pix/file", img, tm);
|
---|
1080 |
|
---|
1081 | if (fWriteType->IsEntryChecked(IDM_kOnce))
|
---|
1082 | ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | MStarList spots;
|
---|
1086 | if (fDisplay->IsEntryChecked(IDM_kFilter))
|
---|
1087 | f.Execute();
|
---|
1088 |
|
---|
1089 | Ring center(768/2, 576/2);
|
---|
1090 | if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
|
---|
1091 | {
|
---|
1092 | const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds);
|
---|
1093 | const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings);
|
---|
1094 | ZdAz pos;
|
---|
1095 | if (fCosy)
|
---|
1096 | pos = fCosy->GetPointingPos();
|
---|
1097 |
|
---|
1098 | center = fCaos->Run(img, printl, printr, pos, t);
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | if (fDisplay->IsEntryChecked(IDM_kFindStar))
|
---|
1102 | FindStar(f, f2, center, t);
|
---|
1103 |
|
---|
1104 | byte zimg[kZOOM*kZOOM];
|
---|
1105 | for (int y=0; y<kZOOM; y++)
|
---|
1106 | for (int x=0; x<kZOOM; x++)
|
---|
1107 | zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
|
---|
1108 |
|
---|
1109 | fZoomImage->DrawImg(zimg);
|
---|
1110 |
|
---|
1111 | if (fCosy)
|
---|
1112 | {
|
---|
1113 | byte simg[(768/2-1)*(576/2-1)];
|
---|
1114 | for (int y=0; y<576/2-1; y++)
|
---|
1115 | for (int x=0; x<768/2-1; x++)
|
---|
1116 | simg[x+y*(768/2-1)] = ((unsigned int)img[2*x+2*y*768]+img[2*x+2*y*768+1]+img[2*x+2*(y+1)*768]+img[2*x+2*(y+1)*768+1])/4;
|
---|
1117 |
|
---|
1118 | fCosy->GetWin()->GetImage()->DrawImg(simg);
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | if (fDisplay->IsEntryChecked(IDM_kCatalog))
|
---|
1122 | {
|
---|
1123 | MTime time(*tm);
|
---|
1124 |
|
---|
1125 | XY xy = fCRaDec->GetCoordinates();
|
---|
1126 | fRaDec->Set(xy.X()*360/24, xy.Y());
|
---|
1127 |
|
---|
1128 | UpdatePosZoom();
|
---|
1129 |
|
---|
1130 | /*
|
---|
1131 | if (fDisplay->IsEntryChecked(IDM_kStarguider))
|
---|
1132 | {
|
---|
1133 | Leds leds;
|
---|
1134 | f.Execute(leds);
|
---|
1135 |
|
---|
1136 | cout << "Found: " << leds.GetEntries() << " stars." << endl;
|
---|
1137 |
|
---|
1138 | CalcTrackingError(leds, stars);
|
---|
1139 | }
|
---|
1140 | */
|
---|
1141 |
|
---|
1142 | // Always call SetMjd first!
|
---|
1143 | fSao->SetPointing(time.GetMjd(), *fRaDec);
|
---|
1144 | fCZdAz->SetCoordinates(fSao->GetZdAz());
|
---|
1145 |
|
---|
1146 | MStarList stars;
|
---|
1147 | fSao->CalcStars(stars);
|
---|
1148 | fSao->DrawStars(stars, cimg);
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
|
---|
1152 | {
|
---|
1153 | f2.DrawCircle(center, 0x0a);
|
---|
1154 | f2.DrawCircle(center, 5.0, fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0);
|
---|
1155 | f2.DrawCircle(center, 115.0, 0x0a);
|
---|
1156 | f2.DrawCircle(center, 230.0, 0x0a);
|
---|
1157 | f2.DrawCircle(center, 245.0, 0x0a);
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | if (fDisplay->IsEntryChecked(IDM_kCatalog))
|
---|
1161 | {
|
---|
1162 | fSao->PaintImg(cimg, 768, 576);
|
---|
1163 |
|
---|
1164 | const float r = 60*60/fSao->GetPixSize();
|
---|
1165 |
|
---|
1166 | f2.DrawCircle(0.5*r, 0x0a);
|
---|
1167 | f2.DrawCircle(1.0*r, 0x0a);
|
---|
1168 | f2.DrawCircle(1.5*r, 0x0a);
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | if (fDisplay->IsEntryChecked(IDM_kCaosFilter) ||
|
---|
1172 | fDisplay->IsEntryChecked(IDM_kCatalog) ||
|
---|
1173 | fDisplay->IsEntryChecked(IDM_kFindStar))
|
---|
1174 | fImage->DrawColImg(img, cimg);
|
---|
1175 | else
|
---|
1176 | fImage->DrawImg(img);
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | void MStarguider::UpdatePosZoom()
|
---|
1180 | {
|
---|
1181 | MString txt;
|
---|
1182 | if (fDisplay->IsEntryChecked(IDM_kCatalog))
|
---|
1183 | {
|
---|
1184 | // FIXME: Necessary?
|
---|
1185 | fSao->Now();
|
---|
1186 | AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
|
---|
1187 |
|
---|
1188 | if (aa.Az()<0)
|
---|
1189 | aa.Az(aa.Az()+360);
|
---|
1190 |
|
---|
1191 | txt.Print("%.1fd/%.1fd (%d, %d)", -aa.Alt(), aa.Az()-180, fDx, fDy);
|
---|
1192 | }
|
---|
1193 | else
|
---|
1194 | txt.Print("(%d, %d)", fDx, fDy);
|
---|
1195 |
|
---|
1196 | fPosZoom->SetText(txt);
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | Bool_t MStarguider::HandleDoubleClick(Event_t *event)
|
---|
1200 | {
|
---|
1201 | const Int_t w = fImage->GetWidth();
|
---|
1202 | const Int_t h = fImage->GetHeight();
|
---|
1203 | const Int_t x = fImage->GetX();
|
---|
1204 | const Int_t y = fImage->GetY();
|
---|
1205 |
|
---|
1206 | if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
|
---|
1207 | return kTRUE;
|
---|
1208 |
|
---|
1209 | Int_t dx = event->fX-x;
|
---|
1210 | Int_t dy = event->fY-y;
|
---|
1211 |
|
---|
1212 | if (dx<kZOOM/4) dx=kZOOM/4;
|
---|
1213 | if (dy<kZOOM/4) dy=kZOOM/4;
|
---|
1214 | if (dx>766-kZOOM/4) dx=766-kZOOM/4;
|
---|
1215 | if (dy>574-kZOOM/4) dy=574-kZOOM/4;
|
---|
1216 |
|
---|
1217 | fDx = dx;
|
---|
1218 | fDy = dy;
|
---|
1219 |
|
---|
1220 | UpdatePosZoom();
|
---|
1221 | return kTRUE;
|
---|
1222 | }
|
---|