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