Stellarium 0.15.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)
100  , defaultAngleForGravityText(0.f)
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  , widthStretch(1.f) {;}
111 
112  Vector4<int> viewportXywh;
113  float fov;
117  float zNear, zFar;
120  float viewportFovDiameter;
122  bool flipHorz, flipVert;
124  float widthStretch;
125  };
126 
128  virtual ~StelProjector() {}
129 
131  // Methods which must be reimplemented by all instance of StelProjector
133  virtual QString getNameI18() const = 0;
135  virtual QString getDescriptionI18() const {return "No description";}
137  QString getHtmlSummary() const;
139  virtual float getMaxFov() const = 0;
146  virtual bool forward(Vec3f& v) const = 0;
148  virtual bool backward(Vec3d& v) const = 0;
150  virtual float deltaZoom(float fov) const = 0;
151 
155  bool intersectViewportDiscontinuity(const Vec3d& p1, const Vec3d& p2) const;
156  bool intersectViewportDiscontinuity(const SphericalCap& cap) const;
157 
159  virtual float fovToViewScalingFactor(float fov) const = 0;
161  virtual float viewScalingFactorToFov(float vsf) const = 0;
162 
166  bool getFlagGravityLabels() const;
167 
169  const Vec4i& getViewport() const;
170 
172  Vec2f getViewportCenter() const;
173  Vec2f getViewportCenterOffset() const;
174 
176  int getViewportPosX() const;
178  int getViewportPosY() const;
180  int getViewportWidth() const;
182  int getViewportHeight() const;
183 
185  float getDevicePixelsPerPixel() const {return devicePixelsPerPixel;}
186 
192  SphericalRegionP getViewportConvexPolygon(float marginX=0., float marginY=0.) const;
193 
195  const SphericalCap& getBoundingCap() const;
196 
198  float getPixelPerRadAtCenter() const;
199 
201  float getFov() const;
202 
204  bool needGlFrontFaceCW() const;
205 
207  // Full projection methods
210  bool checkInViewport(const Vec3d& pos) const;
211 
214  bool checkInViewport(const Vec3f& pos) const;
215 
218  Vec3d viewPortIntersect(const Vec3d& p1, const Vec3d& p2) const;
219 
224  bool project(const Vec3d& v, Vec3d& win) const;
225 
230  bool project(const Vec3f& v, Vec3f& win) const;
231 
232  virtual void project(int n, const Vec3d* in, Vec3f* out);
233 
234  virtual void project(int n, const Vec3f* in, Vec3f* out);
235 
239  bool projectInPlace(Vec3d& vd) const;
240 
244  bool projectInPlace(Vec3f& v) const;
245 
250  bool projectCheck(const Vec3d& v, Vec3d& win) const;
251 
256  bool projectCheck(const Vec3f& v, Vec3f& win) const;
257 
262  bool unProject(const Vec3d& win, Vec3d& v) const;
263  bool unProject(double x, double y, Vec3d& v) const;
264 
271  bool projectLineCheck(const Vec3d& v1, Vec3d& win1, const Vec3d& v2, Vec3d& win2) const;
272 
274  ModelViewTranformP getModelViewTransform() const;
275 
277  Mat4f getProjectionMatrix() const;
278 
281  static const QString maskTypeToString(StelProjectorMaskType type);
283  static StelProjectorMaskType stringToMaskType(const QString &s);
284 
287 
288 protected:
290  StelProjector(ModelViewTranformP amodelViewTransform)
291  : modelViewTransform(amodelViewTransform),
292  flipHorz(0.f),
293  flipVert(0.f),
294  pixelPerRad(0.f),
295  maskType(MaskNone),
296  zNear(0.f),
297  oneOverZNearMinusZFar(0.f),
298  viewportFovDiameter(0.f),
299  gravityLabels(true),
300  defaultAngleForGravityText(0.f),
301  devicePixelsPerPixel(1.f),
302  widthStretch(1.0f) {;}
303 
305  virtual bool hasDiscontinuity() const =0;
309  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& p1, const Vec3d& p2) const = 0;
310 
312  virtual bool intersectViewportDiscontinuityInternal(const Vec3d& capN, double capD) const = 0;
313 
315  virtual void computeBoundingCap();
316 
317  ModelViewTranformP modelViewTransform; // Operator to apply (if not NULL) before the modelview projection step
318 
319  float flipHorz,flipVert; // Whether to flip in horizontal or vertical directions
320  float pixelPerRad; // pixel per rad at the center of the viewport disk
321  StelProjectorMaskType maskType; // The current projector mask
322  float zNear, oneOverZNearMinusZFar; // Near and far clipping planes
323  Vec4i viewportXywh; // Viewport parameters
324  Vec2f viewportCenter; // Viewport center in screen pixel
325  Vec2f viewportCenterOffset; // Viewport center's offset in fractions of screen width/height. Usable e.g. in cylindrical projection to move horizon down.
326  // Currently only Y shift is fully implemented, X shift likely not too meaningful.
327  float viewportFovDiameter; // diameter of the FOV disk in pixel
328  bool gravityLabels; // should label text align with the horizon?
329  float defaultAngleForGravityText; // a rotation angle to apply to gravity text (only if gravityLabels is set to false)
330  SphericalCap boundingCap; // Bounding cap of the whole viewport
331  float devicePixelsPerPixel; // The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina screens)
332  float widthStretch; // A factor to adapt to special installation setups, e.g. multi-projector with edge blending. Allow to stretch/squeeze projected content. Larger than 1 means the image is stretched wider.
333 private:
335  void init(const StelProjectorParams& param);
336 };
337 
338 #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 widthStretch
The number of device pixel per "Device Independent Pixels" (value is usually 1, but 2 for mac retina ...
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.
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.
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.
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.