• 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
  • 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 
65 GeoDataLatLonAltBox& GeoDataLatLonAltBox::operator=( const GeoDataCoordinates &other )
66 {
67  setWest( other.longitude() );
68  setEast( other.longitude() );
69  setNorth( other.latitude() );
70  setSouth( other.latitude() );
71  setMinAltitude( other.altitude() );
72  setMaxAltitude( other.altitude() );
73  return *this;
74 }
75 
76 GeoDataLatLonAltBox::GeoDataLatLonAltBox()
77  : GeoDataLatLonBox(),
78  d( new GeoDataLatLonAltBoxPrivate )
79 {
80 }
81 
82 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataLatLonAltBox & other )
83  : GeoDataLatLonBox( other ),
84  d( new GeoDataLatLonAltBoxPrivate( *other.d ))
85 {
86 }
87 
88 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataLatLonBox &other, qreal minAltitude, qreal maxAltitude )
89  : GeoDataLatLonBox( other ),
90  d( new GeoDataLatLonAltBoxPrivate )
91 {
92  setWest( other.west() );
93  setEast( other.east() );
94  setNorth( other.north() );
95  setSouth( other.south() );
96  setRotation( other.rotation() );
97 
98  d->m_minAltitude = minAltitude;
99  d->m_maxAltitude = maxAltitude;
100 }
101 
102 
103 GeoDataLatLonAltBox::GeoDataLatLonAltBox( const GeoDataCoordinates & coordinates )
104  : GeoDataLatLonBox(),
105  d( new GeoDataLatLonAltBoxPrivate )
106 {
107  setWest( coordinates.longitude() );
108  setEast( coordinates.longitude() );
109  setNorth( coordinates.latitude() );
110  setSouth( coordinates.latitude() );
111 
112  d->m_minAltitude = coordinates.altitude();
113  d->m_maxAltitude = coordinates.altitude();
114 }
115 
116 
117 GeoDataLatLonAltBox::~GeoDataLatLonAltBox()
118 {
119  delete d;
120 }
121 
122 const char* GeoDataLatLonAltBox::nodeType() const
123 {
124  return d->nodeType();
125 }
126 
127 qreal GeoDataLatLonAltBox::minAltitude() const
128 {
129  return d->m_minAltitude;
130 }
131 
132 void GeoDataLatLonAltBox::setMinAltitude( const qreal minAltitude )
133 {
134  d->m_minAltitude = minAltitude;
135 }
136 
137 qreal GeoDataLatLonAltBox::maxAltitude() const
138 {
139  return d->m_maxAltitude;
140 }
141 
142 void GeoDataLatLonAltBox::setMaxAltitude( const qreal maxAltitude )
143 {
144  d->m_maxAltitude = maxAltitude;
145 }
146 
147 AltitudeMode GeoDataLatLonAltBox::altitudeMode() const
148 {
149  return d->m_altitudeMode;
150 }
151 
152 GeoDataCoordinates GeoDataLatLonAltBox::center() const
153 {
154  if ( isEmpty() )
155  return GeoDataCoordinates();
156  if( crossesDateLine() )
157  return GeoDataCoordinates( GeoDataCoordinates::normalizeLon(east() + 2 * M_PI - (east() + 2 * M_PI - west()) / 2),
158  north() - (north() - south()) / 2,
159  d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
160  else
161  return GeoDataCoordinates( east() - (east() - west()) / 2,
162  north() - (north() - south()) / 2,
163  d->m_maxAltitude - (d->m_maxAltitude - d->m_minAltitude) / 2);
164 }
165 
166 void GeoDataLatLonAltBox::setAltitudeMode( const AltitudeMode altitudeMode )
167 {
168  d->m_altitudeMode = altitudeMode;
169 }
170 
171 bool GeoDataLatLonAltBox::contains( const GeoDataCoordinates &point ) const
172 {
173  if ( !GeoDataLatLonBox::contains( point ) )
174  return false;
175 
176  if ( point.altitude() < d->m_minAltitude || point.altitude() > d->m_maxAltitude ) {
177  return false;
178  }
179 
180  return true;
181 }
182 
183 bool GeoDataLatLonAltBox::contains( const GeoDataLatLonAltBox &other ) const
184 {
185  // check the contain criterion for the altitude first as this is trivial:
186 
187  // mDebug() << "this " << this->toString(GeoDataCoordinates::Degree);
188  // mDebug() << "other" << other.toString(GeoDataCoordinates::Degree);
189 
190  if ( d->m_maxAltitude >= other.maxAltitude() && d->m_minAltitude <= other.minAltitude() ) {
191  return GeoDataLatLonBox::contains( other );
192  }
193 
194  return false;
195 }
196 
197 bool GeoDataLatLonAltBox::intersects( const GeoDataLatLonAltBox &other ) const
198 {
199  // Case 1: maximum altitude of other box intersects:
200  if ( ( d->m_maxAltitude >= other.maxAltitude() && d->m_minAltitude <= other.maxAltitude() )
201  // Case 2: maximum altitude of this box intersects:
202  || ( other.maxAltitude() >= d->m_maxAltitude && other.minAltitude() <= d->m_maxAltitude )
203  // Case 3: minimum altitude of other box intersects:
204  || ( d->m_maxAltitude >= other.minAltitude() && d->m_minAltitude <= other.minAltitude() )
205  // Case 4: minimum altitude of this box intersects:
206  || ( other.maxAltitude() >= d->m_minAltitude && other.minAltitude() <= d->m_minAltitude ) ) {
207 
208  if ( GeoDataLatLonBox::intersects( other ) )
209  return true;
210 
211  }
212 
213  return false;
214 }
215 
216 GeoDataLatLonAltBox GeoDataLatLonAltBox::fromLineString( const GeoDataLineString& lineString )
217 {
218  // If the line string is empty return a boundingbox that contains everything
219  if ( lineString.size() == 0 ) {
220  return GeoDataLatLonAltBox();
221  }
222 
223  const qreal altitude = lineString.first().altitude();
224 
225  GeoDataLatLonAltBox temp ( GeoDataLatLonBox::fromLineString( lineString ), altitude, altitude );
226 
227  qreal maxAltitude = altitude;
228  qreal minAltitude = altitude;
229 
230  // If there's only a single node stored then the boundingbox only contains that point
231  if ( lineString.size() == 1 ) {
232  temp.setMinAltitude( minAltitude );
233  temp.setMaxAltitude( maxAltitude );
234  return temp;
235  }
236 
237  QVector<GeoDataCoordinates>::ConstIterator it( lineString.constBegin() );
238  QVector<GeoDataCoordinates>::ConstIterator itEnd( lineString.constEnd() );
239 
240  for ( ; it != itEnd; ++it )
241  {
242  // Get coordinates and normalize them to the desired range.
243  const qreal altitude = (it)->altitude();
244 
245  // Determining the maximum and minimum latitude
246  if ( altitude > maxAltitude ) maxAltitude = altitude;
247  if ( altitude < minAltitude ) minAltitude = altitude;
248  }
249 
250  temp.setMinAltitude( minAltitude );
251  temp.setMaxAltitude( maxAltitude );
252  return temp;
253 }
254 
255 QString GeoDataLatLonAltBox::toString( GeoDataCoordinates::Unit unit ) const
256 {
257  switch( unit ){
258  case GeoDataCoordinates::Radian:
259  return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
260  .arg( north() ).arg( west() )
261  .arg( d->m_maxAltitude ).arg( south() )
262  .arg( east() ).arg( d->m_minAltitude );
263  break;
264  case GeoDataCoordinates::Degree:
265  return QString( "North: %1; West: %2 MaxAlt: %3\n South: %4; East: %5 MinAlt: %6" )
266  .arg( north() * RAD2DEG ).arg( west() * RAD2DEG )
267  .arg( d->m_maxAltitude ).arg( south() * RAD2DEG )
268  .arg( east() * RAD2DEG ).arg( d->m_minAltitude );
269  break;
270  }
271 
272  return QString( "GeoDataLatLonAltBox::text(): Error in unit: %1\n" )
273  .arg( unit );
274 }
275 
276 bool GeoDataLatLonAltBox::isNull() const
277 {
278  if ( GeoDataLatLonBox::isNull() && d->m_maxAltitude == d->m_minAltitude )
279  return true;
280 
281  return false;
282 }
283 
284 void GeoDataLatLonAltBox::clear()
285 {
286  GeoDataLatLonBox::clear();
287  d->m_minAltitude = 0;
288  d->m_maxAltitude = 0;
289  d->m_altitudeMode = ClampToGround;
290 }
291 
292 void GeoDataLatLonAltBox::pack( QDataStream& stream ) const
293 {
294  GeoDataObject::pack( stream );
295 
296  stream << d->m_minAltitude << d->m_maxAltitude;
297  stream << d->m_altitudeMode;
298 }
299 
300 void GeoDataLatLonAltBox::unpack( QDataStream& stream )
301 {
302  GeoDataObject::unpack( stream );
303 
304  stream >> d->m_minAltitude >> d->m_maxAltitude;
305  int a;
306  stream >> a;
307  d->m_altitudeMode = static_cast<AltitudeMode>( a );
308 }
309 
310 }
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:201
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:216
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:197
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:216
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
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:134
Marble::GeoDataLatLonAltBox::altitudeMode
AltitudeMode altitudeMode() const
Get the reference system for the altitude.
Definition: GeoDataLatLonAltBox.cpp:147
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:142
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:171
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:122
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:166
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:276
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:145
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:173
Marble::GeoDataLatLonAltBox::maxAltitude
qreal maxAltitude() const
Get the upper altitude boundary of the bounding box.
Definition: GeoDataLatLonAltBox.cpp:137
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:132
Marble::GeoDataTypes::GeoDataLatLonAltBoxType
const char * GeoDataLatLonAltBoxType
Definition: GeoDataTypes.cpp:45
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:152
Marble::GeoDataLatLonAltBox::toString
virtual QString toString(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Creates a text string of the bounding box.
Definition: GeoDataLatLonAltBox.cpp:255
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:292
Marble::GeoDataLatLonAltBox::~GeoDataLatLonAltBox
virtual ~GeoDataLatLonAltBox()
Definition: GeoDataLatLonAltBox.cpp:117
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::GeoDataLineString::constBegin
QVector< GeoDataCoordinates >::ConstIterator constBegin() const
Returns a const iterator that points to the begin of the LineString.
Definition: GeoDataLineString.cpp:211
Marble::ClampToGround
Altitude always sticks to ground level.
Definition: MarbleGlobal.h:146
GeoDataLatLonAltBox.h
Marble::GeoDataLatLonAltBox::clear
virtual void clear()
Resets the bounding box to its uninitialised state (and thus contains nothing).
Definition: GeoDataLatLonAltBox.cpp:284
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:76
GeoDataTypes.h
Marble::GeoDataLatLonBox::setRotation
void setRotation(const qreal rotation, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:177
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:127
Marble::GeoDataLatLonAltBox::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataLatLonAltBox.cpp:300
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-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 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