Stellarium 0.13.1
StelProjectorClasses.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2008 Stellarium Developers
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 _STELPROJECTIONS_HPP_
21 #define _STELPROJECTIONS_HPP_
22 
23 #include "StelProjector.hpp"
24 
25 #include <limits>
26 
28 {
29 public:
31  virtual QString getNameI18() const;
32  virtual QString getDescriptionI18() const;
33  virtual float getMaxFov() const {return 120.f;}
34  bool forward(Vec3f &v) const
35  {
36  const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
37  if (v[2] < 0) {
38  v[0] /= (-v[2]);
39  v[1] /= (-v[2]);
40  v[2] = r;
41  return true;
42  }
43  if (v[2] > 0) {
44  v[0] /= v[2];
45  v[1] /= v[2];
46  v[2] = r;
47  return false;
48  }
49  v[0] = std::numeric_limits<float>::max();
50  v[1] = std::numeric_limits<float>::max();
51  v[2] = r;
52  return false;
53  }
54  bool backward(Vec3d &v) const;
55  float fovToViewScalingFactor(float fov) const;
56  float viewScalingFactorToFov(float vsf) const;
57  float deltaZoom(float fov) const;
58 protected:
59  virtual bool hasDiscontinuity() const {return false;}
60  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {return false;}
61  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {return false;}
62 };
63 
65 {
66 public:
68  virtual QString getNameI18() const;
69  virtual QString getDescriptionI18() const;
70  virtual float getMaxFov() const {return 360.f;}
71  bool forward(Vec3f &v) const
72  {
73  const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
74  const float f = std::sqrt(2.f/(r*(r-v[2])));
75  v[0] *= f;
76  v[1] *= f;
77  v[2] = r;
78  return true;
79  }
80  bool backward(Vec3d &v) const;
81  float fovToViewScalingFactor(float fov) const;
82  float viewScalingFactorToFov(float vsf) const;
83  float deltaZoom(float fov) const;
84 protected:
85  virtual bool hasDiscontinuity() const {return false;}
86  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {return false;}
87  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {return false;}
88 };
89 
91 {
92 public:
94  virtual QString getNameI18() const;
95  virtual QString getDescriptionI18() const;
96  virtual float getMaxFov() const {return 235.f;}
97  bool forward(Vec3f &v) const
98  {
99  const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
100  const float h = 0.5f*(r-v[2]);
101  if (h <= 0.f) {
102  v[0] = std::numeric_limits<float>::max();
103  v[1] = std::numeric_limits<float>::max();
104  v[2] = -std::numeric_limits<float>::min();
105  return false;
106  }
107  const float f = 1.f / h;
108  v[0] *= f;
109  v[1] *= f;
110  v[2] = r;
111  return true;
112  }
113 
114  virtual void project(int n, const Vec3d* in, Vec3f* out)
115  {
116  Vec3d v;
117  for (int i = 0; i < n; ++i, ++out)
118  {
119  v = in[i];
120  modelViewTransform->forward(v);
121  out->set(v[0], v[1], v[2]);
123  out->set(viewportCenter[0] + flipHorz * pixelPerRad * (*out)[0],
124  viewportCenter[1] + flipVert * pixelPerRad * (*out)[1],
125  ((*out)[2] - zNear) * oneOverZNearMinusZFar);
126  }
127  }
128 
129  bool backward(Vec3d &v) const;
130  float fovToViewScalingFactor(float fov) const;
131  float viewScalingFactorToFov(float vsf) const;
132  float deltaZoom(float fov) const;
133 protected:
134  virtual bool hasDiscontinuity() const {return false;}
135  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {return false;}
136  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {return false;}
137 };
138 
140 {
141 public:
143  virtual QString getNameI18() const;
144  virtual QString getDescriptionI18() const;
145  virtual float getMaxFov() const {return 180.00001f;}
146  bool forward(Vec3f &v) const
147  {
148  const float rq1 = v[0]*v[0] + v[1]*v[1];
149  if (rq1 > 0.f) {
150  const float h = std::sqrt(rq1);
151  const float f = std::atan2(h,-v[2]) / h;
152  v[0] *= f;
153  v[1] *= f;
154  v[2] = std::sqrt(rq1 + v[2]*v[2]);
155  return true;
156  }
157  if (v[2] < 0.f) {
158  v[0] = 0.f;
159  v[1] = 0.f;
160  v[2] = 1.f;
161  return true;
162  }
163  v[0] = std::numeric_limits<float>::max();
164  v[1] = std::numeric_limits<float>::max();
165  v[2] = std::numeric_limits<float>::min();
166  return false;
167  }
168  bool backward(Vec3d &v) const;
169  float fovToViewScalingFactor(float fov) const;
170  float viewScalingFactorToFov(float vsf) const;
171  float deltaZoom(float fov) const;
172 protected:
173  virtual bool hasDiscontinuity() const {return false;}
174  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {return false;}
175  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {return false;}
176 };
177 
179 {
180 public:
182  virtual QString getNameI18() const;
183  virtual QString getDescriptionI18() const;
184  virtual float getMaxFov() const {return 360.f;}
185  virtual void project(int n, const Vec3d* in, Vec3f* out)
186  {
187  Vec3d v;
188  for (int i = 0; i < n; ++i)
189  {
190  v = in[i];
191  modelViewTransform->forward(v);
192  out[i].set(v[0], v[1], v[2]);
194  out[i][0] = viewportCenter[0] + flipHorz * pixelPerRad * out[i][0];
195  out[i][1] = viewportCenter[1] + flipVert * pixelPerRad * out[i][1];
196  out[i][2] = (out[i][2] - zNear) * oneOverZNearMinusZFar;
197  }
198  }
199  bool forward(Vec3f &v) const
200  {
201  // Hammer Aitoff
202  const float r = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
203  const float alpha = std::atan2(v[0],-v[2]);
204  const float cosDelta = std::sqrt(1.f-v[1]*v[1]/(r*r));
205  float z = std::sqrt(1.+cosDelta*std::cos(alpha/2.f));
206  v[0] = 2.f*M_SQRT2*cosDelta*std::sin(alpha/2.f)/z;
207  v[1] = M_SQRT2*v[1]/r/z;
208  v[2] = r;
209  return true;
210  }
211  bool backward(Vec3d &v) const;
212  float fovToViewScalingFactor(float fov) const;
213  float viewScalingFactorToFov(float vsf) const;
214  float deltaZoom(float fov) const;
215 protected:
216  virtual bool hasDiscontinuity() const {return true;}
217  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const {return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);}
218  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const
219  {
220  static const SphericalCap cap1(1,0,0);
221  static const SphericalCap cap2(-1,0,0);
222  static const SphericalCap cap3(0,0,-1);
223  SphericalCap cap(capN, capD);
224  return cap.intersects(cap1) && cap.intersects(cap2) && cap.intersects(cap2);
225  }
226 };
227 
229 {
230 public:
232  virtual QString getNameI18() const;
233  virtual QString getDescriptionI18() const;
234  virtual float getMaxFov() const {return 175.f * 4.f/3.f;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
235  bool forward(Vec3f &win) const;
236  bool backward(Vec3d &v) const;
237  float fovToViewScalingFactor(float fov) const;
238  float viewScalingFactorToFov(float vsf) const;
239  float deltaZoom(float fov) const;
240 protected:
241  virtual bool hasDiscontinuity() const {return true;}
242  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
243  {
244  return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
245  }
246  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const
247  {
248  static const SphericalCap cap1(1,0,0);
249  static const SphericalCap cap2(-1,0,0);
250  static const SphericalCap cap3(0,0,-1);
251  SphericalCap cap(capN, capD);
252  return cap.intersects(cap1) && cap.intersects(cap2) && cap.intersects(cap2);
253  }
254 };
255 
257 {
258 public:
260  virtual QString getNameI18() const;
261  virtual QString getDescriptionI18() const;
262  virtual float getMaxFov() const {return 175.f * 4.f/3.f;} // assume aspect ration of 4/3 for getting a full 360 degree horizon
263  bool forward(Vec3f &win) const;
264  bool backward(Vec3d &v) const;
265  float fovToViewScalingFactor(float fov) const;
266  float viewScalingFactorToFov(float vsf) const;
267  float deltaZoom(float fov) const;
268 protected:
269  virtual bool hasDiscontinuity() const {return true;}
270  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const
271  {
272  return p1[0]*p2[0]<0 && !(p1[2]<0 && p2[2]<0);
273  }
274  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const
275  {
276  static const SphericalCap cap1(1,0,0);
277  static const SphericalCap cap2(-1,0,0);
278  static const SphericalCap cap3(0,0,-1);
279  SphericalCap cap(capN, capD);
280  return cap.intersects(cap1) && cap.intersects(cap2) && cap.intersects(cap2);
281  }
282 };
283 
285 {
286 public:
288  virtual QString getNameI18() const;
289  virtual QString getDescriptionI18() const;
290  virtual float getMaxFov() const {return 179.9999f;}
291  bool forward(Vec3f &win) const;
292  bool backward(Vec3d &v) const;
293  float fovToViewScalingFactor(float fov) const;
294  float viewScalingFactorToFov(float vsf) const;
295  float deltaZoom(float fov) const;
296 protected:
297  virtual bool hasDiscontinuity() const {return false;}
298  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {return false;}
299  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {return false;}
300 };
301 
303 {
304 public:
306  virtual QString getNameI18() const;
307  virtual QString getDescriptionI18() const;
308  virtual float getMaxFov() const {return 360.f;}
309  bool forward(Vec3f &win) const;
310  bool backward(Vec3d &v) const;
311  float fovToViewScalingFactor(float fov) const;
312  float viewScalingFactorToFov(float vsf) const;
313  float deltaZoom(float fov) const;
314 protected:
315  virtual bool hasDiscontinuity() const {return false;}
316  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, const Vec3d&) const {Q_ASSERT(0); return false;}
317  virtual bool intersectViewportDiscontinuityInternal(const Vec3d&, double) const {Q_ASSERT(0); return false;}
318  virtual void computeBoundingCap() {;}
319 };
320 
321 #endif // _STELPROJECTIONS_HPP_
322 
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &capN, double capD) const
Determine whether a cap intersects with a projection discontinuity.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
bool forward(Vec3f &win) const
Apply the transformation in the forward direction in place.
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
bool forward(Vec3f &v) const
Apply the transformation in the forward direction in place.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
bool forward(Vec3f &win) const
Apply the transformation in the forward direction in place.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
A SphericalCap is defined by a direction and an aperture.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
bool forward(Vec3f &v) const
Apply the transformation in the forward direction in place.
bool forward(Vec3f &v) const
Apply the transformation in the forward direction in place.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &capN, double capD) const
Determine whether a cap intersects with a projection discontinuity.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
bool forward(Vec3f &win) const
Apply the transformation in the forward direction in place.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
bool forward(Vec3f &win) const
Apply the transformation in the forward direction in place.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &p1, const Vec3d &p2) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
StelProjector(ModelViewTranformP amodelViewTransform)
Private constructor. Only StelCore can create instances of StelProjector.
bool forward(Vec3f &v) const
Apply the transformation in the forward direction in place.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
Provide the main interface to all operations of projecting coordinates from sky to screen...
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &p1, const Vec3d &p2) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual QString getNameI18() const
Get a human-readable name for this projection type.
bool forward(Vec3f &v) const
Apply the transformation in the forward direction in place.
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
virtual bool hasDiscontinuity() const
Return whether the projection presents discontinuities. Used for optimization.
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
virtual void computeBoundingCap()
Initialize the bounding cap.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
bool backward(Vec3d &v) const
Apply the transformation in the backward projection in place.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, double) const
Determine whether a cap intersects with a projection discontinuity.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &, const Vec3d &) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &capN, double capD) const
Determine whether a cap intersects with a projection discontinuity.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
float deltaZoom(float fov) const
Return the small zoom increment to use at the given FOV for nice movements.
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
virtual QString getNameI18() const
Get a human-readable name for this projection type.
float fovToViewScalingFactor(float fov) const
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
virtual float getMaxFov() const
Get the maximum FOV apperture in degree.
float viewScalingFactorToFov(float vsf) const
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &p1, const Vec3d &p2) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...