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

Last change on this file since 7764 was 7764, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 6.6 KB
Line 
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
16ClassImp(StarCatalog);
17
18StarCatalog::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)
19{
20 fAstro = new MAstroCatalog;
21 fAstro->SetObservatory(*this);
22 fAstro->SetPlainScreen();
23}
24
25StarCatalog::~StarCatalog()
26{
27 delete fAstro;
28}
29
30void 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
37double StarCatalog::GetPixSize() const
38{
39 return fPixSize*3600*360.0/D2PI;
40}
41
42void StarCatalog::SetLimitMag(const float mag)
43{
44 fLimitMag = mag;
45 fAstro->SetLimMag(mag);
46}
47
48void StarCatalog::SetMjd(double mjd)
49{
50 SlaStars::SetMjd(mjd);
51 fAstro->SetTime(MTime(mjd));
52}
53
54void 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
62void 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
71void 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
87void 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
96void 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
104void 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
125void StarCatalog::PaintImg(unsigned char *buf, int w, int h)
126{
127 fAstro->PaintImg(buf, w, h);
128}
129
130void 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 Double_t color = 0xf0; //0x0f;
139 // DrawStars flips the picture in X defaultwise now
140 DrawCircle(color, img, 768-(int)star->GetX(), (int)star->GetY(), mag);
141 }
142}
143
144/*
145void StarCatalog::CalcStars(MStarList &list)
146{
147 // full FOV
148 fBox=768/2;
149 CalcStars(list, 768/2, 576/2, 0, 0);
150}
151*/
152
153void StarCatalog::CalcStars(MStarList &list, int xc, int yc,
154 int xo, int yo) const
155{
156 // For an apropriate unit conversion to pixels [pix/rad]
157 const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
158
159 // Offsets to shift [-n/2;n/2] to [0;n] and to
160 // move the stars in the counterdirection of the LEDs
161 const Float_t offx = 768/2 + xo;
162 const Float_t offy = 576/2 + yo;
163
164 // Allow catalog stars to be a bit outside [0.2deg] of the
165 // monitored window. To get the std behaviour set offset=0
166 const Int_t offset = TMath::Nint(0.2*TMath::DegToRad()*scale);
167 const Int_t box = fBox+offset;
168
169 // CalcStars flips the picture in X defaultwise now
170 // This defined the box in which stars are really returned
171 int x0 = (768-xc)-box;
172 int x1 = (768-xc)+box;
173 int y0 = yc-box;
174 int y1 = yc+box;
175
176 if (x0< -offset) x0= -offset;
177 if (y0< -offset) y0= -offset;
178 if (x1>fW+offset) x1=fW+offset;
179 if (y1>fH+offset) y1=fH+offset;
180
181 // Align stars into telescope system
182 // (Move the telescope to pointing position)
183 TRotation align;
184 align.RotateZ(-fAltAz.Az());
185 align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
186 align.RotateZ(TMath::Pi()/2);
187
188 // Get List of stars from catalog
189 TIter Next(fAstro->GetList());
190 TVector3 *star=0;
191
192 const Double_t limmag = pow(10, -fLimitMag/2.5);
193
194 while ((star=(TVector3*)Next()))
195 {
196 // Check for limiting magnitude
197 const Double_t mag = star->Mag();
198 if (mag < limmag)
199 continue;
200
201 // Get star position and do an apropiate
202 // conversion to local coordinates
203 const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
204 const ZdAz za(CalcZdAz(rd));
205
206 // Virtually move telescope to pointing position
207 TVector3 loc;
208 loc.SetMagThetaPhi(1, za.Zd(), za.Az());
209 loc *= align;
210
211 // Sanity check
212 if (loc(2)<0)
213 continue;
214
215 // Stretch such, that the Z-component is alwas the same. Now
216 // X and Y contains the intersection point between the star-light
217 // and the plain of a virtual plain screen (ccd...)
218 loc *= 1./loc(2);
219
220 // Do an apropriate unit conversion to pixels
221 loc *= scale;
222
223 // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
224 // continue;
225
226 // Rotate by the rotation angle of the video camera
227 // and add the offsets on both axis
228 Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle + offx;
229 Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle + offy;
230
231 // Check if the resulting star is in the
232 // search box for the real stars
233 if (rx<x0 || rx>=x1 || ry<y0 || ry>=y1)
234 continue;
235
236 // Store pixel coordinates of star in list
237 list.Add(rx, ry, -2.5*log10(mag));
238 }
239}
240
241AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
242{
243 double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
244 double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
245
246 dx *= fPixSize;
247 dy *= fPixSize;
248
249 //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
250 //const double dy = pixy*fPixSize - fHeight;
251
252 double ha, dec;
253 slaDh2e(dx, dy, DPI/2-fAltAz.Alt(), &ha, &dec);
254
255 return AltAz(-dec, ha+fAltAz.Az());
256}
Note: See TracBrowser for help on using the repository browser.