~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/StarMgr.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Stellarium
 
3
 * Copyright (C) 2002 Fabien Chereau
 
4
 * 
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 * 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 */
 
19
 
 
20
#ifndef _STAR_MGR_H_
 
21
#define _STAR_MGR_H_
 
22
 
 
23
#include <vector>
 
24
#include <map>
 
25
#include <string>
 
26
#include <sstream>
 
27
#include <fstream>
 
28
#include <cstdlib>
 
29
#include <cstdio>
 
30
#include "Fader.hpp"
 
31
#include "StelObjectModule.hpp"
 
32
#include "STextureTypes.hpp"
 
33
 
 
34
using namespace std;
 
35
 
 
36
class StelObject;
 
37
class ToneReproducer;
 
38
class Projector;
 
39
class Navigator;
 
40
class LoadingBar;
 
41
class SFont;
 
42
 
 
43
namespace BigStarCatalogExtension {
 
44
  class ZoneArray;
 
45
  class HipIndexStruct;
 
46
}
 
47
 
 
48
//! @class StarMgr 
 
49
//! Stores the star catalogue data.
 
50
//! Used to render the stars themselves, as well as determine the color table
 
51
//! and render the labels of those stars with names for a given SkyCulture.
 
52
//! 
 
53
//! The celestial sphere is split into zones, which correspond to the
 
54
//! triangular faces of a geodesic sphere. The number of zones (faces)
 
55
//! depends on the level of sub-division of this sphere. The lowest
 
56
//! level, 0, is an icosahedron (20 faces), subsequent levels, L,
 
57
//! of sub-division give the number of zones, n as:
 
58
//!
 
59
//! n=20 x 4^L
 
60
//!
 
61
//! Stellarium uses levels 0 to 7 in the existing star catalogues.
 
62
//! Star Data Records contain the position of a star as an offset from
 
63
//! the central position of the zone in which that star is located,
 
64
//! thus it is necessary to determine the vector from the observer
 
65
//! to the centre of a zone, and add the star's offsets to find the
 
66
//! absolute position of the star on the celestial sphere.
 
67
//!
 
68
//! This position for a star is expressed as a 3-dimensional vector
 
69
//! which points from the observer (at the centre of the geodesic sphere)
 
70
//! to the position of the star as observed on the celestial sphere.
 
71
class StarMgr : public StelObjectModule
 
