Stellarium 0.15.2
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  // Use an union so we can access the data as different types without
99  // aliasing issues.
100  union {
101  quint8 uint8[28];
102  quint16 uint16[14];
103  qint32 int32[7];
104  } d;
105 
106 public:
107  enum {MaxPosVal=0x7FFFFFFF};
108  StelObjectP createStelObject(const SpecialZoneArray<Star1> *a, const SpecialZoneData<Star1> *z) const;
109  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
110  {
111  pos = z->axis0;
112  pos*=((float)(getX0())+movementFactor*getDx0());
113  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
114  pos+=z->center;
115  }
116  inline int getBVIndex() const {return d.uint8[12];}
117  inline int getMag() const {return d.uint8[13];}
118  inline int getSpInt() const {return d.uint16[7];}
119  inline int getX0() const { return qFromLittleEndian(d.int32[1]);}
120  inline int getX1() const { return qFromLittleEndian(d.int32[2]);}
121  inline int getDx0() const {return qFromLittleEndian(d.int32[4]);}
122  inline int getDx1() const {return qFromLittleEndian(d.int32[5]);}
123  inline int getPlx() const {return qFromLittleEndian(d.int32[6]);}
124 
125  inline int getHip() const
126  {
127  quint32 v = d.uint8[0] | d.uint8[1] << 8 | d.uint8[2] << 16;
128  return ((qint32)v) << 8 >> 8;
129  }
130 
131  inline int getComponentIds() const
132  {
133  return d.uint8[3];
134  }
135 
136  float getBV(void) const {return IndexToBV(getBVIndex());}
137  bool hasName() const {return getHip();}
138  QString getNameI18n(void) const;
139  int hasComponentID(void) const;
140  void print(void);
141 };
142 
143 
144 struct Star2 { // 10 byte
145 
146  /*
147  _______________
148  0 x0 | |
149  1 |_______ |
150  2 x1 | |_______|
151  3 | |
152  4 |_______________|
153  5 dx0 |___ |
154  6 dx1 | |___________|
155  7 |_______ |
156  8 bV |_______|_______|
157  9 mag |_________|_____| bV
158 
159  int x0 :20;
160  int x1 :20;
161  int dx0 :14;
162  int dx1 :14;
163  unsigned int bV :7;
164  unsigned int mag:5;
165  */
166 
167 private:
168  quint8 d[10];
169 
170 public:
171  inline int getX0() const
172  {
173  quint32 v = d[0] | d[1] << 8 | (d[2] & 0xF) << 16;
174  return ((qint32)v) << 12 >> 12;
175  }
176 
177  inline int getX1() const
178  {
179  quint32 v = d[2] >> 4 | d[3] << 4 | d[4] << 12;
180  return ((qint32)v) << 12 >> 12;
181  }
182 
183  inline int getDx0() const
184  {
185  Uint16 v = d[5] | (d[6] & 0x3F) << 8;
186  return ((Int16)(v << 2)) >> 2;
187  }
188 
189  inline int getDx1() const
190  {
191  Uint16 v = d[6] >> 6 | d[7] << 2 | (d[8] & 0xF) << 10;
192  return ((Int16)(v << 2)) >> 2;
193  }
194 
195  inline int getBVIndex() const
196  {
197  return d[8] >> 4 | (d[9] & 0x7) << 4;
198  }
199 
200  inline int getMag() const
201  {
202  return d[9] >> 3;
203  }
204 
205  enum {MaxPosVal=((1<<19)-1)};
206  StelObjectP createStelObject(const SpecialZoneArray<Star2> *a, const SpecialZoneData<Star2> *z) const;
207  void getJ2000Pos(const ZoneData *z,float movementFactor, Vec3f& pos) const
208  {
209  pos = z->axis0;
210  pos*=((float)(getX0())+movementFactor*getDx0());
211  pos+=((float)(getX1())+movementFactor*getDx1())*z->axis1;
212  pos+=z->center;
213  }
214  float getBV(void) const {return IndexToBV(getBVIndex());}
215  QString getNameI18n(void) const {return QString();}
216  int hasComponentID(void) const {return 0;}
217  bool hasName() const {return false;}
218  void print(void);
219 };
220 
221 struct Star3 { // 6 byte
222 
223  /*
224  _______________
225  0 x0 | |
226  1 |___________ |
227  2 x1 | |___|
228  3 |_______ |
229  4 bV |_______|_______|
230  5 mag |_________|_____| bV
231 
232  int x0 :18
233  int x1 :18
234  unsigned int bV :7
235  unsigned int mag :5
236  */
237 private:
238  quint8 d[6];
239 
240 public:
241  inline int getX0() const
242  {
243  quint32 v = d[0] | d[1] << 8 | (d[2] & 0x3) << 16;
244  return ((qint32)v) << 14 >> 14;
245  }
246 
247  inline int getX1() const
248  {
249  quint32 v = d[2] >> 2 | d[3] << 6 | (d[4] & 0xF) << 14;
250  return ((qint32)v) << 14 >> 14;
251  }
252 
253  inline int getBVIndex() const
254  {
255  return d[4] >> 4 | (d[5] & 0x7) << 4;
256  }
257 
258  inline int getMag() const
259  {
260  return d[5] >> 3;
261  }
262 
263  enum {MaxPosVal=((1<<17)-1)};
264  StelObjectP createStelObject(const SpecialZoneArray<Star3> *a, const SpecialZoneData<Star3> *z) const;
265  void getJ2000Pos(const ZoneData *z,float, Vec3f& pos) const
266  {
267  pos = z->axis0;
268  pos*=(float)(getX0());
269  pos+=z->center;
270  pos+=(float)(getX1())*z->axis1;
271  }
272  float getBV() const {return IndexToBV(getBVIndex());}
273  QString getNameI18n() const {return QString();}
274  int hasComponentID() const {return 0;}
275  bool hasName() const {return false;}
276  void print();
277 };
278 
279 #endif // _STAR_HPP_
Wrapper struct around ZoneData.
Definition: Star.hpp:36
Definition: Star.hpp:144
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:221
Define the StelObjectP type.
Implements all the virtual methods in ZoneArray.
Definition: Star.hpp:35