• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • projections
equirectangularprojector.cpp
Go to the documentation of this file.
1 /*
2  <one line to give the program's name and a brief idea of what it does.>
3  Copyright (C) <year> <name of author>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 */
20 
21 #include "equirectangularprojector.h"
22 
23 #include "ksutils.h"
24 #include "kstarsdata.h"
25 #include "skycomponents/skylabeler.h"
26 
27 EquirectangularProjector::EquirectangularProjector(const ViewParams& p)
28  : Projector(p)
29 {
30 
31 }
32 
33 SkyMap::Projection EquirectangularProjector::type() const
34 {
35  return SkyMap::Equirectangular;
36 }
37 
38 double EquirectangularProjector::radius() const
39 {
40  return 1.0;
41 }
42 
43 Vector2f EquirectangularProjector::toScreenVec(const SkyPoint* o, bool oRefract, bool* onVisibleHemisphere) const
44 {
45  double Y, dX;
46  Vector2f p;
47 
48  oRefract &= m_vp.useRefraction;
49  if ( m_vp.useAltAz ) {
50  if ( oRefract )
51  Y = SkyPoint::refract( o->alt() ).radians(); //account for atmospheric refraction
52  else
53  Y = o->alt().radians();
54  dX = m_vp.focus->az().reduce().radians() - o->az().reduce().radians();
55 
56  p[1] = 0.5*m_vp.height - m_vp.zoomFactor*(Y - m_vp.focus->alt().radians());
57  } else {
58  dX = o->ra().reduce().radians() - m_vp.focus->ra().reduce().radians();
59  Y = o->dec().radians();
60  p[1] = 0.5*m_vp.height - m_vp.zoomFactor*(Y - m_vp.focus->dec().radians());
61  }
62 
63  dX = KSUtils::reduceAngle(dX, -dms::PI, dms::PI);
64 
65  p[0] = 0.5*m_vp.width - m_vp.zoomFactor*dX;
66 
67  if ( onVisibleHemisphere )
68  *onVisibleHemisphere = dX*dX < M_PI*M_PI/4.;
69 
70  return p;
71 }
72 
73 SkyPoint EquirectangularProjector::fromScreen(const QPointF& p, dms* LST, const dms* lat) const
74 {
75  SkyPoint result;
76 
77  //Convert pixel position to x and y offsets in radians
78  double dx = (0.5*m_vp.width - p.x())/m_vp.zoomFactor;
79  double dy = (0.5*m_vp.height - p.y())/m_vp.zoomFactor;
80 
81  if ( m_vp.useAltAz ) {
82  dms az, alt;
83  dx = -1.0*dx; //Azimuth goes in opposite direction compared to RA
84  az.setRadians( dx + m_vp.focus->az().radians() );
85  alt.setRadians( dy + m_vp.focus->alt().radians() );
86  result.setAz( az.reduce() );
87  if ( m_vp.useRefraction )
88  alt = SkyPoint::unrefract( alt );
89  result.setAlt( alt );
90  result.HorizontalToEquatorial( LST, lat );
91  return result;
92  } else {
93  dms ra, dec;
94  ra.setRadians( dx + m_vp.focus->ra().radians() );
95  dec.setRadians( dy + m_vp.focus->dec().radians() );
96  result.set( ra.reduce(), dec );
97  result.EquatorialToHorizontal( LST, lat );
98  return result;
99  }
100 }
101 
102 bool EquirectangularProjector::unusablePoint(const QPointF& p) const
103 {
104  double dx = (0.5*m_vp.width - p.x())/m_vp.zoomFactor;
105  double dy = (0.5*m_vp.height - p.y())/m_vp.zoomFactor;
106  return (dx*dx > M_PI*M_PI/4.0) || (dy*dy > M_PI*M_PI/4.0);
107 }
108 
109 QVector< Vector2f > EquirectangularProjector::groundPoly(SkyPoint* labelpoint, bool* drawLabel) const
110 {
111  float dX = m_vp.zoomFactor*M_PI/2;
112  float dY = m_vp.zoomFactor*M_PI/2;
113  float x0 = m_vp.width/2.;
114  float y0 = m_vp.width/2.;
115  if( m_vp.useAltAz ) {
116  SkyPoint belowFocus;
117  belowFocus.setAz( m_vp.focus->az().Degrees() );
118  belowFocus.setAlt( 0.0 );
119 
120  Vector2f obf = toScreenVec( &belowFocus, false );
121 
122  //If the horizon is off the bottom edge of the screen,
123  //we can return immediately
124  if ( obf.y() > m_vp.height ) {
125  if( drawLabel )
126  *drawLabel = false;
127  return QVector<Vector2f>();
128  }
129 
130  //We can also return if the horizon is off the top edge,
131  //as long as the ground poly is not being drawn
132  if ( obf.y() < 0. && m_vp.fillGround == false ) {
133  if( drawLabel )
134  *drawLabel = false;
135  return QVector<Vector2f>();
136  }
137 
138  QVector<Vector2f> ground;
139  //Construct the ground polygon, which is a simple rectangle in this case
140  ground << Vector2f( x0 - dX, obf.y() )
141  << Vector2f( x0 + dX, obf.y() )
142  << Vector2f( x0 + dX, y0 + dY )
143  << Vector2f( x0 - dX, y0 + dY );
144 
145  if( labelpoint ) {
146  QPointF pLabel( x0 -dX -50., obf.y() );
147  KStarsData *data = KStarsData::Instance();
148  *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat());
149  }
150  if( drawLabel )
151  *drawLabel = true;
152 
153  return ground;
154  } else {
155  KStarsData *data = KStarsData::Instance();
156  QVector<Vector2f> ground;
157 
158  static const QString horizonLabel = i18n("Horizon");
159  float marginLeft, marginRight, marginTop, marginBot;
160  SkyLabeler::Instance()->getMargins( horizonLabel, &marginLeft, &marginRight,
161  &marginTop, &marginBot );
162  double daz = 90.;
163  double faz = m_vp.focus->az().Degrees();
164  double az1 = faz -daz;
165  double az2 = faz +daz;
166 
167  bool allGround = true;
168  bool allSky = true;
169 
170  double inc = 1.0;
171  //Add points along horizon
172  for(double az = az1; az <= az2 + inc; az += inc) {
173  SkyPoint p = pointAt(az,data);
174  bool visible = false;
175  Vector2f o = toScreenVec(&p, false, &visible);
176  if( visible ) {
177  ground.append( o );
178  //Set the label point if this point is onscreen
179  if ( labelpoint && o.x() < marginRight && o.y() > marginTop && o.y() < marginBot )
180  *labelpoint = p;
181 
182  if ( o.y() > 0. ) allGround = false;
183  if ( o.y() < m_vp.height ) allSky = false;
184  }
185  }
186 
187  if( allSky ) {
188  if( drawLabel)
189  *drawLabel = false;
190  return QVector<Vector2f>();
191  }
192 
193  if( allGround ) {
194  ground.clear();
195  ground.append( Vector2f( x0 - dX, y0 - dY ) );
196  ground.append( Vector2f( x0 + dX, y0 - dY ) );
197  ground.append( Vector2f( x0 + dX, y0 + dY ) );
198  ground.append( Vector2f( x0 - dX, y0 + dY ) );
199  if( drawLabel)
200  *drawLabel = false;
201  return ground;
202  }
203 
204  if( labelpoint ) {
205  QPointF pLabel( x0 -dX -50., ground.last().y() );
206  KStarsData *data = KStarsData::Instance();
207  *labelpoint = fromScreen(pLabel, data->lst(), data->geo()->lat());
208  }
209  if( drawLabel )
210  *drawLabel = true;
211 
212  //Now add points along the ground
213  ground.append( Vector2f( x0 + dX, ground.last().y() ) );
214  ground.append( Vector2f( x0 + dX, y0 + dY ) );
215  ground.append( Vector2f( x0 - dX, y0 + dY ) );
216  ground.append( Vector2f( x0 - dX, ground.first().y() ) );
217  return ground;
218  }
219 }
220 
SkyMap::Projection
Projection
Definition: skymap.h:96
EquirectangularProjector::unusablePoint
virtual bool unusablePoint(const QPointF &p) const
Check if the current point on screen is a valid point on the sky.
Definition: equirectangularprojector.cpp:102
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
SkyPoint::set
void set(const dms &r, const dms &d)
Sets RA, Dec and RA0, Dec0 according to arguments.
Definition: skypoint.cpp:46
EquirectangularProjector::groundPoly
virtual QVector< Vector2f > groundPoly(SkyPoint *labelpoint=0, bool *drawLabel=0) const
Get the ground polygon.
Definition: equirectangularprojector.cpp:109
ViewParams::useRefraction
bool useRefraction
Definition: projector.h:42
KSUtils::reduceAngle
T reduceAngle(T x, T min, T max)
Put angle into range.
Definition: ksutils.h:74
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
SkyPoint::refract
static double refract(const double alt)
Apply refraction correction to altitude.
Definition: skypoint.cpp:765
SkyPoint::setAz
void setAz(dms az)
Sets Az, the Azimuth.
Definition: skypoint.h:152
ViewParams::focus
SkyPoint * focus
Definition: projector.h:45
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
EquirectangularProjector::EquirectangularProjector
EquirectangularProjector(const ViewParams &p)
Definition: equirectangularprojector.cpp:27
SkyLabeler::getMargins
void getMargins(const QString &text, float *left, float *right, float *top, float *bot)
sets four margins for help in keeping labels entirely on the screen.
Definition: skylabeler.cpp:195
EquirectangularProjector::radius
virtual double radius() const
Get the radius of this projection's sky circle.
Definition: equirectangularprojector.cpp:38
SkyLabeler::Instance
static SkyLabeler * Instance()
Definition: skylabeler.cpp:49
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
Projector
This class serves as an interface to handle projections.
Definition: projector.h:49
ViewParams::width
float width
Definition: projector.h:40
Projector::pointAt
static SkyPoint pointAt(double az, KStarsData *data)
Helper function for drawing ground.
Definition: projector.cpp:40
ViewParams::useAltAz
bool useAltAz
Definition: projector.h:43
ViewParams::height
float height
Definition: projector.h:40
SkyPoint::HorizontalToEquatorial
void HorizontalToEquatorial(const dms *LST, const dms *lat)
Determine the (RA, Dec) coordinates of the SkyPoint from its (Altitude, Azimuth) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:102
dms
An angle, stored as degrees, but expressible in many ways.
Definition: dms.h:42
EquirectangularProjector::type
virtual SkyMap::Projection type() const
Return the type of this projection.
Definition: equirectangularprojector.cpp:33
Projector::m_vp
ViewParams m_vp
Definition: projector.h:227
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
SkyPoint::EquatorialToHorizontal
void EquatorialToHorizontal(const dms *LST, const dms *lat)
Determine the (Altitude, Azimuth) coordinates of the SkyPoint from its (RA, Dec) coordinates, given the local sidereal time and the observer's latitude.
Definition: skypoint.cpp:55
SkyMap::Equirectangular
Definition: skymap.h:99
equirectangularprojector.h
PI
#define PI
Definition: satellite.cpp:43
EquirectangularProjector::fromScreen
virtual SkyPoint fromScreen(const QPointF &p, dms *LST, const dms *lat) const
Determine RA, Dec coordinates of the pixel at (dx, dy), which are the screen pixel coordinate offsets...
Definition: equirectangularprojector.cpp:73
ViewParams::zoomFactor
float zoomFactor
Definition: projector.h:41
SkyPoint::unrefract
static double unrefract(const double alt)
Remove refraction correction.
Definition: skypoint.cpp:778
EquirectangularProjector::toScreenVec
virtual Vector2f toScreenVec(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=0) const
Given the coordinates of the SkyPoint argument, determine the pixel coordinates in the SkyMap...
Definition: equirectangularprojector.cpp:43
SkyPoint::setAlt
void setAlt(dms alt)
Sets Alt, the Altitude.
Definition: skypoint.h:141
kstarsdata.h
skylabeler.h
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
ksutils.h
ViewParams
This is just a container that holds infromation needed to do projections.
Definition: projector.h:37
ViewParams::fillGround
bool fillGround
If the ground is filled, then points below horizon are invisible.
Definition: projector.h:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal