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

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