Stellarium  0.16.1
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;}
191  float getNELMFromBortleScale() const;
192 
196  float getLimitMagnitude() const {return limitMagnitude;}
197 
201  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
202  void setFlagStarMagnitudeLimit(bool b) {if(b!=flagStarMagnitudeLimit){ flagStarMagnitudeLimit = b; emit flagStarMagnitudeLimitChanged(b);}}
204  bool getFlagStarMagnitudeLimit() const {return flagStarMagnitudeLimit;}
208  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM
209  void setFlagNebulaMagnitudeLimit(bool b) {if(b!=flagNebulaMagnitudeLimit){ flagNebulaMagnitudeLimit = b; emit flagNebulaMagnitudeLimitChanged(b);}}
211  bool getFlagNebulaMagnitudeLimit() const {return flagNebulaMagnitudeLimit;}
215  // FIXME: Exposed to scripts - make sure it synchs with the GUI. --BM --- GZ: this was copy/paste. Track down BM's changes!!!
216  void setFlagPlanetMagnitudeLimit(bool b) {if(b!=flagPlanetMagnitudeLimit){ flagPlanetMagnitudeLimit = b; emit flagPlanetMagnitudeLimitChanged(b);}}
218  bool getFlagPlanetMagnitudeLimit() const {return flagPlanetMagnitudeLimit;}
219 
221  double getCustomStarMagnitudeLimit() const {return customStarMagLimit;}
224  void setCustomStarMagnitudeLimit(double limit) {if(limit!=customStarMagLimit){ customStarMagLimit=limit; emit customStarMagLimitChanged(limit);}}
226  double getCustomNebulaMagnitudeLimit() const {return customNebulaMagLimit;}
229  void setCustomNebulaMagnitudeLimit(double limit) {if(limit!=customNebulaMagLimit){ customNebulaMagLimit=limit; emit customNebulaMagLimitChanged(limit);}}
231  double getCustomPlanetMagnitudeLimit() const {return customPlanetMagLimit;}
234  void setCustomPlanetMagnitudeLimit(double limit) {if(limit!=customPlanetMagLimit){ customPlanetMagLimit=limit; emit customPlanetMagLimitChanged(limit);}}
235 
239  float getLimitLuminance() const {return limitLuminance;}
240 
242  void setFlagLuminanceAdaptation(bool b) {if(b!=flagLuminanceAdaptation){ flagLuminanceAdaptation=b; emit flagLuminanceAdaptationChanged(b);}}
244  bool getFlagLuminanceAdaptation() const {return flagLuminanceAdaptation;}
245 
248  void setFlagHasAtmosphere(bool b) {flagHasAtmosphere=b;}
250  bool getFlagHasAtmosphere() const {return flagHasAtmosphere;}
251 
253  void setExtinctionCoefficient(double extCoeff) {if(extCoeff!=extinction.getExtinctionCoefficient()){ extinction.setExtinctionCoefficient(extCoeff); emit extinctionCoefficientChanged(extinction.getExtinctionCoefficient());}}
255  double getExtinctionCoefficient() const {return extinction.getExtinctionCoefficient();}
257  void setAtmosphereTemperature(double celsius) {if(celsius!=refraction.getTemperature()){refraction.setTemperature(celsius); emit atmosphereTemperatureChanged(refraction.getTemperature());}}
259  double getAtmosphereTemperature() const {return refraction.getTemperature();}
261  void setAtmospherePressure(double mbar) {if(mbar!=refraction.getPressure()){ refraction.setPressure(mbar); emit atmospherePressureChanged(refraction.getPressure());}}
263  double getAtmospherePressure() const {return refraction.getPressure();}
264 
266  const Extinction& getExtinction() const {return extinction;}
268  const Refraction& getRefraction() const {return refraction;}
269 
271  float getBig3dModelHaloRadius() const {return big3dModelHaloRadius;}
273  void setBig3dModelHaloRadius(float r) {big3dModelHaloRadius=r;}
274 signals:
276  void relativeStarScaleChanged(double b);
278  void absoluteStarScaleChanged(double b);
280  void twinkleAmountChanged(double b);
282  void flagTwinkleChanged(bool b);
284  void bortleScaleIndexChanged(int index);
285 
287  void flagStarMagnitudeLimitChanged(bool b);
289  void flagNebulaMagnitudeLimitChanged(bool b);
291  void flagPlanetMagnitudeLimitChanged(bool b);
292 
294  void customStarMagLimitChanged(double limit);
296  void customNebulaMagLimitChanged(double limit);
298  void customPlanetMagLimitChanged(double limit);
299 
301  void flagLuminanceAdaptationChanged(bool b);
302 
303  void extinctionCoefficientChanged(double coeff);
304  void atmosphereTemperatureChanged(double celsius);
305  void atmospherePressureChanged(double mbar);
306 
307 private:
308  // Debug
309  float reverseComputeRCMag(float rmag) const;
310 
312  float computeLimitMagnitude() const;
313 
315  float computeLimitLuminance() const;
316 
318  float getMaxAdaptFov(void) const {return maxAdaptFov;}
323  void setMaxAdaptFov(float fov) {maxAdaptFov = (fov < 60.f) ? 60.f : fov;}
324 
326  float getMinAdaptFov(void) const {return minAdaptFov;}
331  void setMinAdaptFov(float fov) {minAdaptFov = (fov > 60.f) ? 60.f : fov;}
332 
334  void setInputScale(float in) {inScale = in;}
336  float getInputScale() const {return inScale;}
337 
341  inline float pointSourceMagToLuminance(float mag) const {return std::exp(pointSourceMagToLnLuminance(mag));}
342 
346  float pointSourceLuminanceToMag(float lum);
347 
351  float pointSourceMagToLnLuminance(float mag) const;
352 
355  float findWorldLumForMag(float mag, float targetRadius);
356 
357  StelCore* core;
358  StelToneReproducer* eye;
359 
360  Extinction extinction;
361  Refraction refraction;
362 
363  float maxAdaptFov, minAdaptFov, lnfovFactor;
364  bool flagStarTwinkle;
365  bool flagForcedTwinkle;
366  double twinkleAmount;
367 
370  bool flagHasAtmosphere;
371 
374  bool flagStarMagnitudeLimit;
377  bool flagNebulaMagnitudeLimit;
380  bool flagPlanetMagnitudeLimit;
381 
382  double starRelativeScale;
383  double starAbsoluteScaleF;
384 
385  float starLinearScale; // optimization variable
386 
388  float limitMagnitude;
389 
391  float limitLuminance;
392 
397  double customStarMagLimit;
403  // GZ To explain: we have 3 limits for stars, nebulae, planets. It's easier to maintain the pretty similar code in 1 place.
404  double customNebulaMagLimit;
409  double customPlanetMagLimit;
410 
412  StelTextureSP texHalo;
413 
415  void initColorTableFromConfigFile(class QSettings* conf);
416 
418  static Vec3f colorTable[128];
419 
421  int bortleScaleIndex;
422 
424  float inScale;
425 
426  // Variables used for GL optimization when displaying point sources
429  struct StarVertex {
430  Vec2f pos;
431  unsigned char color[4];
432  };
433 
435  StarVertex* vertexArray;
436 
438  unsigned char* textureCoordArray;
439 
440  class QOpenGLShaderProgram* starShaderProgram;
441  struct StarShaderVars {
442  int projectionMatrix;
443  int texCoord;
444  int pos;
445  int color;
446  int texture;
447  };
448  StarShaderVars starShaderVars;
449 
451  unsigned int nbPointSources;
453  unsigned int maxPointSources;
454 
456  float maxLum;
458  float oldLum;
459 
461  StelTextureSP texBigHalo;
462  StelTextureSP texSunHalo;
463  StelTextureSP texSunCorona;
464 
465  bool flagLuminanceAdaptation;
466 
467  float big3dModelHaloRadius;
468 };
469 
470 #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.