Stellarium 0.13.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  {
96  StelProjectorParams() : viewportXywh(0, 0, 256, 256),
97  fov(60.f),
98  gravityLabels(false),
101  viewportCenter(128.f, 128.f),
102  flipHorz(false),
103  flipVert(false),
104  devicePixelsPerPixel(1.f) {;}
105  Vector4<int> viewportXywh;
106  float fov;
110  float zNear, zFar;
113  bool flipHorz, flipVert;
115  };
116 
118  virtual ~StelProjector() {}
119 
121  // Methods which must be reimplemented by all instance of StelProjector
123  virtual QString getNameI18() const = 0;
125  virtual QString getDescriptionI18() const {return "No description";}
127  QString getHtmlSummary() const;
129  virtual float getMaxFov() const = 0;
136  virtual bool forward(Vec3f& v) const = 0;
138  virtual bool backward(Vec3d& v) const = 0;
140  virtual float deltaZoom(float fov) const = 0;
141 
145  bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2) const;
146  bool intersectViewportDiscontinuity(const SphericalCap& cap) const;
147 
149  virtual float fovToViewScalingFactor(float fov) const = 0;
151  virtual float viewScalingFactorToFov(float vsf) const = 0;
152 
156  bool getFlagGravityLabels() const;
157 
159  const Vec4i& getViewport() const;
160 
162  Vec2f getViewportCenter() const;
163 
165  int getViewportPosX() const;
167  int getViewportPosY() const;
169  int getViewportWidth() const;
171  int getViewportHeight() const;
172 
174  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
175 
181  SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
182 
184  const SphericalCap& getBoundingCap() const;
185 
187  float getPixelPerRadAtCenter() const;
188 
190  float getFov() const;
191 
193  bool needGlFrontFaceCW() const;
194 
196  // Full projection methods
199  bool checkInViewport(const Vec3d& pos) const;
200 
203  bool checkInViewport(const Vec3f& pos) const;
204 
207  Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
208 
213  bool project(const Vec3d& v, Vec3d& win) const;
214 
219  bool project(const Vec3f& v, Vec3f& win) const;
220 
221  virtual void project(int n, const Vec3d* in, Vec3f* out);
222 
223  virtual void project(int n, const Vec3f* in, Vec3f* out);
224 
228  bool projectInPlace(Vec3d& vd) const;
229 
233  bool projectInPlace(Vec3f& v) const;
234 
239  bool projectCheck(const Vec3d& v, Vec3d& win) const;
240 
245  bool projectCheck(const Vec3f& v, Vec3f& win) const;
246 
251  bool unProject(const Vec3d& win, Vec3d& v) const;
252  bool unProject(double x, double y, Vec3d& v) const;
253 
260  bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
261 
264 
266  Mat4f getProjectionMatrix() const;
267 
270  static const QString maskTypeToString(StelProjectorMaskType type);
272  static StelProjectorMaskType stringToMaskType(const QString &s);
273 
276 
277 protected:
279  StelProjector(ModelViewTranformP amodelViewTransform) : modelViewTransform(amodelViewTransform) {;}
280 
282  virtual bool hasDiscontinuity() const =0;
286  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
287 
289  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
290 
292  virtual void computeBoundingCap();
293 
294  ModelViewTranformP modelViewTransform; // Operator to apply (if not NULL) before the modelview projection step
295 
296  float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
297  float pixelPerRad; // pixel per rad at the center of the viewport disk
298  StelProjectorMaskType maskType; // The current projector mask
299  float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
300  Vec4i viewportXywh; // Viewport parameters
301  Vec2f viewportCenter; // Viewport center in screen pixel
302  float viewportFovDiameter; // diameter of the FOV disk in pixel
303  bool gravityLabels; // should label text align with the horizon?
304  float defautAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
305  SphericalCap boundingCap; // Bounding cap of the whole viewport
306  float devicePixelsPerPixel; // The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina screens)
307 
308 private:
310  void init(const StelProjectorParams& param);
311 };
312 
313 #endif // _STELPROJECTOR_HPP_
Regular - no mask.
Definition: StelProjector.hpp:88
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.
StelProjectorMaskType
Define viewport mask types.
Definition: StelProjector.hpp:86
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.
Definition: StelSphereGeometry.hpp:51
virtual bool forward(Vec3f &v) const =0
Apply the transformation in the forward direction in place.
Definition: StelProjector.hpp:50
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.
Definition: StelSphereGeometry.hpp:273
bool projectCheck(const Vec3d &v, Vec3d &win) const
Project the vector v from the current frame into the viewport.
virtual ~StelProjector()
Destructor.
Definition: StelProjector.hpp:118
Definition: StelProjector.hpp:66
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
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) ...
Definition: StelProjector.hpp:109
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 in screen pixel.
Definition: StelProjector.hpp:112
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.
Definition: StelProjector.hpp:114
bool flipHorz
diameter of the FOV disk in pixel
Definition: StelProjector.hpp:113
bool gravityLabels
FOV in degrees.
Definition: StelProjector.hpp:107
StelProjector(ModelViewTranformP amodelViewTransform)
Private constructor. Only StelCore can create instances of StelProjector.
Definition: StelProjector.hpp:279
float zNear
The current projector mask.
Definition: StelProjector.hpp:110
const SphericalCap & getBoundingCap() const
Return a SphericalCap containing the whole viewport.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:71
Provide the main interface to all operations of projecting coordinates from sky to screen...
Definition: StelProjector.hpp:37
For disk viewport mode (circular mask to seem like bins/telescope)
Definition: StelProjector.hpp:89
virtual QString getDescriptionI18() const
Get a human-readable short description for this projection type.
Definition: StelProjector.hpp:125
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...
Definition: StelProjector.hpp:174
Vec2f viewportCenter
Near and far clipping planes.
Definition: StelProjector.hpp:111
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)
Definition: StelProjector.hpp:46
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.
Definition: StelProjector.hpp:94
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
Definition: StelProjector.hpp:106
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.
float defautAngleForGravityText
the flag to use gravity labels or not
Definition: StelProjector.hpp:108
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.