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

Last change on this file since 8809 was 8376, checked in by tbretz, 18 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#include "File.h"
12
13#include "MStarList.h"
14#include "MAstroCatalog.h"
15
16ClassImp(StarCatalog);
17
18using namespace std;
19
20StarCatalog::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)
21{
22 fAstro = new MAstroCatalog;
23 fAstro->SetObservatory(*this);
24 fAstro->SetPlainScreen();
25}
26
27StarCatalog::~StarCatalog()
28{
29 delete fAstro;
30}
31
32void StarCatalog::SetPixSize(const double pixsize)
33{
34 // pixsize [arcsec/pixel]
35 fPixSize = D2PI/360.0*pixsize/3600; // [rad / (deg*pixel)]
36 fAstro->SetRadiusFOV(pixsize, 768, 576);
37}
38
39double StarCatalog::GetPixSize() const
40{
41 return fPixSize*3600*360.0/D2PI;
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 * D2PI/360.0;
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*360.0/D2PI;;
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 * D2PI/360.0;
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 int xo, int yo) const
157{
158 // For an apropriate unit conversion to pixels [pix/rad]
159 const Double_t scale = TMath::RadToDeg()*TMath::Sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
160
161 // Offsets to shift [-n/2;n/2] to [0;n] and to
162 // move the stars in the counterdirection of the LEDs
163 const Int_t offx = 768/2 + xo;
164 const Int_t offy = 576/2 + yo;
165
166 // Allow catalog stars to be a bit outside [0.2deg] of the
167 // monitored window. To get the std behaviour set offset=0
168 const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()*scale);
169 const Int_t box = fBox+offset;
170
171 // CalcStars flips the picture in X defaultwise now
172 // This defined the box in which stars are really returned
173 const int x0 = TMath::Max((768-xc)-box, -offset);
174 const int y0 = TMath::Max(yc-box, -offset);
175 const int x1 = TMath::Min((768-xc)+box, fW+offset);
176 const int y1 = TMath::Min(yc+box, fH+offset);
177
178 // Align stars into telescope system
179 // (Move the telescope to pointing position)
180 TRotation align;
181 align.RotateZ(-fAltAz.Az());
182 align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
183 align.RotateZ(TMath::Pi()/2);
184
185 // Get List of stars from catalog
186 TIter Next(fAstro->GetList());
187 TVector3 *star=0;
188
189 const Double_t limmag = pow(10, -fLimitMag/2.5);
190
191 while ((star=(TVector3*)Next()))
192 {
193 // Check for limiting magnitude
194 const Double_t mag = star->Mag();
195 if (mag < limmag)
196 continue;
197
198 // Get star position and do an apropiate
199 // conversion to local coordinates
200 const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
201 const ZdAz za(CalcZdAz(rd));
202
203 // Virtually move telescope to pointing position
204 TVector3 loc;
205 loc.SetMagThetaPhi(1, za.Zd(), za.Az());
206 loc *= align;
207
208 // Sanity check
209 if (loc(2)<0)
210 continue;
211
212 // Stretch such, that the Z-component is alwas the same. Now
213 // X and Y contains the intersection point between the star-light
214 // and the plain of a virtual plain screen (ccd...)
215 loc *= 1./loc(2);
216
217 // Do an apropriate unit conversion to pixels
218 loc *= scale;
219
220 // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
221 // continue;
222
223 // Rotate by the rotation angle of the video camera
224 // and add the offsets on both axis
225 Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle + offx;
226 Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle + offy;
227
228 // Check if the resulting star is in the
229 // search box for the real stars
230 if (xx<x0 || xx>=x1 || yy<y0 || yy>=y1)
231 continue;
232
233 // Store pixel coordinates of star in list
234 list.Add(xx, yy, -2.5*log10(mag));
235 }
236}
237
238AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
239{
240 double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
241 double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
242
243 dx *= fPixSize;
244 dy *= fPixSize;
245
246 //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
247 //const double dy = pixy*fPixSize - fHeight;
248
249 double ha, dec;
250 slaDh2e(dx, dy, DPI/2-fAltAz.Alt(), &ha, &dec);
251
252 return AltAz(-dec, ha+fAltAz.Az());
253}
Note: See TracBrowser for help on using the repository browser.