source: trunk/Cosy/catalog/StarCatalog.cc@ 15826

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