Stellarium 0.90.0
StelSkyDrawer.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELSKYDRAWER_HPP_
21 #define _STELSKYDRAWER_HPP_
22 
23 #include "RefractionExtinction.hpp"
24 #include "StelTextureTypes.hpp"
25 #include "StelProjectorType.hpp"
26 #include "VecMath.hpp"
27 
28 #include <QObject>
29 
30 class StelToneReproducer;
31 class StelCore;
32 class StelPainter;
33 
36 struct RCMag
37 {
38  float radius;
39  float luminance;
40 };
41 
45 class StelSkyDrawer : public QObject
46 {
47  Q_OBJECT
48 
50  Q_PROPERTY(double relativeStarScale READ getRelativeStarScale WRITE setRelativeStarScale NOTIFY relativeStarScaleChanged)
52  Q_PROPERTY(double absoluteStarScale READ getAbsoluteStarScale WRITE setAbsoluteStarScale NOTIFY absoluteStarScaleChanged)
53  Q_PROPERTY(double twinkleAmount READ getTwinkleAmount WRITE setTwinkleAmount NOTIFY twinkleAmountChanged)
54  Q_PROPERTY(bool flagTwinkle READ getFlagTwinkle WRITE setFlagTwinkle NOTIFY flagTwinkleChanged)
55  Q_PROPERTY(int bortleScaleIndex READ getBortleScaleIndex WRITE setBortleScaleIndex NOTIFY bortleScaleIndexChanged)
56 
57  Q_PROPERTY(bool flagStarMagnitudeLimit READ getFlagStarMagnitudeLimit WRITE setFlagStarMagnitudeLimit NOTIFY flagStarMagnitudeLimitChanged)
58  Q_PROPERTY(bool flagNebulaMagnitudeLimit READ getFlagNebulaMagnitudeLimit WRITE setFlagNebulaMagnitudeLimit NOTIFY flagNebulaMagnitudeLimitChanged)
59  Q_PROPERTY(bool flagPlanetMagnitudeLimit READ getFlagPlanetMagnitudeLimit WRITE setFlagPlanetMagnitudeLimit NOTIFY flagPlanetMagnitudeLimitChanged)
60 
61  Q_PROPERTY(double customStarMagLimit READ getCustomStarMagnitudeLimit WRITE setCustomStarMagnitudeLimit NOTIFY customStarMagLimitChanged)
62  Q_PROPERTY(double customNebulaMagLimit READ getCustomNebulaMagnitudeLimit WRITE setCustomNebulaMagnitudeLimit NOTIFY customNebulaMagLimitChanged)
63  Q_PROPERTY(double customPlanetMagLimit READ getCustomPlanetMagnitudeLimit WRITE setCustomPlanetMagnitudeLimit NOTIFY customPlanetMagLimitChanged)
64 
65  Q_PROPERTY(bool flagLuminanceAdaptation READ getFlagLuminanceAdaptation WRITE setFlagLuminanceAdaptation NOTIFY flagLuminanceAdaptationChanged)
66 
67  Q_PROPERTY(double extinctionCoefficient READ getExtinctionCoefficient WRITE setExtinctionCoefficient NOTIFY extinctionCoefficientChanged)
68  Q_PROPERTY(double atmosphereTemperature READ getAtmosphereTemperature WRITE setAtmosphereTemperature NOTIFY atmosphereTemperatureChanged)
69  Q_PROPERTY(double atmospherePressure READ getAtmospherePressure WRITE setAtmospherePressure NOTIFY atmospherePressureChanged)
70 
71 public:
72 
74  StelSkyDrawer(StelCore* core);
76  ~StelSkyDrawer();
77 
79  void init();
80 
83  void update(double deltaTime);
84 
87  void preDrawPointSource(StelPainter* p);
88 
90  void postDrawPointSource(StelPainter* sPainter);
91 
100  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false, float twinkleFactor=1.0f)
101  {
102  return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen, twinkleFactor);
103  }
104 
105  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, const Vec3f& bcolor, bool checkInScreen=false, float twinkleFactor=1.0f);
106 
107  void drawSunCorona(StelPainter* painter, const Vec3f& v, float radius, const Vec3f& color, const float alpha);
108 
115  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
116 
121  bool computeRCMag(float mag, RCMag*) const;
122 
128  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
129 
131  void preDraw();
132 
136  static float surfacebrightnessToLuminance(float sb);
140  static float luminanceToSurfacebrightness(float lum);
141 
143  static inline float indexToBV(unsigned char bV)
144  {
145  return (float)bV*(4.f/127.f)-0.5f;
146  }
147 
149  static inline const Vec3f& indexToColor(unsigned char bV)
150  {
151  return colorTable[bV];
152  }
153 
154 public slots:
156  void setRelativeStarScale(double b=1.0) {if(b!=starRelativeScale){ starRelativeScale=b; emit relativeStarScaleChanged(b);}}
158  double getRelativeStarScale() const {return starRelativeScale;}
159 
161  void setAbsoluteStarScale(double b=1.0) {if(b!=starAbsoluteScaleF){ starAbsoluteScaleF=b; emit absoluteStarScaleChanged(b);}}
163  double getAbsoluteStarScale() const {return starAbsoluteScaleF;}
164 
166  void setTwinkleAmount(double b) {if(b!=twinkleAmount){ twinkleAmount=b; emit twinkleAmountChanged(b);}}
168  double getTwinkleAmount() const {return twinkleAmount;}
169 
171  void setFlagTwinkle(bool b) {if(b!=flagStarTwinkle){ flagStarTwinkle=b; emit flagTwinkleChanged(b);}}
173  bool getFlagTwinkle() const {return flagStarTwinkle;}
174 
177  void setFlagForcedTwinkle(bool b) {if(b!=flagForcedTwinkle){ flagForcedTwinkle=b;}}
180  bool getFlagForcedTwinkle() const {return flagForcedTwinkle;}
181 
185  void setBortleScaleIndex(int index);
188  int getBortleScaleIndex() const {return bortleScaleIndex;}
189 
193  float getLimitMagnitude() const {return limitMagnitude;}
194 
198  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
199  void setFlagStarMagnitudeLimit(bool b) {if(b!=flagStarMagnitudeLimit){ flagStarMagnitudeLimit = b; emit flagStarMagnitudeLimitChanged(b);}}
201  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
205  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
206  void setFlagNebulaMagnitudeLimit(bool b) {if(b!=flagNebulaMagnitudeLimit){ flagNebulaMagnitudeLimit = b; emit flagNebulaMagnitudeLimitChanged(b);}}
208  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
212  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM --- GZ: this was copy/paste. Track down BM's changes!!!
213  void setFlagPlanetMagnitudeLimit(bool b) {if(b!=flagPlanetMagnitudeLimit){ flagPlanetMagnitudeLimit = b; emit flagPlanetMagnitudeLimitChanged(b);}}
215  bool getFlagPlanetMagnitudeLimit() const {return flagPlanetMagnitudeLimit;}
216 
218  double getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
221  void setCustomStarMagnitudeLimit(double limit) {if(limit!=customStarMagLimit){ customStarMagLimit=limit; emit customStarMagLimitChanged(limit);}}
223  double getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
226  void setCustomNebulaMagnitudeLimit(double limit) {if(limit!=customNebulaMagLimit){ customNebulaMagLimit=limit; emit customNebulaMagLimitChanged(limit);}}
228  double getCustomPlanetMagnitudeLimit() const {return customPlanetMagLimit;}
231  void setCustomPlanetMagnitudeLimit(double limit) {if(limit!=customPlanetMagLimit){ customPlanetMagLimit=limit; emit customPlanetMagLimitChanged(limit);}}
232 
236  float getLimitLuminance() const {return limitLuminance;}
237 
239  void setFlagLuminanceAdaptation(bool b) {if(b!=flagLuminanceAdaptation){ flagLuminanceAdaptation=b; emit flagLuminanceAdaptationChanged(b);}}
241  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
242 
245  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
247  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
248 
250  void setExtinctionCoefficient(double extCoeff) {if(extCoeff!=extinction.getExtinctionCoefficient()){ extinction.setExtinctionCoefficient(extCoeff); emit extinctionCoefficientChanged(extinction.getExtinctionCoefficient());}}
252  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
254  void setAtmosphereTemperature(double celsius) {if(celsius!=refraction.getTemperature()){refraction.setTemperature(celsius); emit atmosphereTemperatureChanged(refraction.getTemperature());}}
256  double getAtmosphereTemperature() const {return refraction.getTemperature();}
258  void setAtmospherePressure(double mbar) {if(mbar!=refraction.getPressure()){ refraction.setPressure(mbar); emit atmospherePressureChanged(refraction.getPressure());}}
260  double getAtmospherePressure() const {return refraction.getPressure();}
261 
263  const Extinction& getExtinction() const {return extinction;}
265  const Refraction& getRefraction() const {return refraction;}
266 
268  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
270  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
271 signals:
273  void relativeStarScaleChanged(double b);
275  void absoluteStarScaleChanged(double b);
277  void twinkleAmountChanged(double b);
279  void flagTwinkleChanged(bool b);
281  void bortleScaleIndexChanged(int index);
282 
284  void flagStarMagnitudeLimitChanged(bool b);
286  void flagNebulaMagnitudeLimitChanged(bool b);
288  void flagPlanetMagnitudeLimitChanged(bool b);
289 
291  void customStarMagLimitChanged(double limit);
293  void customNebulaMagLimitChanged(double limit);
295  void customPlanetMagLimitChanged(double limit);
296 
298  void flagLuminanceAdaptationChanged(bool b);
299 
300  void extinctionCoefficientChanged(double coeff);
301  void atmosphereTemperatureChanged(double celsius);
302  void atmospherePressureChanged(double mbar);
303 
304 private:
305  // Debug
306  float reverseComputeRCMag(float rmag) const;
307 
309  float computeLimitMagnitude() const;
310 
312  float computeLimitLuminance() const;
313 
315  float getMaxAdaptFov(void) const {return maxAdaptFov;}
320  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
321 
323  float getMinAdaptFov(void) const {return minAdaptFov;}
328  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
329 
331  void setInputScale(float in) {inScale = in;}
333  float getInputScale() const {return inScale;}
334 
338  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
339 
343  float pointSourceLuminanceToMag(float lum);
344 
348  float pointSourceMagToLnLuminance(float mag) const;
349 
352  float findWorldLumForMag(float mag, float targetRadius);
353 
354  StelCore* core;
355  StelToneReproducer* eye;
356 
357  Extinction extinction;
358  Refraction refraction;
359 
360  float maxAdaptFov, minAdaptFov, lnfovFactor;
361  bool flagStarTwinkle;
362  bool flagForcedTwinkle;
363  double twinkleAmount;
364 
367  bool flagHasAtmosphere;
368 
371  bool flagStarMagnitudeLimit;
374  bool flagNebulaMagnitudeLimit;
377  bool flagPlanetMagnitudeLimit;
378 
379  double starRelativeScale;
380  double starAbsoluteScaleF;
381 
382  float starLinearScale; // optimization variable
383 
385  float limitMagnitude;
386 
388  float limitLuminance;
389 
394  double customStarMagLimit;
400  // GZ To explain: we have 3 limits for stars, nebulae, planets. It's easier to maintain the pretty similar code in 1 place.
401  double customNebulaMagLimit;
406  double customPlanetMagLimit;
407 
409  StelTextureSP texHalo;
410 
412  void initColorTableFromConfigFile(class QSettings* conf);
413 
415  static Vec3f colorTable[128];
416 
418  int bortleScaleIndex;
419 
421  float inScale;
422 
423  // Variables used for GL optimization when displaying point sources
426  struct StarVertex {
427  Vec2f pos;
428  unsigned char color[4];
429  };
430 
432  StarVertex* vertexArray;
433 
435  unsigned char* textureCoordArray;
436 
437  class QOpenGLShaderProgram* starShaderProgram;
438  struct StarShaderVars {
439  int projectionMatrix;
440  int texCoord;
441  int pos;
442  int color;
443  int texture;
444  };
445  StarShaderVars starShaderVars;
446 
448  unsigned int nbPointSources;
450  unsigned int maxPointSources;
451 
453  float maxLum;
455  float oldLum;
456 
458  StelTextureSP texBigHalo;
459  StelTextureSP texSunHalo;
460  StelTextureSP texSunCorona;
461 
462  bool flagLuminanceAdaptation;
463 
464  float big3dModelHaloRadius;
465 };
466 
467 #endif // _STELSKYDRAWER_HPP_
static const Vec3f & indexToColor(unsigned char bV)
Convert quantized B-V index to RGB colors.
void setFlagForcedTwinkle(bool b)
Set flag for enable twinkling of stars without atmosphere.
bool getFlagTwinkle() const
Get flag for source twinkling.
double getCustomStarMagnitudeLimit() const
Get the value used for forced star magnitude limiting.
bool getFlagNebulaMagnitudeLimit() const
Provide a set of methods used to draw sky objects taking into account eyes adaptation, zoom level, instrument model and artificially set magnitude limits.
void setFlagHasAtmosphere(bool b)
Informing the drawer whether atmosphere is displayed.
void setExtinctionCoefficient(double extCoeff)
Set extinction coefficient, mag/airmass (for extinction).
void setCustomNebulaMagnitudeLimit(double limit)
Sets a lower limit for nebula magnitudes (anything fainter is ignored).
void setBig3dModelHaloRadius(float r)
Set the radius of the big halo texture used when a 3d model is very bright.
Define the StelTextureSP type.
void setFlagStarMagnitudeLimit(bool b)
Toggle the application of user-defined star magnitude limit.
const Extinction & getExtinction() const
Get the current valid extinction computation object.
This class performs extinction computations, following literature from atmospheric optics and astrono...
const Refraction & getRefraction() const
Get the current valid refraction computation object.
float getLimitLuminance() const
Get the luminance of the faintest visible object (e.g.
This class performs refraction computations, following literature from atmospheric optics and astrono...
float getBig3dModelHaloRadius() const
Get the radius of the big halo texture used when a 3d model is very bright.
void setFlagLuminanceAdaptation(bool b)
Set the value of the eye adaptation flag.
void setRelativeStarScale(double b=1.0)
Set the way brighter stars will look bigger as the fainter ones.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void setAtmosphereTemperature(double celsius)
Set atmospheric (ground) temperature in deg celsius (for refraction).
void setFlagNebulaMagnitudeLimit(bool b)
Toggle the application of user-defined deep-sky object magnitude limit.
double getAtmospherePressure() const
Get atmospheric (ground) pressure in mbar (for refraction).
double getAtmosphereTemperature() const
Get atmospheric (ground) temperature in deg celsius (for refraction).
bool getFlagStarMagnitudeLimit() const
double getAbsoluteStarScale() const
Get the absolute star brightness scale.
void setAbsoluteStarScale(double b=1.0)
Set the absolute star brightness scale.
double getExtinctionCoefficient() const
Get extinction coefficient, mag/airmass (for extinction).
Converts tones in function of the eye adaptation to luminance.
bool getFlagPlanetMagnitudeLimit() const
Contains the 2 parameters necessary to draw a star on screen.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
void setFlagTwinkle(bool b)
Set flag for source twinkling.
void setCustomPlanetMagnitudeLimit(double limit)
Sets a lower limit for solar system object magnitudes (anything fainter is ignored).
float getLimitMagnitude() const
Get the magnitude of the currently faintest visible point source It depends on the zoom level...
double getCustomNebulaMagnitudeLimit() const
Get the value used for forced nebula magnitude limiting.
bool getFlagHasAtmosphere() const
This is used to decide whether to apply refraction/extinction before rendering point sources et al...
void setCustomStarMagnitudeLimit(double limit)
Sets a lower limit for star magnitudes (anything fainter is ignored).
bool getFlagLuminanceAdaptation() const
Get the current value of eye adaptation flag.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
Define the StelProjectorP type.
double getRelativeStarScale() const
Get the way brighter stars will look bigger as the fainter ones.
double getCustomPlanetMagnitudeLimit() const
Get the value used for forced solar system object magnitude limiting.
bool getFlagForcedTwinkle() const
Get flag for enable twinkling of stars without atmosphere.
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
void setAtmospherePressure(double mbar)
Set atmospheric (ground) pressure in mbar (for refraction).
int getBortleScaleIndex() const
Get the current Bortle scale index.
double getTwinkleAmount() const
Get source twinkle amount.
void setFlagPlanetMagnitudeLimit(bool b)
Toggle the application of user-defined solar system object magnitude limit.
static float indexToBV(unsigned char bV)
Convert quantized B-V index to float B-V.
void setTwinkleAmount(double b)
Set source twinkle amount.