3
* Copyright (C) 2002 Fabien Chereau
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.
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.
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.
31
#include "StelObjectModule.hpp"
32
#include "STextureTypes.hpp"
43
namespace BigStarCatalogExtension {
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.
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:
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.
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
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
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);
92
//! Draw the stars and the star selection indicator if necessary.
93
virtual double draw(StelCore* core); //! Draw all the stars
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));}
100
virtual void updateI18n();
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();
106
//! Sets the colour scheme (night / chart etc).
107
virtual void setColorScheme(const InitParser& conf, const QString& section);
109
//! Used to determine the order in which the various StelModules are drawn.
110
virtual double getCallOrder(StelModuleActionName actionName) const;
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;
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;
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;
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;
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;}
138
//! Initializes each triangular face of the geodesic grid.
140
void setGrid(class GeodesicGrid* grid);
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;
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));}
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);
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);
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;
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;
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;
178
//! Set the color used to label bright stars.
179
void setLabelColor(const Vec3f& c) {label_color = c;}
181
//! Get the current color used to label bright stars.
182
Vec3f getLabelColor(void) const {return label_color;}
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;}
188
//! Set display flag for Stars.
189
void setFlagStars(bool b) {starsFader=b;}
191
//! Get display flag for Stars
192
bool getFlagStars(void) const {return starsFader==true;}
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;}
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;}
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;}
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;}
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;}
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;}
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;}
229
//! Set stars twinkle amount.
230
void setTwinkleAmount(float b) {twinkleAmount=b;}
231
//! Get stars twinkle amount.
232
float getTwinkleAmount(void) const {return twinkleAmount;}
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);}
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);}
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);}
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);}
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);}
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();}
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
278
mag_converter->setFov(fov);
279
mag_converter->setEye(eye);
280
return mag_converter->computeRCMag(mag,point_star,eye,rc_mag);
283
//! Define font size to use for star names display.
284
void setFontSize(double newFontSize);
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;}
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;
294
//! Get the (translated) common name for a star with a specified
295
//! Hipparcos catalogue number.
296
static wstring getCommonName(int hip);
298
//! Get the (translated) scientifc name for a star with a specified
299
//! Hipparcos catalogue number.
300
static wstring getSciName(int hip);
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);
307
//! Load all the stars from the files.
308
void load_data(const InitParser &conf);
310
//! Draw a nice animated pointer around the object.
311
void drawPointer(const Projector* prj, const Navigator * nav);
313
LinearFader names_fader;
314
LinearFader starsFader;
319
bool flagStarSciName;
320
float maxMagStarName;
321
bool flagStarTwinkle;
326
STextureSP starTexture; // star texture
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,
338
reinterpret_cast<StarMgr*>(context)->initTriangle(lev, index, c0, c1, c2);
341
void initTriangle(int lev, int index,
346
BigStarCatalogExtension::HipIndexStruct *hip_index; // array of hiparcos stars
351
MagConverter(const StarMgr &mgr) : mgr(mgr)
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;
376
float max_fov, min_fov, mag_shift, max_mag, max_scaled_60deg_mag,
377
min_rmag, fov_factor;
380
MagConverter *mag_converter;
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;
387
static map<int, wstring> sci_names_map_i18n;
388
static map<wstring, int> sci_names_index_i18n;
390
static double current_JDay;
394
static bool flagSciNames;
395
Vec3f label_color, circle_color;
396
float twinkle_amount;
398
STextureSP texPointer; // The selection pointer texture
403
#endif // _STAR_MGR_H_