source: trunk/MagicSoft/Cosy/catalog/StarCatalog.cc@ 9439

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