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

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