• 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
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_lineStringNeedsUpdate( false ),
31  m_interpolate( false )
32  {
33  }
34 
35  void equalizeWhenSize()
36  {
37  while ( m_when.size() < m_coordinates.size() ) {
38  //fill coordinates without time information with null QDateTime
39  m_when.append( QDateTime() );
40  }
41  }
42 
43  GeoDataLineString m_lineString;
44  bool m_lineStringNeedsUpdate;
45 
46  QList<QDateTime> m_when;
47  QList<GeoDataCoordinates> m_coordinates;
48 
49  GeoDataExtendedData m_extendedData;
50 
51  bool m_interpolate;
52 };
53 
54 GeoDataTrack::GeoDataTrack()
55  : d( new GeoDataTrackPrivate() )
56 {
57 
58 }
59 
60 GeoDataTrack::GeoDataTrack( const GeoDataGeometry &other )
61  : GeoDataGeometry( other )
62 {
63 
64 }
65 
66 
67 bool GeoDataTrack::operator==( const GeoDataTrack& other ) const
68 {
69  return equals(other) &&
70  d->m_when == other.d->m_when &&
71  d->m_coordinates == other.d->m_coordinates &&
72  d->m_extendedData == other.d->m_extendedData &&
73  d->m_interpolate == other.d->m_interpolate;
74 }
75 
76 bool GeoDataTrack::operator!=( const GeoDataTrack& other ) const
77 {
78  return !this->operator==( other );
79 }
80 
81 int GeoDataTrack::size() const
82 {
83  return d->m_coordinates.size();
84 }
85 
86 bool GeoDataTrack::interpolate() const
87 {
88  return d->m_interpolate;
89 }
90 
91 void GeoDataTrack::setInterpolate(bool on)
92 {
93  d->m_interpolate = on;
94 }
95 
96 QDateTime GeoDataTrack::firstWhen() const
97 {
98  if ( d->m_when.isEmpty() ) {
99  return QDateTime();
100  }
101 
102  return d->m_when.first();
103 }
104 
105 QDateTime GeoDataTrack::lastWhen() const
106 {
107  if ( d->m_when.isEmpty() ) {
108  return QDateTime();
109  }
110 
111  return d->m_when.last();
112 }
113 
114 QList<GeoDataCoordinates> GeoDataTrack::coordinatesList() const
115 {
116  return d->m_coordinates;
117 }
118 
119 QList<QDateTime> GeoDataTrack::whenList() const
120 {
121  return d->m_when;
122 }
123 
124 GeoDataCoordinates GeoDataTrack::coordinatesAt( const QDateTime &when ) const
125 {
126  if ( d->m_when.isEmpty() ) {
127  return GeoDataCoordinates();
128  }
129 
130  if ( d->m_when.contains( when ) ) {
131  //exact match found
132  int index = d->m_when.indexOf( when );
133  if ( index < d->m_coordinates.size() ) {
134  return d->m_coordinates.at( index );
135  }
136  }
137 
138  if ( !interpolate() ) {
139  return GeoDataCoordinates();
140  }
141 
142  typedef QMap<QDateTime, GeoDataCoordinates> PointMap;
143  PointMap pointMap;
144  for ( int i = 0; i < qMin( d->m_when.size(), d->m_coordinates.size() ); ++i) {
145  if ( d->m_when.at( i ).isValid() ) {
146  pointMap[ d->m_when.at( i ) ] = d->m_coordinates.at( i );
147  }
148  }
149 
150  QMap<QDateTime, GeoDataCoordinates>::const_iterator nextEntry = const_cast<const PointMap&>(pointMap).upperBound( when );
151 
152  // No tracked point happened before "when"
153  if ( nextEntry == pointMap.constBegin() ) {
154  mDebug() << "No tracked point before " << when;
155  return GeoDataCoordinates();
156  }
157 
158  QMap<QDateTime, GeoDataCoordinates>::const_iterator previousEntry = nextEntry - 1;
159  GeoDataCoordinates previousCoord = previousEntry.value();
160 
161  QDateTime previousWhen = previousEntry.key();
162  QDateTime nextWhen = nextEntry.key();
163  GeoDataCoordinates nextCoord = nextEntry.value();
164 
165  int interval = previousWhen.msecsTo( nextWhen );
166  int position = previousWhen.msecsTo( when );
167  qreal t = (qreal)position / (qreal)interval;
168 
169  Quaternion interpolated;
170  interpolated.slerp( previousCoord.quaternion(), nextCoord.quaternion(), t );
171  qreal lon, lat;
172  interpolated.getSpherical( lon, lat );
173 
174  qreal alt = previousCoord.altitude() + ( nextCoord.altitude() - previousCoord.altitude() ) * t;
175 
176  return GeoDataCoordinates( lon, lat, alt );
177 }
178 
179 GeoDataCoordinates GeoDataTrack::coordinatesAt( int index ) const
180 {
181  return d->m_coordinates.at( index );
182 }
183 
184 void GeoDataTrack::addPoint( const QDateTime &when, const GeoDataCoordinates &coord )
185 {
186  d->equalizeWhenSize();
187  d->m_lineStringNeedsUpdate = true;
188  int i=0;
189  while ( i < d->m_when.size() ) {
190  if ( d->m_when.at( i ) > when ) {
191  break;
192  }
193  ++i;
194  }
195  d->m_when.insert(i, when );
196  d->m_coordinates.insert(i, coord );
197 }
198 
199 void GeoDataTrack::appendCoordinates( const GeoDataCoordinates &coord )
200 {
201  d->equalizeWhenSize();
202  d->m_lineStringNeedsUpdate = true;
203  d->m_coordinates.append( coord );
204 }
205 
206 void GeoDataTrack::appendAltitude( qreal altitude )
207 {
208  d->m_lineStringNeedsUpdate = true;
209  Q_ASSERT( !d->m_coordinates.isEmpty() );
210  if ( d->m_coordinates.isEmpty() ) return;
211  GeoDataCoordinates coordinates = d->m_coordinates.takeLast();
212  coordinates.setAltitude( altitude );
213  d->m_coordinates.append( coordinates );
214 }
215 
216 void GeoDataTrack::appendWhen( const QDateTime &when )
217 {
218  d->m_when.append( when );
219 }
220 
221 void GeoDataTrack::clear()
222 {
223  d->m_when.clear();
224  d->m_coordinates.clear();
225  d->m_lineStringNeedsUpdate = true;
226 }
227 
228 void GeoDataTrack::removeBefore( const QDateTime &when )
229 {
230  Q_ASSERT( d->m_coordinates.size() == d->m_when.size() );
231  if ( d->m_when.isEmpty() ) {
232  return;
233  }
234  d->equalizeWhenSize();
235 
236  while ( !d->m_when.isEmpty() && d->m_when.first() < when ) {
237  d->m_when.takeFirst();
238  d->m_coordinates.takeFirst();
239  }
240 }
241 
242 void GeoDataTrack::removeAfter( const QDateTime &when )
243 {
244  Q_ASSERT( d->m_coordinates.size() == d->m_when.size() );
245  if ( d->m_when.isEmpty() ) {
246  return;
247  }
248  d->equalizeWhenSize();
249  while ( !d->m_when.isEmpty() && d->m_when.last() > when ) {
250  d->m_when.takeLast();
251  d->m_coordinates.takeLast();
252 
253  }
254 }
255 
256 const GeoDataLineString *GeoDataTrack::lineString() const
257 {
258  if ( d->m_lineStringNeedsUpdate ) {
259  d->m_lineString = GeoDataLineString();
260  foreach ( const GeoDataCoordinates &coordinates, coordinatesList() ) {
261  d->m_lineString.append( coordinates );
262  }
263  d->m_lineStringNeedsUpdate = false;
264  }
265  return &d->m_lineString;
266 }
267 
268 GeoDataExtendedData& GeoDataTrack::extendedData() const
269 {
270  return d->m_extendedData;
271 }
272 
273 void GeoDataTrack::setExtendedData( const GeoDataExtendedData& extendedData )
274 {
275  d->m_extendedData = extendedData;
276 }
277 
278 const char* GeoDataTrack::nodeType() const
279 {
280  return GeoDataTypes::GeoDataTrackType;
281 }
282 
283 EnumGeometryId GeoDataTrack::geometryId() const
284 {
285  return GeoDataTrackId;
286 }
287 
288 const GeoDataLatLonAltBox& GeoDataTrack::latLonAltBox() const
289 {
290  return lineString()->latLonAltBox();
291 }
292 
293 //TODO
294 void GeoDataTrack::pack( QDataStream& stream ) const
295 {
296  GeoDataGeometry::pack( stream );
297 }
298 //TODO
299 void GeoDataTrack::unpack( QDataStream& stream )
300 {
301  GeoDataGeometry::unpack( stream );
302 }
303 
304 }
Marble::GeoDataTrack::removeAfter
void removeAfter(const QDateTime &when)
Remove all points from the track whose time value is greater than when.
Definition: GeoDataTrack.cpp:242
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:273
Marble::GeoDataGeometry::unpack
virtual void unpack(QDataStream &stream)
Unserialize the contents of the feature from stream.
Definition: GeoDataGeometry.cpp:135
Marble::GeoDataTrack
A geometry for tracking objects made of (time, coordinates) pairs.
Definition: GeoDataTrack.h:54
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:294
Marble::GeoDataTrack::operator!=
bool operator!=(const GeoDataTrack &other) const
Definition: GeoDataTrack.cpp:76
QDataStream
Marble::GeoDataTrack::operator==
bool operator==(const GeoDataTrack &other) const
: Equality operators.
Definition: GeoDataTrack.cpp:67
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
QMap
Marble::GeoDataTrack::lineString
const GeoDataLineString * lineString() const
Return the GeoDataLineString representing the current track.
Definition: GeoDataTrack.cpp:256
Marble::GeoDataTrack::whenList
QList< QDateTime > whenList() const
Returns the time value of all the points in the map, in chronological order.
Definition: GeoDataTrack.cpp:119
Marble::GeoDataTrack::nodeType
virtual const char * nodeType() const
Provides type information for downcasting a GeoData.
Definition: GeoDataTrack.cpp:278
Marble::GeoDataTrack::extendedData
GeoDataExtendedData & extendedData() const
Return the ExtendedData assigned to the feature.
Definition: GeoDataTrack.cpp:268
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:184
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:299
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:54
Marble::GeoDataTrack::appendWhen
void appendWhen(const QDateTime &when)
Add the time value part for a new point.
Definition: GeoDataTrack.cpp:216
Marble::Quaternion::slerp
static Quaternion slerp(const Quaternion &q1, const Quaternion &q2, qreal t)
Definition: Quaternion.cpp:201
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:105
Marble::GeoDataTrack::appendAltitude
void appendAltitude(qreal altitude)
Add altitude information to the last appended coordinates.
Definition: GeoDataTrack.cpp:206
GeoDataLineString.h
QMap::const_iterator
Marble::GeoDataTrack::clear
void clear()
Remove all the points contained in the track.
Definition: GeoDataTrack.cpp:221
QList< QDateTime >
Marble::GeoDataTrack::size
int size() const
Returns the number of points in the track.
Definition: GeoDataTrack.cpp:81
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:283
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:124
Marble::GeoDataTrack::interpolate
bool interpolate() const
Returns true if coordinatesAt() should use interpolation, false otherwise.
Definition: GeoDataTrack.cpp:86
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:96
GeoDataLatLonAltBox.h
Marble::GeoDataTrack::setInterpolate
void setInterpolate(bool on)
Set whether coordinatesAt() should use interpolation.
Definition: GeoDataTrack.cpp:91
Marble::Quaternion
Definition: Quaternion.h:41
Marble::GeoDataTrack::appendCoordinates
void appendCoordinates(const GeoDataCoordinates &coord)
Add the coordinates part for a new point.
Definition: GeoDataTrack.cpp:199
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:114
Marble::GeoDataTrack::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataTrack.cpp:288
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:86
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:36
Marble::GeoDataTrack::removeBefore
void removeBefore(const QDateTime &when)
Remove all points from the track whose time value is less than when.
Definition: GeoDataTrack.cpp:228
Marble::GeoDataGeometry::equals
bool equals(const GeoDataGeometry &other) const
Definition: GeoDataGeometry.cpp:146
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
QDateTime
Marble::GeoDataCoordinates::quaternion
const Quaternion & quaternion() const
return a Quaternion with the used coordinates
Definition: GeoDataCoordinates.cpp:1236
QDateTime::msecsTo
qint64 msecsTo(const QDateTime &other) const
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