72
{
 
73
public:
 
74
        StarMgr(void);
 
75
        ~StarMgr(void);
 
76
        
 
77
        ///////////////////////////////////////////////////////////////////////////
 
78
        // Methods defined in the StelModule class
 
79
        //! Initialize the StarMgr.
 
80
        //! - Loads the star catalogue data into memory
 
81
        //! - Sets up the star color table
 
82
        //! - Loads the star texture
 
83
        //! - Loads the star font (for labels on named stars)
 
84
        //! - Loads the texture of the sar selection indicator
 
85
        //! - Lets various display flags from the ini parser object
 
86
        //!
 
87
        //! @param conf The ini parser object containing relevant settings.
 
88
        //! @param lb The LoadingBar object which shows progress and current operation.
 
89
        virtual void init(const InitParser& conf);
 
90
        
 
91
        
 
92
        //! Draw the stars and the star selection indicator if necessary.
 
93
        virtual double draw(StelCore* core); //! Draw all the stars
 
94
        
 
95
        //! Update any time-dependent features.
 
96
        //! Includes fading in and out stars and labels when they are turned on and off.
 
97
        virtual void update(double deltaTime) {names_fader.update((int)(deltaTime*1000)); starsFader.update((int)(deltaTime*1000));}
 
98
        
 
99
        //! Translate text.
 
100
        virtual void updateI18n();
 
101
        
 
102
        //! Called when the sky culture is updated.
 
103
        //! Loads common and scientific names of stars for a given sky culture.
 
104
        virtual void updateSkyCulture();
 
105
        
 
106
        //! Sets the colour scheme (night / chart etc).
 
107
        virtual void setColorScheme(const InitParser& conf, const QString& section);
 
108
        
 
109
        //! Used to determine the order in which the various StelModules are drawn.
 
110
        virtual double getCallOrder(StelModuleActionName actionName) const;
 
111
        
 
112
        ///////////////////////////////////////////////////////////////////////////
 
113
        // Methods defined in StelObjectManager class
 
114
        //! Return a stl vector containing the stars located inside the lim_fov circle around position v
 
115
        virtual vector<StelObjectP > searchAround(const Vec3d& v, double limitFov, const StelCore* core) const;
 
116
        
 
117
        //! Return the matching Stars object's pointer if exists or NULL
 
118
        //! @param nameI18n The case sensistive star common name or HP
 
119
        //! catalog name (format can be HP1234 or HP 1234) or sci name
 
120
        virtual StelObjectP searchByNameI18n(const wstring& nameI18n) const;    
 
121
 
 
122
        //! Return the matching star if exists or NULL
 
123
        //! @param name The case sensistive standard program planet name
 
124
        virtual StelObjectP searchByName(const string& name) const;
 
125
 
 
126
        //! Find and return the list of at most maxNbItem objects auto-completing the passed object I18n name.
 
127
        //! @param objPrefix the case insensitive first letters of the searched object
 
128
        //! @param maxNbItem the maximum number of returned object names
 
129
        //! @return a vector of matching object name by order of relevance, or an empty vector if nothing match
 
130
        virtual vector<wstring> listMatchingObjectsI18n(const wstring& objPrefix, unsigned int maxNbItem=5) const;
 
131
        
 
132
        ///////////////////////////////////////////////////////////////////////////
 
133
        // Properties setters and getters
 
134
        //! Get the maximum level of the geodesic sphere used.
 
135
        //! See the class description for a short introduction to the meaning of this value.
 
136
        int getMaxGridLevel(void) const {return max_geodesic_grid_level;}
 
137
        
 
138
        //! Initializes each triangular face of the geodesic grid.
 
139
        // TODO: But why?
 
140
        void setGrid(class GeodesicGrid* grid);
 
141
        
 
142
        //! Gets the maximum search level.
 
143
        // TODO: add a non-lame description - what is the purpose of the max search level?
 
144
        int getMaxSearchLevel(const ToneReproducer *eye, const Projector *prj) const;
 
145
        
 
146
        //! Sets the time it takes for star names to fade and off.
 
147
        //! @param duration the time in seconds.
 
148
        void set_names_fade_duration(float duration) {names_fader.set_duration((int) (duration * 1000.f));}
 
149
        
 
150
        //! Loads common names for stars from a file.
 
151
        //! Called when the SkyCulture is updated.
 
152
        //! @param the path to a file containing the common names for bright stars.
 
153
        int load_common_names(const QString& commonNameFile);
 
154
        
 
155
        //! Loads scientific names for stars from a file.
 
156
        //! Called when the SkyCulture is updated.
 
157
        //! @param the path to a file containing the scientific names for bright stars.
 
158
        void load_sci_names(const QString& sciNameFile);
 
159
        
 
160
        //! Search for the nearest star to some position.
 
161
        //! @param Pos the 3d vector representing the direction to search.
 
162
        //! @return the nearest star from the specified position, or an 
 
163
        //! empty StelObjectP if none were found close by.
 
164
        StelObjectP search(Vec3d Pos) const;
 
165
        
 
166
        //! Search for a star by catalogue number (including catalogue prefix).
 
167
        //! @param id the catalogue identifier for the required star.
 
168
        //! @return the requested StelObjectP or an empty objecy if the requested
 
169
        //! one was not found.
 
170
        StelObjectP search(const string& id) const;
 
171
        
 
172
        //! Search bu Hipparcos catalogue number.
 
173
        //! @param num the Hipparcos catalogue number of the star which is required.
 
174
        //! @return the requested StelObjectP or an empty objecy if the requested
 
175
        //! one was not found.
 
176
        StelObjectP searchHP(int num) const;
 
177
        
 
178
        //! Set the color used to label bright stars.
 
179
        void setLabelColor(const Vec3f& c) {label_color = c;}
 
180
        
 
181
        //! Get the current color used to label bright stars.
 
182
        Vec3f getLabelColor(void) const {return label_color;}
 
183
        
 
184
        // TODO: *Doxygen* what is this? Is it obsolete?
 
185
        void setCircleColor(const Vec3f& c) {circle_color = c;}
 
186
        Vec3f getCircleColor(void) const {return circle_color;}
 
187
        
 
188
        //! Set display flag for Stars.
 
189
        void setFlagStars(bool b) {starsFader=b;}
 
190
        
 
191
        //! Get display flag for Stars 
 
192
        bool getFlagStars(void) const {return starsFader==true;}
 
193
        
 
194
        //! Set display flag for Star names (labels).
 
195
        void setFlagNames(bool b) {names_fader=b;}
 
196
        //! Get display flag for Star names (labels).
 
197
        bool getFlagNames(void) const {return names_fader==true;}
 
198
        
 
199
        //! Set display flag for Star Scientific names.
 
200
        void setFlagStarsSciNames(bool b) {flagStarSciName=b;}
 
201
        //! Get display flag for Star Scientific names.
 
202
        bool getFlagStarsSciNames(void) const {return flagStarSciName;}
 
203
        
 
204
        //! Set flag for Star twinkling.
 
205
        void setFlagTwinkle(bool b) {flagStarTwinkle=b;}
 
206
        //! Get flag for Star twinkling.
 
207
        bool getFlagTwinkle(void) const {return flagStarTwinkle;}
 
208
        
 
209
        //! Set flag for displaying Star as GLpoints (faster on some hardware but not so nice).
 
210
        void setFlagPointStar(bool b) {flagPointStar=b;}
 
211
        //! Get flag for displaying Star as GLpoints (faster on some hardware but not so nice).
 
212
        bool getFlagPointStar(void) const {return flagPointStar;}
 
213
        
 
214
        //! Set maximum magnitude at which stars names are displayed.
 
215
        void setMaxMagName(float b) {maxMagStarName=b;}
 
216
        //! Get maximum magnitude at which stars names are displayed.
 
217
        float getMaxMagName(void) const {return maxMagStarName;} 
 
218
        
 
219
        //! Set base stars display scaling factor.
 
220
        void setScale(float b) {starScale=b;}
 
221
        //! Get base stars display scaling factor.
 
222
        float getScale(void) const {return starScale;}
 
223
        
 
224
        //! Set stars display scaling factor wrt magnitude.
 
225
        void setMagScale(float b) {starMagScale=b;}
 
226
        //! Get base stars display scaling factor wrt magnitude.
 
227
        float getMagScale(void) const {return starMagScale;}
 
228
        
 
229
        //! Set stars twinkle amount.
 
230
        void setTwinkleAmount(float b) {twinkleAmount=b;}
 
231
        //! Get stars twinkle amount.
 
232
        float getTwinkleAmount(void) const {return twinkleAmount;}
 
233
        
 
234
        
 
235
        //! Set MagConverter maximum FOV.
 
236
        //! Usually stars/planet halos are drawn fainter when FOV gets larger, 
 
237
        //! but when FOV gets larger than this value, the stars do not become
 
238
        //! fainter any more. Must be >= 60.0.
 
239
        void setMagConverterMaxFov(float x) {mag_converter->setMaxFov(x);}
 
240
        
 
241
        //! Set MagConverter minimum FOV.
 
242
        //! Usually stars/planet halos are drawn brighter when FOV gets smaller.
 
243
        //! But when FOV gets smaller than this value, the stars do not become
 
244
        //! brighter any more. Must be <= 60.0.
 
245
        void setMagConverterMinFov(float x) {mag_converter->setMinFov(x);}
 
246
        
 
247
        //! Set MagConverter magnitude shift.
 
248
        //! draw the stars/planet halos as if they were brighter of fainter
 
249
        //! by this amount of magnitude
 
250
        void setMagConverterMagShift(float x) {mag_converter->setMagShift(x);}
 
251
        
 
252
        //! Set MagConverter maximum magnitude.
 
253
        //! stars/planet halos, whose original (unshifted) magnitude is greater
 
254
        //! than this value will not be drawn.
 
255
        void setMagConverterMaxMag(float mag) {mag_converter->setMaxMag(mag);}
 
256
        
 
257
        //! Set MagConverter maximum scaled magnitude wrt 60 degree FOV.
 
258
        //! Stars/planet halos, whose original (unshifted) magnitude is greater
 
259
        //! than this value will not be drawn at 60 degree FOV.
 
260
        void setMagConverterMaxScaled60DegMag(float mag) {mag_converter->setMaxScaled60DegMag(mag);}
 
261
        
 
262
        //! Get MagConverter maximum FOV.
 
263
        float getMagConverterMaxFov(void) const {return mag_converter->getMaxFov();}
 
264
        //! Get MagConverter minimum FOV.
 
265
        float getMagConverterMinFov(void) const {return mag_converter->getMinFov();}
 
266
        //! Get MagConverter magnitude shift.
 
267
        float getMagConverterMagShift(void) const {return mag_converter->getMagShift();}
 
268
        //! Get MagConverter maximum magnitude.
 
269
        float getMagConverterMaxMag(void) const {return mag_converter->getMaxMag();}
 
270
        //! Get MagConverter maximum scaled magnitude wrt 60 degree FOV.
 
271
        float getMagConverterMaxScaled60DegMag(void) const {return mag_converter->getMaxScaled60DegMag();}
 
272
        
 
273
        //! Compute RMag and CMag from magnitude.
 
274
        //! Useful for conststent drawing of Planet halos.
 
275
        int computeRCMag(float mag, bool point_star, float fov, 
 
276
                         const ToneReproducer *eye, float rc_mag[2]) const
 
277
        {
 
278
                mag_converter->setFov(fov);
 
279
                mag_converter->setEye(eye);
 
280
                return mag_converter->computeRCMag(mag,point_star,eye,rc_mag);
 
281
        }
 
282
        
 
283
        //! Define font size to use for star names display.
 
284
        void setFontSize(double newFontSize);
 
285
        
 
286
        //! Show scientific or catalog names on stars without common names.
 
287
        static void setFlagSciNames(bool f) {flagSciNames = f;}
 
288
        static bool getFlagSciNames(void) {return flagSciNames;}
 
289
        
 
290
        //! Draw a star of specified position, magnitude and color.
 
291
        int drawStar(const Projector *prj, const Vec3d &XY,
 
292
                        const float rc_mag[2], const Vec3f &color) const;
 
293
        
 
294
        //! Get the (translated) common name for a star with a specified 
 
295
        //! Hipparcos catalogue number.
 
296
        static wstring getCommonName(int hip);
 
297
        
 
298
        //! Get the (translated) scientifc name for a star with a specified 
 
299
        //! Hipparcos catalogue number.
 
300
        static wstring getSciName(int hip);
 
301
 
 
302
        static Vec3f color_table[128];
 
303
        static double getCurrentJDay(void) {return current_JDay;}
 
304
        static string convertToSpectralType(int index);
 
305
        static string convertToComponentIds(int index);
 
306
private:
 
307
        //! Load all the stars from the files.
 
308
        void load_data(const InitParser &conf);
 
309
        
 
310
        //! Draw a nice animated pointer around the object.
 
311
        void drawPointer(const Projector* prj, const Navigator * nav);
 
312
        
 
313
        LinearFader names_fader;
 
314
        LinearFader starsFader;
 
315
        
 
316
        float starScale;
 
317
        float starMagScale;
 
318
        bool flagStarName;
 
319
        bool flagStarSciName;
 
320
        float maxMagStarName;
 
321
        bool flagStarTwinkle;
 
322
        float twinkleAmount;
 
323
        bool flagPointStar;
 
324
        bool gravityLabel;
 
325
        
 
326
        STextureSP starTexture; // star texture
 
327
        
 
328
        int max_geodesic_grid_level;
 
329
        int last_max_search_level;
 
330
        typedef map<int,BigStarCatalogExtension::ZoneArray*> ZoneArrayMap;
 
331
        ZoneArrayMap zone_arrays; // index is the grid level
 
332
        static void initTriangleFunc(int lev, int index,
 
333
                                const Vec3d &c0,
 
334
                                const Vec3d &c1,
 
335
                                const Vec3d &c2,
 
336
                                void *context)
 
337
        {
 
338
                reinterpret_cast<StarMgr*>(context)->initTriangle(lev, index, c0, c1, c2);
 
339
        }
 
340
        
 
341
        void initTriangle(int lev, int index,
 
342
                        const Vec3d &c0,
 
343
                        const Vec3d &c1,
 
344
                        const Vec3d &c2);
 
345
        
 
346
        BigStarCatalogExtension::HipIndexStruct *hip_index; // array of hiparcos stars
 
347
        
 
348
        class MagConverter
 
349
        {
 
350
        public:
 
351
                MagConverter(const StarMgr &mgr) : mgr(mgr)
 
352
                {
 
353
                        setMaxFov(180.f);
 
354
                        setMinFov(0.1f);
 
355
                        setFov(180.f);
 
356
                        setMagShift(0.f);
 
357
                        setMaxMag(30.f);
 
358
                        min_rmag = 0.01f;
 
359
                }
 
360
                void setMaxFov(float fov) {max_fov = (fov < 60.f) ? 60.f : fov;}
 
361
                void setMinFov(float fov) {min_fov = (fov > 60.f) ? 60.f : fov;}
 
362
                void setMagShift(float d) {mag_shift = d;}
 
363
                void setMaxMag(float mag) {max_mag = mag;}
 
364
                void setMaxScaled60DegMag(float mag) {max_scaled_60deg_mag = mag;}
 
365
                float getMaxFov(void) const {return max_fov;}
 
366
                float getMinFov(void) const {return min_fov;}
 
367
                float getMagShift(void) const {return mag_shift;}
 
368
                float getMaxMag(void) const {return max_mag;}
 
369
                float getMaxScaled60DegMag(void) const {return max_scaled_60deg_mag;}
 
370
                void setFov(float fov);
 
371
                void setEye(const ToneReproducer *eye);
 
372
                int computeRCMag(float mag, bool point_star,
 
373
                         const ToneReproducer *eye, float rc_mag[2]) const;
 
374
        private:
 
375
                const StarMgr &mgr;
 
376
                float max_fov, min_fov, mag_shift, max_mag, max_scaled_60deg_mag,
 
377
                min_rmag, fov_factor;
 
378
        };
 
379
 
 
380
        MagConverter *mag_converter;
 
381
        
 
382
        static map<int, string> common_names_map;
 
383
        static map<int, wstring> common_names_map_i18n;
 
384
        static map<string, int> common_names_index;
 
385
        static map<wstring, int> common_names_index_i18n;
 
386
        
 
387
        static map<int, wstring> sci_names_map_i18n;
 
388
        static map<wstring, int> sci_names_index_i18n;
 
389
 
 
390
        static double current_JDay;
 
391
        
 
392
        double fontSize;
 
393
        SFont *starFont;
 
394
        static bool flagSciNames;
 
395
        Vec3f label_color, circle_color;
 
396
        float twinkle_amount;
 
397
        
 
398
        STextureSP texPointer;          // The selection pointer texture
 
399
 
 
400
};
 
401
 
 
402
 
 
403
#endif // _STAR_MGR_H_