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), fAstro(0), /*fSao(NULL), fSrt(NULL), fEntries(0),*/ fSinAngle(0), fCosAngle(1)
|
---|
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 |
|
---|
139 | Double_t color = 0xf0; //0x0f;
|
---|
140 | DrawCircle(color, img, (int)star->GetX(), (int)star->GetY(), mag);
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | void StarCatalog::CalcStars(MStarList &list) const
|
---|
145 | {
|
---|
146 | // Align stars into telescope system
|
---|
147 | // (Move the telescope to pointing position)
|
---|
148 | TRotation align;
|
---|
149 | align.RotateZ(-fAltAz.Az());
|
---|
150 | align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
|
---|
151 | align.RotateZ(TMath::Pi()/2);
|
---|
152 |
|
---|
153 | // For an apropriate unit conversion to pixels
|
---|
154 | const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
|
---|
155 |
|
---|
156 | // Get List of stars from catalog
|
---|
157 | TIter Next(fAstro->GetList());
|
---|
158 | TVector3 *star=0;
|
---|
159 |
|
---|
160 | const Double_t limmag = pow(10, -fLimitMag/2.5);
|
---|
161 |
|
---|
162 | while ((star=(TVector3*)Next()))
|
---|
163 | {
|
---|
164 | // Check for limiting magnitude
|
---|
165 | const Double_t mag = star->Mag();
|
---|
166 | if (mag < limmag)
|
---|
167 | continue;
|
---|
168 |
|
---|
169 | // Get star position and do an apropiate
|
---|
170 | // conversion to local coordinates
|
---|
171 | const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
|
---|
172 | const ZdAz za(CalcZdAz(rd));
|
---|
173 |
|
---|
174 | // Virtually move telescope to pointing position
|
---|
175 | TVector3 loc;
|
---|
176 | loc.SetMagThetaPhi(1, za.Zd(), za.Az());
|
---|
177 | loc *= align;
|
---|
178 |
|
---|
179 | // Sanity check
|
---|
180 | if (loc(2)<0)
|
---|
181 | continue;
|
---|
182 |
|
---|
183 | // Stretch such, that the Z-component is alwas the same. Now
|
---|
184 | // X and Y contains the intersection point between the star-light
|
---|
185 | // and the plain of a virtual plain screen (ccd...)
|
---|
186 | loc *= 1./loc(2);
|
---|
187 |
|
---|
188 | // Do an apropriate unit conversion to pixels
|
---|
189 | loc *= scale;
|
---|
190 |
|
---|
191 | // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
|
---|
192 | // continue;
|
---|
193 |
|
---|
194 | // Rotate by the rotation angle of the video camera
|
---|
195 | Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle;
|
---|
196 | Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle;
|
---|
197 |
|
---|
198 | if (xx<0 || xx >=768 || yy<0 || yy>=576)
|
---|
199 | continue;
|
---|
200 |
|
---|
201 | // Store pixel coordinates of star in list
|
---|
202 | list.Add(xx+768/2, yy+576/2, -2.5*log10(mag));
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
|
---|
207 | {
|
---|
208 | double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
|
---|
209 | double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
|
---|
210 |
|
---|
211 | dx *= fPixSize;
|
---|
212 | dy *= fPixSize;
|
---|
213 |
|
---|
214 | //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
|
---|
215 | //const double dy = pixy*fPixSize - fHeight;
|
---|
216 |
|
---|
217 | double ha, dec;
|
---|
218 | slaDh2e(dx, dy, DPI/2-fAltAz.Alt(), &ha, &dec);
|
---|
219 |
|
---|
220 | return AltAz(-dec, ha+fAltAz.Az());
|
---|
221 | }
|
---|