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

Last change on this file since 5842 was 4865, checked in by rwagner, 20 years ago
*** empty log message ***
File size: 6.0 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
144void StarCatalog::CalcStars(MStarList &list)
145{
146 // full FOV
147 fBox=768;
148 CalcStars(list, 0, 576, 0, 0);
149}
150
151void StarCatalog::CalcStars(MStarList &list, int xc, int yc,
152 int xo, int yo) const
153{
154
155 // CalcStars flips the picture in X defaultwise now
156 int x0 = (768-xc)-fBox;
157 int x1 = (768-xc)+fBox;
158 int y0 = yc-fBox;
159 int y1 = yc+fBox;
160
161 if (x0<0) x0=0;
162 if (y0<0) y0=0;
163 if (x1>fW) x1=fW;
164 if (y1>fH) y1=fH;
165
166 // Align stars into telescope system
167 // (Move the telescope to pointing position)
168 TRotation align;
169 align.RotateZ(-fAltAz.Az());
170 align.RotateY(-(TMath::Pi()/2-fAltAz.Alt()));
171 align.RotateZ(TMath::Pi()/2);
172
173 // For an apropriate unit conversion to pixels
174 const Double_t scale = TMath::RadToDeg()*sqrt(768*768 + 576*576)/(fAstro->GetRadiusFOV()*2);
175
176 // Get List of stars from catalog
177 TIter Next(fAstro->GetList());
178 TVector3 *star=0;
179
180 const Double_t limmag = pow(10, -fLimitMag/2.5);
181
182 while ((star=(TVector3*)Next()))
183 {
184 // Check for limiting magnitude
185 const Double_t mag = star->Mag();
186 if (mag < limmag)
187 continue;
188
189 // Get star position and do an apropiate
190 // conversion to local coordinates
191 const RaDec rd(star->Phi(), TMath::Pi()/2-star->Theta());
192 const ZdAz za(CalcZdAz(rd));
193
194 // Virtually move telescope to pointing position
195 TVector3 loc;
196 loc.SetMagThetaPhi(1, za.Zd(), za.Az());
197 loc *= align;
198
199 // Sanity check
200 if (loc(2)<0)
201 continue;
202
203 // Stretch such, that the Z-component is alwas the same. Now
204 // X and Y contains the intersection point between the star-light
205 // and the plain of a virtual plain screen (ccd...)
206 loc *= 1./loc(2);
207
208 // Do an apropriate unit conversion to pixels
209 loc *= scale;
210
211 // if (loc.Mod2()>fRadiusFOV*fRadiusFOV)
212 // continue;
213
214 // Rotate by the rotation angle of the video camera
215 Float_t xx = loc.X()*fCosAngle - loc.Y()*fSinAngle;
216 Float_t yy = loc.X()*fSinAngle + loc.Y()*fCosAngle;
217
218 if (xx<(x0-768/2) || xx >=(x1-768/2)
219 || yy<(y0-(576/2+yo)) || yy>=(y1-(576/2+yo)))
220 continue;
221
222 // Store pixel coordinates of star in list
223 list.Add(xx+768/2+xo, yy+576/2+yo, -2.5*log10(mag));
224
225 }
226}
227
228AltAz StarCatalog::CalcAltAzFromPix(Double_t pixx, Double_t pixy) const
229{
230 double dx = (pixx-576/2)*fCosAngle + (pixy-768/2)*fSinAngle;
231 double dy = -(pixx-576/2)*fSinAngle + (pixy-768/2)*fCosAngle;
232
233 dx *= fPixSize;
234 dy *= fPixSize;
235
236 //const double dx = (pixx-768.0)*fPixSize + fWidth+DPI;
237 //const double dy = pixy*fPixSize - fHeight;
238
239 double ha, dec;
240 slaDh2e(dx, dy, DPI/2-fAltAz.Alt(), &ha, &dec);
241
242 return AltAz(-dec, ha+fAltAz.Az());
243}
Note: See TracBrowser for help on using the repository browser.