• 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
  • tools
  • dateline
dateline.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 2006-2007 Torsten Rahn <tackat@kde.org>
9 // Copyright 2007 Inge Wallin <ingwa@kde.org>
10 //
11 
12 
13 #include <cmath>
14 
15 #include <QCoreApplication>
16 #include <QDebug>
17 #include <QFile>
18 #include <QVector>
19 #include <QStringList>
20 #include "Quaternion.h"
21 
22 using namespace Marble;
23 
24 int getHeader( int count, int size )
25 {
26  int header = 0;
27  if ( size > 14 ) {
28  if ( count % 9 == 0 )
29  header = 5;
30  else if ( count % 5 == 0 )
31  header = 3;
32  else if ( count % 2 == 0 )
33  header = 2;
34  else
35  header = 1;
36  }
37  else if ( size > 6 ) {
38  if ( count % 2 == 0 )
39  header = 3;
40  else
41  header = 1;
42  }
43  else {
44  header = 2;
45  }
46  if ( count == size - 1 )
47  header = 5;
48 
49  return header;
50 }
51 
52 double deg2rad = M_PI / 180.0;
53 
54 int main(int argc, char *argv[])
55 {
56 
57  QString sourcefilename;
58  QString targetfilename;
59 
60  QCoreApplication app( argc, argv );
61 
62 
63  if ( argc != 4 || strcmp( argv[ 1 ], "-o" ) != 0 )
64  {
65  qDebug(" dateline -o targetfile sourcefile");
66  return 0;
67  }
68 
69  targetfilename = QString(argv[2]);
70  sourcefilename = QString(argv[3]);
71 
72  QVector<float> idlPosList;
73 
74  QFile sourcefile( sourcefilename );
75  sourcefile.open( QIODevice::ReadOnly );
76 
77  qDebug() << "Source: " << sourcefilename;
78  qDebug() << "Target: " << targetfilename;
79 
80  // Read the data serialized from the file.
81  QTextStream sourcestream( &sourcefile );
82  sourcestream.setCodec("UTF-8");
83 
84  QString rawline;
85  QString lonstring;
86  QString latstring;
87 
88  QStringList splitline;
89 
90  int line = 0;
91 
92  while ( !sourcestream.atEnd() )
93  {
94  rawline = sourcestream.readLine();
95 
96  if ( !rawline.contains( QChar(' ') ) )
97  {
98  qDebug() << "Line " << line << " does not contain a space separator.";
99  continue;
100  }
101  splitline = rawline.split( QChar(' ') );
102 
103  lonstring = splitline[0];
104  latstring = splitline[1];
105 
106 // qDebug() << "Point read at: " << lonstring << ", " << latstring;
107 
108  float lon = lonstring.toFloat();
109  float lat = latstring.toFloat();
110 
111  idlPosList.append(lon);
112  idlPosList.append(lat);
113  ++line;
114  }
115 
116  QFile targetfile( targetfilename );
117 
118  // Read the data serialized from the file.
119  targetfile.open( QIODevice::WriteOnly );
120  QDataStream stream( &targetfile );
121  stream.setByteOrder( QDataStream::LittleEndian );
122 
123  int count = 0;
124  bool firstheader = true;
125 
126  QVector<float>::iterator i = idlPosList.begin();
127 
128  float lastlon = 99999.0f;
129  float lastlat = 99999.0f;
130 
131  const float step = 50.0f;
132 
133  while ( i != idlPosList.end() ) {
134  float lonf = *i++;
135  float latf = *i++;
136  // qDebug() << "Writing point" << lonf << ", " << latf;
137 
138  float header;
139  float lat;
140  float lon;
141 
142  header = 5;
143  if ( firstheader ) {
144  header = 19000;
145  firstheader = false;
146  }
147 
148  lon = ( lonf * 60.0f );
149  lat = ( latf * 60.0f );
150 
151  if ( lastlon != 99999.0f || lastlat != 99999.0f )
152  {
153  Quaternion lastPos = Quaternion::fromSpherical((lastlon/60.0) * deg2rad , (lastlat/60.0) * -deg2rad );
154  Quaternion currentPos = Quaternion::fromSpherical((lon/60.0) * deg2rad , (lat/60.0) * -deg2rad );
155 // qDebug() << "lastPos: " << lastPos << "currentPos: " << currentPos;
156  Quaternion itPos = currentPos;
157 
158  float distance = sqrt( ( lon - lastlon ) * ( lon - lastlon )
159  + ( lat - lastlat ) * ( lat - lastlat ) );
160  int numsteps = (int)( distance / step );
161 
162  for ( int i = 1; i < numsteps; ++i )
163  {
164  itPos = itPos.slerp( lastPos, currentPos, (double)(i)/(double)(numsteps) );
165 // qDebug() << "itPos: " << itPos;
166  double alpha = 0;
167  double beta = 0;
168  itPos.getSpherical( alpha, beta);
169 // qDebug() << "alpha: " << alpha << " beta: " << beta;
170  float ipLon = alpha * 180.0 / M_PI * 60;
171  float ipLat = - beta * 180.0 / M_PI * 60;
172 
173  short ipHeader = getHeader( i, numsteps );
174 
175  qDebug() << "numsteps: " << numsteps << "ipLon:" << (short)ipLon << "ipLat:" << (short)ipLat << "ipHeader:" << (short)ipHeader << "node#:" << count;
176  stream << (short)(ipHeader) << (short)(ipLat) << (short)(ipLon);
177 
178  count ++;
179  }
180 
181 
182  }
183 
184  qDebug() << "lng:" << (short)(lon) << "lat:" << (short)(lat) << "header:"
185  << (short)(header) << "node#:" << count;
186 
187  stream << (short)(header) << (short)(lat) << (short)(lon);
188 
189  lastlon = lon;
190  lastlat = lat;
191  count++;
192  }
193  targetfile.close();
194 
195  qDebug("Finished!");
196 
197  app.exit();
198 }
Quaternion.h
main
int main(int argc, char *argv[])
Definition: dateline.cpp:54
Marble::Quaternion::slerp
static Quaternion slerp(const Quaternion &q1, const Quaternion &q2, qreal t)
Definition: Quaternion.cpp:177
getHeader
int getHeader(int count, int size)
Definition: dateline.cpp:24
deg2rad
double deg2rad
Definition: dateline.cpp:52
QCoreApplication
Marble::Quaternion
Definition: Quaternion.h:43
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
Marble::Quaternion::getSpherical
void getSpherical(qreal &lon, qreal &lat) const
Definition: Quaternion.cpp:48
Marble::Quaternion::fromSpherical
static Quaternion fromSpherical(qreal lon, qreal lat)
used to generate Quaternion from longitude and latitude
Definition: Quaternion.cpp:38
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