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  Vec2f getViewportCenterOffset() const;
172 
174  int getViewportPosX() const;
176  int getViewportPosY() const;
178  int getViewportWidth() const;
180  int getViewportHeight() const;
181 
183  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
184 
190  SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
191 
193  const SphericalCap& getBoundingCap() const;
194 
196  float getPixelPerRadAtCenter() const;
197 
199  float getFov() const;
200 
202  bool needGlFrontFaceCW() const;
203 
205  // Full projection methods
208  bool checkInViewport(const Vec3d& pos) const;
209 
212  bool checkInViewport(const Vec3f& pos) const;
213 
216  Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
217 
222  bool project(const Vec3d& v, Vec3d& win) const;
223 
228  bool project(const Vec3f& v, Vec3f& win) const;
229 
230  virtual void project(int n, const Vec3d* in, Vec3f* out);
231 
232  virtual void project(int n, const Vec3f* in, Vec3f* out);
233 
237  bool projectInPlace(Vec3d& vd) const;
238 
242  bool projectInPlace(Vec3f& v) const;
243 
248  bool projectCheck(const Vec3d& v, Vec3d& win) const;
249 
254  bool projectCheck(const Vec3f& v, Vec3f& win) const;
255 
260  bool unProject(const Vec3d& win, Vec3d& v) const;
261  bool unProject(double x, double y, Vec3d& v) const;
262 
269  bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
270 
272  ModelViewTranformP getModelViewTransform() const;
273 
275  Mat4f getProjectionMatrix() const;
276 
279  static const QString maskTypeToString(StelProjectorMaskType type);
281  static StelProjectorMaskType stringToMaskType(const QString &s);
282 
285 
286 protected:
288  StelProjector(ModelViewTranformP amodelViewTransform)
289  : modelViewTransform(amodelViewTransform),
290  flipHorz(0.f),
291  flipVert(0.f),
292  pixelPerRad(0.f),
293  maskType(MaskNone),
294  zNear(0.f),
295  oneOverZNearMinusZFar(0.f),
296  viewportFovDiameter(0.f),
297  gravityLabels(true),
298  defaultAngleForGravityText(0.f),
299  devicePixelsPerPixel(1.f) {;}
300 
302  virtual bool hasDiscontinuity() const =0;
306  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
307 
309  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
310 
312  virtual void computeBoundingCap();
313 
314  ModelViewTranformP modelViewTransform; // Operator to apply (if not NULL) before the modelview projection step
315 
316  float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
317  float pixelPerRad; // pixel per rad at the center of the viewport disk
318  StelProjectorMaskType maskType; // The current projector mask
319  float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
320  Vec4i viewportXywh; // Viewport parameters
321  Vec2f viewportCenter; // Viewport center in screen pixel
322  Vec2f viewportCenterOffset; // Viewport center's offset in fractions of screen width/height. Usable e.g. in cylindrical projection to move horizon down.
323  // Currently only Y shift is fully implemented, X shift likely not too meaningful.
324  float viewportFovDiameter; // diameter of the FOV disk in pixel
325  bool gravityLabels; // should label text align with the horizon?
326  float defaultAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
327  SphericalCap boundingCap; // Bounding cap of the whole viewport
328  float devicePixelsPerPixel; // The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina screens)
329 
330 private:
332  void init(const StelProjectorParams& param);
333 };
334 
335 #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.