#include "StarCatalog.h" #include // cout #include // cout #include #include "slalib.h" #include "slamac.h" #include "File.h" #include "timer.h" StarCatalog::StarCatalog() : fEntries(0) { // p = pointer to MainFrame (not owner) // // read index file // File idx("sao/sao-sort.idx", "r"); if (!idx) exit(0); while (!idx.Eof()) { idx.Newline(); fEntries++; } idx.Reset(); fSrt = new sort_t[fEntries]; for (int i=0; i Alt: " << 360.0/D2PI*fAltAz.Alt(); cout << " Az: " << fAltAz.Az() << endl; fRaDec = sla.CalcRaDec(fAltAz); cout << "Ra: " << 360.0/D2PI*fRaDec.Ra(); cout << " Dec: " << 360.0/D2PI*fRaDec.Dec() << endl; CalcAltAzRange(); CalcRaDecRange(); } void StarCatalog::SetRaDec(const RaDec &radec) { fRaDec = radec; fRaDec *= D2PI/360.0; fAltAz = sla.CalcAltAz(fRaDec); cout << "Alt: " << 360.0/D2PI*fAltAz.Alt() << " "; cout << "Az: " << 360.0/D2PI*fAltAz.Az() << endl; CalcRaDecRange(); CalcAltAzRange(); } void StarCatalog::CalcAltAzRange() { byte fAlt0[180]; for (int h=0; h<180; h++) fAlt0[h] = kFALSE; for (int h=0; h<360; h++) fAz0[h] = kFALSE; double az0, alt0; double az1, alt1; // // scan horizontal border // for (int x=-768/2; x<768/2+1; x++) { slaDh2e(DPI+x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &az0, &alt0); slaDh2e(DPI+x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &az1, &alt1); const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360; const int t0 = (int)(360.0/D2PI*alt0); fAz0[z0] = kTRUE; if (-89<=t0 && t0<=90) fAlt0[90-t0] = kTRUE; const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360; const int t1 = (int)(360.0/D2PI*alt1); fAz0[z1] = kTRUE; if (-89<=t1 && t1<=90) fAlt0[90-t1] = kTRUE; } // // scan vertical border // for (int y=-576/2; y<576/2+1; y++) { slaDh2e(DPI-fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az0, &alt0); slaDh2e(DPI+fWidth, y*fPixSize, DPI/2-fAltAz.Alt(), &az1, &alt1); const int z0 = ((int)(360.0/D2PI*(az0+fAltAz.Az()))+360)%360; const int t0 = (int)(360.0/D2PI*alt0); fAz0[z0] = kTRUE; if (-89<=t0 && t0<=90) fAlt0[90-t0] = kTRUE; const int z1 = ((int)(360.0/D2PI*(az1+fAltAz.Az()))+360)%360; const int t1 = (int)(360.0/D2PI*alt1); fAz0[z1] = kTRUE; if (-89<=t1 && t1<=90) fAlt0[90-t1] = kTRUE; } // // count degrees of azimut // fAzCnt=0; for (int x=0; x<360; x++) if (fAz0[x]) fAzCnt++; cout << "fAzCnt: " << setw(3) << fAzCnt << " " << flush; // // calculate min and max of altitude // fAltMin=0; fAltMax=0; for (int y=0; y<180; y++) { if (fAlt0[y]) fAltMax = y; if (fAlt0[179-y]) fAltMin = 179-y; } fAltMin -= 90; fAltMax -= 90; // // check whether altaz north- or south-pole is in the visible region // byte img[768*576]; if (DrawAltAz(0, img, 90, 0)) { fAltMax=89; cout << "Alt Az Pole1 Inside!" << endl; } if (DrawAltAz(0, img, -90, 0)) { fAltMin=-90; cout << "Alt Az Pole2 Inside!" << endl; } cout << "fAltMin: " << setw(3) << fAltMin << " "; cout << "fAltMax: " << setw(3) << fAltMax << endl; } void StarCatalog::CalcRaDecRange() { // // calculate range to search in // byte fDec[180]; for (int h=0; h<180; h++) fDec[h] = kFALSE; for (int h=0; h<360; h++) fRa0[h] = kFALSE; double ha0, ha1; double de0, de1; const double phi = sla.GetPhi(); const double alpha = sla.GetAlpha(); // // scan horizontal border // for (int x=-768/2; x<768/2+1; x++) { double dx, dy; slaDh2e(DPI-x*fPixSize, -fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); slaDh2e(DPI-x*fPixSize, +fHeight, DPI/2-fAltAz.Alt(), &dx, &dy); slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; const int d0 = (int)(360.0/D2PI*de0); fRa0[h0] = kTRUE; if (-90<=d0 && d0<=89) fDec[d0+90] = kTRUE; const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; const int d1 = (int)(360.0/D2PI*de1); fRa0[h1] = kTRUE; if (-90<=d1 && d1<=89) fDec[d1+90] = kTRUE; } // // scan vertical border // for (int y=-576/2; y<576/2+1; y++) { double dx, dy; slaDh2e(DPI-fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha0, &de0); slaDh2e(DPI+fWidth, -y*fPixSize, DPI/2-fAltAz.Alt(), &dx, &dy); slaDh2e(fAltAz.Az()+dx, -dy, phi, &ha1, &de1); const int h0 = ((int)(360.0/D2PI*(alpha-ha0))+360)%360; const int d0 = (int)(360.0/D2PI*de0); fRa0[h0] = kTRUE; if (-90<=d0 && d0<=89) fDec[d0+90] = kTRUE; const int h1 = ((int)(360.0/D2PI*(alpha-ha1))+360)%360; const int d1 = (int)(360.0/D2PI*de1); fRa0[h1] = kTRUE; if (-90<=d1 && d1<=89) fDec[d1+90] = kTRUE; } // // count degrees of right ascension // fRaCnt=0; for (int x=0; x<360; x++) if (fRa0[x]) fRaCnt++; cout << "fRaCnt: " << setw(3) << fRaCnt << " " << flush; // // calculate min and max of declination // for (int y=0; y<180; y++) { if (fDec[y]) fDecMax = y; if (fDec[179-y]) fDecMin = 179-y; } fDecMin -= 90; fDecMax -= 90; // // check whether radec north- or south-pole is in the visible region // byte img[768*576]; if (DrawRaDec(0, img, 0, 90)) { fDecMax=89; cout << "Ra Dec Pole1 Inside!" << endl; } if (DrawRaDec(0, img, 0, -90)) { fDecMin=-90; cout << "Ra Dec Pole1 Inside!" << endl; } cout << "fDecMin: " << setw(3) << fDecMin << " "; cout << "fDecMax: " << setw(3) << fDecMax << endl; } void StarCatalog::DrawSCAltAz(byte *img, const int color) { // // ------------ draw az lines --------------- // for (int az=0; az<360; az++) { if (!fAz0[az]) continue; for (double alt=fAltMin-1; alt88 && az%5) || alt>89.5) continue; DrawAltAz(color, img, alt, az); } } // // ------------ draw alt lines --------------- // for (int alt=fAltMin; alt88 && ra%5) || dec>89.5) continue; DrawRaDec(color, img, ra, dec, ra==0||ra==90); } } // // ------------ draw dec lines --------------- // for (int dec=fDecMin; dec767) continue; const float p = xx+size-x; const float q = 2*size - p; const int h = (int)sqrt(p*q); const int y1 = yy-h; if (y1>=0 && y1<576) img[y1*768+x] = color; const int y2 = yy+h; if (y2>=0 && y2<576) img[y2*768+x] = color; } } Bool_t StarCatalog::DrawAltAz(const int color, byte *img, double alt, double az, int size) { // // alt/az[deg] -> alt/az[rad] // alt *= D2PI/360.0; az *= D2PI/360.0; // // alt/az[rad] -> alt/az[pix] // double dx, dy; slaDe2h(az-fAltAz.Az(), -alt, DPI/2-fAltAz.Alt(), &dx, &dy); // // Align alt/az[pix] // const int xx = 767-(int)((fWidth-dx+DPI)/fPixSize); const int yy = (int)((fHeight+dy)/fPixSize); // // Range Check // if (!(0<=xx && xx<768 && 0<=yy && yy<576)) return kFALSE; // // Draw // DrawCircle(color, img, xx, yy, size); return kTRUE; } Bool_t StarCatalog::Draw(const int color, byte *img, const AltAz &altaz) { return DrawAltAz(color, img, altaz.Alt(), altaz.Az()); } Bool_t StarCatalog::Draw(const int color, byte *img, const SaoFile *sao) { // // ---- mean to observed --- // AltAz altaz=sla.CalcAltAz(sao->GetRaDec()) * 360.0/D2PI; if (sao->MagV() > fLimitMag) return kFALSE; const int mag = (10 - (sao->MagV()>1 ? (int)sao->MagV() : 1))/2; // // ---- imaging ----- // return DrawAltAz(color, img, altaz.Alt(), altaz.Az(), mag); } Bool_t StarCatalog::DrawRaDec(const int color, byte *img, double ra, double dec, int size) { // // radec[deg] -> radec[rad] // ra *= D2PI/360.0; dec *= D2PI/360.0; // // radec[rad] -> hadec[rad] // const double ha = sla.GetAlpha()-ra; // // hadec[rad] -> altaz[rad] // double alt, az; slaDe2h(ha, dec, sla.GetPhi(), &az, &alt); // // altaz[rad] -> altaz[deg] // alt *= 360.0/D2PI; az *= 360.0/D2PI; return DrawAltAz(color, img, alt, az, size); } Bool_t StarCatalog::Draw(const int color, byte *img, const RaDec &radec) { return DrawRaDec(color, img, radec.Ra(), radec.Dec()); } void StarCatalog::CalcImg(byte *img) { // // --------- search for stars in catalog ---------- // int count = 0; int deleted = 0; int idx = 0; while (fSrt[idx].decGetEntry(nr++); // // Try to draw star into the image (white) // if (!Draw(0xff, img, fSao)) deleted++; count++; } while ((int)(360.0/D2PI*fSao->Ra())==ra); } cout << " " << count << "-" << deleted << "=" << count-deleted << " " << flush; }