• 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
GeoDataTrack.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 2011 Guillaume Martres <smarter@ubuntu.com>
9 //
10 
11 #include "GeoDataTrack.h"
12 
13 #include "GeoDataLatLonAltBox.h"
14 #include "GeoDataTypes.h"
15 #include "MarbleDebug.h"
16 #include "Quaternion.h"
17 
18 #include "GeoDataLineString.h"
19 
20 #include <QMap>
21 #include <QLinkedList>
22 #include "GeoDataExtendedData.h"
23 
24 namespace Marble {
25 
26 class GeoDataTrackPrivate
27 {
28 public:
29  GeoDataTrackPrivate()
30  : m_lineString( new GeoDataLineString() ),
31  m_lineStringNeedsUpdate( false ),
32  m_interpolate( false )
33  {
34  }
35 
36  void equalizeWhenSize()
37  {
38  while ( m_when.size() < m_coordinates.size() ) {
39  //fill coordinates without time information with null QDateTime
40  m_when.append( QDateTime() );
41  }
42  }
43 
44  GeoDataLineString *m_lineString;
45  bool m_lineStringNeedsUpdate;
46 
47  QList<QDateTime> m_when;
48  QList<GeoDataCoordinates> m_coordinates;
49 
50  GeoDataExtendedData m_extendedData;
51 
52  bool m_interpolate;
53 };
54 
55 GeoDataTrack::GeoDataTrack()
56  : d( new GeoDataTrackPrivate() )
57 {
58 
59 }
60 
61 GeoDataTrack::GeoDataTrack( const GeoDataGeometry &other )
62  : GeoDataGeometry( other )
63 {
64 
65 }
66 
67 int GeoDataTrack::size() const
68 {
69  return d->m_coordinates.size();
70 }
71 
72 bool GeoDataTrack::interpolate() const
73 {
74  return d->m_interpolate;
75 }
76 
77 void GeoDataTrack::setInterpolate(bool on)
78 {
79  d->m_interpolate = on;
80 }
81 
82 QDateTime GeoDataTrack::firstWhen() const
83 {
84  if ( d->m_when.isEmpty() ) {
85  return QDateTime();
86  }
87 
88  return d->m_when.first();
89 }
90 
91 QDateTime GeoDataTrack::lastWhen() const
92 {
93  if ( d->m_when.isEmpty() ) {
94  return QDateTime();
95  }
96 
97  return d->m_when.last();
98 }
99 
100 QList<GeoDataCoordinates> GeoDataTrack::coordinatesList() const
101 {
102  return d->m_coordinates;
103 }
104 
105 QList<QDateTime> GeoDataTrack::whenList() const
106 {
107  return d->m_when;
108 }
109 
110 GeoDataCoordinates GeoDataTrack::coordinatesAt( const QDateTime &when ) const
111 {
112  if ( d->m_when.isEmpty() ) {
113  return GeoDataCoordinates();
114  }
115 
116  if ( d->m_when.contains( when ) ) {
117  //exact match found
118  int index = d->m_when.indexOf( when );
119  if ( index < d->m_coordinates.size() ) {
120  return d->m_coordinates.at( index );
121  }
122  }
123 
124  if ( !interpolate() ) {
125  return GeoDataCoordinates();
126  }
127 
128  typedef QMap<QDateTime, GeoDataCoordinates> PointMap;
129  PointMap pointMap;
130  for ( int i = 0; i < qMin( d->m_when.size(), d->m_coordinates.size() ); ++i) {
131  if ( d->m_when.at( i ).isValid() ) {
132  pointMap[ d->m_when.at( i ) ] = d->m_coordinates.at( i );
133  }
134  }
135 
136  QMap<QDateTime, GeoDataCoordinates>::const_iterator nextEntry = const_cast<const PointMap&>(pointMap).upperBound( when );
137 
138  // No tracked point happened before "when"
139  if ( nextEntry == pointMap.constBegin() ) {
140  mDebug() << "No tracked point before " << when;
141  return GeoDataCoordinates();
142  }
143 
144  QMap<QDateTime, GeoDataCoordinates>::const_iterator previousEntry = nextEntry - 1;
145  GeoDataCoordinates previousCoord = previousEntry.value();
146 
147  QDateTime previousWhen = previousEntry.key();
148  QDateTime nextWhen = nextEntry.key();
149  GeoDataCoordinates nextCoord = nextEntry.value();
150 
151 #if QT_VERSION < 0x040700
152  int interval = 1000 * previousWhen.secsTo( nextWhen );
153  int position = 1000 * previousWhen.secsTo( when );
154 #else
155  int interval = previousWhen.msecsTo( nextWhen );
156  int position = previousWhen.msecsTo( when );
157 #endif
158  qreal t = (qreal)position / (qreal)interval;
159 
160  Quaternion interpolated;
161  interpolated.slerp( previousCoord.quaternion(), nextCoord.quaternion(), t );
162  qreal lon, lat;
163  interpolated.getSpherical( lon, lat );
164 
165  qreal alt = previousCoord.altitude() + ( nextCoord.altitude() - previousCoord.altitude() ) * t;
166 
167  return GeoDataCoordinates( lon, lat, alt );
168 }
169 
170 GeoDataCoordinates GeoDataTrack::coordinatesAt( int index ) const
171 {
172  return d->m_coordinates.at( index );
173 }
174 
175 void GeoDataTrack::addPoint( const QDateTime &when, const GeoDataCoordinates &coord )
176 {
177  d->equalizeWhenSize();
178  d->m_lineStringNeedsUpdate = true;
179  int i=0;
180  while ( i < d->m_when.size() ) {
181  if ( d->m_when.at( i ) > when ) {
182  break;
183  }
184  ++i;
185  }
186  d->m_when.insert(i, when );
187  d->m_coordinates.insert(i, coord );
188 }
189 
190 void GeoDataTrack::appendCoordinates( const GeoDataCoordinates &coord )
191 {
192  d->equalizeWhenSize();
193  d->m_lineStringNeedsUpdate = true;
194  d->m_coordinates.append( coord );
195 }
196 
197 void GeoDataTrack::appendAltitude( qreal altitude )
198 {
199  d->m_lineStringNeedsUpdate = true;
200  Q_ASSERT( !d->m_coordinates.isEmpty() );
201  if ( d->m_coordinates.isEmpty() ) return;
202  GeoDataCoordinates coordinates = d->m_coordinates.takeLast();
203  coordinates.setAltitude( altitude );
204  d->m_coordinates.append( coordinates );
205 }
206 
207 void GeoDataTrack::appendWhen( const QDateTime &when )
208 {
209  d->m_when.append( when );
210 }
211 
212 void GeoDataTrack::clear()
213 {
214  d->m_when.clear();
215  d->m_coordinates.clear();
216  d->m_lineStringNeedsUpdate = true;
217 }
218 
219 void GeoDataTrack::removeBefore( const QDateTime &when )
220 {
221  Q_ASSERT( d->m_coordinates.size() == d->m_when.size() );
222  if ( d->m_when.isEmpty() ) {
223  return;
224  }
225  d->equalizeWhenSize();
226 
227  while ( !d->m_when.isEmpty() && d->m_when.first() < when ) {
228  d->m_when.takeFirst();
229  d->m_coordinates.takeFirst();
230  }
231 }
232 
233 void GeoDataTrack::removeAfter( const QDateTime &when )
234 {
235  Q_ASSERT( d->m_coordinates.size() == d->m_when.size() );
236  if ( d->m_when.isEmpty() ) {
237  return;
238  }
239  d->equalizeWhenSize();
240  while ( !d->m_when.isEmpty() && d->m_when.last() > when ) {
241  d->m_when.takeLast();
242  d->m_coordinates.takeLast();
243 
244  }
245 }
246 
247 const GeoDataLineString *GeoDataTrack::lineString() const
248 {
249  if ( d->m_lineStringNeedsUpdate ) {
250  delete d->m_lineString;
251  d->m_lineString = new GeoDataLineString();
252  foreach ( const GeoDataCoordinates &coordinates, coordinatesList() ) {
253  d->m_lineString->append( coordinates );
254  }
255  d->m_lineStringNeedsUpdate = false;
256  }
257  return d->m_lineString;
258 }
259 
260 GeoDataExtendedData& GeoDataTrack::extendedData() const
261 {
262  return d->m_extendedData;
263 }
264 
265 void GeoDataTrack::setExtendedData( const GeoDataExtendedData& extendedData )
266 {
267  d->m_extendedData = extendedData;
268 }
269 
270 const char* GeoDataTrack::nodeType() const
271 {
272  return GeoDataTypes::GeoDataTrackType;
273 }
274 
275 EnumGeometryId GeoDataTrack::geometryId() const
276 {
277  return GeoDataTrackId;
278 }
279 
280 const GeoDataLatLonAltBox& GeoDataTrack::latLonAltBox() const
281 {
282  return lineString()->latLonAltBox();
283 }
284 
285 //TODO
286 void GeoDataTrack::pack( QDataStream& stream ) const
287 {
288  GeoDataGeometry::pack( stream );
289 }
290 //TODO
291 void GeoDataTrack::unpack( QDataStream& stream )
292 {
293  GeoDataGeometry::unpack( stream );
294 }
295 
296 }
Marble::GeoDataTrack::removeAfter
void removeAfter(const QDateTime &when)
Remove all points from the track whose time value is greater than when.
Definition: GeoDataTrack.cpp:233
Quaternion.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataTrack::setExtendedData
void setExtendedData(const GeoDataExtendedData &extendedData)
Sets the ExtendedData of the feature.
Definition: GeoDataTrack.cpp:265
Marble::GeoDataGeometry::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataGeometry.cpp:135
Marble::GeoDataCoordinates::setAltitude
void setAltitude(const qreal altitude)
set the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1191
Marble::GeoDataTrack::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataTrack.cpp:286
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataTrack::lineString
const GeoDataLineString * lineString() const
Return the GeoDataLineString representing the current track.
Definition: GeoDataTrack.cpp:247
Marble::GeoDataTrack::whenList
QList< QDateTime > whenList() const
Returns the time value of all the points in the map, in chronological order.
Definition: GeoDataTrack.cpp:105
Marble::GeoDataTrack::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataTrack.cpp:270
Marble::GeoDataTrack::extendedData
GeoDataExtendedData & extendedData() const
Return the ExtendedData assigned to the feature.
Definition: GeoDataTrack.cpp:260
GeoDataExtendedData.h
Marble::GeoDataTrack::addPoint
void addPoint(const QDateTime &when, const GeoDataCoordinates &coord)
Add a new point with coordinates coord associated with the time value when.
Definition: GeoDataTrack.cpp:175
MarbleDebug.h
GeoDataTrack.h
Marble::GeoDataExtendedData
a class which allows to add custom data to KML Feature.
Definition: GeoDataExtendedData.h:35
Marble::GeoDataGeometry::pack
virtual void pack(QDataStream &stream) const
Serialize the contents of the feature to stream.
Definition: GeoDataGeometry.cpp:127
Marble::GeoDataTrack::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataTrack.cpp:291
Marble::GeoDataCoordinates::altitude
qreal altitude() const
return the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1197
Marble::GeoDataTrack::GeoDataTrack
GeoDataTrack()
Definition: GeoDataTrack.cpp:55
Marble::GeoDataTrack::appendWhen
void appendWhen(const QDateTime &when)
Add the time value part for a new point.
Definition: GeoDataTrack.cpp:207
Marble::Quaternion::slerp
static Quaternion slerp(const Quaternion &q1, const Quaternion &q2, qreal t)
Definition: Quaternion.cpp:177
Marble::GeoDataTrack::lastWhen
QDateTime lastWhen() const
Return the time value of the last point in the track, or an invalid QDateTime if the track is empty...
Definition: GeoDataTrack.cpp:91
Marble::GeoDataTrack::appendAltitude
void appendAltitude(qreal altitude)
Add altitude information to the last appended coordinates.
Definition: GeoDataTrack.cpp:197
GeoDataLineString.h
Marble::GeoDataTrack::clear
void clear()
Remove all the points contained in the track.
Definition: GeoDataTrack.cpp:212
Marble::GeoDataTrack::size
int size() const
Returns the number of points in the track.
Definition: GeoDataTrack.cpp:67
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataTrack::geometryId
virtual EnumGeometryId geometryId() const
Definition: GeoDataTrack.cpp:275
Marble::GeoDataTrackId
Definition: Serializable.h:49
Marble::GeoDataTrack::coordinatesAt
GeoDataCoordinates coordinatesAt(const QDateTime &when) const
If interpolate() is true, return the coordinates interpolated from the time values before and after w...
Definition: GeoDataTrack.cpp:110
Marble::GeoDataTrack::interpolate
bool interpolate() const
Returns true if coordinatesAt() should use interpolation, false otherwise.
Definition: GeoDataTrack.cpp:72
Marble::GeoDataTrack::firstWhen
QDateTime firstWhen() const
Return the time value of the first point in the track, or an invalid QDateTime if the track is empty...
Definition: GeoDataTrack.cpp:82
GeoDataLatLonAltBox.h
Marble::GeoDataTrack::setInterpolate
void setInterpolate(bool on)
Set whether coordinatesAt() should use interpolation.
Definition: GeoDataTrack.cpp:77
Marble::Quaternion
Definition: Quaternion.h:43
Marble::GeoDataTrack::appendCoordinates
void appendCoordinates(const GeoDataCoordinates &coord)
Add the coordinates part for a new point.
Definition: GeoDataTrack.cpp:190
Marble::EnumGeometryId
EnumGeometryId
Definition: Serializable.h:40
Marble::GeoDataTrack::coordinatesList
QList< GeoDataCoordinates > coordinatesList() const
Returns the coordinates of all the points in the map, sorted by their time value. ...
Definition: GeoDataTrack.cpp:100
Marble::GeoDataTrack::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataTrack.cpp:280
GeoDataTypes.h
Marble::Quaternion::getSpherical
void getSpherical(qreal &lon, qreal &lat) const
Definition: Quaternion.cpp:48
Marble::GeoDataTypes::GeoDataTrackType
const char * GeoDataTrackType
Definition: GeoDataTypes.cpp:77
Marble::GeoDataGeometry::GeoDataLineString
friend class GeoDataLineString
Definition: GeoDataGeometry.h:51
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoDataTrack::removeBefore
void removeBefore(const QDateTime &when)
Remove all points from the track whose time value is less than when.
Definition: GeoDataTrack.cpp:219
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::GeoDataCoordinates::quaternion
const Quaternion & quaternion() const
return a Quaternion with the used coordinates
Definition: GeoDataCoordinates.cpp:1226
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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