Stellarium 0.15.2
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 #include "StelOpenGL.hpp"
28 
29 #include <QObject>
30 
31 class StelToneReproducer;
32 class StelCore;
33 class StelPainter;
34 
37 struct RCMag
38 {
39  float radius;
40  float luminance;
41 };
42 
46 class StelSkyDrawer : public QObject, protected QOpenGLFunctions
47 {
48  Q_OBJECT
49 
51  Q_PROPERTY(double relativeStarScale READ getRelativeStarScale WRITE setRelativeStarScale NOTIFY relativeStarScaleChanged)
53  Q_PROPERTY(double absoluteStarScale READ getAbsoluteStarScale WRITE setAbsoluteStarScale NOTIFY absoluteStarScaleChanged)
54  Q_PROPERTY(double twinkleAmount READ getTwinkleAmount WRITE setTwinkleAmount NOTIFY twinkleAmountChanged)
55  Q_PROPERTY(bool flagTwinkle READ getFlagTwinkle WRITE setFlagTwinkle NOTIFY flagTwinkleChanged)
56  Q_PROPERTY(int bortleScaleIndex READ getBortleScaleIndex WRITE setBortleScaleIndex NOTIFY bortleScaleIndexChanged)
57 
58  Q_PROPERTY(bool flagStarMagnitudeLimit READ getFlagStarMagnitudeLimit WRITE setFlagStarMagnitudeLimit NOTIFY flagStarMagnitudeLimitChanged)
59  Q_PROPERTY(bool flagNebulaMagnitudeLimit READ getFlagNebulaMagnitudeLimit WRITE setFlagNebulaMagnitudeLimit NOTIFY flagNebulaMagnitudeLimitChanged)
60  Q_PROPERTY(bool flagPlanetMagnitudeLimit READ getFlagPlanetMagnitudeLimit WRITE setFlagPlanetMagnitudeLimit NOTIFY flagPlanetMagnitudeLimitChanged)
61 
62  Q_PROPERTY(double customStarMagLimit READ getCustomStarMagnitudeLimit WRITE setCustomStarMagnitudeLimit NOTIFY customStarMagLimitChanged)
63  Q_PROPERTY(double customNebulaMagLimit READ getCustomNebulaMagnitudeLimit WRITE setCustomNebulaMagnitudeLimit NOTIFY customNebulaMagLimitChanged)
64  Q_PROPERTY(double customPlanetMagLimit READ getCustomPlanetMagnitudeLimit WRITE setCustomPlanetMagnitudeLimit NOTIFY customPlanetMagLimitChanged)
65 
66  Q_PROPERTY(bool flagLuminanceAdaptation READ getFlagLuminanceAdaptation WRITE setFlagLuminanceAdaptation NOTIFY flagLuminanceAdaptationChanged)
67 
68  Q_PROPERTY(double extinctionCoefficient READ getExtinctionCoefficient WRITE setExtinctionCoefficient NOTIFY extinctionCoefficientChanged)
69  Q_PROPERTY(double atmosphereTemperature READ getAtmosphereTemperature WRITE setAtmosphereTemperature NOTIFY atmosphereTemperatureChanged)
70  Q_PROPERTY(double atmospherePressure READ getAtmospherePressure WRITE setAtmospherePressure NOTIFY atmospherePressureChanged)
71 
72 public:
73 
75  StelSkyDrawer(StelCore* core);
77  ~StelSkyDrawer();
78 
80  void init();
81 
84  void update(double deltaTime);
85 
88  void preDrawPointSource(StelPainter* p);
89 
91  void postDrawPointSource(StelPainter* sPainter);
92 
101  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, unsigned int bV, bool checkInScreen=false, float twinkleFactor=1.0f)
102  {
103  return drawPointSource(sPainter, v, rcMag, colorTable[bV], checkInScreen, twinkleFactor);
104  }
105 
106  bool drawPointSource(StelPainter* sPainter, const Vec3f& v, const RCMag &rcMag, const Vec3f& bcolor, bool checkInScreen=false, float twinkleFactor=1.0f);
107 
108  void drawSunCorona(StelPainter* painter, const Vec3f& v, float radius, const Vec3f& color, const float alpha);
109 
116  void postDrawSky3dModel(StelPainter* p, const Vec3f& v, float illuminatedArea, float mag, const Vec3f& color = Vec3f(1.f,1.f,1.f));
117 
122  bool computeRCMag(float mag, RCMag*) const;
123 
129  void reportLuminanceInFov(float lum, bool fastAdaptation=false);
130 
132  void preDraw();
133 
137  static float surfacebrightnessToLuminance(float sb);
141  static float luminanceToSurfacebrightness(float lum);
142 
144  static inline float indexToBV(unsigned char bV)
145  {
146  return (float)bV*(4.f/127.f)-0.5f;
147  }
148 
150  static inline const Vec3f& indexToColor(unsigned char bV)
151  {
152  return colorTable[bV];
153  }
154 
155 public slots:
157  void setRelativeStarScale(double b=1.0) {if(b!=starRelativeScale){ starRelativeScale=b; emit relativeStarScaleChanged(b);}}
159  double getRelativeStarScale() const {return starRelativeScale;}
160 
162  void setAbsoluteStarScale(double b=1.0) {if(b!=starAbsoluteScaleF){ starAbsoluteScaleF=b; emit absoluteStarScaleChanged(b);}}
164  double getAbsoluteStarScale() const {return starAbsoluteScaleF;}
165 
167  void setTwinkleAmount(double b) {if(b!=twinkleAmount){ twinkleAmount=b; emit twinkleAmountChanged(b);}}
169  double getTwinkleAmount() const {return twinkleAmount;}
170 
172  void setFlagTwinkle(bool b) {if(b!=flagStarTwinkle){ flagStarTwinkle=b; emit flagTwinkleChanged(b);}}
174  bool getFlagTwinkle() const {return flagStarTwinkle;}
175 
178  void setFlagForcedTwinkle(bool b) {if(b!=flagForcedTwinkle){ flagForcedTwinkle=b;}}
181  bool getFlagForcedTwinkle() const {return flagForcedTwinkle;}
182 
186  void setBortleScaleIndex(int index);
189  int getBortleScaleIndex() const {return bortleScaleIndex;}
190 
194  float getLimitMagnitude() const {return limitMagnitude;}
195 
199  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
200  void setFlagStarMagnitudeLimit(bool b) {if(b!=flagStarMagnitudeLimit){ flagStarMagnitudeLimit = b; emit flagStarMagnitudeLimitChanged(b);}}
202  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
206  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
207  void setFlagNebulaMagnitudeLimit(bool b) {if(b!=flagNebulaMagnitudeLimit){ flagNebulaMagnitudeLimit = b; emit flagNebulaMagnitudeLimitChanged(b);}}
209  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
213  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM --- GZ: this was copy/paste. Track down BM's changes!!!
214  void setFlagPlanetMagnitudeLimit(bool b) {if(b!=flagPlanetMagnitudeLimit){ flagPlanetMagnitudeLimit = b; emit flagPlanetMagnitudeLimitChanged(b);}}
216  bool getFlagPlanetMagnitudeLimit() const {return flagPlanetMagnitudeLimit;}
217 
219  double getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
222  void setCustomStarMagnitudeLimit(double limit) {if(limit!=customStarMagLimit){ customStarMagLimit=limit; emit customStarMagLimitChanged(limit);}}
224  double getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
227  void setCustomNebulaMagnitudeLimit(double limit) {if(limit!=customNebulaMagLimit){ customNebulaMagLimit=limit; emit customNebulaMagLimitChanged(limit);}}
229  double getCustomPlanetMagnitudeLimit() const {return customPlanetMagLimit;}
232  void setCustomPlanetMagnitudeLimit(double limit) {if(limit!=customPlanetMagLimit){ customPlanetMagLimit=limit; emit customPlanetMagLimitChanged(limit);}}
233 
237  float getLimitLuminance() const {return limitLuminance;}
238 
240  void setFlagLuminanceAdaptation(bool b) {if(b!=flagLuminanceAdaptation){ flagLuminanceAdaptation=b; emit flagLuminanceAdaptationChanged(b);}}
242  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
243 
246  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
248  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
249 
251  void setExtinctionCoefficient(double extCoeff) {if(extCoeff!=extinction.getExtinctionCoefficient()){ extinction.setExtinctionCoefficient(extCoeff); emit extinctionCoefficientChanged(extinction.getExtinctionCoefficient());}}
253  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
255  void setAtmosphereTemperature(double celsius) {if(celsius!=refraction.getTemperature()){refraction.setTemperature(celsius); emit atmosphereTemperatureChanged(refraction.getTemperature());}}
257  double getAtmosphereTemperature() const {return refraction.getTemperature();}
259  void setAtmospherePressure(double mbar) {if(mbar!=refraction.getPressure()){ refraction.setPressure(mbar); emit atmospherePressureChanged(refraction.getPressure());}}
261  double getAtmospherePressure() const {return refraction.getPressure();}
262 
264  const Extinction& getExtinction() const {return extinction;}
266  const Refraction& getRefraction() const {return refraction;}
267 
269  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
271  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
272 signals:
274  void relativeStarScaleChanged(double b);
276  void absoluteStarScaleChanged(double b);
278  void twinkleAmountChanged(double b);
280  void flagTwinkleChanged(bool b);
282  void bortleScaleIndexChanged(int index);
283 
285  void flagStarMagnitudeLimitChanged(bool b);
287  void flagNebulaMagnitudeLimitChanged(bool b);
289  void flagPlanetMagnitudeLimitChanged(bool b);
290 
292  void customStarMagLimitChanged(double limit);
294  void customNebulaMagLimitChanged(double limit);
296  void customPlanetMagLimitChanged(double limit);
297 
299  void flagLuminanceAdaptationChanged(bool b);
300 
301  void extinctionCoefficientChanged(double coeff);
302  void atmosphereTemperatureChanged(double celsius);
303  void atmospherePressureChanged(double mbar);
304 
305 private:
306  // Debug
307  float reverseComputeRCMag(float rmag) const;
308 
310  float computeLimitMagnitude() const;
311 
313  float computeLimitLuminance() const;
314 
316  float getMaxAdaptFov(void) const {return maxAdaptFov;}
321  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
322 
324  float getMinAdaptFov(void) const {return minAdaptFov;}
329  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
330 
332  void setInputScale(float in) {inScale = in;}
334  float getInputScale() const {return inScale;}
335 
339  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
340 
344  float pointSourceLuminanceToMag(float lum);
345 
349  float pointSourceMagToLnLuminance(float mag) const;
350 
353  float findWorldLumForMag(float mag, float targetRadius);
354 
355  StelCore* core;
356  StelToneReproducer* eye;
357 
358  Extinction extinction;
359  Refraction refraction;
360 
361  float maxAdaptFov, minAdaptFov, lnfovFactor;
362  bool flagStarTwinkle;
363  bool flagForcedTwinkle;
364  double twinkleAmount;
365 
368  bool flagHasAtmosphere;
369 
372  bool flagStarMagnitudeLimit;
375  bool flagNebulaMagnitudeLimit;
378  bool flagPlanetMagnitudeLimit;
379 
380  double starRelativeScale;
381  double starAbsoluteScaleF;
382 
383  float starLinearScale; // optimization variable
384 
386  float limitMagnitude;
387 
389  float limitLuminance;
390 
395  double customStarMagLimit;
401  // GZ To explain: we have 3 limits for stars, nebulae, planets. It's easier to maintain the pretty similar code in 1 place.
402  double customNebulaMagLimit;
407  double customPlanetMagLimit;
408 
410  StelTextureSP texHalo;
411 
413  void initColorTableFromConfigFile(class QSettings* conf);
414 
416  static Vec3f colorTable[128];
417 
419  int bortleScaleIndex;
420 
422  float inScale;
423 
424  // Variables used for GL optimization when displaying point sources
427  struct StarVertex {
428  Vec2f pos;
429  unsigned char color[4];
430  };
431 
433  StarVertex* vertexArray;
434 
436  unsigned char* textureCoordArray;
437 
438  class QOpenGLShaderProgram* starShaderProgram;
439  struct StarShaderVars {
440  int projectionMatrix;
441  int texCoord;
442  int pos;
443  int color;
444  int texture;
445  };
446  StarShaderVars starShaderVars;
447 
449  unsigned int nbPointSources;
451  unsigned int maxPointSources;
452 
454  float maxLum;
456  float oldLum;
457 
459  StelTextureSP texBigHalo;
460  StelTextureSP texSunHalo;
461  StelTextureSP texSunCorona;
462 
463  bool flagLuminanceAdaptation;
464 
465  float big3dModelHaloRadius;
466 };
467 
468 #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.