Stellarium 0.13.2
RefractionExtinction.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2010 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  * Refraction and extinction computations.
20  * Implementation: 2010-03-23 GZ=Georg Zotti, Georg.Zotti@univie.ac.at
21  * 2010-12 FC split into 2 classes, implemented Refraction */
22 
23 #ifndef _REFRACTIONEXTINCTION_HPP_
24 #define _REFRACTIONEXTINCTION_HPP_
25 // USABILITY: added 3 more flags/switches in GUI:
26 // Temperature [C] [influences refraction]
27 // Pressure [mbar] [influences refraction]
28 // extinction Coeff. k=0...(0.01)...1, [if k=0, no ext. effect]
29 // SUGGESTION: Allow Temperature/Pressure/ex.Coeff./LightPollution set in the landscape files
30 
31 #include "VecMath.hpp"
32 #include "StelProjector.hpp"
33 
46 {
47 public:
53  };
54 
55  Extinction();
56 
61  void forward(const Vec3d& altAzPos, float* mag) const
62  {
63  Q_ASSERT(std::fabs(altAzPos.length()-1.f)<0.001f);
64  *mag += airmass(altAzPos[2], false) * ext_coeff;
65  }
66 
67  void forward(const Vec3f& altAzPos, float* mag) const
68  {
69  Q_ASSERT(std::fabs(altAzPos.length()-1.f)<0.001f);
70  *mag += airmass(altAzPos[2], false) * ext_coeff;
71  }
72 
76  void backward(const Vec3d& altAzPos, float* mag) const
77  {
78  *mag -= airmass(altAzPos[2], false) * ext_coeff;
79  }
80 
81  void backward(const Vec3f& altAzPos, float* mag) const
82  {
83  *mag -= airmass(altAzPos[2], false) * ext_coeff;
84  }
85 
88  void setExtinctionCoefficient(float k) { ext_coeff=k; }
89  float getExtinctionCoefficient() const {return ext_coeff;}
90 
91  void setUndergroundExtinctionMode(UndergroundExtinctionMode mode) {undergroundExtinctionMode=mode;}
92  UndergroundExtinctionMode getUndergroundExtinctionMode() const {return undergroundExtinctionMode;}
93 
94 private:
102  float airmass(float cosZ, const bool apparent_z=true) const;
103 
105  float ext_coeff;
106 
108  UndergroundExtinctionMode undergroundExtinctionMode;
109 };
110 
120 
122 {
123 public:
124  Refraction();
125 
129  void forward(Vec3d& altAzPos) const;
130 
134  void backward(Vec3d& altAzPos) const;
135 
139  void forward(Vec3f& altAzPos) const;
140 
144  void backward(Vec3f& altAzPos) const;
145 
146  void combine(const Mat4d& m)
147  {
148  setPreTransfoMat(preTransfoMat*m);
149  }
150 
151  Mat4d getApproximateLinearTransfo() const {return postTransfoMat*preTransfoMat;}
152 
153  StelProjector::ModelViewTranformP clone() const {Refraction* refr = new Refraction(); *refr=*this; return StelProjector::ModelViewTranformP(refr);}
154 
156  void setPressure(float p_mbar);
157  float getPressure() const {return pressure;}
158 
160  void setTemperature(float t_C);
161  float getTemperature() const {return temperature;}
162 
164  void setPreTransfoMat(const Mat4d& m);
165  void setPostTransfoMat(const Mat4d& m);
166 
167 private:
169  void updatePrecomputed();
170 
171  void innerRefractionForward(Vec3d& altAzPos) const;
172  void innerRefractionBackward(Vec3d& altAzPos) const;
173 
176  float pressure;
178  float temperature;
180  float press_temp_corr_Saemundson;
182  float press_temp_corr_Bennett;
183 
185  Mat4d preTransfoMat;
186  Mat4d invertPreTransfoMat;
187  Mat4f preTransfoMatf;
188  Mat4f invertPreTransfoMatf;
189 
191  Mat4d postTransfoMat;
192  Mat4d invertPostTransfoMat;
193  Mat4f postTransfoMatf;
194  Mat4f invertPostTransfoMatf;
195 };
196 
197 #endif // _REFRACTIONEXTINCTION_HPP_
void setExtinctionCoefficient(float k)
Set visual extinction coefficient (mag/airmass), influences extinction computation.
void forward(Vec3d &altAzPos) const
Apply refraction.
void backward(const Vec3d &altAzPos, float *mag) const
Compute inverse extinction effect for arrays of size.
This class performs extinction computations, following literature from atmospheric optics and astrono...
void backward(Vec3d &altAzPos) const
Remove refraction from position ("reduce").
This class performs refraction computations, following literature from atmospheric optics and astrono...
UndergroundExtinctionMode
Define the extinction strategy for rendering underground objects (usefull when ground is not rendered...
Maximum extinction: coef 42, i.e practically invisible.
void setPressure(float p_mbar)
Set surface air pressure (mbars), influences refraction computation.
void setPreTransfoMat(const Mat4d &m)
Set the transformation matrices used to transform input vector to AltAz frame.
Zero extinction: stars visible in full brightness.
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
void setTemperature(float t_C)
Set surface air temperature (degrees Celsius), influences refraction computation. ...
void forward(const Vec3d &altAzPos, float *mag) const
Compute extinction effect for arrays of size.
Mirror the extinction for the same altutide above the ground.