Stellarium  0.16.1
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 extern const QString STAR_TYPE;
33 
34 typedef short int Int16;
35 typedef unsigned short int Uint16;
36 
37 template <class Star> class SpecialZoneArray;
38 template <class Star> struct SpecialZoneData;
39 
40 
41 // structs for storing the stars in binary form. The idea is
42 // to store much data for bright stars (Star1), but only little or even
43 // very little data for faints stars (Star3). Using only 6 bytes for Star3
44 // makes it feasable to store hundreds of millions of them in main memory.
45 
46 
47 static inline float IndexToBV(unsigned char bV)
48 {
49  return (float)bV*(4.f/127.f)-0.5f;
50 }
51 
52 
53 struct Star1 { // 28 byte
54 
55  /*
56  _______________
57  0 hip | |
58  1 | |
59  2 |_______________|
60  3 cIds |_______________|
61  4 x0 | |
62  5 | |
63  6 | |
64  7 |_______________|
65  8 x1 | |
66  9 | |
67  10 | |
68  11 |_______________|
69  12 bV |_______________|
70  13 mag |_______________|
71  14 spInt | |
72  15 |_______________|
73  16 dx0 | |
74  17 | |
75  18 | |
76  19 |_______________|
77  20 dx1 | |
78  21 | |
79  22 | |
80  23 |_______________|
81  24 plx | |
82  25 | |
83  26 | |
84  27 |_______________|
85 
86  */
87 
88  // componentIds 8
89  // hip 24
90  //
91  // qint32 x0 32
92  // qint32 x1 32
93  //
94  // unsigned char bV 8
95  // unsigned char mag 8
96  // Uint16 spInt 16
97  //
98  // qint32 dx0,dx1,plx 32
99 private:
100  // Use an union so we can access the data as different types without
101  // aliasing issues.
102  union {
103  quint8 uint8[28];
104  quint16 uint16[14];
105  qint32 int32[7];
106  } d;
107 
108 public:
109  enum {MaxPosVal=0x7FFFFFFF};
110  StelObjectP createStelObject(const SpecialZoneArray<Star1> *a, const SpecialZoneData<Star1> *z) const;
111  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
112  {
113  pos = z->axis0;
114  pos*=((float)(getX0())+movementFactor*getDx0());
115  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
116  pos+=z->center;
117  }
118  inline int getBVIndex() const {return d.uint8[12];}
119  inline int getMag() const {return d.uint8[13];}
120  inline int getSpInt() const {return d.uint16[7];}
121  inline int getX0() const { return qFromLittleEndian(d.int32[1]);}
122  inline int getX1() const { return qFromLittleEndian(d.int32[2]);}
123  inline int getDx0() const {return qFromLittleEndian(d.int32[4]);}
124  inline int getDx1() const {return qFromLittleEndian(d.int32[5]);}
125  inline int getPlx() const {return qFromLittleEndian(d.int32[6]);}
126 
127  inline int getHip() const
128  {
129  quint32 v = d.uint8[0] | d.uint8[1] << 8 | d.uint8[2] << 16;
130  return ((qint32)v) << 8 >> 8;
131  }
132 
133  inline int getComponentIds() const
134  {
135  return d.uint8[3];
136  }
137 
138  float getBV(void) const {return IndexToBV(getBVIndex());}
139  bool hasName() const {return getHip();}
140  QString getNameI18n(void) const;
141  int hasComponentID(void) const;
142  void print(void) const;
143 };
144 
145 
146 struct Star2 { // 10 byte
147 
148  /*
149  _______________
150  0 x0 | |
151  1 |_______ |
152  2 x1 | |_______|
153  3 | |
154  4 |_______________|
155  5 dx0 |___ |
156  6 dx1 | |___________|
157  7 |_______ |
158  8 bV |_______|_______|
159  9 mag |_________|_____| bV
160 
161  int x0 :20;
162  int x1 :20;
163  int dx0 :14;
164  int dx1 :14;
165  unsigned int bV :7;
166  unsigned int mag:5;
167  */
168 
169 private:
170  quint8 d[10];
171 
172 public:
173  inline int getX0() const
174  {
175  quint32 v = d[0] | d[1] << 8 | (d[2] & 0xF) << 16;
176  return ((qint32)v) << 12 >> 12;
177  }
178 
179  inline int getX1() const
180  {
181  quint32 v = d[2] >> 4 | d[3] << 4 | d[4] << 12;
182  return ((qint32)v) << 12 >> 12;
183  }
184 
185  inline int getDx0() const
186  {
187  Uint16 v = d[5] | (d[6] & 0x3F) << 8;
188  return ((Int16)(v << 2)) >> 2;
189  }
190 
191  inline int getDx1() const
192  {
193  Uint16 v = d[6] >> 6 | d[7] << 2 | (d[8] & 0xF) << 10;
194  return ((Int16)(v << 2)) >> 2;
195  }
196 
197  inline int getBVIndex() const
198  {
199  return d[8] >> 4 | (d[9] & 0x7) << 4;
200  }
201 
202  inline int getMag() const
203  {
204  return d[9] >> 3;
205  }
206 
207  enum {MaxPosVal=((1<<19)-1)};
208  StelObjectP createStelObject(const SpecialZoneArray<Star2> *a, const SpecialZoneData<Star2> *z) const;
209  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
210  {
211  pos = z->axis0;
212  pos*=((float)(getX0())+movementFactor*getDx0());
213  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
214  pos+=z->center;
215  }
216  float getBV(void) const {return IndexToBV(getBVIndex());}
217  QString getNameI18n(void) const {return QString();}
218  int hasComponentID(void) const {return 0;}
219  bool hasName() const {return false;}
220  void print(void) const;
221 };
222 
223 struct Star3 { // 6 byte
224 
225  /*
226  _______________
227  0 x0 | |
228  1 |___________ |
229  2 x1 | |___|
230  3 |_______ |
231  4 bV |_______|_______|
232  5 mag |_________|_____| bV
233 
234  int x0 :18
235  int x1 :18
236  unsigned int bV :7
237  unsigned int mag :5
238  */
239 private:
240  quint8 d[6];
241 
242 public:
243  inline int getX0() const
244  {
245  quint32 v = d[0] | d[1] << 8 | (d[2] & 0x3) << 16;
246  return ((qint32)v) << 14 >> 14;
247  }
248 
249  inline int getX1() const
250  {
251  quint32 v = d[2] >> 2 | d[3] << 6 | (d[4] & 0xF) << 14;
252  return ((qint32)v) << 14 >> 14;
253  }
254 
255  inline int getBVIndex() const
256  {
257  return d[4] >> 4 | (d[5] & 0x7) << 4;
258  }
259 
260  inline int getMag() const
261  {
262  return d[5] >> 3;
263  }
264 
265  enum {MaxPosVal=((1<<17)-1)};
266  StelObjectP createStelObject(const SpecialZoneArray<Star3> *a, const SpecialZoneData<Star3> *z) const;
267  void getJ2000Pos(const ZoneData *z,float, Vec3f& pos) const
268  {
269  pos = z->axis0;
270  pos*=(float)(getX0());
271  pos+=z->center;
272  pos+=(float)(getX1())*z->axis1;
273  }
274  float getBV() const {return IndexToBV(getBVIndex());}
275  QString getNameI18n() const {return QString();}
276  int hasComponentID() const {return 0;}
277  bool hasName() const {return false;}
278  void print();
279 };
280 
281 #endif // _STAR_HPP_
Wrapper struct around ZoneData.
Definition: Star.hpp:38
Definition: Star.hpp:146
The base abstract class for sky objects used in Stellarium like Stars, Planets, Constellations etc...
Definition: StelObject.hpp:36
Definition: Star.hpp:53
A single triangle.
Definition: ZoneData.hpp:37
Definition: Star.hpp:223
Define the StelObjectP type.
Implements all the virtual methods in ZoneArray.
Definition: Star.hpp:37