Changeset 18627 for trunk/FACT++/drive/MStarguider.cc
- Timestamp:
- 09/18/16 14:53:16 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/drive/MStarguider.cc
r18618 r18627 4 4 #include "MStarguider.h" 5 5 6 #include <fstream> // ifstream 7 8 #include <TH2F.h> 9 #include <TGraph.h> 10 #include <TTimer.h> 6 #ifdef HAVE_PNG 7 #include <png.h> 8 #endif 9 #include <iostream> 10 #include <fstream> 11 12 #include <math.h> 13 11 14 #include <TEnv.h> 12 15 #include <TSystem.h> 13 #include <TFile.h> // temp writeout of histos14 //#include <TSocket.h>15 16 16 17 #include <TGMenu.h> … … 20 21 #include <TGTextEntry.h> 21 22 #include <TGLayout.h> 22 #include "MString.h" 23 24 #include "MLog.h" 25 #include "MLogManip.h" 26 27 #include "MAstro.h" 28 #include "MString.h" 29 30 31 #include "MCosy.h" 23 32 24 #include "MCaos.h" 33 // #include "MStargLeds.h"34 #include "MStargHistograms.h"35 #include "MDriveCom.h"36 37 #include "MGStarg.h"38 #include "MGNumStars.h"39 40 25 #include "MGImage.h" 41 #include "MGCoordinates.h"42 43 26 #include "Camera.h" 44 #include "PngReader.h" 45 27 #include "../src/DimSetup.h" 46 28 #include "Led.h" 47 #include "Writer.h"29 //#include "Writer.h" 48 30 #include "FilterLed.h" 49 #include "MStarList.h" 50 #include "CaosFilter.h" 51 #include "StarCatalog.h" 52 #include "MGeomCamMagic.h" 53 #include "MAstroCamera.h" 54 55 #include "MGCosy.h" 56 57 ClassImp(MStarguider); 31 //#include "CaosFilter.h" 58 32 59 33 using namespace std; … … 63 37 IDM_kFindStar, 64 38 IDM_kCaosFilter, 65 IDM_kCatalog,66 39 IDM_kStarguider, 67 IDM_kStart,68 IDM_kStop,69 IDM_kFileType,70 IDM_kPPM,71 IDM_kPNG,72 IDM_kOnce,73 40 IDM_kStretch, 74 41 IDM_kInput, 75 IDM_kChannel1,76 IDM_kChannel2,77 IDM_kChannel3,78 IDM_kContinous,79 IDM_kRate25ps,80 IDM_kRate5ps,81 IDM_kRate1s,82 IDM_kRate5s,83 IDM_kRate30s,84 IDM_kRate1m,85 IDM_kRate5m,86 42 IDM_kSetup, 87 IDM_kLimMag3,88 IDM_kLimMag4,89 IDM_kLimMag5,90 IDM_kLimMag6,91 IDM_kLimMag7,92 IDM_kLimMag8,93 IDM_kLimMag9,94 IDM_kPixSize,95 IDM_kAngle,96 43 IDM_kCut, 97 44 IDM_kInterpol250, … … 103 50 IDM_kInterpol2, 104 51 IDM_kInterpol1, 105 IDM_kCaosPrintRings, 106 IDM_kCaosPrintLeds, 107 IDM_kCaosAnalStart, 108 IDM_kCaosAnalStop, 52 //IDM_kCaosPrintRings, 53 //IDM_kCaosPrintLeds, 109 54 IDM_kCaosWriteStart, 110 55 IDM_kCaosWriteStop, 111 56 IDM_kResetHistograms, 112 IDM_kStargAnalysis,113 IDM_kStargCaosFilter,114 IDM_kStarguiderMode,115 IDM_kTpointMode116 117 57 }; 118 58 119 Bool_t MStarguider::HandleTimer(TTimer * t)59 Bool_t MStarguider::HandleTimer(TTimer *) 120 60 { 121 61 if (IsMapped()) 122 {123 62 fImage->DoRedraw(); 124 fZoomImage->DoRedraw();125 }126 127 if (fCosy && fCosy->GetWin()->IsMapped())128 fCosy->GetWin()->GetImage()->DoRedraw();129 130 fGStarg->Update(fPos, fD);131 if (fDisplay->IsEntryChecked(IDM_kStarguider))132 fGNumStars->Update(fNumStarsDetected, fNumStarsCorrelated);133 63 134 64 return kTRUE; … … 136 66 137 67 #define kZOOM 96 138 68 /* 139 69 XY MStarguider::GetCoordinates() const 140 70 { 141 71 return fPZdAz->GetCoordinates(); 142 72 } 143 144 void MStarguider::InitGui(Int_t channel) 145 { 146 fList = new MGList; 147 fList->SetOwner(); 148 149 const TGWindow *p=gClient->GetRoot(); 73 */ 74 void MStarguider::InitGui(Int_t) 75 { 76 //fList = new MGList; 77 //fList->SetOwner(); 78 79 /* 80 const TGWindow *p=gClient->GetRoot(); 150 81 151 82 fChannel = new TGPopupMenu(p); 152 83 fChannel->AddEntry("Starfield Camera", IDM_kChannel1); 153 84 fChannel->AddEntry("TPoint Camera", IDM_kChannel2); 154 fChannel->AddEntry("Read from File", IDM_kChannel3);155 if (channel<0)156 fChannel->CheckEntry(IDM_kChannel3);157 else85 //fChannel->AddEntry("Read from File", IDM_kChannel3); 86 //if (channel<0) 87 // fChannel->CheckEntry(IDM_kChannel3); 88 //else 158 89 fChannel->CheckEntry(channel==0?IDM_kChannel1:IDM_kChannel2); 159 90 fChannel->Associate(this); … … 199 130 fLimMag->Associate(this); 200 131 fList->Add(fLimMag); 201 202 fSao->SetLimitMag(9.0); 132 */ 133 //fSao->SetLimitMag(9.0); 134 135 const TGWindow *p=gClient->GetRoot(); 203 136 204 137 fInterpol = new TGPopupMenu(p); … … 212 145 fInterpol->AddEntry("Off", IDM_kInterpol1); 213 146 fInterpol->Associate(this); 214 fList->Add(fInterpol);147 //fList->Add(fInterpol); 215 148 216 149 TString disp=gVirtualX->DisplayName(); 217 gLog << all<< "Display: " << disp << endl;150 cout << "Display: " << disp << endl; 218 151 if (disp.First(':')>=0) 219 152 disp=disp(0, disp.First(':')); … … 221 154 if (disp.IsNull() || disp==(TString)"localhost") 222 155 { 223 fInterpol->CheckEntry(IDM_kInterpol 5);224 fIntRate = 50;156 fInterpol->CheckEntry(IDM_kInterpol25); 157 fIntRate = 25; 225 158 } 226 159 else … … 230 163 } 231 164 165 /* 232 166 fCaosPrint = new TGPopupMenu(p); 233 167 fCaosPrint->AddEntry("&Leds", IDM_kCaosPrintLeds); … … 249 183 fCaosAnalyse->Associate(this); 250 184 fList->Add(fCaosAnalyse); 251 185 */ 252 186 fMenu = new TGMenuBar(this, 0, 0, kHorizontalFrame); 253 187 fDisplay = fMenu->AddPopup("&Display"); 254 fMode = fMenu->AddPopup("&Mode");255 fWritePictures = fMenu->AddPopup("&WritePics");188 //fMode = fMenu->AddPopup("&Mode"); 189 //fWritePictures = fMenu->AddPopup("&WritePics"); 256 190 fSetup = fMenu->AddPopup("&Setup"); 257 fOperations = fMenu->AddPopup("&Operations");191 //fOperations = fMenu->AddPopup("&Operations"); 258 192 fMenu->Resize(fMenu->GetDefaultSize()); 259 AddFrame(fMenu); 193 AddFrame(fMenu); 260 194 261 195 // … … 268 202 fDisplay->AddEntry("Find &Star", IDM_kFindStar); 269 203 fDisplay->AddEntry("C&aos Filter", IDM_kCaosFilter); 270 fDisplay->AddSeparator(); 271 fDisplay->AddEntry("SAO &Catalog", IDM_kCatalog); 272 fDisplay->AddEntry("Starguider", IDM_kStarguider); 273 fDisplay->AddEntry("Starguider LED Filter", IDM_kStargCaosFilter); 274 fDisplay->AddSeparator(); 275 if (channel>=0) 276 fDisplay->AddPopup("&Input", fChannel); 277 fDisplay->CheckEntry(IDM_kStretch); 204 //fDisplay->AddSeparator(); 205 //if (channel>=0) 206 // fDisplay->AddPopup("&Input", fChannel); 207 // fDisplay->CheckEntry(IDM_kStretch); 208 fDisplay->CheckEntry(IDM_kFindStar); 209 fDisplay->CheckEntry(IDM_kCaosFilter); 278 210 fDisplay->Associate(this); 279 211 280 fMode->AddEntry("Starguider", IDM_kStarguiderMode); 281 fMode->AddEntry("Tpoint", IDM_kTpointMode); 282 fMode->Associate(this); 283 212 //fMode->AddEntry("Tpoint", IDM_kTpointMode); 213 //fMode->Associate(this); 214 /* 284 215 fWritePictures->AddEntry("&Start", IDM_kStart); 285 216 fWritePictures->AddEntry("Sto&p", IDM_kStop); 286 217 fWritePictures->AddSeparator(); 287 fWritePictures->AddPopup("File &Type", fFileType);218 //fWritePictures->AddPopup("File &Type", fFileType); 288 219 fWritePictures->AddPopup("&Write Type", fWriteType); 289 220 fWritePictures->AddPopup("Write &Rate", fWriteRate); 290 221 fWritePictures->DisableEntry(IDM_kStop); 291 222 fWritePictures->Associate(this); 292 293 fSetup->AddPopup("Lim. &Magnitude", fLimMag); 223 */ 294 224 fSetup->AddPopup("Disp. &Interpolation", fInterpol); 295 225 fSetup->Associate(this); 296 226 297 fOperations->AddEntry("Starguider Analysis", IDM_kStargAnalysis); 298 fOperations->DisableEntry(IDM_kStargAnalysis); 299 fOperations->Associate(this); 300 227 /* 301 228 fCaOs = new TGPopupMenu(p); 302 fCaOs->AddPopup("&Write", fCaosWrite);229 //fCaOs->AddPopup("&Write", fCaosWrite); 303 230 fCaOs->AddPopup("&Print", fCaosPrint); 304 fCaOs->AddPopup("&Analyse", fCaosAnalyse);231 //fCaOs->AddPopup("&Analyse", fCaosAnalyse); 305 232 fCaOs->Associate(this); 306 233 fList->Add(fCaOs); 307 308 fGStarg = new MGStarg(this, 235); 309 fGStarg->Move(530,596+5); 310 fList->Add(fGStarg); 311 234 */ 312 235 //RA,Dec for catalog 236 /* 313 237 fCRaDec = new MGCoordinates(this, kETypeRaDec); 314 238 fCRaDec->Move(4, fMenu->GetDefaultHeight()+584); … … 344 268 fTPoint->AllowStayDown(kTRUE); 345 269 AddFrame(fTPoint); 346 /* 347 270 271 fStargTPoint = new TGTextButton(this, "StargTPoint"); 348 272 fStargTPoint->Move(170, fMenu->GetDefaultHeight()+785); 349 273 fStargTPoint->AllowStayDown(kTRUE); 350 274 AddFrame(fStargTPoint); 351 */ 352 353 fFps = new TGLabel(this, "---fps"); 275 276 fFps = new TGLabel(this, "---fps"); 354 277 fFps->SetTextJustify(kTextRight); 355 278 fFps->Move(650-495, fMenu->GetDefaultHeight()+714+23); … … 395 318 fDZdAzText->Move(240+12+20+7, fMenu->GetDefaultHeight()+676+2*20-5-46); 396 319 AddFrame(fDZdAzText); 397 320 */ 398 321 // Set input box for rotation angle 322 /* 399 323 fAngle = new TGTextEntry(this, " ", IDM_kAngle); 400 324 fAngle->SetAlignment(kTextCenterX); … … 402 326 AddFrame(fAngle); 403 327 404 SetRotationAngle(-0.2);328 //SetRotationAngle(-0.2); 405 329 406 330 // Set input box for pixel size … … 409 333 fPixSize->Move(547-410, fMenu->GetDefaultHeight()+690); 410 334 AddFrame(fPixSize); 411 412 SetPixSize(48.9);335 */ 336 //SetPixSize(48.9); 413 337 414 338 // Set input box for cleaning cut 415 fCut = new TGTextEntry(this, " ", IDM_kCut);416 fCut->SetAlignment(kTextCenterX);417 fCut->Move(547-410, fMenu->GetDefaultHeight()+713);418 AddFrame(fCut);419 420 SetCut(3.0);339 //fCut = new TGTextEntry(this, " ", IDM_kCut); 340 //fCut->SetAlignment(kTextCenterX); 341 //fCut->Move(547-410, fMenu->GetDefaultHeight()+713); 342 //AddFrame(fCut); 343 344 //SetCut(3.0); 421 345 422 346 // TGHorizontal3DLine *fLineSep = new TGHorizontal3DLine(this); … … 426 350 // 427 351 // Create Image Display 428 / /352 /* 429 353 fZoomImage = new MGImage(this, kZOOM, kZOOM); 430 354 // fZoomImage->Move(768-kZOOM-2, 700-kZOOM-2); 431 355 fZoomImage->Move(4, 700-kZOOM-2+85); 432 356 AddFrame(fZoomImage); 433 357 */ 434 358 fImage = new MGImage(this, 768, 576); 435 359 fImage->Move(0, fMenu->GetDefaultHeight()); … … 437 361 438 362 const Int_t w = 768; 439 const Int_t h = 840;363 const Int_t h = 576; 440 364 SetWMSizeHints(w, h, w, h, 1, 1); // set the smallest and biggest size of the Main frame 441 365 … … 443 367 // Make everything visible 444 368 // 445 SetWindowName(" MStarguiderMain Window");446 SetIconName(" MStarguider");369 SetWindowName("TPoint Main Window"); 370 SetIconName("TPoint"); 447 371 448 372 MapSubwindows(); 449 fTPoint->UnmapWindow();373 //fTPoint->UnmapWindow(); 450 374 //fStargTPoint->UnmapWindow(); 451 fGStarg->UnmapWindow();452 fGNumStars->UnmapWindow();453 fCRaDec->UnmapWindow();454 fCZdAz->UnmapWindow();455 fCZdAzText->UnmapWindow();456 fPZdAz->UnmapWindow();457 fPZdAzText->UnmapWindow();458 fDZdAz->UnmapWindow();459 fDZdAzText->UnmapWindow();460 fSZdAz->UnmapWindow();461 fSkyBright->UnmapWindow();375 //fGStarg->UnmapWindow(); 376 //fGNumStars->UnmapWindow(); 377 //fCRaDec->UnmapWindow(); 378 //fCZdAz->UnmapWindow(); 379 //fCZdAzText->UnmapWindow(); 380 //fPZdAz->UnmapWindow(); 381 //fPZdAzText->UnmapWindow(); 382 //fDZdAz->UnmapWindow(); 383 //fDZdAzText->UnmapWindow(); 384 //fSZdAz->UnmapWindow(); 385 //fSkyBright->UnmapWindow(); 462 386 MapWindow(); 463 387 … … 472 396 } 473 397 474 MStarguider::MStarguider(MObservatory::LocationName_t obs, Int_t channel) 475 : TGMainFrame(gClient->GetRoot(), 768, 840), 476 fNumStarsDetected(0), 477 fNumStarsCorrelated(0), 478 fCosy(NULL), 479 fOutTp(0), 480 fOutStargTp(0), 481 // fOutRq(0), 482 fDx((768-kZOOM)/2), 483 fDy((512-kZOOM)/2), 484 fStatus(MDriveCom::kStandby), 485 fRadius(200), 486 fTPointFromCC(-1), 487 fFindStarCut(3.0), fFindStarBox(70) 488 { 489 gLog << warn << " #### FIXME: Make MCaos Thread safe!" << endl; 398 MStarguider::MStarguider(Int_t channel) : TGMainFrame(gClient->GetRoot(), 768, 840), 399 fDimData("TPOINT/DATA", "D:11", (void*)NULL, 0), 400 fDimTPoint("TPOINT/EXECUTE", "", this), 401 fDimScreenshot("TPOINT/SCREENSHOT", "B:1;C", this), 402 fRadius(200), fFindStarCut(2.), fFindStarBox(30), fTPointMode(0) 403 { 404 cout << " #### FIXME: Make MCaos Thread safe!" << endl; 490 405 491 406 // This means that all objects added with AddFrame are deleted … … 493 408 SetCleanup(); 494 409 495 fSao = new StarCatalog(obs);496 fRaDec = new RaDec(180, 40);497 498 410 fCaos = new MCaos; 499 fStargCaos = new MCaos; 500 501 fStargHistograms = new MStargHistograms(); 411 fCaos->ReadResources("leds_fact.txt"); 502 412 503 413 InitGui(channel); … … 506 416 fTimer->TurnOn(); 507 417 508 fTime.Now();509 510 fTimeFromTp.Clear();511 fAltAzOffsetFromTp = AltAz(-1000,-1000);512 513 418 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kTRUE); 514 419 515 if (channel<0) 516 fGetter = new PngReader(*this); 517 else 518 fGetter = new Camera(*this, channel); 519 } 520 521 void MStarguider::SetRotationAngle(Double_t angle) 522 { 523 fSao->SetRotationAngle(angle); 524 525 TString txt; 526 txt += angle; 527 528 fAngle->SetText(txt); 529 } 530 531 void MStarguider::SetPixSize(Double_t size) 532 { 533 fSao->SetPixSize(size); 534 535 TString txt; 536 txt += size; 537 538 fPixSize->SetText(txt); 539 } 540 541 void MStarguider::SetCut(Double_t cut) 542 { 543 TString txt; 544 txt += cut; 545 546 fCut->SetText(txt); 547 } 548 420 fGetter = new Camera(*this, channel); 421 422 DimClient::setNoDataCopy(); 423 DimServer::start("TPOINT"); 424 } 425 426 MStarguider::~MStarguider() 427 { 428 DimServer::stop(); 429 430 fGetter->ExitLoop(); 431 delete fGetter; 432 433 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE); 434 435 fTimer->TurnOff(); 436 delete fTimer; 437 438 delete fInterpol; 439 440 //delete fList; 441 delete fCaos; 442 443 cout << "Camera Display destroyed." << endl; 444 } 445 446 /* 549 447 void MStarguider::SetupEnv(TEnv &env) 550 448 { 551 449 fCaos->ReadEnv(env, "TPointLeds", kTRUE); 552 fStargCaos->ReadEnv(env, "StarguiderLeds", kTRUE);553 554 SetRotationAngle(env.GetValue("Starguider.RotationAngle", fSao->GetRotationAngle()));555 SetCut(env.GetValue("Starguider.CleaningLevel", atof(fCut->GetText())));556 557 SetPixSize(env.GetValue("StarguiderLeds.ArcsecPerPixel", fSao->GetPixSize()));450 //fStargCaos->ReadEnv(env, "StarguiderLeds", kTRUE); 451 452 //SetRotationAngle(env.GetValue("Starguider.RotationAngle", fSao->GetRotationAngle())); 453 //SetCut(env.GetValue("Starguider.CleaningLevel", atof(fCut->GetText()))); 454 455 //SetPixSize(env.GetValue("StarguiderLeds.ArcsecPerPixel", fSao->GetPixSize())); 558 456 559 457 fRadius = env.GetValue("Leds.Radius", fRadius); … … 570 468 fFindStarCut = env.GetValue("FindStar.CleaningLevel", fFindStarCut); 571 469 } 572 573 MStarguider::~MStarguider() 574 { 575 fGetter->ExitLoop(); 576 delete fGetter; 577 578 gVirtualX->GrabButton(fId, kButton2, 0, 0, 0, 0, kFALSE); 579 580 fTimer->TurnOff(); 581 delete fTimer; 582 583 delete fList; 584 585 delete fCaos; 586 delete fStargCaos; 587 delete fStargHistograms; 588 delete fSao; 589 delete fRaDec; 590 591 if (fOutTp) 592 delete fOutTp; 593 594 if (fOutStargTp) 595 delete fOutStargTp; 596 597 // if (fOutRq) 598 // delete fOutRq; 599 600 gLog << inf2 << "Camera Display destroyed." << endl; 601 } 470 */ 602 471 603 472 void MStarguider::Layout() … … 608 477 void MStarguider::CloseWindow() 609 478 { 610 gLog << inf2<< "EventDisplay::CloseWindow: Exit Application Loop." << endl;479 cout << "EventDisplay::CloseWindow: Exit Application Loop." << endl; 611 480 612 481 //fClient.ExitLoop(); … … 622 491 } 623 492 493 /* 624 494 void MStarguider::SetChannel() 625 495 { … … 643 513 fGetter->SetChannel(ch); 644 514 } 645 } 515 }*/ 646 516 647 517 void MStarguider::Toggle(TGPopupMenu *p, UInt_t id) … … 653 523 } 654 524 655 void MStarguider::ToggleStargAnalysis() 656 { 657 if (fOperations->IsEntryChecked(IDM_kStargAnalysis)) 658 fStargHistograms->OpenFile(); 659 else 660 fStargHistograms->CloseFile(); 661 } 662 663 /* 664 void MStarguider::ToggleFindStar() 665 { 666 if (fDisplay->IsEntryChecked(IDM_kFindStar) && fCosy) 667 fTPoint->MapWindow(); 668 else 669 { 670 fTPoint->UnmapWindow(); 671 fTPoint->SetDown(kFALSE); 672 } 673 } 674 */ 675 void MStarguider::ToggleStarguider() 676 { 677 if (fDisplay->IsEntryChecked(IDM_kStarguider)) 678 { 679 fLastBright = 0xff; 680 681 fChannel->EnableEntry(IDM_kChannel1); 682 fDisplay->DisableEntry(IDM_kFindStar); 683 fDisplay->DisableEntry(IDM_kCaosFilter); 684 fOperations->EnableEntry(IDM_kStargAnalysis); 685 686 //fStargTPoint->MapWindow(); 687 688 fPZdAz->MapWindow(); 689 fDZdAz->MapWindow(); 690 fSkyBright->MapWindow(); 691 692 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++) 693 fLimMag->UnCheckEntry(i); 694 fLimMag->CheckEntry(IDM_kLimMag9); 695 fSao->SetLimitMag(9.0); 696 697 for (int i=IDM_kInterpol250; i<=IDM_kInterpol1; i++) 698 fInterpol->UnCheckEntry(i); 699 fInterpol->CheckEntry(IDM_kInterpol125); 700 fIntRate = 125; 701 702 //catalog 703 fDisplay->CheckEntry(IDM_kCatalog); 704 fCRaDec->MapWindow(); 705 fCZdAz->MapWindow(); 706 fCZdAzText->MapWindow(); 707 708 fPZdAz->MapWindow(); 709 fPZdAzText->MapWindow(); 710 fDZdAz->MapWindow(); 711 fDZdAzText->MapWindow(); 712 713 fGStarg->MapWindow(); 714 fGNumStars->MapWindow(); 715 716 SwitchOff(fChannel, IDM_kChannel2); 717 fChannel->CheckEntry(IDM_kChannel1); 718 } 719 else 720 { 721 fStatus = MDriveCom::kStandby; 722 723 //fStargTPoint->UnmapWindow(); 724 //fStargTPoint->SetDown(kFALSE); 725 726 fPZdAz->UnmapWindow(); 727 fPZdAzText->UnmapWindow(); 728 fDZdAz->UnmapWindow(); 729 fDZdAzText->UnmapWindow(); 730 fSkyBright->UnmapWindow(); 731 //catalog 732 fCRaDec->UnmapWindow(); 733 fCZdAz->UnmapWindow(); 734 fCZdAzText->UnmapWindow(); 735 fDisplay->UnCheckEntry(IDM_kCatalog); 736 737 fGStarg->UnmapWindow(); 738 fGNumStars->UnmapWindow(); 739 740 fChannel->EnableEntry(IDM_kChannel2); 741 fDisplay->EnableEntry(IDM_kFindStar); 742 fDisplay->EnableEntry(IDM_kCaosFilter); 743 fOperations->DisableEntry(IDM_kStargAnalysis); 744 } 745 746 SetChannel(); 747 //gSystem->Unlink("tracking_error.txt"); 748 } 749 750 void MStarguider::ToggleCaosFilter() 751 { 752 if (fDisplay->IsEntryChecked(IDM_kCaosFilter)) 753 { 754 if (!fMode->IsEntryChecked(IDM_kStarguiderMode) 755 && !fMode->IsEntryChecked(IDM_kTpointMode)) 756 fMenu->AddPopup("&CaOs", fCaOs, NULL); 757 758 SwitchOff(fDisplay, IDM_kStarguider); 759 SwitchOff(fDisplay, IDM_kStargCaosFilter); 760 } 761 else 762 { 763 fCaosWrite->UnCheckEntry(IDM_kCaosPrintLeds); 764 fCaosWrite->UnCheckEntry(IDM_kCaosPrintRings); 765 766 if (fCaosAnalyse->IsEntryEnabled(IDM_kCaosAnalStop)) 767 { 768 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStop); 769 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStart); 770 fCaos->DeleteHistograms(); 771 } 772 if (fCaosWrite->IsEntryEnabled(IDM_kCaosWriteStop)) 773 { 774 fCaosWrite->DisableEntry(IDM_kCaosWriteStop); 775 fCaosWrite->EnableEntry(IDM_kCaosWriteStart); 776 fCaos->CloseFile(); 777 } 778 fMenu->RemovePopup("CaOs"); 779 780 fDisplay->EnableEntry(IDM_kStargCaosFilter); 781 fDisplay->EnableEntry(IDM_kStarguider); 782 } 783 fMenu->Resize(fMenu->GetDefaultSize()); 784 MapSubwindows(); // maps everything, but we don't want that 785 fTPoint->UnmapWindow(); 786 //fStargTPoint->UnmapWindow(); 787 fGStarg->UnmapWindow(); 788 fGNumStars->UnmapWindow(); 789 fCRaDec->UnmapWindow(); 790 fCZdAz->UnmapWindow(); 791 fCZdAzText->UnmapWindow(); 792 fPZdAz->UnmapWindow(); 793 fPZdAzText->UnmapWindow(); 794 fDZdAz->UnmapWindow(); 795 fDZdAzText->UnmapWindow(); 796 fSZdAz->UnmapWindow(); 797 fSkyBright->UnmapWindow(); 798 MapWindow(); 799 } 800 801 Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2) 525 526 Bool_t MStarguider::ProcessMessage(Long_t msg, Long_t mp1, Long_t) 802 527 { 803 528 switch (GET_MSG(msg)) … … 807 532 switch (mp1) 808 533 { 534 /* 809 535 case IDM_kPixSize: 810 536 { … … 826 552 gLog << all << "Starguider cleaning level changed to " << cut << " sigma." << endl; 827 553 return kTRUE; 828 } 554 }*/ 829 555 } 830 556 return kTRUE; … … 836 562 switch (mp1) 837 563 { 838 case IDM_kCatalog: 839 Toggle(fDisplay, IDM_kCatalog); 840 if (fDisplay->IsEntryChecked(IDM_kCatalog)) 841 { 842 fCRaDec->MapWindow(); 843 fCZdAz->MapWindow(); 844 fCZdAzText->MapWindow(); 845 } 846 else 847 { 848 fCRaDec->UnmapWindow(); 849 fCZdAz->UnmapWindow(); 850 fCZdAzText->UnmapWindow(); 851 } 852 return kTRUE; 853 854 case IDM_kStarguider: 855 Toggle(fDisplay, IDM_kStarguider); 856 ToggleStarguider(); 857 return kTRUE; 858 859 case IDM_kStargAnalysis: 860 Toggle(fOperations, IDM_kStargAnalysis); 861 ToggleStargAnalysis(); 862 return kTRUE; 863 864 case IDM_kStarguiderMode: 865 Toggle(fMode, IDM_kStarguiderMode); 866 867 if (fMode->IsEntryChecked(IDM_kStarguiderMode)) 868 { 869 //uncheck not needed items 870 //general 871 SwitchOff(fDisplay, IDM_kFilter); 872 SwitchOff(fChannel, IDM_kChannel3); 873 SwitchOff(fOperations, IDM_kStargAnalysis); 874 875 //tpoint 876 SwitchOff(fDisplay, IDM_kFindStar); 877 SwitchOff(fDisplay, IDM_kCaosFilter); 878 ToggleCaosFilter(); 879 fMode->UnCheckEntry(IDM_kTpointMode); 880 881 //enable starguider items 882 fDisplay->EnableEntry(IDM_kStargCaosFilter); 883 fDisplay->EnableEntry(IDM_kStarguider); 884 fDisplay->EnableEntry(IDM_kCatalog); 885 886 //check needed items 887 fDisplay->UnCheckEntry(IDM_kStretch); 888 fDisplay->CheckEntry(IDM_kStargCaosFilter); 889 fDisplay->CheckEntry(IDM_kStarguider); 890 ToggleStarguider(); 891 892 fTPoint->MapWindow(); 893 } 894 else 895 { 896 //uncheck 897 //starguider items 898 fDisplay->UnCheckEntry(IDM_kStargCaosFilter); 899 fDisplay->UnCheckEntry(IDM_kStarguider); 900 fTPoint->UnmapWindow(); 901 ToggleStarguider(); 902 903 //general 904 fDisplay->UnCheckEntry(IDM_kCatalog); 905 fDisplay->EnableEntry(IDM_kFilter); 906 fDisplay->EnableEntry(IDM_kCaosFilter); 907 fDisplay->EnableEntry(IDM_kFindStar); 908 fChannel->EnableEntry(IDM_kChannel3); 909 } 910 return kTRUE; 911 564 /* 912 565 case IDM_kTpointMode: 913 566 Toggle(fMode, IDM_kTpointMode); … … 921 574 922 575 //from starguider 923 SwitchOff(fDisplay, IDM_kStargCaosFilter);924 SwitchOff(fDisplay, IDM_kCatalog);925 SwitchOff(fDisplay, IDM_kStarguider);926 ToggleStarguider();927 fMode->UnCheckEntry(IDM_kStarguiderMode);928 SwitchOff(fOperations, IDM_kStargAnalysis);929 ToggleStargAnalysis();576 //SwitchOff(fDisplay, IDM_kStargCaosFilter); 577 //SwitchOff(fDisplay, IDM_kCatalog); 578 //SwitchOff(fDisplay, IDM_kStarguider); 579 //ToggleStarguider(); 580 //fMode->UnCheckEntry(IDM_kStarguiderMode); 581 //SwitchOff(fOperations, IDM_kStargAnalysis); 582 //ToggleStargAnalysis(); 930 583 931 584 //switch camera … … 946 599 //enable 947 600 //starguider items 948 fDisplay->EnableEntry(IDM_kStargCaosFilter);949 fDisplay->EnableEntry(IDM_kCatalog);950 fDisplay->EnableEntry(IDM_kStarguider);951 fOperations->EnableEntry(IDM_kStargAnalysis);601 //fDisplay->EnableEntry(IDM_kStargCaosFilter); 602 //fDisplay->EnableEntry(IDM_kCatalog); 603 //fDisplay->EnableEntry(IDM_kStarguider); 604 //fOperations->EnableEntry(IDM_kStargAnalysis); 952 605 953 606 //general … … 963 616 } 964 617 return kTRUE; 965 618 */ 966 619 case IDM_kFilter: 967 620 Toggle(fDisplay, IDM_kFilter); … … 979 632 case IDM_kCaosFilter: 980 633 Toggle(fDisplay, IDM_kCaosFilter); 981 ToggleCaosFilter(); 982 return kTRUE; 983 984 case IDM_kStargCaosFilter: 985 Toggle(fDisplay, IDM_kStargCaosFilter); 986 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter)) 987 { 988 SwitchOff(fDisplay, IDM_kCaosFilter); 989 SwitchOff(fDisplay, IDM_kFindStar); 990 SwitchOff(fDisplay, IDM_kFilter); 991 } 992 else 993 { 994 fDisplay->EnableEntry(IDM_kFilter); 995 fDisplay->EnableEntry(IDM_kFindStar); 996 fDisplay->EnableEntry(IDM_kCaosFilter); 997 } 998 return kTRUE; 999 634 //ToggleCaosFilter(); 635 return kTRUE; 636 /* 1000 637 case IDM_kCaosPrintLeds: 1001 638 case IDM_kCaosPrintRings: … … 1006 643 fCaosAnalyse->DisableEntry(IDM_kCaosAnalStart); 1007 644 fCaosAnalyse->EnableEntry(IDM_kCaosAnalStop); 1008 fCaos->InitHistograms();645 //fCaos->InitHistograms(); 1009 646 return kTRUE; 1010 647 … … 1111 748 } 1112 749 return kTRUE; 1113 750 */ 1114 751 case IDM_kInterpol250: 1115 752 case IDM_kInterpol125: … … 1153 790 } 1154 791 return kTRUE; 1155 1156 case IDM_kLimMag3:1157 case IDM_kLimMag4:1158 case IDM_kLimMag5:1159 case IDM_kLimMag6:1160 case IDM_kLimMag7:1161 case IDM_kLimMag8:1162 case IDM_kLimMag9:1163 for (int i=IDM_kLimMag3; i<=IDM_kLimMag9; i++)1164 if (mp1==i)1165 fLimMag->CheckEntry(i);1166 else1167 fLimMag->UnCheckEntry(i);1168 1169 fSao->SetLimitMag(mp1-IDM_kLimMag3+3);1170 return kTRUE;1171 792 } 1172 793 break; … … 1177 798 return kTRUE; 1178 799 } 1179 1180 void MStarguider::SetPointingPosition(RaDec rd)1181 {1182 rd.Ra(rd.Ra()*24/360);1183 fCRaDec->SetCoordinates(rd);1184 }1185 1186 ZdAz MStarguider::TrackingError(TArrayF &x, TArrayF &y, TArrayF &mag,1187 Int_t &num) const1188 {1189 num = -1;1190 1191 // Width of the final 2D gaussian1192 const Double_t width = 0.8;1193 1194 // The binning is made 1.7 sigma (which, in the 1D case, gives the1195 // highest significance of a gaussian signal) (1bin equiv 3x3 sigma)1196 const Double_t max = 50;1197 const Int_t n = TMath::Nint(2*max/(1.77*1.7*width));1198 //1.77=sqrt(pi) comes from pir=bin1199 1200 // Fill a histogram with the dx/dy values from the file1201 TH2F hist("Hist", "dX/dY", n, -max, max, n, -max, max);1202 // hist.SetDirectory(0);1203 1204 //1205 // Search for matching Magnitudes1206 //1207 //for (int i=0; i<mag.GetSize(); i++)1208 //{1209 // if (mag[i]>48-15 && mag[i]<48+15)1210 // h.Fill(x[i], y[i]);1211 //}1212 1213 // fill dx and dy into histogram1214 for (int i=0; i<mag.GetSize(); i++)1215 hist.Fill(x[i], y[i]);1216 1217 // Remove all bins which have content of only a single event1218 // including under- and overflow bins1219 for (int i=0; i<hist.GetSize(); i++)1220 if (hist.GetBinContent(i)<1.5)1221 hist.SetBinContent(i, 0);1222 1223 // Find the bin containing the maximum1224 Int_t bx, by, bz;1225 hist.GetMaximumBin(bx, by, bz);1226 1227 // In the worst case the events are spread through the1228 // bins which are the neighbors of the maximum1229 // Normally neighbors which do not belong to the signal are empty!1230 hist.GetXaxis()->SetRange(bx-1, bx+1); // 3x3bins ~8x8pix ~9x9sigma1231 hist.GetYaxis()->SetRange(by-1, by+1); // 3x3bins ~8x8pix ~9x9sigma1232 1233 // Check whether this region contains events1234 num = TMath::Nint(hist.Integral());1235 if (num<1)1236 return ZdAz();1237 1238 // Get Mean for the given axis range1239 Double_t mx = hist.GetMean(1);1240 Double_t my = hist.GetMean(2);1241 1242 const Int_t max1 = TMath::Nint(hist.GetBinContent(bx, by));1243 1244 // Check if the maximum is unique1245 Int_t bx2, by2, bz2;1246 hist.GetXaxis()->SetRange(-1, 9999);1247 hist.GetYaxis()->SetRange(-1, 9999);1248 hist.SetBinContent(bx, by, 0);1249 hist.GetMaximumBin(bx2, by2, bz2);1250 1251 const Int_t max2 = TMath::Nint(hist.GetBinContent(bx2, by2));1252 if (max1==max2 && TMath::Abs(bx2-bx)+TMath::Abs(by2-by)>1)1253 return ZdAz();1254 1255 // loop again over the file and fill the histogram again.1256 // to get closer to the correct value1257 Double_t sumx = 0;1258 Double_t sumy = 0;1259 num = 0;1260 for (int i=0; i<mag.GetSize(); i++)1261 {1262 // only fill values into the histogram which1263 // are inside 2*1.7=3.4 sigma (99.7%)1264 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*3.4)1265 continue;1266 1267 sumx += x[i];1268 sumy += y[i];1269 num++;1270 }1271 1272 if (num<1)1273 return ZdAz();1274 1275 // calc MeanX and MeanY1276 mx = sumx/num;1277 my = sumy/num;1278 1279 // loop again to fill the mispointing corrected histograms1280 // and fill another histogram to check the quality of the calculated1281 // mispointing.1282 sumx = 0;1283 sumy = 0;1284 num = 0;1285 for (int i=0; i<mag.GetSize(); i++)1286 {1287 // only fill values into the histogram which1288 // are inside 1.7=3.4 sigma (92%)1289 // Cut at 1.7 sigma which gives the best background supression1290 if (TMath::Hypot(x[i]-mx, y[i]-my)>width*1.7)1291 continue;1292 1293 sumx += x[i];1294 sumy += y[i];1295 num++;1296 }1297 1298 if (num<1)1299 return ZdAz(); // FIXME!!!!!!!!!!!!1300 1301 // Mispointing1302 mx = sumx/num;1303 my = sumy/num;1304 1305 #ifdef EXPERT1306 cout << "Offset-XY: " << mx << " +- " << my << endl;1307 #endif1308 1309 return fSao->CalcDeltaZdAzFromPix(mx, my)*TMath::RadToDeg();1310 800 /* 1311 AltAz pos0 = fSao->CalcAltAzFromPix(768/2, 576/2)*kRad2Deg; 1312 AltAz pos1 = fSao->CalcAltAzFromPix(768/2+mx, 576/2+my)*kRad2Deg; 1313 1314 pos1 -= pos0; 1315 1316 ZdAz res2 = ZdAz(-pos1.Alt(), pos1.Az()); 1317 1318 return res1; 1319 */ 1320 } 1321 1322 Int_t MStarguider::CalcTrackingError(const Leds &leds, MStarList &stars, 1323 ZdAz &d, const MTime &t, const double &bright, 1324 Int_t &num, const Ring ¢er, Int_t numleds, Int_t numrings) 801 void MStarguider::DrawZoomImage(const byte *img) 802 { 803 byte zimg[kZOOM*kZOOM]; 804 for (int y=0; y<kZOOM; y++) 805 for (int x=0; x<kZOOM; x++) 806 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768]; 807 808 fZoomImage->DrawImg(zimg); 809 } 810 811 void MStarguider::DrawCosyImage(const byte *img) 812 { 813 if (!fCosy) 814 return; 815 816 byte simg[(768/2-1)*(576/2-1)]; 817 for (int y=0; y<576/2-1; y++) 818 for (int x=0; x<768/2-1; x++) 819 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; 820 821 fCosy->GetWin()->GetImage()->DrawImg(simg); 822 } 823 824 Led MStarguider::FindStar(const FilterLed &f, const FilterLed &f2, const Ring ¢er, Int_t numleds, Int_t numrings) 1325 825 { 1326 826 // Get tracking coordinates 1327 const XY xy = fCRaDec->GetCoordinates(); 1328 1329 num = leds.GetEntries(); 1330 if (num < 3) //was 1 1331 { 1332 gLog << warn << "Sorry, less than 3 detected spot in FOV!" << endl; 1333 if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 1334 fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num); // Report 1335 fTPoint->SetDown(kFALSE); 1336 return 0; 1337 } 1338 1339 if (stars.GetRealEntries() < 3) 1340 { 1341 gLog << warn << "Sorry, less than 3 stars in FOV!" << endl; 1342 if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 1343 fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num); // Report 1344 fTPoint->SetDown(kFALSE); 1345 return 0; 1346 } 1347 1348 stars.Sort(); // Sort by magnitude 1349 1350 #ifdef EXPERT 1351 TString str = "data/tracking_"; 1352 str += fSao->GetMjd(); 1353 str += ".txt"; 1354 1355 ofstream fout(str); 1356 #endif 1357 1358 TArrayF x, y, mag; 1359 1360 // FIXME: Is predefined value 3 a good idea? 1361 Int_t cnt=0; 1362 1363 MStar *star=0; 1364 MStarListIter NextStar(&stars); 1365 while ((star=NextStar()) && cnt<num+5) 1366 { 1367 TIter NextSp(&leds); 1368 Led *spot=NULL; 1369 while ((spot=(Led*)NextSp())) 1370 { 1371 const XY dpos(spot->GetX()-(768-star->GetX()), 1372 spot->GetY()-star->GetY()); 1373 1374 const Int_t idx = x.GetSize(); 1375 1376 x.Set(idx+1); 1377 y.Set(idx+1); 1378 mag.Set(idx+1); 1379 1380 x.AddAt(dpos.X(), idx); 1381 y.AddAt(dpos.Y(), idx); 1382 mag.AddAt(1, idx); 1383 // mag.AddAt(log(spot->GetMag())/star->GetMag(), idx); 1384 /* 1385 #ifdef EXPERT 1386 if (fout) 1387 { 1388 fout << spot->GetX() << " " 1389 << spot->GetY() << " " 1390 << -2.5*log(spot->GetMag()) << " " 1391 << star->GetX() << " " 1392 << star->GetY() << " " 1393 << star->GetMag() << " "; 1394 fout << x[idx] << " " << y[idx] << " " << mag[idx] << endl; 1395 } 1396 #endif 1397 */ 1398 } 1399 cnt++; 1400 } 1401 1402 Int_t numcor = 0; 1403 d = TrackingError(x, y, mag, numcor); 1404 if (numcor<1) 1405 { 1406 fTPoint->SetDown(kFALSE); 1407 if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 1408 fCosy->GetDriveCom()->SendTPoint(false, 'S', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings, num, numcor); // Report 1409 return 0; 1410 } 1411 1412 fDZdAz->SetCoordinates(d); 1413 1414 // 1415 // Current Pointing position 1416 // 1417 ZdAz cpos = fSao->GetZdAz()-d; 1418 fPZdAz->SetCoordinates(cpos); 1419 1420 // Check StargTPoint data set request 1421 if (!fMode->IsEntryChecked(IDM_kStarguiderMode) || !fTPoint->IsDown()) 1422 return numcor; 1423 fTPoint->SetDown(kFALSE); 1424 1425 // If no file open: open new file 1426 if (!fOutStargTp) 1427 { 1428 // open tpoint file 1429 const TString name = MCosy::GetFileName("tpoint", "starg", "txt"); 1430 gLog << all << "TPoint-Starg File ********* " << name << " ********** " << endl; 1431 1432 fOutStargTp = new ofstream(name); 1433 *fOutStargTp << "Magic Model STARGTPOINT data file" << endl; 1434 *fOutStargTp << ": ALTAZ" << endl; 1435 *fOutStargTp << "49 48 0 "; 1436 *fOutStargTp << t << endl; 1437 } 1438 1439 const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad()); 1440 1441 // From the star position in the camera we calculate the Alt/Az 1442 // position we are currently tracking (real pointing position) 1443 fSao->SetMjd(t.GetMjd()); 1444 AltAz za0 = fSao->CalcAltAz(rd)*kRad2Deg; 1445 1446 //correction with offset from last tpoint measurement 1447 za0 -= fAltAzOffsetFromTp; 1448 1449 //if the difference between the tpoint and the starguider tpoint 1450 //is too big, the starguider tpoint is not stored 1451 if ((t.GetMjd()-fTimeFromTp.GetMjd())>0.001) //1min20sec 1452 { 1453 cout << " time difference between tpoint and starguider-tpoint > 1m20s" << endl; 1454 cout << " => starguider tpoint hasn't been stored. " << endl; 1455 cout << " Please repeat whole procedure. " << endl; 1456 return numcor; 1457 } 1458 1459 1460 // Write real pointing position 1461 *fOutStargTp << setprecision(7) << za0.Az() << " " << za0.Alt() << " "; 1462 1463 // Write system pointing position 1464 *fOutStargTp << fmod(cpos.Az()+360, 360) << " " << 90-cpos.Zd(); 1465 1466 *fOutStargTp << " " << xy.X() << " " << xy.Y(); 1467 *fOutStargTp << " " << d.Zd() << " " << d.Az(); 1468 *fOutStargTp << " " << setprecision(11) << t.GetMjd(); 1469 *fOutStargTp << " " << setprecision(4) << center.GetMag(); 1470 *fOutStargTp << " 0";// << star->GetMag(); 1471 *fOutStargTp << " " << center.GetX() << " " << center.GetY(); 1472 *fOutStargTp << " 0 0"; 1473 *fOutStargTp << " " << numleds << " " << numrings; 1474 *fOutStargTp << " " << num << " " << numcor << " " << bright; 1475 *fOutStargTp << " " << fTPointStarMag << " " << fTPointStarName; 1476 *fOutStargTp << endl; 1477 1478 gLog << all << "Starguider TPoint successfully taken." << endl; 1479 1480 fTimeFromTp.Clear(); 1481 1482 if (!fCosy) 1483 return numcor; 1484 1485 MDriveCom *com = fCosy->GetDriveCom(); 1486 if (!com) 1487 return numcor; 1488 1489 com->SendTPoint(true, 'S', fTPointStarMag, fTPointStarName, za0, cpos, xy, d.Zd(), d.Az(), t, center, Led(), numleds, numrings, num, numcor); // Report 1490 1491 return numcor; 1492 } 1493 1494 void MStarguider::FindStar(const FilterLed &f, const FilterLed &f2, const Ring ¢er, const MTime &t, Int_t numleds, Int_t numrings) 1495 { 1496 // Get tracking coordinates 1497 const XY xy = fCRaDec->GetCoordinates(); // [h, deg] 827 //const XY xy = fCRaDec->GetCoordinates(); // [h, deg] 1498 828 1499 829 if (center.GetX()<=0 && center.GetY()<=0) 1500 830 { 1501 gLog << warn<< "Couldn't determine center of the camera." << endl;1502 if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom())1503 fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings); // Report831 cout << "Couldn't determine center of the camera." << endl; 832 //if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 833 // fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings); // Report 1504 834 return; 1505 835 } … … 1510 840 1511 841 // Check whether star found 1512 Led *star = (Led*)leds.At(0); 1513 if (!star) 1514 { 1515 gLog << warn << "No star found." << endl; 1516 if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 1517 fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings); // Report 842 if (leds.size()==0) 843 { 844 cout << "No star found." << endl; 845 //if (fTPoint->IsDown() && fCosy && fCosy->GetDriveCom()) 846 // fCosy->GetDriveCom()->SendTPoint(false, 'T', fTPointStarMag, fTPointStarName, AltAz(), ZdAz(), xy, 0, 0, t, center, Led(), numleds, numrings); // Report 1518 847 return; 1519 848 } 1520 849 1521 850 cout << "Found star @ " << flush; 1522 star->Print(); 1523 f2.MarkPoint(star->GetX(), star->GetY(), 2<<2); 851 852 const Led &star = leds.front(); 853 854 star.Print(); 855 f2.MarkPoint(star.GetX(), star.GetY(), 2<<2); 856 857 return star; 1524 858 1525 859 const RaDec rd(xy.X()*MAstro::HorToRad(), xy.Y()*TMath::DegToRad()); … … 1530 864 ac.SetGeom(geom); 1531 865 ac.SetRadiusFOV(3); 1532 ac.SetObservatory(*fSao);866 //ac.SetObservatory(*fSao); 1533 867 ac.SetTime(t); 1534 868 ac.SetRaDec(rd.Ra(), rd.Dec()); … … 1536 870 // Convert from Pixel to millimeter (1pix=2.6mm) [deg/pix / deg/mm = mm/pix] 1537 871 // Correct for abberation. 1538 const Double_t conv = fCaos->GetArcsecPerPixel()/3600/geom.GetConvMm2Deg()/ 1.0713; 872 const double sec_per_pix = 45.311; 873 const double mm_to_deg = 0.011693; 874 const Double_t conv = sec_per_pix/3600/mm_to_deg / 1.0713; 1539 875 1540 876 // Adapt coordinate system (GUIs and humans are counting Y in different directions) … … 1558 894 // open tpoint file 1559 895 // 896 1560 897 const TString name = MCosy::GetFileName("tpoint", "tpoint", "txt"); 1561 898 cout << "TPoint File ********* " << name << " ********** " << endl; … … 1566 903 *fOutTp << "49 48 0 "; 1567 904 *fOutTp << t << endl; 1568 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m )905 // temp(°C) pressure(mB) height(m) humidity(1) wavelength(microm) troplapserate(K/m 1569 906 } 1570 907 … … 1608 945 1609 946 gLog << all << "TPoint successfully taken." << endl; 1610 /* 947 1611 948 MLog &outrep = *fCosy->GetOutRep(); 1612 949 if (outrep.Lock("MStarguider::FindStar")) … … 1622 959 outrep << setprecision(11) << t.GetMjd() << endl; 1623 960 outrep.UnLock("MStarguider::FindStar"); 1624 } */961 } 1625 962 1626 963 // return zdaz; … … 1635 972 com->SendTPoint(true, 'T', fTPointStarMag, fTPointStarName, za0, za1, xy, -dzd, -daz, t, center, *star, numleds, numrings); // Report 1636 973 } 974 */ 975 976 void MStarguider::WritePNG(const char *name, const byte *gbuf, const byte *cbuf) 977 { 978 string fname(name); 979 if (fname.size()<4 || fname.compare(fname.size()-4,4, ".png")==0) 980 fname += ".png"; 981 982 cout << "Writing PNG '" << fname << "'" << endl; 983 984 #ifdef HAVE_PNG 985 // 986 // open file 987 // 988 FILE *fd = fopen(fname.c_str(), "w"); 989 if (!fd) 990 { 991 cout << "Warning: Cannot open file for writing." << endl; 992 return; 993 } 994 995 // 996 // allocate memory 997 // 998 png_structp fPng = png_create_write_struct(PNG_LIBPNG_VER_STRING, 999 NULL, NULL, NULL); 1000 1001 if (!fPng) 1002 { 1003 cout << "Warning: Unable to create PNG structure" << endl; 1004 fclose(fd); 1005 return; 1006 } 1007 1008 1009 png_infop fInfo = png_create_info_struct(fPng); 1010 1011 if (!fInfo) 1012 { 1013 cout << "Warning: Unable to create PNG info structure" << endl; 1014 png_destroy_write_struct (&fPng, NULL); 1015 fclose(fd); 1016 return; 1017 } 1018 1019 fInfo->width = 768; 1020 fInfo->height = 576; 1021 fInfo->bit_depth = 8; 1022 fInfo->color_type = PNG_COLOR_TYPE_RGB; 1023 // fInfo->color_type = PNG_COLOR_TYPE_GRAY; 1024 1025 // 1026 // set jump-back point in case of errors 1027 // 1028 if (setjmp(fPng->jmpbuf)) 1029 { 1030 cout << "longjmp Warning: PNG encounterd an error!" << endl; 1031 png_destroy_write_struct (&fPng, &fInfo); 1032 fclose(fd); 1033 return; 1034 } 1035 1036 // 1037 // connect file to PNG-Structure 1038 // 1039 png_init_io(fPng, fd); 1040 1041 // png_set_compression_level (fPng, Z_BEST_COMPRESSION); 1042 1043 // 1044 // Write header 1045 // 1046 png_write_info(fPng, fInfo); 1047 1048 png_byte buf[768*576*3]; 1049 1050 png_byte *d = buf; 1051 const byte *g = gbuf; 1052 const byte *c = cbuf; 1053 1054 // d=destination, s1=source1, s2=source2, e=end 1055 while (d<buf+768*576*3) 1056 { 1057 if (fScreenshotColor && *c) 1058 { 1059 *d++ = ((*c>>4)&0x3)*85; 1060 *d++ = ((*c>>2)&0x3)*85; 1061 *d++ = ((*c++ )&0x3)*85; 1062 g++; 1063 } 1064 else 1065 { 1066 *d++ = *g; 1067 *d++ = *g; 1068 *d++ = *g++; 1069 c++; 1070 } 1071 } 1072 1073 // 1074 // Write bitmap data 1075 // 1076 for (unsigned int y=0; y<768*576*3; y+=768*3) 1077 png_write_row (fPng, buf+y); 1078 1079 // 1080 // Write footer 1081 // 1082 png_write_end (fPng, fInfo); 1083 1084 // 1085 // free memory 1086 // 1087 png_destroy_write_struct (&fPng, &fInfo); 1088 1089 fclose(fd); 1090 #else 1091 cout << "Sorry, no png support compiled into tpoint." << endl; 1092 #endif 1093 } 1637 1094 1638 1095 bool MStarguider::Interpolate(const unsigned long n, byte *img) const … … 1641 1098 return true; 1642 1099 1100 const int rate = fTPointMode>0 ? 5*25 : fIntRate; 1101 1643 1102 static unsigned short myimg[768*576]; 1644 1103 … … 1647 1106 const byte *end = img+768*576; 1648 1107 1649 if (n% fIntRate)1108 if (n%rate) 1650 1109 { 1651 1110 while (img<end) … … 1657 1116 while (img<end) 1658 1117 { 1659 *img = (*img + *f)/ fIntRate;1118 *img = (*img + *f)/rate; 1660 1119 ++img; 1661 1120 *f++ = 0; … … 1666 1125 } 1667 1126 1668 void MStarguider::DrawZoomImage(const byte *img) 1669 { 1670 byte zimg[kZOOM*kZOOM]; 1671 for (int y=0; y<kZOOM; y++) 1672 for (int x=0; x<kZOOM; x++) 1673 zimg[x+y*kZOOM] = img[(fDx+(x-kZOOM/2)/2)+(fDy+(y-kZOOM/2)/2)*768]; 1674 1675 fZoomImage->DrawImg(zimg); 1676 } 1677 1678 void MStarguider::DrawCosyImage(const byte *img) 1679 { 1680 if (!fCosy) 1681 return; 1682 1683 byte simg[(768/2-1)*(576/2-1)]; 1684 for (int y=0; y<576/2-1; y++) 1685 for (int x=0; x<768/2-1; x++) 1686 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; 1687 1688 fCosy->GetWin()->GetImage()->DrawImg(simg); 1689 } 1690 1691 void MStarguider::StartTPoint(char *cmd) 1692 { 1693 fTPointStarName = "Dummy"; 1694 fTPointStarMag = 0; 1695 1696 TString str(cmd); 1697 1698 TObjArray *arr = str.Tokenize(' '); 1699 1700 if (arr->GetEntries()==2) 1701 { 1702 fTPointStarName = (*arr)[0]->GetName(); 1703 fTPointStarMag = atof((*arr)[1]->GetName()); 1704 } 1705 1706 delete arr; 1707 1708 if (fTPointFromCC<0) 1709 fTPointFromCC=0; 1710 } 1711 1712 void MStarguider::StartStarguider(bool on) 1713 { 1714 // Switch to starguider mode 1715 if (on) 1716 { 1717 cout << " * Switching Starguider mode on" << endl; 1718 fMode->UnCheckEntry(IDM_kStarguiderMode); 1719 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0); 1720 } 1721 else 1722 { 1723 cout << " * Switching Starguider mode off" << endl; 1724 fMode->CheckEntry(IDM_kStarguiderMode); 1725 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0); 1726 } 1727 } 1728 1729 Int_t MStarguider::GetStarguiderMode() const 1730 { 1731 return fMode->IsEntryChecked(IDM_kStarguiderMode) ? 1 : 2; 1732 1733 } 1734 1735 Bool_t MStarguider::DoTPoint() 1736 { 1737 if (fTPoint->IsDown() && fTPointFromCC<0) 1738 { 1739 fTPointFromCC = 0; 1740 fTPoint->SetDown(kFALSE); 1741 } 1742 1743 if (fTPointFromCC<0) 1744 return kTRUE; 1745 1746 switch (++fTPointFromCC) 1747 { 1748 case 1: 1749 fTimeFromTp.Clear(); 1750 fNumStarsDetected = 0; 1751 1752 if (!fMode->IsEntryChecked(IDM_kTpointMode)) 1753 { 1754 cout << " * Switching to TPoint mode" << endl; 1755 // Switch to tpoint mode 1756 fMode->UnCheckEntry(IDM_kTpointMode); 1757 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kTpointMode, 0); 1758 return kFALSE; 1759 } 1760 fTPointFromCC++; 1761 1762 case 2: 1763 case 3: 1764 cout << " * Waiting one frame" << endl; 1765 // Wait one frame 1766 return kFALSE; 1767 1768 case 4: 1769 cout << " * Taking TPoint" << endl; 1770 fTPoint->SetDown(); // kTRUE 1771 return kTRUE; 1772 1773 case 5: 1774 if (!fTimeFromTp) // TPoint failed 1775 break; 1776 #ifdef FACT 1777 fTPointFromCC = -1; 1778 return kFALSE; 1779 #else 1780 // Switch to starguider mode 1781 cout << " * Switching to Starguider mode" << endl; 1782 fMode->UnCheckEntry(IDM_kStarguiderMode); 1783 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStarguiderMode, 0); 1784 return kFALSE; 1785 #endif 1786 case 6: 1787 case 7: 1788 cout << " * Waiting one frame" << endl; 1789 // Wait one frame 1790 return kFALSE; 1791 1792 case 8: 1793 cout << " * Taking Starguider TPoint" << endl; 1794 fTPoint->SetDown(); // kTRUE 1795 return kTRUE; 1796 1797 // case 9: 1798 // cout << " * Send Report" << endl; 1799 // return kTRUE; 1800 1801 case 9: 1802 cout << " * Switching to TPoint mode" << endl; 1803 // Switch to tpoint mode 1804 fMode->UnCheckEntry(IDM_kTpointMode); 1805 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kTpointMode, 0); 1806 fTPointFromCC = -1; 1807 return kFALSE; 1808 } 1809 1810 // Send report 1811 /* 1812 if (!fCosy) 1813 return kTRUE; 1814 1815 MDriveCom *com = fCosy->GetDriveCom(); 1816 if (!com) 1817 return kTRUE; 1818 1819 // nominalaz, nominalel, realaz, realel, nomra, nomdec, 1820 // diffaz, diffel, mjd, numleds, artmag 1821 1822 //fTimeFromTp.Clear(); 1823 //fStatus==MDriveCom::kMonitoring 1824 //fNumStarsDetected = numstars; 1825 //fNumStarsCorrelated = rc; 1826 com->SendTPoint(fNumStarsCorrelated>0); 1827 */ 1828 return kTRUE; 1829 } 1830 1831 void MStarguider::ProcessFrame(const unsigned long n, byte *img, 1127 void MStarguider::ProcessFrame(const unsigned long n, byte *img, 1832 1128 struct timeval *tm) 1833 1129 { 1834 static unsigned long n0 = n;1835 1836 MTime t(*tm);1837 1838 const Double_t d = t-fTime;1839 if (d>1)1840 {1841 const TString txt = MString::Format("%dfps", (int)((n-n0)/d+.5));1842 fFps->SetText(txt);1843 fTime = t;1844 n0 = n;1845 }1846 1847 1130 if (!Interpolate(n, img)) 1848 1131 return; 1132 1133 if (fTPointMode==2) 1134 { 1135 fTPointMode=1; 1136 return; 1137 } 1849 1138 1850 1139 byte cimg[768*576]; 1851 1140 memset(cimg, 0, 768*576); 1852 1141 1853 FilterLed f (img,768, 576, 2.5); // 2.51854 FilterLed f2(cimg, 768, 576); // former color 0xb01855 1856 if ( fDisplay->IsEntryChecked(IDM_kStretch))1142 FilterLed f (img, 768, 576, 2.5); // 2.5 1143 FilterLed f2(cimg, 768, 576); // former color 0xb0 1144 1145 if (!fTPointMode && fScreenshotName.empty() && fDisplay->IsEntryChecked(IDM_kStretch)) 1857 1146 f.Stretch(); 1858 1147 1859 if (!fWritePictures->IsEntryEnabled(IDM_kStart) &&1860 (!(n%fWrtRate) || fWriteType->IsEntryChecked(IDM_kOnce)))1861 {1862 1863 if (fFileType->IsEntryChecked(IDM_kPNG))1864 Writer::Png("pix/file", img, tm, fCRaDec->GetCoordinates());1865 1866 if (fFileType->IsEntryChecked(IDM_kPPM))1867 Writer::Ppm("pix/file", img, tm, fCRaDec->GetCoordinates());1868 1869 if (fWriteType->IsEntryChecked(IDM_kOnce))1870 ProcessMessage(MK_MSG(kC_COMMAND, kCM_MENU), IDM_kStop, 0);1871 }1872 1873 1148 // Visual Filter, whole FOV 1874 if (fDisplay->IsEntryChecked(IDM_kFilter)) 1875 f.Execute(); 1876 1877 if (!DoTPoint()) 1878 return; 1879 1880 Int_t numleds = 0; 1881 Int_t numrings = 0; 1149 if (!fTPointMode && fDisplay->IsEntryChecked(IDM_kFilter)) 1150 { 1151 vector<Led> leds; 1152 f.Execute(leds, 768/2, 576/2); 1153 for (auto it=leds.begin(); it!=leds.end(); it++) 1154 f.MarkPoint(*it); 1155 } 1882 1156 1883 1157 // Find Center of Camera for Caos and Tpoints 1884 // Ring center;//(-1, -1); 1885 Ring center(5, 5);//(-1, -1); 1886 if (fDisplay->IsEntryChecked(IDM_kCaosFilter)) 1887 { 1888 const bool printl = fCaosPrint->IsEntryChecked(IDM_kCaosPrintLeds); 1889 const bool printr = fCaosPrint->IsEntryChecked(IDM_kCaosPrintRings); 1890 ZdAz pos; 1891 if (fCosy) 1892 pos = fCosy->GetPointingPos(); 1893 1894 center = fCaos->Run(img, printl, printr, pos, t); 1895 1158 int numleds = 0; 1159 int numrings = 0; 1160 Ring center(-1, -1);//(5, 5); 1161 1162 if (fTPointMode || fDisplay->IsEntryChecked(IDM_kCaosFilter)) 1163 { 1164 center = fCaos->Run(img); 1896 1165 numleds = fCaos->GetNumDetectedLEDs(); 1897 1166 numrings = fCaos->GetNumDetectedRings(); 1898 1167 } 1899 1168 1169 //cout << "cx=" << center.GetX() << " cy=" << center.GetY() << " Nled=" << numleds << " Nrings=" << numrings << endl; 1170 1900 1171 // Find Star at Center---for Tpoint Procedure 1901 if (fDisplay->IsEntryChecked(IDM_kFindStar)) 1902 { 1903 // Set search Paremeters (FIXME: Get them from user input!) 1904 f.SetCut(fFindStarCut); 1905 f.SetBox(fFindStarBox); 1906 1907 FindStar(f, f2, center, t, numleds, numrings); 1908 } 1909 1910 DrawZoomImage(img); 1911 DrawCosyImage(img); 1912 1913 // Position corresponding to the camera center (53.2, 293.6) 1914 Ring sgcenter;//(-1, -1); // Center of camera in SG picture [px] 1915 1916 // Find Center of Camera in Starfield Camera picture 1917 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter)) 1918 { 1919 ZdAz pos; 1920 if (fCosy) 1921 pos = fCosy->GetPointingPos(); 1922 1923 sgcenter = fStargCaos->Run(img, kFALSE, kFALSE, pos, t); // [px] 1924 1925 numleds = fStargCaos->GetNumDetectedLEDs(); 1926 numrings = fStargCaos->GetNumDetectedRings(); 1927 } 1928 1929 // we obtain a list of stars in the FOV from the SAO catalog 1930 if (fDisplay->IsEntryChecked(IDM_kCatalog)) 1931 { 1932 MTime time(*tm); 1933 1934 XY xy = fCRaDec->GetCoordinates(); //[h, deg] 1935 fRaDec->Set(xy.X()*15, xy.Y()); //[deg,deg] 1936 1937 UpdatePosZoom(); 1938 1939 // Always call SetMjd first! 1940 fSao->SetPointing(time.GetMjd(), *fRaDec); 1941 fCZdAz->SetCoordinates(fSao->GetZdAz()); 1942 1943 fSao->SetBox(fStarguiderW, fStarguiderH); // 280 Region of interest around center 1944 1945 // If center of camera cannot be determined sgcenter is (0,0) 1946 const Bool_t centerisvalid = sgcenter.GetX()>0 && sgcenter.GetY()>0; 1947 1948 // We determine the ideal starfield using camera sagging info 1949 // from the LEDs 1950 //Please never change this offsets!!! 1951 // 53.2 and 293.6 are the "preliminary" camera center 1952 // -9 and 28.5 are the offsets of the pointing position in the sky 1953 //const XY off(sgcenter.GetX()- 53.2-9, 1954 // sgcenter.GetY()-293.6+28.5); 1955 1956 // Skycenter 1957 const XY off(sgcenter.GetX() + fSkyOffsetX, 1958 sgcenter.GetY() + fSkyOffsetY); 1959 1960 MStarList stars; 1961 if (centerisvalid) 1172 Led star(-1, -1); 1173 if (center.GetX()>0 && center.GetY()>0) 1174 { 1175 if (fTPointMode || fDisplay->IsEntryChecked(IDM_kFindStar)) 1962 1176 { 1963 // we obtain stars in the effective star FOV and draw them. 1964 // coordinates are video frame coords. 1965 fSao->CalcStars(stars, fStarguiderX, fStarguiderY, off.X(), off.Y()); 1966 fSao->DrawStars(stars, cimg); 1177 // Set search Paremeters (FIXME: Get them from user input!) 1178 f.SetCut(fFindStarCut+1.5); // FindStar.CleaningLevel 1179 f.SetBox(fFindStarBox+12/*+80*/); // FindStar.SizeBox 1180 1181 // Try to find the star 1182 vector<Led> leds; 1183 f.FindStar(leds, (Int_t)center.GetX(), (Int_t)center.GetY(), true); 1184 1185 // Check whether star found 1186 if (leds.size()>0) 1187 { 1188 //cout << "Found star @ " << flush; 1189 //leds[0].Print(); 1190 f2.MarkPoint(leds[0].GetX(), leds[0].GetY(), 2<<2); 1191 star = leds[0]; 1192 } 1967 1193 } 1968 1194 1969 // There are two corrections to the mispointing 1970 // - Sagging of the camera as measured with the LEDs 1971 // - Star not ideally centered on MAGIC Camera 1972 1973 // Next we evaluate the offset given by the LEDs. This we obtain 1974 // in Zd/Az and add it to the tracking error. 1975 if (fDisplay->IsEntryChecked(IDM_kStarguider)) 1195 // DrawZoomImage(img); 1196 // DrawCosyImage(img); 1197 1198 // Position corresponding to the camera center (53.2, 293.6) 1199 // Draw Circles around center of Camera 1200 if (fTPointMode || fDisplay->IsEntryChecked(IDM_kCaosFilter)) 1976 1201 { 1977 const Float_t cut = atof(fCut->GetText()); 1978 1979 Leds spots; 1980 f.SetBox(fStarguiderW, fStarguiderH); // 280 1981 f.SetCut(cut); 1982 1983 double bright; 1984 f.ExecuteAndMark(spots, fStarguiderX, fStarguiderY, bright); 1985 1986 ULong_t color; 1987 gClient->GetColorByName("Green", color); 1988 if (bright> 60) 1989 gClient->GetColorByName("Yellow", color); 1990 if (bright> 85) 1991 gClient->GetColorByName("Orange", color); 1992 if (bright> 95) 1993 gClient->GetColorByName("Red", color); 1994 fSkyBright->SetBackgroundColor(color); 1995 1996 const MString txt = MString::Format("Sky Brightness: %.1f", bright); 1997 fSkyBright->SetText(txt); 1998 1999 const Bool_t brightnessisvalid = bright<1.75*fLastBright && 2000 bright>30 && bright<110; 2001 2002 fLastBright = bright; 2003 2004 Int_t numstars = 0; 2005 const Int_t rc = CalcTrackingError(spots, stars, fD, t, bright, numstars, sgcenter, numleds, numrings); 2006 2007 const Bool_t monitoring = brightnessisvalid && centerisvalid && fNumStarsCorrelated>2; 2008 2009 fStatus = monitoring ? MDriveCom::kMonitoring : MDriveCom::kError; 2010 2011 if (fCosy) 2012 fPos = fCosy->GetPointingPos(); 2013 2014 if (fOperations->IsEntryChecked(IDM_kStargAnalysis)) 2015 fStargHistograms->Fill(spots, stars, fD, fSao->GetZdAz(), 2016 sgcenter, bright, fPos, t); 2017 2018 fNumStarsDetected = numstars; 2019 fNumStarsCorrelated = rc; 2020 2021 if (fCosy) 2022 { 2023 MDriveCom *com = fCosy->GetDriveCom(); 2024 if (com) 2025 com->SendStargReport(fStatus, fD, fSao->GetZdAz(), 2026 sgcenter, numstars, rc, bright, 2027 time.GetMjd(), numleds, numrings); // Report 2028 } 2029 2030 } //kStarguider 2031 2032 if (centerisvalid && fNumStarsCorrelated>2) 2033 { 2034 // Position around which the circles are drawn. 2035 const Ring skycenter(off.X(), off.Y()); 2036 2037 f2.DrawCircle(skycenter, 2.0, 0x0a); 2038 2039 const Double_t ap = fSao->GetPixSize()/3600; //[deg/pix] 2040 2041 f2.DrawCircle(skycenter, 0.10/ap, 0x0a); //0.1deg 2042 f2.DrawHexagon(skycenter, 2.06/ap, 0x0a); 2043 f2.DrawHexagon(skycenter, 3.50/ap, 0x0a); 1202 f2.DrawCircle(center, 0x0a); 1203 f2.DrawCircle(center, 7.0, 1204 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0); 1205 //f2.DrawCircle(center, 115.0, 0x0a); 1206 //f2.DrawCircle(center, 230.0, 0x0a); 1207 //f2.DrawCircle(center, 245.0, 0x0a); 2044 1208 } 2045 2046 } //CalcStars 2047 2048 if (fTPoint->IsDown()) 2049 fTPoint->SetDown(kFALSE); 2050 2051 // Draw Circles around center of Camera 2052 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) && 2053 center.GetX()>0 && center.GetY()>0) 2054 { 2055 f2.DrawCircle(center, 0x0a); 2056 f2.DrawCircle(center, 7.0, 2057 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0); 2058 f2.DrawCircle(center, 115.0, 0x0a); 2059 f2.DrawCircle(center, 230.0, 0x0a); 2060 f2.DrawCircle(center, 245.0, 0x0a); 2061 } 2062 2063 if (fDisplay->IsEntryChecked(IDM_kStargCaosFilter) && 2064 sgcenter.GetX()>0 && sgcenter.GetY()>0) 2065 { 2066 f2.DrawCircle(sgcenter, 0x0a); 2067 f2.DrawCircle(sgcenter, 5.0, 2068 fDisplay->IsEntryChecked(IDM_kFindStar)?3:0xb0); 2069 } 2070 2071 if (fDisplay->IsEntryChecked(IDM_kCaosFilter) || 2072 fDisplay->IsEntryChecked(IDM_kCatalog) || 1209 } 1210 1211 if (fTPointMode || 1212 fDisplay->IsEntryChecked(IDM_kCaosFilter) || 2073 1213 fDisplay->IsEntryChecked(IDM_kFindStar)) 2074 1214 fImage->DrawColImg(img, cimg); 2075 1215 else 2076 1216 fImage->DrawImg(img); 2077 } 2078 1217 1218 if (fTPointMode && !fScreenshotName.empty()) 1219 { 1220 WritePNG(fScreenshotName.c_str(), img, cimg); 1221 fScreenshotName = ""; 1222 fTPointMode = 0; 1223 return; 1224 } 1225 1226 1227 if (star.GetX()<0 || star.GetY()<0 || fTPointMode==0) 1228 return; 1229 1230 if (fTPointMode==1) 1231 fTPointMode=0; 1232 1233 // Convert from Pixel to millimeter (1pix=2.6mm) [deg/pix / deg/mm = mm/pix] 1234 // Correct for abberation. 1235 1236 //const float Dleds = 510; // 5.96344 deg 1237 //const float Dpix = 2*237.58; 1238 1239 // The DC reflector elongates light from off axis sources 1240 // This is a correction. It is 7% for MAGIC (1:1) and 1241 // less for FACT (1:1.4). This is an estimate from a 1242 // Orbit mode observation at 0.17deg distance to the 1243 // camera center [4.90m might also not be very accurate 1244 // depending on the position of the CCD camera] 1245 const double abberation = 1.0638; //1.0713; 1246 const double sec_per_pix = 45.14; //45.311; (atan(510mm/2 / 4.90m) / 237.58) // FACT LEDs 1247 1248 const double conv = sec_per_pix/abberation; 1249 1250 const double dx = star.GetX()-center.GetX(); 1251 const double dy = star.GetY()-center.GetY(); 1252 1253 //const double dxx = - conv * (star.GetX()-center.GetX()); 1254 //const double dyy = conv * (star.GetY()-center.GetY()); 1255 1256 const double dphi = - center.GetPhi() * M_PI/180; 1257 1258 // The sign is because the pixels are not counted in 1259 // both directions in the same direction as Zd/Az 1260 const double dxx = - conv * (dx*cos(dphi) - dy*sin(dphi)); 1261 const double dyy = conv * (dx*sin(dphi) + dy*cos(dphi)); 1262 1263 double arr[11] = { 1264 dxx, dyy, 1265 double(numleds), double(numrings), 1266 center.GetX(), center.GetY(), center.GetMag(), 1267 star.GetX(), star.GetY(), star.GetMag(), 1268 center.GetPhi() 1269 }; 1270 1271 fDimData.setData(arr, 11*sizeof(double)); 1272 fDimData.setQuality(0); 1273 fDimData.setTimestamp(tm->tv_sec, tm->tv_usec/1000); 1274 fDimData.updateService(); 1275 } 1276 1277 /* 2079 1278 void MStarguider::UpdatePosZoom() 2080 1279 { 2081 MString txt; /*1280 MString txt; 2082 1281 if (fDisplay->IsEntryChecked(IDM_kCatalog)) 2083 1282 { … … 2089 1288 txt.Form("(%d, %d) %.1fd/%.1fd", fDx, fDy, -aa.Alt(), aa.Az()-180); 2090 1289 } 2091 else */1290 else 2092 1291 txt.Form("(%d, %d)", fDx, fDy); 2093 1292 fPosZoom->SetText(txt); … … 2115 1314 fDy = dy; 2116 1315 2117 UpdatePosZoom();1316 //UpdatePosZoom(); 2118 1317 return kTRUE; 2119 1318 } 2120 1319 2121 void MStarguider::Print(TString &str, Double_t deg) const 2122 { 2123 Char_t sgn; 2124 UShort_t d, m, s; 2125 2126 MAstro::Deg2Dms(deg, sgn, d, m, s); 2127 2128 str += MString::Format("%c %03d %02d %03d ", sgn, d, m, s); 2129 } 1320 */ 1321 1322 /// Overwritten DimCommand::commandHandler 1323 void MStarguider::commandHandler() 1324 { 1325 DimCommand *cmd = getCommand(); 1326 if (!cmd) 1327 return; 1328 1329 if (cmd==&fDimTPoint) 1330 { 1331 fTPointMode = 2; 1332 fScreenshotName = ""; 1333 cout << "DimCommand[TPOINT]: " << cmd->itsSize << " " << string((char*)cmd->itsData, cmd->itsSize) << endl; 1334 return; 1335 } 1336 1337 if (cmd==&fDimScreenshot && fTPointMode==0) 1338 { 1339 if (cmd->itsSize<2) 1340 return; 1341 1342 fTPointMode = 2; 1343 fScreenshotColor = ((uint8_t*)cmd->itsData)[0]; 1344 fScreenshotName = string((char*)cmd->itsData+1, cmd->itsSize-1); 1345 cout << "DimCommand[SCREENSHOT]: " << fScreenshotName << endl; 1346 return; 1347 } 1348 1349 cout << "DimCommand[UNKNOWN]: " << cmd->itsSize << " " << string((char*)cmd->itsData, cmd->itsSize) << endl; 1350 }
Note:
See TracChangeset
for help on using the changeset viewer.