Stellarium 0.13.3
Star.hpp
1 /*
2  * The big star catalogue extension to Stellarium:
3  * Author and Copyright: Johannes Gajdosik, 2006, 2007
4  *
5  * Thanks go to Nigel Kerr for ideas and testing of BE/LE star repacking
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
20  */
21 
22 #ifndef _STAR_HPP_
23 #define _STAR_HPP_
24 
25 #include "ZoneData.hpp"
26 #include "StelObjectType.hpp"
27 #include <QString>
28 #include <QtEndian>
29 
30 class StelObject;
31 
32 typedef short int Int16;
33 typedef unsigned short int Uint16;
34 
35 template <class Star> class SpecialZoneArray;
36 template <class Star> struct SpecialZoneData;
37 
38 
39 // structs for storing the stars in binary form. The idea is
40 // to store much data for bright stars (Star1), but only little or even
41 // very little data for faints stars (Star3). Using only 6 bytes for Star3
42 // makes it feasable to store hundreds of millions of them in main memory.
43 
44 
45 static inline float IndexToBV(unsigned char bV)
46 {
47  return (float)bV*(4.f/127.f)-0.5f;
48 }
49 
50 
51 struct Star1 { // 28 byte
52 
53  /*
54  _______________
55  0 hip | |
56  1 | |
57  2 |_______________|
58  3 cIds |_______________|
59  4 x0 | |
60  5 | |
61  6 | |
62  7 |_______________|
63  8 x1 | |
64  9 | |
65  10 | |
66  11 |_______________|
67  12 bV |_______________|
68  13 mag |_______________|
69  14 spInt | |
70  15 |_______________|
71  16 dx0 | |
72  17 | |
73  18 | |
74  19 |_______________|
75  20 dx1 | |
76  21 | |
77  22 | |
78  23 |_______________|
79  24 plx | |
80  25 | |
81  26 | |
82  27 |_______________|
83 
84  */
85 
86  // componentIds 8
87  // hip 24
88  //
89  // qint32 x0 32
90  // qint32 x1 32
91  //
92  // unsigned char bV 8
93  // unsigned char mag 8
94  // Uint16 spInt 16
95  //
96  // qint32 dx0,dx1,plx 32
97 private:
98  quint8 d[28];
99 
100 public:
101  enum {MaxPosVal=0x7FFFFFFF};
102  StelObjectP createStelObject(const SpecialZoneArray<Star1> *a, const SpecialZoneData<Star1> *z) const;
103  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
104  {
105  pos = z->axis0;
106  pos*=((float)(getX0())+movementFactor*getDx0());
107  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
108  pos+=z->center;
109  }
110  inline int getBVIndex() const {return d[12];}
111  inline int getMag() const {return d[13];}
112  inline int getSpInt() const {return ((Uint16*)d)[7];}
113  inline int getX0() const { return qFromLittleEndian(((qint32*)d)[1]); }
114  inline int getX1() const { return qFromLittleEndian(((qint32*)d)[2]); }
115  inline int getDx0() const {return qFromLittleEndian(((qint32*)d)[4]);}
116  inline int getDx1() const {return qFromLittleEndian(((qint32*)d)[5]);}
117  inline int getPlx() const {return qFromLittleEndian(((qint32*)d)[6]);}
118 
119  inline int getHip() const
120  {
121  quint32 v = d[0] | d[1] << 8 | d[2] << 16;
122  return ((qint32)v) << 8 >> 8;
123  }
124 
125  inline int getComponentIds() const
126  {
127  return (qint32)d[3];
128  }
129 
130  float getBV(void) const {return IndexToBV(getBVIndex());}
131  bool hasName() const {return getHip();}
132  QString getNameI18n(void) const;
133  int hasComponentID(void) const;
134  void print(void);
135 };
136 
137 
138 struct Star2 { // 10 byte
139 
140  /*
141  _______________
142  0 x0 | |
143  1 |_______ |
144  2 x1 | |_______|
145  3 | |
146  4 |_______________|
147  5 dx0 |___ |
148  6 dx1 | |___________|
149  7 |_______ |
150  8 bV |_______|_______|
151  9 mag |_________|_____| bV
152 
153  int x0 :20;
154  int x1 :20;
155  int dx0 :14;
156  int dx1 :14;
157  unsigned int bV :7;
158  unsigned int mag:5;
159  */
160 
161 private:
162  quint8 d[10];
163 
164 public:
165  inline int getX0() const
166  {
167  quint32 v = d[0] | d[1] << 8 | (d[2] & 0xF) << 16;
168  return ((qint32)v) << 12 >> 12;
169  }
170 
171  inline int getX1() const
172  {
173  quint32 v = d[2] >> 4 | d[3] << 4 | d[4] << 12;
174  return ((qint32)v) << 12 >> 12;
175  }
176 
177  inline int getDx0() const
178  {
179  Uint16 v = d[5] | (d[6] & 0x3F) << 8;
180  return ((Int16)(v << 2)) >> 2;
181  }
182 
183  inline int getDx1() const
184  {
185  Uint16 v = d[6] >> 6 | d[7] << 2 | (d[8] & 0xF) << 10;
186  return ((Int16)(v << 2)) >> 2;
187  }
188 
189  inline int getBVIndex() const
190  {
191  return d[8] >> 4 | (d[9] & 0x7) << 4;
192  }
193 
194  inline int getMag() const
195  {
196  return d[9] >> 3;
197  }
198 
199  enum {MaxPosVal=((1<<19)-1)};
200  StelObjectP createStelObject(const SpecialZoneArray<Star2> *a, const SpecialZoneData<Star2> *z) const;
201  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
202  {
203  pos = z->axis0;
204  pos*=((float)(getX0())+movementFactor*getDx0());
205  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
206  pos+=z->center;
207  }
208  float getBV(void) const {return IndexToBV(getBVIndex());}
209  QString getNameI18n(void) const {return QString();}
210  int hasComponentID(void) const {return 0;}
211  bool hasName() const {return false;}
212  void print(void);
213 };
214 
215 struct Star3 { // 6 byte
216 
217  /*
218  _______________
219  0 x0 | |
220  1 |___________ |
221  2 x1 | |___|
222  3 |_______ |
223  4 bV |_______|_______|
224  5 mag |_________|_____| bV
225 
226  int x0 :18
227  int x1 :18
228  unsigned int bV :7
229  unsigned int mag :5
230  */
231 private:
232  quint8 d[6];
233 
234 public:
235  inline int getX0() const
236  {
237  quint32 v = d[0] | d[1] << 8 | (d[2] & 0x3) << 16;
238  return ((qint32)v) << 14 >> 14;
239  }
240 
241  inline int getX1() const
242  {
243  quint32 v = d[2] >> 2 | d[3] << 6 | (d[4] & 0xF) << 14;
244  return ((qint32)v) << 14 >> 14;
245  }
246 
247  inline int getBVIndex() const
248  {
249  return d[4] >> 4 | (d[5] & 0x7) << 4;
250  }
251 
252  inline int getMag() const
253  {
254  return d[5] >> 3;
255  }
256 
257  enum {MaxPosVal=((1<<17)-1)};
258  StelObjectP createStelObject(const SpecialZoneArray<Star3> *a, const SpecialZoneData<Star3> *z) const;
259  void getJ2000Pos(const ZoneData *z,float, Vec3f& pos) const
260  {
261  pos = z->axis0;
262  pos*=(float)(getX0());
263  pos+=z->center;
264  pos+=(float)(getX1())*z->axis1;
265  }
266  float getBV() const {return IndexToBV(getBVIndex());}
267  QString getNameI18n() const {return QString();}
268  int hasComponentID() const {return 0;}
269  bool hasName() const {return false;}
270  void print();
271 };
272 
273 #endif // _STAR_HPP_
Wrapper struct around ZoneData.
Definition: Star.hpp:36
Definition: Star.hpp:138
The base abstract class for sky objects used in Stellarium like Stars, Planets, Constellations etc...
Definition: StelObject.hpp:36
Definition: Star.hpp:51
A single triangle.
Definition: ZoneData.hpp:37
Definition: Star.hpp:215
Define the StelObjectP type.
Implements all the virtual methods in ZoneArray.
Definition: Star.hpp:35