• 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
  • geodata
  • data
GeoDataLatLonAltBox.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 Andrew Manson <g.real.ate@gmail.com>
9 // Copyright 2008 Torsten Rahn <rahn@kde.org>
10 //
11 
12 
13 #include "GeoDataLatLonAltBox.h"
14 
15 #include "MarbleDebug.h"
16 #include "GeoDataCoordinates.h"
17 #include "GeoDataLineString.h"
18 
19 #include "GeoDataTypes.h"
20 
21 namespace Marble
22 {
23 
24 class GeoDataLatLonAltBoxPrivate
25 {
26  public:
27  GeoDataLatLonAltBoxPrivate()
28  : m_minAltitude( 0 ),
29  m_maxAltitude( 0 ),
30  m_altitudeMode( ClampToGround )
31  {
32  }
33 
34  const char* nodeType() const
35  {
36  return GeoDataTypes::GeoDataLatLonAltBoxType;
37  }
38 
39  qreal m_minAltitude;
40  qreal m_maxAltitude;
41  AltitudeMode m_altitudeMode;
42 };
43 
44 bool operator==( GeoDataLatLonAltBox const& lhs, GeoDataLatLonAltBox const& rhs )
45 {
46  return lhs.west() == rhs.west() &&
47  lhs.east() == rhs.east() &&
48  lhs.north() == rhs.north() &&
49  lhs.south() == rhs.south() &&
50  lhs.rotation() == rhs.rotation() &&
51  lhs.d->m_minAltitude == rhs.d->m_minAltitude &&
52  lhs.d->m_maxAltitude == rhs.d->m_maxAltitude &&
53  lhs.d->m_altitudeMode == rhs.d->m_altitudeMode;
54 }
55 
56 GeoDataLatLonAltBox& GeoDataLatLonAltBox::operator=( const GeoDataLatLonAltBox &other )
57 {
58  GeoDataLatLonBox::operator=( other );
59 
60  *d = *other.d;
61  return *this;
62 }
63 
64 GeoDataLatLonAltBox& GeoDataLatLonAltBox::operator=( const GeoDataCoordinates &other )
65 {
66  setWest( other.longitude() );
67  setEast( other.longitude() );
68  setNorth( other.latitude() );
69  setSouth( other.latitude() );
70  setMinAltitude( other.altitude() );
71  setMaxAltitude( other.altitude() );
72  return *this;
73 }
74 
75 GeoDataLatLonAltBox::GeoDataLatLonAltBox()
76  : GeoDataLatLonBox(),
77  d( new GeoDataLatLonAltBoxPrivate )
78 {
79 }
80 
81 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataLatLonAltBox & other )
82  : GeoDataLatLonBox( other ),
83  d( new GeoDataLatLonAltBoxPrivate( *other.d ))
84 {
85 }
86 
87 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataLatLonBox &other, qreal minAltitude, qreal maxAltitude )
88  : GeoDataLatLonBox( other ),
89  d( new GeoDataLatLonAltBoxPrivate )
90 {
91  setWest( other.west() );
92  setEast( other.east() );
93  setNorth( other.north() );
94  setSouth( other.south() );
95  setRotation( other.rotation() );
96 
97  d->m_minAltitude = minAltitude;
98  d->m_maxAltitude = maxAltitude;
99 }
100 
101 
102 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataCoordinates & coordinates )
103  : GeoDataLatLonBox(),
104  d( new GeoDataLatLonAltBoxPrivate )
105 {
106  setWest( coordinates.longitude() );
107  setEast( coordinates.longitude() );
108  setNorth( coordinates.latitude() );
109  setSouth( coordinates.latitude() );
110 
111  d->m_minAltitude = coordinates.altitude();
112  d->m_maxAltitude = coordinates.altitude();
113 }
114 
115 
116 GeoDataLatLonAltBox::~GeoDataLatLonAltBox()
117 {
118  delete d;
119 }
120 
121 const char* GeoDataLatLonAltBox::nodeType() const
122 {
123  return d->nodeType();
124 }
125 
126 qreal GeoDataLatLonAltBox::minAltitude() const
127 {
128  return d->m_minAltitude;
129 }
130 
131 void GeoDataLatLonAltBox::setMinAltitude( const qreal minAltitude )
132 {
133  d->m_minAltitude = minAltitude;
134 }
135 
136 qreal GeoDataLatLonAltBox::maxAltitude() const
137 {
138  return d->m_maxAltitude;
139 }
140 
141 void GeoDataLatLonAltBox::setMaxAltitude( const qreal maxAltitude )
142 {
143  d->m_maxAltitude = maxAltitude;
144 }
145 
146 AltitudeMode GeoDataLatLonAltBox::altitudeMode() const
147 {
148  return d->m_altitudeMode;
149 }
150 
151 GeoDataCoordinates GeoDataLatLonAltBox::center() const
152 {
153  if ( isEmpty() )
154  return GeoDataCoordinates();
155  if( crossesDateLine() )
156  return GeoDataCoordinates( GeoDataCoordinates::normalizeLon(east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2),
157  north() - (north() - south()) / 2,
158  d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
159  else
160  return GeoDataCoordinates( east() - (east() - west()) / 2,
161  north() - (north() - south()) / 2,
162  d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
163 }
164 
165 void GeoDataLatLonAltBox::setAltitudeMode( const AltitudeMode altitudeMode )
166 {
167  d->m_altitudeMode = altitudeMode;
168 }
169 
170 bool GeoDataLatLonAltBox::contains( const GeoDataCoordinates &point ) const
171 {
172  if ( !GeoDataLatLonBox::contains( point ) )
173  return false;
174 
175  if ( point.altitude() < d->m_minAltitude || point.altitude() > d->m_maxAltitude ) {
176  return false;
177  }
178 
179  return true;
180 }
181 
182 bool GeoDataLatLonAltBox::contains( const GeoDataLatLonAltBox &other ) const
183 {
184  // check the contain criterion for the altitude first as this is trivial:
185 
186  // mDebug() << "this " << this->toString(GeoDataCoordinates::Degree);
187  // mDebug() << "other" << other.toString(GeoDataCoordinates::Degree);
188 
189  if ( d->m_maxAltitude >= other.maxAltitude() && d->m_minAltitude <= other.minAltitude() ) {
190  return GeoDataLatLonBox::contains( other );
191  }
192 
193  return false;
194 }
195 
196 bool GeoDataLatLonAltBox::intersects( const GeoDataLatLonAltBox &other ) const
197 {
198  // Case 1: maximum altitude of other box intersects:
199  if ( ( d->m_maxAltitude >= other.maxAltitude() && d->m_minAltitude <= other.maxAltitude() )
200  // Case 2: maximum altitude of this box intersects:
201  || ( other.maxAltitude() >= d->m_maxAltitude && other.minAltitude() <= d->m_maxAltitude )
202  // Case 3: minimum altitude of other box intersects:
203  || ( d->m_maxAltitude >= other.minAltitude() && d->m_minAltitude <= other.minAltitude() )
204  // Case 4: minimum altitude of this box intersects:
205  || ( other.maxAltitude() >= d->m_minAltitude && other.minAltitude() <= d->m_minAltitude ) ) {
206 
207  if ( GeoDataLatLonBox::intersects( other ) )
208  return true;
209 
210  }
211 
212  return false;
213 }
214 
215 GeoDataLatLonAltBox GeoDataLatLonAltBox::fromLineString( const GeoDataLineString& lineString )
216 {
217  // If the line string is empty return a boundingbox that contains everything
218  if ( lineString.size() == 0 ) {
219  return GeoDataLatLonAltBox();
220  }
221 
222  const qreal altitude = lineString.first().altitude();
223 
224  GeoDataLatLonAltBox temp ( GeoDataLatLonBox::fromLineString( lineString ), altitude, altitude );
225 
226  qreal maxAltitude = altitude;
227  qreal minAltitude = altitude;
228 
229  // If there's only a single node stored then the boundingbox only contains that point
230  if ( lineString.size() == 1 ) {
231  temp.setMinAltitude( minAltitude );
232  temp.setMaxAltitude( maxAltitude );
233  return temp;
234  }
235 
236  QVector<GeoDataCoordinates>::ConstIterator it( lineString.constBegin() );
237  QVector<GeoDataCoordinates>::ConstIterator itEnd( lineString.constEnd() );
238 
239  for ( ; it != itEnd; ++it )
240  {
241  // Get coordinates and normalize them to the desired range.
242  const qreal altitude = (it)->altitude();
243 
244  // Determining the maximum and minimum latitude
245  if ( altitude > maxAltitude ) maxAltitude = altitude;
246  if ( altitude < minAltitude ) minAltitude = altitude;
247  }
248 
249  temp.setMinAltitude( minAltitude );
250  temp.setMaxAltitude( maxAltitude );
251  return temp;
252 }
253 
254 QString GeoDataLatLonAltBox::toString( GeoDataCoordinates::Unit unit ) const
255 {
256  switch( unit ){
257  case GeoDataCoordinates::Radian:
258  return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
259  .arg( north() ).arg( west() )
260  .arg( d->m_maxAltitude ).arg( south() )
261  .arg( east() ).arg( d->m_minAltitude );
262  break;
263  case GeoDataCoordinates::Degree:
264  return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
265  .arg( north() * RAD2DEG ).arg( west() * RAD2DEG )
266  .arg( d->m_maxAltitude ).arg( south() * RAD2DEG )
267  .arg( east() * RAD2DEG ).arg( d->m_minAltitude );
268  break;
269  }
270 
271  return QString( "GeoDataLatLonAltBox::text(): Error in unit: %1\n" )
272  .arg( unit );
273 }
274 
275 bool GeoDataLatLonAltBox::isNull() const
276 {
277  if ( GeoDataLatLonBox::isNull() && d->m_maxAltitude == d->m_minAltitude )
278  return true;
279 
280  return false;
281 }
282 
283 void GeoDataLatLonAltBox::clear()
284 {
285  GeoDataLatLonBox::clear();
286  d->m_minAltitude = 0;
287  d->m_maxAltitude = 0;
288  d->m_altitudeMode = ClampToGround;
289 }
290 
291 void GeoDataLatLonAltBox::pack( QDataStream& stream ) const
292 {
293  GeoDataObject::pack( stream );
294 
295  stream << d->m_minAltitude << d->m_maxAltitude;
296  stream << d->m_altitudeMode;
297 }
298 
299 void GeoDataLatLonAltBox::unpack( QDataStream& stream )
300 {
301  GeoDataObject::unpack( stream );
302 
303  stream >> d->m_minAltitude >> d->m_maxAltitude;
304  int a;
305  stream >> a;
306  d->m_altitudeMode = static_cast<AltitudeMode>( a );
307 }
308 
309 }
Marble::GeoDataCoordinates::Unit
Unit
enum used constructor to specify the units used
Definition: GeoDataCoordinates.h:64
Marble::GeoDataLatLonBox::operator=
GeoDataLatLonBox & operator=(const GeoDataLatLonBox &other)
Definition: GeoDataLatLonBox.cpp:586
GeoDataCoordinates.h
Marble::RAD2DEG
const qreal RAD2DEG
Definition: MarbleGlobal.h:220
Marble::GeoDataLatLonBox::isNull
virtual bool isNull() const
Indicates whether the bounding box only contains a single 2D point ("singularity").
Definition: GeoDataLatLonBox.cpp:760
Marble::GeoDataLatLonAltBox::fromLineString
static GeoDataLatLonAltBox fromLineString(const GeoDataLineString &lineString)
Create the smallest bounding box from a line string.
Definition: GeoDataLatLonAltBox.cpp:215
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataCoordinates::Radian
Definition: GeoDataCoordinates.h:65
Marble::GeoDataLatLonAltBox::intersects
virtual bool intersects(const GeoDataLatLonAltBox &) const
Check if this GeoDataLatLonAltBox intersects with the given one.
Definition: GeoDataLatLonAltBox.cpp:196
Marble::GeoDataLatLonBox::isEmpty
virtual bool isEmpty() const
Indicates whether the bounding box is not initialised (and contains nothing).
Definition: GeoDataLatLonBox.cpp:768
Marble::GeoDataLatLonBox::setNorth
void setNorth(const qreal north, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:101
Marble::GeoDataLineString::constEnd
QVector< GeoDataCoordinates >::ConstIterator constEnd() const
Returns a const iterator that points to the end of the LineString.
Definition: GeoDataLineString.cpp:220
Marble::GeoDataCoordinates::normalizeLon
static qreal normalizeLon(qreal lon, GeoDataCoordinates::Unit=GeoDataCoordinates::Radian)
normalize the longitude to always be -M_PI <= lon <= +M_PI (Radian).
Definition: GeoDataCoordinates.cpp:776
QDataStream
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
Marble::GeoDataLatLonAltBox::altitudeMode
AltitudeMode altitudeMode() const
Get the reference system for the altitude.
Definition: GeoDataLatLonAltBox.cpp:146
Marble::GeoDataObject::pack
virtual void pack(QDataStream &stream) const
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:114
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::GeoDataCoordinates::latitude
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
Definition: GeoDataCoordinates.cpp:751
Marble::GeoDataLatLonBox::setWest
void setWest(const qreal west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:164
Marble::GeoDataLatLonAltBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonAltBox.cpp:170
Marble::GeoDataLatLonBox::contains
virtual bool contains(const GeoDataCoordinates &) const
Definition: GeoDataLatLonBox.cpp:309
Marble::GeoDataLatLonAltBox::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataLatLonAltBox.cpp:121
MarbleDebug.h
Marble::GeoDataLatLonBox::clear
virtual void clear()
Resets the bounding box to its uninitialised state (and thus contains nothing).
Definition: GeoDataLatLonBox.cpp:773
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::operator==
bool operator==(const DownloadPolicyKey &lhs, const DownloadPolicyKey &rhs)
Definition: DownloadPolicy.h:49
Marble::GeoDataLatLonAltBox::setAltitudeMode
void setAltitudeMode(const AltitudeMode altitudeMode)
Definition: GeoDataLatLonAltBox.cpp:165
Marble::GeoDataCoordinates::altitude
qreal altitude() const
return the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1197
Marble::GeoDataLatLonAltBox::isNull
bool isNull() const
Indicates whether the bounding box only contains a single 2D point ("singularity").
Definition: GeoDataLatLonAltBox.cpp:275
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::GeoDataLatLonAltBox::operator=
GeoDataLatLonAltBox & operator=(const GeoDataLatLonAltBox &other)
Definition: GeoDataLatLonAltBox.cpp:56
Marble::AltitudeMode
AltitudeMode
Definition: MarbleGlobal.h:147
Marble::GeoDataLatLonBox::intersects
virtual bool intersects(const GeoDataLatLonBox &) const
Definition: GeoDataLatLonBox.cpp:385
GeoDataLineString.h
Marble::GeoDataLineString::first
GeoDataCoordinates & first()
Returns a reference to the first node in the LineString. This method detaches the returned coordinate...
Definition: GeoDataLineString.cpp:177
Marble::GeoDataLatLonAltBox::maxAltitude
qreal maxAltitude() const
Get the upper altitude boundary of the bounding box.
Definition: GeoDataLatLonAltBox.cpp:136
QString
Marble::GeoDataLatLonBox::rotation
qreal rotation(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the rotation of the bounding box.
Definition: GeoDataLatLonBox.cpp:190
Marble::GeoDataLatLonBox::fromLineString
static GeoDataLatLonBox fromLineString(const GeoDataLineString &lineString)
Create the smallest bounding box from a line string.
Definition: GeoDataLatLonBox.cpp:620
Marble::GeoDataLatLonAltBox::setMinAltitude
void setMinAltitude(const qreal minAltitude)
Definition: GeoDataLatLonAltBox.cpp:131
Marble::GeoDataTypes::GeoDataLatLonAltBoxType
const char * GeoDataLatLonAltBoxType
Definition: GeoDataTypes.cpp:49
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataCoordinates::longitude
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
Definition: GeoDataCoordinates.cpp:739
Marble::GeoDataLatLonAltBox::center
virtual GeoDataCoordinates center() const
returns the center of this box
Definition: GeoDataLatLonAltBox.cpp:151
Marble::GeoDataLatLonAltBox::toString
virtual QString toString(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Creates a text string of the bounding box.
Definition: GeoDataLatLonAltBox.cpp:254
Marble::GeoDataLatLonBox::crossesDateLine
bool crossesDateLine() const
Detect whether the bounding box crosses the IDL.
Definition: GeoDataLatLonBox.cpp:266
Marble::GeoDataLatLonAltBox::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataLatLonAltBox.cpp:291
Marble::GeoDataLatLonAltBox::~GeoDataLatLonAltBox
virtual ~GeoDataLatLonAltBox()
Definition: GeoDataLatLonAltBox.cpp:116
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
QVector
Marble::GeoDataLineString::constBegin
QVector< GeoDataCoordinates >::ConstIterator constBegin() const
Returns a const iterator that points to the begin of the LineString.
Definition: GeoDataLineString.cpp:215
Marble::ClampToGround
Altitude always sticks to ground level.
Definition: MarbleGlobal.h:148
GeoDataLatLonAltBox.h
Marble::GeoDataLatLonAltBox::clear
virtual void clear()
Resets the bounding box to its uninitialised state (and thus contains nothing).
Definition: GeoDataLatLonAltBox.cpp:283
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::GeoDataObject::unpack
virtual void unpack(QDataStream &steam)
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:120
Marble::GeoDataLatLonAltBox::GeoDataLatLonAltBox
GeoDataLatLonAltBox()
Definition: GeoDataLatLonAltBox.cpp:75
GeoDataTypes.h
Marble::GeoDataLatLonBox::setRotation
void setRotation(const qreal rotation, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:177
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataLatLonAltBox::minAltitude
qreal minAltitude() const
Get the lower altitude boundary of the bounding box.
Definition: GeoDataLatLonAltBox.cpp:126
Marble::GeoDataLatLonAltBox::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataLatLonAltBox.cpp:299
Marble::GeoDataLatLonBox
A class that defines a 2D bounding box for geographic data.
Definition: GeoDataLatLonBox.h:51
Marble::GeoDataLatLonBox::setEast
void setEast(const qreal east, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 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