Stellarium 0.13.2
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  , viewportFovDiameter(0.f)
106  , flipHorz(false)
107  , flipVert(false)
108  , devicePixelsPerPixel(1.f) {;}
109 
110  Vector4<int> viewportXywh;
111  float fov;
115  float zNear, zFar;
118  bool flipHorz, flipVert;
120  };
121 
123  virtual ~StelProjector() {}
124 
126  // Methods which must be reimplemented by all instance of StelProjector
128  virtual QString getNameI18() const = 0;
130  virtual QString getDescriptionI18() const {return "No description";}
132  QString getHtmlSummary() const;
134  virtual float getMaxFov() const = 0;
141  virtual bool forward(Vec3f& v) const = 0;
143  virtual bool backward(Vec3d& v) const = 0;
145  virtual float deltaZoom(float fov) const = 0;
146 
150  bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2) const;
151  bool intersectViewportDiscontinuity(const SphericalCap& cap) const;
152 
154  virtual float fovToViewScalingFactor(float fov) const = 0;
156  virtual float viewScalingFactorToFov(float vsf) const = 0;
157 
161  bool getFlagGravityLabels() const;
162 
164  const Vec4i& getViewport() const;
165 
167  Vec2f getViewportCenter() const;
168 
170  int getViewportPosX() const;
172  int getViewportPosY() const;
174  int getViewportWidth() const;
176  int getViewportHeight() const;
177 
179  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
180 
186  SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
187 
189  const SphericalCap& getBoundingCap() const;
190 
192  float getPixelPerRadAtCenter() const;
193 
195  float getFov() const;
196 
198  bool needGlFrontFaceCW() const;
199 
201  // Full projection methods
204  bool checkInViewport(const Vec3d& pos) const;
205 
208  bool checkInViewport(const Vec3f& pos) const;
209 
212  Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
213 
218  bool project(const Vec3d& v, Vec3d& win) const;
219 
224  bool project(const Vec3f& v, Vec3f& win) const;
225 
226  virtual void project(int n, const Vec3d* in, Vec3f* out);
227 
228  virtual void project(int n, const Vec3f* in, Vec3f* out);
229 
233  bool projectInPlace(Vec3d& vd) const;
234 
238  bool projectInPlace(Vec3f& v) const;
239 
244  bool projectCheck(const Vec3d& v, Vec3d& win) const;
245 
250  bool projectCheck(const Vec3f& v, Vec3f& win) const;
251 
256  bool unProject(const Vec3d& win, Vec3d& v) const;
257  bool unProject(double x, double y, Vec3d& v) const;
258 
265  bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
266 
269 
271  Mat4f getProjectionMatrix() const;
272 
275  static const QString maskTypeToString(StelProjectorMaskType type);
277  static StelProjectorMaskType stringToMaskType(const QString &s);
278 
281 
282 protected:
284  StelProjector(ModelViewTranformP amodelViewTransform)
285  : modelViewTransform(amodelViewTransform),
286  flipHorz(0.f),
287  flipVert(0.f),
288  pixelPerRad(0.f),
289  maskType(MaskNone),
290  zNear(0.f),
291  oneOverZNearMinusZFar(0.f),
292  viewportFovDiameter(0.f),
293  gravityLabels(true),
294  defaultAngleForGravityText(0.f),
295  devicePixelsPerPixel(1.f) {;}
296 
298  virtual bool hasDiscontinuity() const =0;
302  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
303 
305  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
306 
308  virtual void computeBoundingCap();
309 
310  ModelViewTranformP modelViewTransform; // Operator to apply (if not NULL) before the modelview projection step
311 
312  float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
313  float pixelPerRad; // pixel per rad at the center of the viewport disk
314  StelProjectorMaskType maskType; // The current projector mask
315  float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
316  Vec4i viewportXywh; // Viewport parameters
317  Vec2f viewportCenter; // Viewport center in screen pixel
318  float viewportFovDiameter; // diameter of the FOV disk in pixel
319  bool gravityLabels; // should label text align with the horizon?
320  float defaultAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
321  SphericalCap boundingCap; // Bounding cap of the whole viewport
322  float devicePixelsPerPixel; // The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina screens)
323 
324 private:
326  void init(const StelProjectorParams& param);
327 };
328 
329 #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.
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: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) ...
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.
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.
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.
float defautAngleForGravityText
the flag to use gravity labels or not
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.