Stellarium 0.15.0
StelProjector.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2003 Fabien Chereau
4  * Copyright (C) 2012 Matthew Gates
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _STELPROJECTOR_HPP_
22 #define _STELPROJECTOR_HPP_
23 
24 #include "StelProjectorType.hpp"
25 #include "VecMath.hpp"
26 #include "StelSphereGeometry.hpp"
27 
38 {
39 public:
40  friend class StelPainter;
41  friend class StelCore;
42 
43  class ModelViewTranform;
46  typedef QSharedPointer<ModelViewTranform> ModelViewTranformP;
47 
51  {
52  public:
53  ModelViewTranform() {;}
54  virtual ~ModelViewTranform() {;}
55  virtual void forward(Vec3d&) const =0;
56  virtual void backward(Vec3d&) const =0;
57  virtual void forward(Vec3f&) const =0;
58  virtual void backward(Vec3f&) const =0;
59 
60  virtual void combine(const Mat4d&)=0;
61  virtual ModelViewTranformP clone() const=0;
62 
63  virtual Mat4d getApproximateLinearTransfo() const=0;
64  };
65 
67  {
68  public:
69  Mat4dTransform(const Mat4d& m);
70  void forward(Vec3d& v) const;
71  void backward(Vec3d& v) const;
72  void forward(Vec3f& v) const;
73  void backward(Vec3f& v) const;
74  void combine(const Mat4d& m);
75  Mat4d getApproximateLinearTransfo() const;
76  ModelViewTranformP clone() const;
77 
78  private:
80  Mat4d transfoMat;
81  Mat4f transfoMatf;
82  };
83 
87  {
90  };
91 
95  {
97  : viewportXywh(0, 0, 256, 256)
98  , fov(60.f)
99  , gravityLabels(false)
101  , maskType(MaskNone)
102  , zNear(0.f)
103  , zFar(0.f)
104  , viewportCenter(128.f, 128.f)
105  , viewportCenterOffset(0.f, 0.f)
106  , viewportFovDiameter(0.f)
107  , flipHorz(false)
108  , flipVert(false)
109  , devicePixelsPerPixel(1.f) {;}
110 
111  Vector4<int> viewportXywh;
112  float fov;
116  float zNear, zFar;
119  float viewportFovDiameter;
121  bool flipHorz, flipVert;
123  };
124 
126  virtual ~StelProjector() {}
127 
129  // Methods which must be reimplemented by all instance of StelProjector
131  virtual QString getNameI18() const = 0;
133  virtual QString getDescriptionI18() const {return "No description";}
135  QString getHtmlSummary() const;
137  virtual float getMaxFov() const = 0;
144  virtual bool forward(Vec3f& v) const = 0;
146  virtual bool backward(Vec3d& v) const = 0;
148  virtual float deltaZoom(float fov) const = 0;
149 
153  bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2) const;
154  bool intersectViewportDiscontinuity(const SphericalCap& cap) const;
155 
157  virtual float fovToViewScalingFactor(float fov) const = 0;
159  virtual float viewScalingFactorToFov(float vsf) const = 0;
160 
164  bool getFlagGravityLabels() const;
165 
167  const Vec4i& getViewport() const;
168 
170  Vec2f getViewportCenter() const;
171 
173  int getViewportPosX() const;
175  int getViewportPosY() const;
177  int getViewportWidth() const;
179  int getViewportHeight() const;
180 
182  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
183 
189  SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
190 
192  const SphericalCap& getBoundingCap() const;
193 
195  float getPixelPerRadAtCenter() const;
196 
198  float getFov() const;
199 
201  bool needGlFrontFaceCW() const;
202 
204  // Full projection methods
207  bool checkInViewport(const Vec3d& pos) const;
208 
211  bool checkInViewport(const Vec3f& pos) const;
212 
215  Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
216 
221  bool project(const Vec3d& v, Vec3d& win) const;
222 
227  bool project(const Vec3f& v, Vec3f& win) const;
228 
229  virtual void project(int n, const Vec3d* in, Vec3f* out);
230 
231  virtual void project(int n, const Vec3f* in, Vec3f* out);
232 
236  bool projectInPlace(Vec3d& vd) const;
237 
241  bool projectInPlace(Vec3f& v) const;
242 
247  bool projectCheck(const Vec3d& v, Vec3d& win) const;
248 
253  bool projectCheck(const Vec3f& v, Vec3f& win) const;
254 
259  bool unProject(const Vec3d& win, Vec3d& v) const;
260  bool unProject(double x, double y, Vec3d& v) const;
261 
268  bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
269 
271  ModelViewTranformP getModelViewTransform() const;
272 
274  Mat4f getProjectionMatrix() const;
275 
278  static const QString maskTypeToString(StelProjectorMaskType type);
280  static StelProjectorMaskType stringToMaskType(const QString &s);
281 
284 
285 protected:
287  StelProjector(ModelViewTranformP amodelViewTransform)
288  : modelViewTransform(amodelViewTransform),
289  flipHorz(0.f),
290  flipVert(0.f),
291  pixelPerRad(0.f),
292  maskType(MaskNone),
293  zNear(0.f),
294  oneOverZNearMinusZFar(0.f),
295  viewportFovDiameter(0.f),
296  gravityLabels(true),
297  defaultAngleForGravityText(0.f),
298  devicePixelsPerPixel(1.f) {;}
299 
301  virtual bool hasDiscontinuity() const =0;
305  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
306 
308  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
309 
311  virtual void computeBoundingCap();
312 
313  ModelViewTranformP modelViewTransform; // Operator to apply (if not NULL) before the modelview projection step
314 
315  float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
316  float pixelPerRad; // pixel per rad at the center of the viewport disk
317  StelProjectorMaskType maskType; // The current projector mask
318  float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
319  Vec4i viewportXywh; // Viewport parameters
320  Vec2f viewportCenter; // Viewport center in screen pixel
321  Vec2f viewportCenterOffset; // Viewport center's offset in fractions of screen width/height. Usable e.g. in cylindrical projection to move horizon down.
322  // Currently only Y shift is fully implemented, X shift likely not too meaningful.
323  float viewportFovDiameter; // diameter of the FOV disk in pixel
324  bool gravityLabels; // should label text align with the horizon?
325  float defaultAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
326  SphericalCap boundingCap; // Bounding cap of the whole viewport
327  float devicePixelsPerPixel; // The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina screens)
328 
329 private:
331  void init(const StelProjectorParams& param);
332 };
333 
334 #endif // _STELPROJECTOR_HPP_
Regular - no mask.
bool project(const Vec3d &v, Vec3d &win) const
Project the vector v from the current frame into the viewport.
virtual float deltaZoom(float fov) const =0
Return the small zoom increment to use at the given FOV for nice movements.
int getViewportWidth() const
Get the viewport width in pixels.
Mat4f getProjectionMatrix() const
Get the current projection matrix.
float defaultAngleForGravityText
the flag to use gravity labels or not
StelProjectorMaskType
Define viewport mask types.
int getViewportPosX() const
Get the horizontal viewport offset in pixels.
Vec2f getViewportCenter() const
Get the center of the viewport relative to the lower left corner of the screen.
A shared pointer on a SphericalRegion.
virtual bool forward(Vec3f &v) const =0
Apply the transformation in the forward direction in place.
Allows to define non linear operations in addition to the standard linear (Matrix 4d) ModelView trans...
SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const
Return a convex polygon on the sphere which includes the viewport in the current frame.
A SphericalCap is defined by a direction and an aperture.
bool projectCheck(const Vec3d &v, Vec3d &win) const
Project the vector v from the current frame into the viewport.
virtual ~StelProjector()
Destructor.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual float fovToViewScalingFactor(float fov) const =0
Convert a Field Of View radius value in radians in ViewScalingFactor (used internally) ...
StelProjectorMaskType maskType
a rotation angle to apply to gravity text (only if gravityLabels is set to false) ...
virtual bool intersectViewportDiscontinuityInternal(const Vec3d &p1, const Vec3d &p2) const =0
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
bool projectInPlace(Vec3d &vd) const
Project the vector v from the current frame into the viewport.
ModelViewTranformP getModelViewTransform() const
Get the current model view matrix.
float viewportFovDiameter
Viewport center's offset in fractions of screen width/height.
bool unProject(const Vec3d &win, Vec3d &v) const
Project the vector v from the viewport frame into the current frame.
const Vec4i & getViewport() const
Get the lower left corner of the viewport and the width, height.
float devicePixelsPerPixel
Whether to flip in horizontal or vertical directions.
Vec2f viewportCenterOffset
Viewport center in screen pixel.
bool flipHorz
diameter of the FOV disk in pixel
StelProjector(ModelViewTranformP amodelViewTransform)
Private constructor. Only StelCore can create instances of StelProjector.
float zNear
The current projector mask.
const SphericalCap & getBoundingCap() const
Return a SphericalCap containing the whole viewport.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
Provide the main interface to all operations of projecting coordinates from sky to screen...
For disk viewport mode (circular mask to seem like bins/telescope)
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
bool needGlFrontFaceCW() const
Get whether front faces need to be oriented in the clockwise direction.
static StelProjectorMaskType stringToMaskType(const QString &s)
Get a StelProjectorMaskType from a string description.
int getViewportHeight() const
Get the viewport height in pixels.
float getDevicePixelsPerPixel() const
Get the number of device pixels per "Device Independent Pixels" (value is usually 1...
Vec2f viewportCenter
Near and far clipping planes.
float getFov() const
Get the current FOV diameter in degrees.
bool checkInViewport(const Vec3d &pos) const
Check to see if a 2d position is inside the viewport.
virtual bool hasDiscontinuity() const =0
Return whether the projection presents discontinuities. Used for optimization.
virtual bool backward(Vec3d &v) const =0
Apply the transformation in the backward projection in place.
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
Vec3d viewPortIntersect(const Vec3d &p1, const Vec3d &p2) const
Return the position where the 2 2D point p1 and p2 cross the viewport edge P1 must be inside the view...
QString getHtmlSummary() const
Get a HTML version of the short description for this projection type.
virtual void computeBoundingCap()
Initialize the bounding cap.
StelProjectorMaskType getMaskType(void) const
Get the current type of the mask if any.
bool getFlagGravityLabels() const
Get the current state of the flag which decides whether to arrage labels so that they are aligned wit...
Define the StelProjectorP type.
float getPixelPerRadAtCenter() const
Get size of a radian in pixels at the center of the viewport disk.
Contains all the param needed to initialize a StelProjector.
bool intersectViewportDiscontinuity(const Vec3d &p1, const Vec3d &p2) const
Determine whether a great circle connection p1 and p2 intersects with a projection discontinuity...
virtual float getMaxFov() const =0
Get the maximum FOV apperture in degree.
float fov
posX, posY, width, height
virtual QString getNameI18() const =0
Get a human-readable name for this projection type.
Define all SphericalGeometry primitives as well as the SphericalRegionP type.
int getViewportPosY() const
Get the vertical viewport offset in pixels.
virtual float viewScalingFactorToFov(float vsf) const =0
Convert a ViewScalingFactor value (used internally) in Field Of View radius in radians.
bool projectLineCheck(const Vec3d &v1, Vec3d &win1, const Vec3d &v2, Vec3d &win2) const
Project the vectors v1 and v2 from the current frame into the viewport.
static const QString maskTypeToString(StelProjectorMaskType type)
Get a string description of a StelProjectorMaskType.