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

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • projections
AbstractProjection.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2007 Inge Wallin <ingwa@kde.org>
9 // Copyright 2007-2012 Torsten Rahn <rahn@kde.org>
10 // Copyright 2012 Cezar Mocan <mocancezar@gmail.com>
11 //
12 
13 // Local
14 #include "AbstractProjection.h"
15 
16 #include "AbstractProjection_p.h"
17 
18 #include "MarbleDebug.h"
19 #include <QRegion>
20 
21 // Marble
22 #include "GeoDataLineString.h"
23 #include "GeoDataLinearRing.h"
24 #include "ViewportParams.h"
25 
26 using namespace Marble;
27 
28 AbstractProjection::AbstractProjection()
29  : d_ptr( new AbstractProjectionPrivate( this ) )
30 {
31 }
32 
33 AbstractProjection::AbstractProjection( AbstractProjectionPrivate* dd )
34  : d_ptr( dd )
35 {
36 }
37 
38 AbstractProjection::~AbstractProjection()
39 {
40 }
41 
42 AbstractProjectionPrivate::AbstractProjectionPrivate( AbstractProjection * parent )
43  : m_maxLat(0),
44  m_minLat(0),
45  q_ptr( parent)
46 {
47 }
48 
49 qreal AbstractProjection::maxValidLat() const
50 {
51  return +90.0 * DEG2RAD;
52 }
53 
54 qreal AbstractProjection::maxLat() const
55 {
56  Q_D(const AbstractProjection );
57  return d->m_maxLat;
58 }
59 
60 void AbstractProjection::setMaxLat( qreal maxLat )
61 {
62  if ( maxLat < maxValidLat() ) {
63  mDebug() << Q_FUNC_INFO << "Trying to set maxLat to a value that is out of the valid range.";
64  return;
65  }
66 
67  Q_D( AbstractProjection );
68  d->m_maxLat = maxLat;
69 }
70 
71 qreal AbstractProjection::minValidLat() const
72 {
73  return -90.0 * DEG2RAD;
74 }
75 
76 qreal AbstractProjection::minLat() const
77 {
78  Q_D( const AbstractProjection );
79  return d->m_minLat;
80 }
81 
82 void AbstractProjection::setMinLat( qreal minLat )
83 {
84  if ( minLat < minValidLat() ) {
85  mDebug() << Q_FUNC_INFO << "Trying to set minLat to a value that is out of the valid range.";
86  return;
87  }
88 
89  Q_D( AbstractProjection );
90  d->m_minLat = minLat;
91 }
92 
93 bool AbstractProjection::screenCoordinates( const qreal lon, const qreal lat,
94  const ViewportParams *viewport,
95  qreal &x, qreal &y ) const
96 {
97  bool globeHidesPoint;
98  GeoDataCoordinates geopoint(lon, lat);
99  return screenCoordinates( geopoint, viewport, x, y, globeHidesPoint );
100 }
101 
102 bool AbstractProjection::screenCoordinates( const GeoDataCoordinates &geopoint,
103  const ViewportParams *viewport,
104  qreal &x, qreal &y ) const
105 {
106  bool globeHidesPoint;
107 
108  return screenCoordinates( geopoint, viewport, x, y, globeHidesPoint );
109 }
110 
111 GeoDataLatLonAltBox AbstractProjection::latLonAltBox( const QRect& screenRect,
112  const ViewportParams *viewport ) const
113 {
114  // For the case where the whole viewport gets covered there is a
115  // pretty dirty and generic detection algorithm:
116 
117  // Move along the screenborder and save the highest and lowest lon-lat values.
118  QRect projectedRect = mapRegion( viewport ).boundingRect();
119  QRect mapRect = screenRect.intersected( projectedRect );
120 
121  GeoDataLineString boundingLineString;
122 
123  qreal lon, lat;
124 
125  for ( int x = mapRect.left(); x < mapRect.right(); x += latLonAltBoxSamplingRate ) {
126  if ( geoCoordinates( x, mapRect.bottom(), viewport, lon, lat,
127  GeoDataCoordinates::Radian ) ) {
128  boundingLineString << GeoDataCoordinates( lon, lat );
129  }
130 
131  if ( geoCoordinates( x, mapRect.top(),
132  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
133  boundingLineString << GeoDataCoordinates( lon, lat );
134  }
135  }
136 
137  if ( geoCoordinates( mapRect.right(), mapRect.top(), viewport, lon, lat,
138  GeoDataCoordinates::Radian ) ) {
139  boundingLineString << GeoDataCoordinates( lon, lat );
140  }
141 
142  if ( geoCoordinates( mapRect.right(), mapRect.bottom(),
143  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
144  boundingLineString << GeoDataCoordinates( lon, lat );
145  }
146 
147  for ( int y = mapRect.bottom(); y < mapRect.top(); y += latLonAltBoxSamplingRate ) {
148  if ( geoCoordinates( mapRect.left(), y, viewport, lon, lat,
149  GeoDataCoordinates::Radian ) ) {
150  boundingLineString << GeoDataCoordinates( lon, lat );
151  }
152 
153  if ( geoCoordinates( mapRect.right(), y,
154  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
155  boundingLineString << GeoDataCoordinates( lon, lat );
156  }
157  }
158 
159  GeoDataLatLonAltBox latLonAltBox = boundingLineString.latLonAltBox();
160 
161  // Now we need to check whether maxLat (e.g. the north pole) gets displayed
162  // inside the viewport.
163 
164  // We need a point on the screen at maxLat that definitely gets displayed:
165 
166  // FIXME: Some of the following code can be safely removed as soon as we properly handle
167  // GeoDataLinearRing::latLonAltBox().
168  qreal averageLongitude = ( latLonAltBox.west() + latLonAltBox.east() ) / 2.0;
169 
170  GeoDataCoordinates maxLatPoint( averageLongitude, maxLat(), 0.0, GeoDataCoordinates::Radian );
171  GeoDataCoordinates minLatPoint( averageLongitude, minLat(), 0.0, GeoDataCoordinates::Radian );
172 
173  qreal dummyX, dummyY; // not needed
174 
175  if ( latLonAltBox.north() > maxLat() ||
176  screenCoordinates( maxLatPoint, viewport, dummyX, dummyY ) ) {
177  latLonAltBox.setNorth( maxLat() );
178  }
179  if ( latLonAltBox.north() < minLat() ||
180  screenCoordinates( minLatPoint, viewport, dummyX, dummyY ) ) {
181  latLonAltBox.setSouth( minLat() );
182  }
183 
184  latLonAltBox.setMinAltitude( -100000000.0 );
185  latLonAltBox.setMaxAltitude( 100000000000000.0 );
186 
187  return latLonAltBox;
188 }
189 
190 
191 QRegion AbstractProjection::mapRegion( const ViewportParams *viewport ) const
192 {
193  return QRegion( mapShape( viewport ).toFillPolygon().toPolygon() );
194 }
Marble::AbstractProjectionPrivate
Definition: AbstractProjection_p.h:20
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataLatLonBox::setNorth
void setNorth(const qreal north, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:101
AbstractProjection_p.h
Marble::AbstractProjection::minValidLat
virtual qreal minValidLat() const
Definition: AbstractProjection.cpp:71
Marble::AbstractProjection::maxLat
qreal maxLat() const
Definition: AbstractProjection.cpp:54
Marble::GeoDataLatLonAltBox::setMaxAltitude
void setMaxAltitude(const qreal maxAltitude)
Definition: GeoDataLatLonAltBox.cpp:142
Marble::GeoDataLatLonBox::setSouth
void setSouth(const qreal south, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:122
Marble::AbstractProjection::latLonAltBox
virtual GeoDataLatLonAltBox latLonAltBox(const QRect &screenRect, const ViewportParams *viewport) const
Definition: AbstractProjection.cpp:111
MarbleDebug.h
AbstractProjection.h
This file contains the headers for AbstractProjection.
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
Marble::AbstractProjection::setMaxLat
void setMaxLat(qreal maxLat)
Definition: AbstractProjection.cpp:60
GeoDataLineString.h
Marble::AbstractProjection::mapRegion
QRegion mapRegion(const ViewportParams *viewport) const
Definition: AbstractProjection.cpp:191
Marble::AbstractProjection::maxValidLat
virtual qreal maxValidLat() const
Definition: AbstractProjection.cpp:49
Marble::AbstractProjection::geoCoordinates
virtual bool geoCoordinates(const int x, const int y, const ViewportParams *viewport, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const =0
Get the earth coordinates corresponding to a pixel in the map.
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:200
Marble::GeoDataLatLonAltBox::setMinAltitude
void setMinAltitude(const qreal minAltitude)
Definition: GeoDataLatLonAltBox.cpp:132
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
Marble::AbstractProjection::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, const ViewportParams *viewport, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: AbstractProjection.cpp:93
Marble::AbstractProjection::mapShape
virtual QPainterPath mapShape(const ViewportParams *viewport) const =0
GeoDataLinearRing.h
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::AbstractProjection::AbstractProjection
AbstractProjection()
Construct a new AbstractProjection.
Definition: AbstractProjection.cpp:28
Marble::AbstractProjection
A base class for all projections in Marble.
Definition: AbstractProjection.h:49
Marble::AbstractProjectionPrivate::AbstractProjectionPrivate
AbstractProjectionPrivate(AbstractProjection *parent)
Definition: AbstractProjection.cpp:42
Marble::latLonAltBoxSamplingRate
static const int latLonAltBoxSamplingRate
Definition: AbstractProjection.h:38
Marble::AbstractProjection::~AbstractProjection
virtual ~AbstractProjection()
Definition: AbstractProjection.cpp:38
Marble::AbstractProjection::minLat
qreal minLat() const
Definition: AbstractProjection.cpp:76
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:545
Marble::AbstractProjection::setMinLat
void setMinLat(qreal minLat)
Definition: AbstractProjection.cpp:82
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • 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