| 1 | #include "StarCatalog.h"
|
|---|
| 2 |
|
|---|
| 3 | #include <iomanip.h> // cout
|
|---|
| 4 | #include <iostream.h> // cout
|
|---|
| 5 |
|
|---|
| 6 | #include <TSystem.h>
|
|---|
| 7 | #include <TRotation.h>
|
|---|
| 8 |
|
|---|
| 9 | #include "slalib.h"
|
|---|
| 10 | #include "slamac.h"
|
|---|
| 11 | #include "File.h"
|
|---|
| 12 |
|
|---|
| 13 | #include "MStarList.h"
|
|---|
| 14 | #include "MAstroCatalog.h"
|
|---|
| 15 |
|
|---|
| 16 | ClassImp(StarCatalog);
|
|---|
| 17 |
|
|---|
| 18 | StarCatalog::StarCatalog(MObservatory::LocationName_t key) : SlaStars(key), fW(768), fH(576), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1), fBox(768)
|
|---|
| 19 | {
|
|---|
| 20 | fAstro = new MAstroCatalog;
|
|---|
| 21 | fAstro->SetObservatory(*this);
|
|---|
| 22 | fAstro->SetPlainScreen();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | StarCatalog::~StarCatalog()
|
|---|
| 26 | {
|
|---|
| 27 | delete fAstro;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void StarCatalog::SetPixSize(const double pixsize)
|
|---|
| 31 | {
|
|---|
| 32 | // pixsize [arcsec/pixel]
|
|---|
| 33 | fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)]
|
|---|
| 34 | fAstro->SetRadiusFOV(pixsize, 768, 576);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | double StarCatalog::GetPixSize() const
|
|---|
| 38 | {
|
|---|
| 39 | return fPixSize*3600*360.0/D2PI;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | void StarCatalog::SetLimitMag(const float mag)
|
|---|
| 43 | {
|
|---|
| 44 | fLimitMag = mag;
|
|---|
| 45 | fAstro->SetLimMag(mag);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | void StarCatalog::SetMjd(double mjd)
|
|---|
| 49 | {
|
|---|
| 50 | SlaStars::SetMjd(mjd);
|
|---|
| 51 | fAstro->SetTime(MTime(mjd));
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | void StarCatalog::SetAltAz(const AltAz &altaz)
|
|---|
| 55 | {
|
|---|
| 56 | fAltAz = altaz * D2PI/360.0;
|
|---|
| 57 | fRaDec = CalcRaDec(fAltAz);
|
|---|
| 58 |
|
|---|
| 59 | fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec());
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | void StarCatalog::Reload()
|
|---|
| 63 | {
|
|---|
| 64 | fAstro->SetLimMag(99);
|
|---|
| 65 | //fAstro->ReadBSC("bsc5.dat");
|
|---|
| 66 | //fAstro->ReadHeasarcPPM("heasarc_ppm.tdat");
|
|---|
| 67 | fAstro->ReadCompressed("ppm9.bin");
|
|---|
| 68 | fAstro->SetLimMag(fLimitMag);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | void StarCatalog::SetRaDec(const RaDec &radec)
|
|---|
| 72 | {
|
|---|
| 73 | const RaDec rd = fRaDec*360.0/D2PI;;
|
|---|
| 74 |
|
|---|
| 75 | const Bool_t same =
|
|---|
| 76 | rd.Ra() >radec.Ra() -1e-5 && rd.Ra() <radec.Ra() +1e-5 &&
|
|---|
| 77 | rd.Dec()>radec.Dec()-1e-5 && rd.Dec()<radec.Dec()+1e-5;
|
|---|
| 78 |
|
|---|
| 79 | fRaDec = radec * D2PI/360.0;
|
|---|
| 80 | fAltAz = CalcAltAz(fRaDec);
|
|---|
| 81 |
|
|---|
| 82 | fAstro->SetRaDec(fRaDec.Ra(), fRaDec.Dec());
|
|---|
| 83 | if (!same)
|
|---|
| 84 | Reload();
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | void StarCatalog::DrawCross(byte *img, const int x, const int y)
|
|---|
| 88 | {
|
|---|
| 89 | for (int dx=-4; dx<5; dx++)
|
|---|
| 90 | if (dx) img[y*768+x+dx] = 0xff;
|
|---|
| 91 |
|
|---|
| 92 | for (int dy=-4; dy<5; dy++)
|
|---|
| 93 | if (dy) img[(y+dy)*768+x] = 0xff;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | void StarCatalog::GetImg(byte *img, byte *cimg, MStarList &list) const
|
|---|
| 97 | {
|
|---|
| 98 | memset(cimg, 0, 768*576);
|
|---|
| 99 |
|
|---|
| 100 | DrawStars(list, cimg);
|
|---|
| 101 | DrawCross(img, 768/2, 576/2);
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | void StarCatalog::DrawCircle(int color, byte *img, int xx, int yy, int size)
|
|---|
| 105 | {
|
|---|
| 106 | for (int x=xx-size; x<xx+size+1; x++)
|
|---|
| 107 | {
|
|---|
| 108 | if (x<0 || x>767)
|
|---|
| 109 | continue;
|
|---|
| 110 |
|
|---|
| 111 | const float p = xx+size-x;
|
|---|
| 112 | const float q = 2*size - p;
|
|---|
| 113 | const int h = (int)sqrt(p*q);
|
|---|
| 114 |
|
|---|
| 115 | const int y1 = yy-h;
|
|---|
| 116 | if (y1>=0 && y1<576)
|
|---|
| 117 | img[y1*768+x] = color;
|
|---|
| 118 |
|
|---|
| 119 | const int y2 = yy+h;
|
|---|
| 120 | if (y2>=0 && y2<576)
|
|---|
| 121 | img[y2*768+x] = color;
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | void StarCatalog::PaintImg(unsigned char *buf, int w, int h)
|
|---|
| 126 | {
|
|---|
| 127 | fAstro->PaintImg(buf, w, h);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | void StarCatalog::DrawStars(MStarList &list, byte *img)
|
|---|
| 131 | {
|
|---|
| 132 | MStarListIter Next(&list);
|
|---|
| 133 |
|
|---|
| 134 | MStar *star;
|
|---|
| 135 | while ((star=Next()))
|
|---|
| 136 | {
|
|---|
| 137 | const int mag = (10 - (star->GetMag()>1 ? (int)star->GetMag() : 1))/2;
|
|---|
| 138 | Double_t color = 0xf0; //0x0f;
|
|---|
| 139 | // DrawStars flips the picture in X defaultwise now
|
|---|
| 140 | DrawCircle(color, img, 768-(int)star->GetX(), (int)star->GetY(), mag);
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | /*
|
|---|
| 145 | void StarCatalog::CalcStars(MStarList &list)
|
|---|
| 146 | {
|
|---|
| 147 | // full FOV
|
|---|
| 148 | fBox=768/2;
|
|---|
| 149 | CalcStars(list, 768/2, 576/2, 0, 0);
|
|---|
| 150 | }
|
|---|
| 151 | */
|
|---|
| 152 |
|
|---|
| 153 | void StarCatalog::CalcStars(MStarList &list, int xc, int yc,
|
|---|
| 154 | int xo, int yo) const
|
|---|
| 155 | {
|
|---|
| 156 | // For an apropriate unit conversion to pixels [pix/rad]
|
|---|
| 157 | const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
|
|---|
| 158 |
|
|---|
| 159 | // Offsets to shift [-n/2;n/2] to [0;n] and to
|
|---|
| 160 | // move the stars in the counterdirection of the LEDs
|
|---|
| 161 | const Int_t offx = 768/2 + xo;
|
|---|
| 162 | const Int_t offy = 576/2 + yo;
|
|---|
| 163 |
|
|---|
| 164 | // Allow catalog stars to be a bit outside [0.2deg] of the
|
|---|
| 165 | // monitored window. To get the std behaviour set offset=0
|
|---|
| 166 | const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()*scale);
|
|---|
| 167 | const Int_t box = fBox+offset;
|
|---|
| 168 |
|
|---|
| 169 | // CalcStars flips the picture in X defaultwise now
|
|---|
| 170 | // This defined the box in which stars are really returned
|
|---|
| 171 | const int x0 = TMath::Max((768-xc)-box, -offset);
|
|---|
| 172 | const int y0 = TMath::Max(yc-box, -offset);
|
|---|
| 173 | const int x1 = TMath::Min((768-xc)+box, fW+offset);
|
|---|
| 174 | const int y1 = TMath::Min(yc+box, fH+offset);
|
|---|
| 175 |
|
|---|
| 176 | // Align stars into telescope system
|
|---|
| 177 | // (Move the telescope to pointing position)
|
|---|
| 178 | TRotation align;
|
|---|
| 179 | align.RotateZ(-fAltAz.Az());
|
|---|
| 180 | align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
|
|---|
| 181 | align.RotateZ(TMath::Pi()/2);
|
|---|
| 182 |
|
|---|
| 183 | // Get List of stars from catalog
|
|---|
| 184 | TIter Next(fAstro->GetList());
|
|---|
| 185 | TVector3 *star=0;
|
|---|
| 186 |
|
|---|
| 187 | const Double_t limmag = pow(10, -fLimitMag/2.5);
|
|---|
| 188 |
|
|---|
| 189 | while ((star=(TVector3*)Next()))
|
|---|
| 190 | {
|
|---|
| 191 | // Check for limiting magnitude
|
|---|
| 192 | const Double_t mag = star->Mag();
|
|---|
| 193 | if (mag < limmag)
|
|---|
| 194 | continue;
|
|---|
| 195 |
|
|---|
| 196 | // Get star position and do an apropiate
|
|---|
| 197 | // conversion to local coordinates
|
|---|
| 198 | const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
|
|---|
| 199 | const ZdAz za(CalcZdAz(rd));
|
|---|
| 200 |
|
|---|
| 201 | // Virtually move telescope to pointing position
|
|---|
| 202 | TVector3 loc;
|
|---|
| 203 | loc.SetMagThetaPhi(1, za.Zd(), za.Az());
|
|---|
| 204 | loc *= align;
|
|---|
| 205 |
|
|---|
| 206 | // Sanity check
|
|---|
| 207 | if (loc(2)<0)
|
|---|
| 208 | continue;
|
|---|
| 209 |
|
|---|
| 210 | // Stretch such, that the Z-component is alwas the same. Now
|
|---|
| 211 | // X and Y contains the intersection point between the star-light
|
|---|
| 212 | // and the plain of a virtual plain screen (ccd...)
|
|---|
| 213 | loc *= 1./loc(2);
|
|---|
| 214 |
|
|---|
| 215 | // Do an apropriate unit conversion to pixels
|
|---|
| 216 | loc *= scale;
|
|---|
| 217 |
|
|---|
| 218 | // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
|
|---|
| 219 | // continue;
|
|---|
| 220 |
|
|---|
| 221 | // Rotate by the rotation angle of the video camera
|
|---|
| 222 | // and add the offsets on both axis
|
|---|
| 223 | Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle + offx;
|
|---|
| 224 | Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle + offy;
|
|---|
| 225 |
|
|---|
| 226 | // Check if the resulting star is in the
|
|---|
| 227 | // search box for the real stars
|
|---|
| 228 | if (xx<x0 || xx>=x1 || yy<y0 || yy>=y1)
|
|---|
| 229 | continue;
|
|---|
| 230 |
|
|---|
| 231 | // Store pixel coordinates of star in list
|
|---|
| 232 | list.Add(xx, yy, -2.5*log10(mag));
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
|
|---|
| 237 | {
|
|---|
| 238 | double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
|
|---|
| 239 | double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
|
|---|
| 240 |
|
|---|
| 241 | dx *= fPixSize;
|
|---|
| 242 | dy *= fPixSize;
|
|---|
| 243 |
|
|---|
| 244 | //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
|
|---|
| 245 | //const double dy = pixy*fPixSize - fHeight;
|
|---|
| 246 |
|
|---|
| 247 | double ha, dec;
|
|---|
| 248 | slaDh2e(dx, dy, DPI/2-fAltAz.Alt(), &ha, &dec);
|
|---|
| 249 |
|
|---|
| 250 | return AltAz(-dec, ha+fAltAz.Az());
|
|---|
| 251 | }
|
|---|