source: trunk/MagicSoft/Cosy/main/MStarguider.cc@ 3253

Last change on this file since 3253 was 2615, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 27.0 KB
Line 
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
11#include <TGMenu.h>
12#include <TGLabel.h>
13#include <TSystem.h>
14#include <TGSplitter.h> // TGHorizontal3DLine
15#include <TGTextEntry.h>
16
17#include "MCosy.h"
18#include "MCaos.h"
19
20#include "MGImage.h"
21#include "MGCoordinates.h"
22
23#include "coord.h"
24
25#include "Led.h"
26#include "Writer.h"
27#include "FilterLed.h"
28#include "MStarList.h"
29#include "CaosFilter.h"
30#include "StarCatalog.h"
31
32#include "MGMenu.h"
33
34ClassImp(MStarguider);
35
36enum {
37 IDM_kFilter,
38 IDM_kCaosFilter,
39 IDM_kCatalog,
40 IDM_kStarguider,
41 IDM_kStart,
42 IDM_kStop,
43 IDM_kFileType,
44 IDM_kPPM,
45 IDM_kPNG,
46 IDM_kOnce,
47 IDM_kStretch,
48// IDM_kUseFileRaDec,
49 IDM_kContinous,
50 IDM_kRate25ps,
51 IDM_kRate5ps,
52 IDM_kRate1s,
53 IDM_kRate5s,
54 IDM_kRate30s,
55 IDM_kRate1m,
56 IDM_kRate5m,
57 IDM_kSetup,
58 IDM_kLimMag3,
59 IDM_kLimMag4,
60 IDM_kLimMag5,
61 IDM_kLimMag6,
62 IDM_kLimMag7,
63 IDM_kLimMag8,
64 IDM_kLimMag9,
65 IDM_kPixSize,
66 IDM_kAngle,
67 IDM_kInterpol125,
68 IDM_kInterpol50,
69 IDM_kInterpol25,
70 IDM_kInterpol10,
71 IDM_kInterpol5,
72 IDM_kInterpol2,
73 IDM_kInterpol1,
74 IDM_kCaosPrintRings,
75 IDM_kCaosPrintLeds,
76 IDM_kCaosAnalStart,
77 IDM_kCaosAnalStop,
78 IDM_kCaosWriteStart,
79 IDM_kCaosWriteStop,
80 IDM_kResetHistograms
81};
82
83Bool_t MStarguider::HandleTimer(TTimer *t)
84{
85 fImage->DoRedraw();
86 fZoomImage->DoRedraw();
87 return kTRUE;
88}
89
90#define kZOOM 96
91
92XY MStarguider::GetCoordinates() const
93{
94 return fPZdAz->GetCoordinates();
95}
96
97void MStarguider::InitGui()
98{
99 fList = new MGList;
100
101 const TGWindow *p=gClient->GetRoot();
102
103 //
104 // Create Menu for MStarguider Display
105 //
106 fDisplay = new MGPopupMenu(p);
107 fDisplay->AddEntry("&Filter", IDM_kFilter);
108 fDisplay->AddEntry("C&aosFilter", IDM_kCaosFilter);
109 fDisplay->AddEntry("Sao &Catalog", IDM_kCatalog);
110 fDisplay->AddEntry("Starguider", IDM_kStarguider);
111 fDisplay->AddEntry("Stretch", IDM_kStretch);
112 fDisplay->DisableEntry(IDM_kStarguider);
113 fDisplay->CheckEntry(IDM_kStretch);
114 fDisplay->Associate(this);
115 fList->Add(fDisplay);
116
117 fFileType = new MGPopupMenu(p);
118 fFileType->AddEntry("PP&M", IDM_kPPM);
119 fFileType->AddEntry("&PNG", IDM_kPNG);
120 fFileType->CheckEntry(IDM_kPNG);
121 fFileType->Associate(this);
122 fList->Add(fFileType);
123
124 fWriteType = new MGPopupMenu(p);
125 fWriteType->AddEntry("&Once", IDM_kOnce);
126 fWriteType->AddEntry("&Continous", IDM_kContinous);
127 fWriteType->CheckEntry(IDM_kOnce);
128 fWriteType->Associate(this);
129 fList->Add(fWriteType);
130
131 fWriteRate = new MGPopupMenu(p);
132 fWriteRate->AddEntry("25/s", IDM_kRate25ps);
133 fWriteRate->AddEntry("5/s", IDM_kRate5ps);
134 fWriteRate->AddEntry("1s", IDM_kRate1s);
135 fWriteRate->AddEntry("5s", IDM_kRate5s);
136 fWriteRate->AddEntry("30s", IDM_kRate30s);
137 fWriteRate->AddEntry("1min", IDM_kRate1m);
138 fWriteRate->AddEntry("5min", IDM_kRate5m);
139 fWriteRate->CheckEntry(IDM_kRate1m);
140 fWriteRate->Associate(this);
141 fList->Add(fWriteRate);
142
143 fWrtRate = 25*60;
144
145 fWritePictures = new MGPopupMenu(p);
146 fWritePictures->AddEntry("&Start", IDM_kStart);
147 fWritePictures->AddEntry("Sto&p", IDM_kStop);
148 fWritePictures->AddSeparator();
149 fWritePictures->AddPopup("File &Type", fFileType);
150 fWritePictures->AddPopup("&Write Type", fWriteType);
151 fWritePictures->AddPopup("Write &Rate", fWriteRate);
152 fWritePictures->DisableEntry(IDM_kStop);
153 fWritePictures->Associate(this);
154 fList->Add(fWritePictures);
155
156 fLimMag = new MGPopupMenu(p);
157 fLimMag->AddEntry("3", IDM_kLimMag3);
158 fLimMag->AddEntry("4", IDM_kLimMag4);
159 fLimMag->AddEntry("5", IDM_kLimMag5);
160 fLimMag->AddEntry("6", IDM_kLimMag6);
161 fLimMag->AddEntry("7", IDM_kLimMag7);
162 fLimMag->AddEntry("8", IDM_kLimMag8);
163 fLimMag->AddEntry("9", IDM_kLimMag9);
164 fLimMag->CheckEntry(IDM_kLimMag8);
165 fLimMag->Associate(this);
166 fList->Add(fLimMag);
167
168 fSao->SetLimitMag(7.0);
169
170 fInterpol = new MGPopupMenu(p);
171 fInterpol->AddEntry("125", IDM_kInterpol125);
172 fInterpol->AddEntry("50", IDM_kInterpol50);
173 fInterpol->AddEntry("25", IDM_kInterpol25);
174 fInterpol->AddEntry("10", IDM_kInterpol10);
175 fInterpol->AddEntry("5", IDM_kInterpol5);
176 fInterpol->AddEntry("2", IDM_kInterpol2);
177 fInterpol->AddEntry("Off", IDM_kInterpol1);
178 fInterpol->Associate(this);
179 fList->Add(fInterpol);
180
181 TString disp=gVirtualX->DisplayName();
182 cout << "Display: " << disp << endl;
183 if (disp.First(':')>=0)
184 disp=disp(0, disp.First(':'));
185
186 if (disp.IsNull() || disp==(TString)"localhost")
187 {
188 fInterpol->CheckEntry(IDM_kInterpol5);
189 fIntRate = 5;
190 }
191 else
192 {
193 fInterpol->CheckEntry(IDM_kInterpol125);
194 fIntRate = 125;
195 }
196
197 fSetup = new MGPopupMenu(p);
198 fSetup->AddPopup("Lim. &Magnitude", fLimMag);
199 fSetup->AddPopup("Disp. &Interpolation", fInterpol);
200 //fSetup->AddEntry("Use Ra/Dec from file", IDM_kUseFileRaDec);
201 fSetup->Associate(this);
202 fList->Add(fSetup);
203
204 fCaosPrint = new MGPopupMenu(p);
205 fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds);
206 fCaosPrint->AddEntry("&Rings", IDM_kCaosPrintRings);
207 fCaosPrint->Associate(this);
208 fList->Add(fCaosPrint);
209
210 fCaosWrite = new MGPopupMenu(p);
211 fCaosWrite->AddEntry("&Start", IDM_kCaosWriteStart);
212 fCaosWrite->AddEntry("Sto&p", IDM_kCaosWriteStop);
213 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
214 fCaosWrite->Associate(this);
215 fList->Add(fCaosWrite);
216
217 fCaosAnalyse = new MGPopupMenu(p);
218 fCaosAnalyse->AddEntry("S&tart Analyse", IDM_kCaosAnalStart);
219 fCaosAnalyse->AddEntry("St&opp Analyse", IDM_kCaosAnalStop);
220 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
221 // fCaosAnalyse->AddEntry("&Reset Histograms", IDM_kResetHistograms);
222 // fCaosAnalyse->AddEntry("Reset &Graph", IDM_kResetGraph);
223 fCaosAnalyse->Associate(this);
224 fList->Add(fCaosAnalyse);
225
226 fMenu = new MGMenuBar(this, 0, 0, kHorizontalFrame);
227 fMenu->AddPopup("&Display", fDisplay, NULL);
228 fMenu->AddPopup("&WritePics", fWritePictures, NULL);
229 fMenu->AddPopup("&Setup", fSetup, NULL);
230 fMenu->Resize(fMenu->GetDefaultSize());
231 fMenu->BindKeys(this);
232 AddFrame(fMenu);
233 fList->Add(fMenu);
234
235 fCaOs = new MGPopupMenu(p);
236 fCaOs->AddPopup("&Write", fCaosWrite);
237 fCaOs->AddPopup("&Print", fCaosPrint);
238 fCaOs->AddPopup("&Analyse", fCaosAnalyse);
239 fCaOs->Associate(this);
240 fCaOs->BindKeys(fMenu, this);
241 fList->Add(fCaOs);
242
243 fCRaDec = new MGCoordinates(this, kETypeRaDec);
244 fCRaDec->Move(1, fMenu->GetDefaultHeight()+584);
245 AddFrame(fCRaDec);
246 fList->Add(fCRaDec);
247
248 fCZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
249 fCZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+584);
250 AddFrame(fCZdAz);
251 fList->Add(fCZdAz);
252
253 fPZdAz = new MGCoordinates(this, kETypeZdAz, kFALSE);
254 fPZdAz->Move(240+12+10, fMenu->GetDefaultHeight()+630);
255 AddFrame(fPZdAz);
256 fList->Add(fPZdAz);
257
258 fFps = new TGLabel(this, "---fps");
259 fFps->SetTextJustify(kTextRight);
260 fFps->Move(633, fMenu->GetDefaultHeight()+578);
261 AddFrame(fFps);
262 fList->Add(fFps);
263
264 fPosZoom = new TGLabel(this, "----.--d/----.--d (----, ----)");
265 fPosZoom->SetTextJustify(kTextRight);
266 fPosZoom->Move(620, fMenu->GetDefaultHeight()+678);
267 AddFrame(fPosZoom);
268 fList->Add(fPosZoom);
269
270 TGLabel *l = new TGLabel(this, "Arb.-Sky Pos");
271 l->SetTextJustify(kTextLeft);
272 l->Move(480+32, fMenu->GetDefaultHeight()+590);
273 AddFrame(l);
274 fList->Add(l);
275
276 l = new TGLabel(this, "arcsec/pix");
277 l->SetTextJustify(kTextLeft);
278 l->Move(605, fMenu->GetDefaultHeight()+619+13);
279 AddFrame(l);
280 fList->Add(l);
281
282 l = new TGLabel(this, "deg");
283 l->SetTextJustify(kTextLeft);
284 l->Move(605, fMenu->GetDefaultHeight()+619-10);
285 AddFrame(l);
286 fList->Add(l);
287
288 l = new TGLabel(this, "Pointing Pos");
289 l->SetTextJustify(kTextLeft);
290 l->Move(480+32, fMenu->GetDefaultHeight()+655);
291 AddFrame(l);
292 fList->Add(l);
293
294 const Double_t pixsize = 23.4;
295
296 fSao->SetPixSize(pixsize/3600);
297 fSao->SetRotationAngle(0);
298
299 TString txt;
300 txt += pixsize;
301
302 fPixSize = new TGTextEntry(this, txt, IDM_kPixSize);
303 fPixSize->SetAlignment(kTextCenterX);
304 fPixSize->Move(547, fMenu->GetDefaultHeight()+617+13);
305 AddFrame(fPixSize);
306 fList->Add(fPixSize);
307
308 fAngle = new TGTextEntry(this, " 0", IDM_kAngle);
309 fAngle->SetAlignment(kTextCenterX);
310 fAngle->Move(547, fMenu->GetDefaultHeight()+617-10);
311 AddFrame(fAngle);
312 fList->Add(fAngle);
313
314 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this);
315 // AddFrame(fLineSep, new TGLayoutHints (kLHintsNormal | kLHintsExpandX));
316 // fList->Add(fLineSep);
317
318 //
319 // Create Image Display
320 //
321 fZoomImage = new MGImage(this, kZOOM, kZOOM);
322 fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2);
323 AddFrame(fZoomImage);
324 fList->Add(fZoomImage);
325
326 fImage = new MGImage(this, 768, 576);
327 fImage->Move(0, fMenu->GetDefaultHeight());
328 AddFrame(fImage);
329 fList->Add(fImage);
330
331 //
332 // Make everything visible
333 //
334 SetWindowName("MStarguider Main Window");
335 SetIconName("MStarguider");
336
337 MapSubwindows();
338 MapWindow();
339
340 //------------------------------------------------------------
341 // XY xy(3.819444, 24.05333);
342 // fCRaDec->SetCoordinates(xy);
343 // fRaDec->Set(xy.X()*360/24, xy.Y());
344 //------------------------------------------------------------
345}
346
347MStarguider::MStarguider(MObservatory::LocationName_t obs)
348: TGMainFrame(gClient->GetRoot(), 768, 740), fCosy(NULL), fDx((768-kZOOM)/2), fDy((512-kZOOM)/2)
349{
350 cout << " #### FIXME: Make MCaos Thread safe!" << endl;
351
352 fSao = new StarCatalog(obs);
353 fRaDec = new RaDec(180, 40);
354
355 fCaos = new MCaos;
356 fCaos->ReadResources();
357
358 InitGui();
359
360 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE);
361
362 fTimer=new TTimer(this, 1000/25); // 40ms
363 fTimer->TurnOn();
364
365 fTime.Now();
366}
367
368MStarguider::~MStarguider()
369{
370 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE);
371
372 fTimer->TurnOff();
373 delete fTimer;
374
375 delete fList;
376
377 delete fCaos;
378 delete fSao;
379 delete fRaDec;
380
381 cout << "Camera Display destroyed." << endl;
382}
383
384void MStarguider::Layout()
385{
386 // Resize(GetDefaultSize());
387}
388
389void MStarguider::CloseWindow()
390{
391 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl;
392
393 //fClient.ExitLoop();
394 // cout << "FIXME: ExitLoop not called!!!!!!" << endl;
395 gSystem->ExitLoop();
396}
397
398void MStarguider::Toggle(MGPopupMenu *p, UInt_t id)
399{
400 if (p->IsEntryChecked(id))
401 p->UnCheckEntry(id);
402 else
403 p->CheckEntry(id);
404}
405
406Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
407{
408 switch (GET_MSG(msg))
409 {
410 case kC_TEXTENTRY:
411 if (GET_SUBMSG(msg)==kTE_ENTER)
412 switch (mp1)
413 {
414 case IDM_kPixSize:
415 {
416 const Float_t pixsize = atof(fPixSize->GetText());
417 cout << "Pixel Size changed to " << pixsize << "\"/pix" << endl;
418 fSao->SetPixSize(pixsize/3600);
419 return kTRUE;
420 }
421 case IDM_kAngle:
422 {
423 const Float_t angle = atof(fAngle->GetText());
424 cout << "Rotation Angle changed to " << angle << "deg" << endl;
425 fSao->SetRotationAngle(angle);
426 return kTRUE;
427 }
428 }
429 return kTRUE;
430
431 case kC_COMMAND:
432 switch (GET_SUBMSG(msg))
433 {
434 case kCM_MENU:
435 switch (mp1)
436 {
437 case IDM_kCatalog:
438 Toggle(fDisplay, IDM_kCatalog);
439 if (fDisplay->IsEntryChecked(IDM_kCatalog))
440 fDisplay->EnableEntry(IDM_kStarguider);
441 else
442 {
443 fDisplay->UnCheckEntry(IDM_kStarguider);
444 fDisplay->DisableEntry(IDM_kStarguider);
445 }
446 return kTRUE;
447
448 case IDM_kStarguider:
449 Toggle(fDisplay, IDM_kStarguider);
450 gSystem->Unlink("tracking_error.txt");
451 return kTRUE;
452
453 case IDM_kFilter:
454 Toggle(fDisplay, IDM_kFilter);
455 if (fDisplay->IsEntryChecked(IDM_kFilter))
456 fDisplay->EnableEntry(IDM_kStarguider);
457 else
458 {
459 fDisplay->UnCheckEntry(IDM_kStarguider);
460 fDisplay->DisableEntry(IDM_kStarguider);
461 }
462 return kTRUE;
463
464 case IDM_kStretch:
465 Toggle(fDisplay, IDM_kStretch);
466 return kTRUE;
467
468 case IDM_kCaosFilter:
469 //if (!fDisplay->IsEntryChecked(IDM_kCaosFilter))
470 // fCaos->OpenFile();
471 Toggle(fDisplay, IDM_kCaosFilter);
472 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
473 fMenu->AddPopup("&CaOs", fCaOs, NULL);
474 else
475 {
476 if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintLeds))
477 fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds);
478 if(fCaosWrite->IsEntryChecked(IDM_kCaosPrintRings))
479 fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings);
480 if(fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop))
481 {
482 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
483 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
484 fCaos->DeleteHistograms();
485 }
486 if(fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop))
487 {
488 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
489 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
490 fCaos->CloseFile();
491 }
492 fMenu->RemovePopup("CaOs");
493 }
494 fMenu->Resize(fMenu->GetDefaultSize());
495 MapSubwindows();
496 MapWindow();
497 return kTRUE;
498
499 case IDM_kCaosPrintLeds:
500 case IDM_kCaosPrintRings:
501 Toggle(fCaosPrint, mp1);
502 return kTRUE;
503
504 case IDM_kCaosAnalStart:
505 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart);
506 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop);
507 fCaos->InitHistograms();
508 return kTRUE;
509
510 case IDM_kCaosAnalStop:
511 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop);
512 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart);
513 fCaos->ShowHistograms();
514 fCaos->DeleteHistograms();
515 return kTRUE;
516
517 case IDM_kCaosWriteStart:
518 fCaosWrite->DisableEntry(IDM_kCaosWriteStart);
519 fCaosWrite->EnableEntry(IDM_kCaosWriteStop);
520 fCaos->OpenFile();
521 return kTRUE;
522
523 case IDM_kCaosWriteStop:
524 fCaosWrite->DisableEntry(IDM_kCaosWriteStop);
525 fCaosWrite->EnableEntry(IDM_kCaosWriteStart);
526 fCaos->CloseFile();
527 return kTRUE;
528
529 case IDM_kStart:
530 fWritePictures->DisableEntry(IDM_kStart);
531 fWritePictures->EnableEntry(IDM_kStop);
532 return kTRUE;
533
534 case IDM_kStop:
535 fWritePictures->DisableEntry(IDM_kStop);
536 fWritePictures->EnableEntry(IDM_kStart);
537 return kTRUE;
538
539 case IDM_kPNG:
540 fFileType->CheckEntry(IDM_kPNG);
541 fFileType->UnCheckEntry(IDM_kPPM);
542 return kTRUE;
543
544 case IDM_kPPM:
545 fFileType->CheckEntry(IDM_kPPM);
546 fFileType->UnCheckEntry(IDM_kPNG);
547 return kTRUE;
548
549 case IDM_kOnce:
550 fWriteType->CheckEntry(IDM_kOnce);
551 fWriteType->UnCheckEntry(IDM_kContinous);
552 return kTRUE;
553
554 case IDM_kContinous:
555 fWriteType->CheckEntry(IDM_kContinous);
556 fWriteType->UnCheckEntry(IDM_kOnce);
557 return kTRUE;
558
559 case IDM_kRate25ps:
560 case IDM_kRate5ps:
561 case IDM_kRate1s:
562 case IDM_kRate5s:
563 case IDM_kRate30s:
564 case IDM_kRate1m:
565 case IDM_kRate5m:
566 for (int i=IDM_kRate25ps; i<=IDM_kRate5m; i++)
567 if (mp1==i)
568 fWriteRate->CheckEntry(i);
569 else
570 fWriteRate->UnCheckEntry(i);
571 switch (mp1)
572 {
573 case IDM_kRate25ps:
574 fWrtRate = 1;
575 return kTRUE;
576 case IDM_kRate5ps:
577 fWrtRate = 5;
578 return kTRUE;
579 case IDM_kRate1s:
580 fWrtRate = 25;
581 return kTRUE;
582 case IDM_kRate5s:
583 fWrtRate = 5*25;
584 return kTRUE;
585 case IDM_kRate30s:
586 fWrtRate = 30*25;
587 return kTRUE;
588 case IDM_kRate1m:
589 fWrtRate = 60*25;
590 return kTRUE;
591 case IDM_kRate5m:
592 fWrtRate = 5*60*25;
593 return kTRUE;
594 }
595 return kTRUE;
596
597 case IDM_kInterpol125:
598 case IDM_kInterpol50:
599 case IDM_kInterpol25:
600 case IDM_kInterpol10:
601 case IDM_kInterpol5:
602 case IDM_kInterpol2:
603 case IDM_kInterpol1:
604 for (int i=IDM_kInterpol125; i<=IDM_kInterpol1; i++)
605 if (mp1==i)
606 fInterpol->CheckEntry(i);
607 else
608 fInterpol->UnCheckEntry(i);
609 switch (mp1)
610 {
611 case IDM_kInterpol1:
612 fIntRate = 1;
613 return kTRUE;
614 case IDM_kInterpol2:
615 fIntRate = 2;
616 return kTRUE;
617 case IDM_kInterpol5:
618 fIntRate = 5;
619 return kTRUE;
620 case IDM_kInterpol10:
621 fIntRate = 10;
622 return kTRUE;
623 case IDM_kInterpol25:
624 fIntRate = 25;
625 return kTRUE;
626 case IDM_kInterpol50:
627 fIntRate = 50;
628 return kTRUE;
629 case IDM_kInterpol125:
630 fIntRate = 125;
631 return kTRUE;
632 }
633 return kTRUE;
634
635 case IDM_kLimMag3:
636 case IDM_kLimMag4:
637 case IDM_kLimMag5:
638 case IDM_kLimMag6:
639 case IDM_kLimMag7:
640 case IDM_kLimMag8:
641 case IDM_kLimMag9:
642 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)
643 if (mp1==i)
644 fLimMag->CheckEntry(i);
645 else
646 fLimMag->UnCheckEntry(i);
647
648 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);
649 return kTRUE;
650 }
651 break;
652 }
653 break;
654 }
655
656 return kTRUE;
657}
658
659void MStarguider::SetPointingPosition(RaDec rd)
660{
661 rd.Ra(rd.Ra()*24/360);
662 fCRaDec->SetCoordinates(rd);
663}
664
665ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag) const
666{
667 //
668 // Viewable area (FIXME: AZ)
669 //
670 TH2F h("Hist", "dX/dY", 77, -768/2-.5, 768/2+.5, 58, -576/2-.5, 576/2+.5); // 3
671
672 /*
673 TH1F hmag("HistMag", "Mag", 19, 0, 100);
674 for (int i=0; i<mag.GetSize(); i++)
675 hmag.Fill(mag[i]);
676 */
677
678 //
679 // Search for matching Magnitudes
680 //
681 for (int i=0; i<mag.GetSize(); i++)
682 {
683 if (mag[i]>48-15 && mag[i]<48+15)
684 h.Fill(x[i], y[i]);
685 }
686
687 //
688 // Serach for an excess in the histogram
689 //
690 Int_t mx, my, dummy;
691 h.GetMaximumBin(mx, my, dummy);
692
693 const double xmax = h.GetXaxis()->GetBinCenter(mx);
694 const double dx = h.GetXaxis()->GetBinWidth(mx);
695
696 const double ymax = h.GetYaxis()->GetBinCenter(my);
697 const double dy = h.GetYaxis()->GetBinWidth(my);
698
699 cout << setprecision(3);
700 cout << "Cut-XY: " << xmax << " +- " << dx << " / " << ymax << " +- " << dy << endl;
701
702 TGraph g;
703 for (int i=0; i<mag.GetSize(); i++)
704 {
705 if (!(x[i]>xmax-dx && x[i]<xmax+dx &&
706 y[i]>ymax-dy && y[i]<ymax+dy &&
707 mag[i]>48-15 && mag[i]<48+15))
708 continue;
709
710 g.SetPoint(g.GetN(), x[i], y[i]);
711 }
712
713 cout << "Offset-XY: " << g.GetMean(1) << " +- " << g.GetRMS(1) << " / ";
714 cout << g.GetMean(2) << " +- " << g.GetRMS(2) << endl;
715
716 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg;
717 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+g.GetMean(1), 576/2+g.GetMean(2))*kRad2Deg;
718
719 ofstream fout1("pointingpos.txt");
720 fout1 << setprecision(10) << fSao->GetMjd()-52000 << " ";
721 if (fCosy)
722 fout1 << fCosy->GetPointingPos() << " ";
723 fout1 << -pos1.Alt() << " " << pos1.Az() << endl;
724
725 pos1 -= pos0;
726
727 ofstream fout2("tracking_error.txt", ios::app);
728 fout2 << setprecision(10) << fSao->GetMjd()-52000 << " ";
729 if (fCosy)
730 fout2 << fCosy->GetPointingPos() << " ";
731 fout2 << -pos1.Alt() << " " << pos1.Az() << endl;
732
733 return ZdAz(-pos1.Alt(), pos1.Az());
734}
735
736void MStarguider::CalcTrackingError(Leds &leds, MStarList &stars)
737{
738 const Int_t max = leds.GetEntries();
739
740 if (stars.GetRealEntries() < 3)
741 {
742 cout << "Sorry, less than 3 stars in FOV!" << endl;
743 return;
744 }
745
746 if (max < 1)
747 {
748 cout << "Sorry, less than 1 detected spot in FOV!" << endl;
749 return;
750 }
751
752 stars.Sort(); // Sort by magnitude
753
754 TString str = "data/tracking_";
755 str += fSao->GetMjd()-52000;
756 str += ".txt";
757
758 ofstream fout(str);
759
760 TArrayF x, y, mag;
761
762 Int_t num = 0;
763
764 // FIXME: Is predifined value 3 a good idea?
765
766 MStar *star;
767 MStarListIter NextStar(&stars);
768 while ((star=NextStar()) && num++<max+3)
769 {
770 TIter NextSp(&leds);
771 Led *spot=NULL;
772 while ((spot=(Led*)NextSp()))
773 {
774 const XY dpos(spot->GetX()-star->GetX(), spot->GetY()-star->GetY());
775
776 const Int_t idx = x.GetSize();
777
778 x.Set(idx+1);
779 y.Set(idx+1);
780 mag.Set(idx+1);
781
782 x.AddAt(dpos.X(), idx);
783 y.AddAt(dpos.Y(), idx);
784 mag.AddAt(spot->GetMag()/star->GetMag(), idx);
785
786 if (fout)
787 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl;
788 }
789 }
790
791 ZdAz d = TrackingError(x, y, mag);
792
793 //
794 // Calculated offsets
795 //
796
797 // round= floor(x+.5)
798 cout << "Offset-ZdAz: " << d.Zd()*60 << "' / " << d.Az()*60 << "'" << endl;
799 cout << "Offset-ZdAz: " << d.Zd()/360*16384 << " / " << d.Az()/360*16384 << " (SE) " << endl;
800
801 //
802 // Current Pointing position
803 //
804 ZdAz cpos = fSao->GetZdAz()-d;
805 fPZdAz->SetCoordinates(cpos);
806}
807
808bool MStarguider::Interpolate(const unsigned long n, byte *img) const
809{
810 if (fIntRate<=1)
811 return true;
812
813 static unsigned short myimg[768*576];
814
815 unsigned short *f = myimg;
816 byte *i = img;
817 byte *e = img+768*576;
818
819 while (i<e)
820 *f++ += *i++;
821
822 if (n%fIntRate)
823 return false;
824
825 f = myimg;
826 i = img;
827 e = img+768*576;
828
829 while (i<e)
830 *i++ = (byte)(*f++/fIntRate);
831
832 memset(myimg, 0, sizeof(myimg));
833
834 return true;
835}
836
837void MStarguider::ProcessFrame(const unsigned long n, byte *img, struct timeval *tm)
838{
839 static unsigned long n0 = n;
840
841 MTime t(*tm);
842
843 const Double_t d = t-fTime;
844 if (d>1)
845 {
846 fFps->SetText(Form("%dfps", (int)((n-n0)/d+.5)));
847 fTime = t;
848 n0 = n;
849 }
850
851 if (!Interpolate(n, img))
852 return;
853
854 FilterLed f(img, 768, 576, 2.5); // 2.5
855
856 if (fDisplay->IsEntryChecked(IDM_kStretch))
857 f.Stretch();
858
859 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&
860 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))
861 {
862 if (fFileType->IsEntryChecked(IDM_kPNG))
863 Writer::Png("pix/file", img, tm);
864
865 if (fFileType->IsEntryChecked(IDM_kPPM))
866 Writer::Ppm("pix/file", img, tm);
867
868 if (fWriteType->IsEntryChecked(IDM_kOnce))
869 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);
870 }
871
872 MStarList spots;
873 if (fDisplay->IsEntryChecked(IDM_kFilter))
874 f.Execute();
875
876 if (fDisplay->IsEntryChecked(IDM_kCaosFilter))
877 {
878 const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds);
879 const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings);
880 ZdAz pos;
881 if (fCosy)
882 pos = fCosy->GetPointingPos();
883
884 fCaos->Run(img, printl, printr, pos, t);
885 }
886
887 byte zimg[kZOOM*kZOOM];
888 for (int y=0; y<kZOOM; y++)
889 for (int x=0; x<kZOOM; x++)
890 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768];
891
892 fZoomImage->DrawImg(zimg);
893
894 if (fDisplay->IsEntryChecked(IDM_kCatalog))
895 {
896 MTime time(*tm);
897
898 XY xy = fCRaDec->GetCoordinates();
899 fRaDec->Set(xy.X()*360/24, xy.Y());
900
901 UpdatePosZoom();
902
903 MStarList stars;
904 fSao->GetStars(stars, time.GetMjd(), *fRaDec);
905
906 if (fDisplay->IsEntryChecked(IDM_kStarguider))
907 {
908 Leds leds;
909 f.Execute(leds);
910
911 cout << "Found: " << leds.GetEntries() << " stars." << endl;
912
913 CalcTrackingError(leds, stars);
914 }
915
916 byte cimg[768*576];
917 fSao->GetImg(img, cimg, stars);
918
919 const float r = 60*60/fSao->GetPixSize()+1;
920 f.DrawCircle(0.5*r);
921 f.DrawCircle(1.0*r);
922 f.DrawCircle(1.5*r);
923
924 fCZdAz->SetCoordinates(fSao->GetZdAz());
925
926 fImage->DrawColImg(img, cimg);
927 }
928 else
929 fImage->DrawImg(img);
930}
931
932void MStarguider::UpdatePosZoom()
933{
934 if (fDisplay->IsEntryChecked(IDM_kCatalog))
935 {
936 // FIXME: Necessary?
937 fSao->Now();
938 AltAz aa = fSao->CalcAltAzFromPix(fDx, fDy)*kRad2Deg;
939
940 if (aa.Az()<0)
941 aa.Az(aa.Az()+360);
942 fPosZoom->SetText(Form("%.1fd/%.1fd (%d, %d)",
943 -aa.Alt(), aa.Az()-180, fDx, fDy));
944 }
945 else
946 fPosZoom->SetText(Form("(%d, %d)", fDx, fDy));
947}
948
949Bool_t MStarguider::HandleDoubleClick(Event_t *event)
950{
951 const Int_t w = fImage->GetWidth();
952 const Int_t h = fImage->GetHeight();
953 const Int_t x = fImage->GetX();
954 const Int_t y = fImage->GetY();
955
956 if (!(event->fX>x && event->fX<x+w && event->fY>y && event->fY<y+h))
957 return kTRUE;
958
959 Int_t dx = event->fX-x;
960 Int_t dy = event->fY-y;
961
962 if (dx<kZOOM/4) dx=kZOOM/4;
963 if (dy<kZOOM/4) dy=kZOOM/4;
964 if (dx>766-kZOOM/4) dx=766-kZOOM/4;
965 if (dy>574-kZOOM/4) dy=574-kZOOM/4;
966
967 fDx = dx;
968 fDy = dy;
969
970 UpdatePosZoom();
971 return kTRUE;
972}
Note: See TracBrowser for help on using the repository browser.