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

marble

  • sources
  • kde-4.14
  • 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::repeatableX() const
94 {
95  return false;
96 }
97 
98 bool AbstractProjection::traversablePoles() const
99 {
100  return false;
101 }
102 
103 bool AbstractProjection::traversableDateLine() const
104 {
105  return false;
106 }
107 
108 AbstractProjection::PreservationType AbstractProjection::preservationType() const
109 {
110  return NoPreservation;
111 }
112 
113 bool AbstractProjection::isOrientedNormal() const
114 {
115  return true;
116 }
117 
118 bool AbstractProjection::screenCoordinates( const qreal lon, const qreal lat,
119  const ViewportParams *viewport,
120  qreal &x, qreal &y ) const
121 {
122  bool globeHidesPoint;
123  GeoDataCoordinates geopoint(lon, lat);
124  return screenCoordinates( geopoint, viewport, x, y, globeHidesPoint );
125 }
126 
127 bool AbstractProjection::screenCoordinates( const GeoDataCoordinates &geopoint,
128  const ViewportParams *viewport,
129  qreal &x, qreal &y ) const
130 {
131  bool globeHidesPoint;
132 
133  return screenCoordinates( geopoint, viewport, x, y, globeHidesPoint );
134 }
135 
136 GeoDataLatLonAltBox AbstractProjection::latLonAltBox( const QRect& screenRect,
137  const ViewportParams *viewport ) const
138 {
139  // For the case where the whole viewport gets covered there is a
140  // pretty dirty and generic detection algorithm:
141 
142  // Move along the screenborder and save the highest and lowest lon-lat values.
143  QRect projectedRect = mapRegion( viewport ).boundingRect();
144  QRect mapRect = screenRect.intersected( projectedRect );
145 
146  GeoDataLineString boundingLineString;
147 
148  qreal lon, lat;
149 
150  for ( int x = mapRect.left(); x < mapRect.right(); x += latLonAltBoxSamplingRate ) {
151  if ( geoCoordinates( x, mapRect.bottom(), viewport, lon, lat,
152  GeoDataCoordinates::Radian ) ) {
153  boundingLineString << GeoDataCoordinates( lon, lat );
154  }
155 
156  if ( geoCoordinates( x, mapRect.top(),
157  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
158  boundingLineString << GeoDataCoordinates( lon, lat );
159  }
160  }
161 
162  if ( geoCoordinates( mapRect.right(), mapRect.top(), viewport, lon, lat,
163  GeoDataCoordinates::Radian ) ) {
164  boundingLineString << GeoDataCoordinates( lon, lat );
165  }
166 
167  if ( geoCoordinates( mapRect.right(), mapRect.bottom(),
168  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
169  boundingLineString << GeoDataCoordinates( lon, lat );
170  }
171 
172  for ( int y = mapRect.bottom(); y < mapRect.top(); y += latLonAltBoxSamplingRate ) {
173  if ( geoCoordinates( mapRect.left(), y, viewport, lon, lat,
174  GeoDataCoordinates::Radian ) ) {
175  boundingLineString << GeoDataCoordinates( lon, lat );
176  }
177 
178  if ( geoCoordinates( mapRect.right(), y,
179  viewport, lon, lat, GeoDataCoordinates::Radian ) ) {
180  boundingLineString << GeoDataCoordinates( lon, lat );
181  }
182  }
183 
184  GeoDataLatLonAltBox latLonAltBox = boundingLineString.latLonAltBox();
185 
186  // Now we need to check whether maxLat (e.g. the north pole) gets displayed
187  // inside the viewport.
188 
189  // We need a point on the screen at maxLat that definitely gets displayed:
190 
191  // FIXME: Some of the following code can be safely removed as soon as we properly handle
192  // GeoDataLinearRing::latLonAltBox().
193  qreal averageLongitude = ( latLonAltBox.west() + latLonAltBox.east() ) / 2.0;
194 
195  GeoDataCoordinates maxLatPoint( averageLongitude, maxLat(), 0.0, GeoDataCoordinates::Radian );
196  GeoDataCoordinates minLatPoint( averageLongitude, minLat(), 0.0, GeoDataCoordinates::Radian );
197 
198  qreal dummyX, dummyY; // not needed
199 
200  if ( latLonAltBox.north() > maxLat() ||
201  screenCoordinates( maxLatPoint, viewport, dummyX, dummyY ) ) {
202  latLonAltBox.setNorth( maxLat() );
203  }
204  if ( latLonAltBox.north() < minLat() ||
205  screenCoordinates( minLatPoint, viewport, dummyX, dummyY ) ) {
206  latLonAltBox.setSouth( minLat() );
207  }
208 
209  latLonAltBox.setMinAltitude( -100000000.0 );
210  latLonAltBox.setMaxAltitude( 100000000000000.0 );
211 
212  return latLonAltBox;
213 }
214 
215 
216 QRegion AbstractProjection::mapRegion( const ViewportParams *viewport ) const
217 {
218  return QRegion( mapShape( viewport ).toFillPolygon().toPolygon() );
219 }
Marble::AbstractProjection::repeatableX
virtual bool repeatableX() const
Definition: AbstractProjection.cpp:93
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
Marble::AbstractProjection::NoPreservation
Definition: AbstractProjection.h:63
AbstractProjection_p.h
Marble::AbstractProjection::preservationType
virtual PreservationType preservationType() const
Definition: AbstractProjection.cpp:108
QRect::right
int right() const
Marble::AbstractProjection::minValidLat
virtual qreal minValidLat() const
Definition: AbstractProjection.cpp:71
Marble::AbstractProjection::maxLat
qreal maxLat() const
Definition: AbstractProjection.cpp:54
QRegion::boundingRect
QRect boundingRect() const
Marble::GeoDataLatLonAltBox::setMaxAltitude
void setMaxAltitude(const qreal maxAltitude)
Definition: GeoDataLatLonAltBox.cpp:141
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:136
MarbleDebug.h
AbstractProjection.h
This file contains the headers for AbstractProjection.
Marble::AbstractProjection::traversableDateLine
virtual bool traversableDateLine() const
Definition: AbstractProjection.cpp:103
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
QRect
Marble::AbstractProjection::setMaxLat
void setMaxLat(qreal maxLat)
Definition: AbstractProjection.cpp:60
QRect::top
int top() const
Marble::AbstractProjection::traversablePoles
virtual bool traversablePoles() const
Definition: AbstractProjection.cpp:98
QRect::left
int left() const
GeoDataLineString.h
Marble::AbstractProjection::mapRegion
QRegion mapRegion(const ViewportParams *viewport) const
Definition: AbstractProjection.cpp:216
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:219
QRect::intersected
QRect intersected(const QRect &rectangle) const
Marble::GeoDataLatLonAltBox::setMinAltitude
void setMinAltitude(const qreal minAltitude)
Definition: GeoDataLatLonAltBox.cpp:131
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:118
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::PreservationType
PreservationType
Definition: AbstractProjection.h:62
Marble::AbstractProjection::isOrientedNormal
virtual bool isOrientedNormal() const
Definition: AbstractProjection.cpp:113
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
QRect::bottom
int bottom() const
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:36
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:580
Marble::AbstractProjection::setMinLat
void setMinLat(qreal minLat)
Definition: AbstractProjection.cpp:82
QRegion
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:38 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
  • 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