• 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
  • mapreproject
tools/mapreproject/main.cpp
Go to the documentation of this file.
1 #include "BilinearInterpolation.h"
2 #include "NasaWorldWindToOpenStreetMapConverter.h"
3 #include "NearestNeighborInterpolation.h"
4 #include "OsmTileClusterRenderer.h"
5 #include "ReadOnlyMapDefinition.h"
6 #include "Thread.h"
7 #include "mapreproject.h"
8 
9 #include <QCoreApplication>
10 #include <QDebug>
11 #include <QDir>
12 #include <QPair>
13 #include <QThread>
14 #include <QVector>
15 
16 #include <getopt.h>
17 
18 #include <cstdlib>
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 
23 /* example usage
24 mapreproject --simulate --output-directory=/home/jmho --jobs 7 --cluster-size 64 --output-tile-level=10 \
25  --input=type=NasaWW,base-directory=/home,tile-level=8,interpolation-method=bilinear,cache-size=200000000 \
26  --input type=Bathymetry,file=BLAH.tiff
27 */
28 
29 void printUsage()
30 {
31  std::cout << "Usage: mapreproject [OPTIONS] [INPUT] ...\n"
32  " --help display this help and exit\n"
33  " --output-directory output base directory, where the resulting tiles will be stored\n"
34  " --output-tile-level tile level of resulting map\n"
35  " --cluster-size edge length of tile clusters in tiles\n"
36  " --jobs number of threads, use to override default of one thread per cpu core\n"
37  " --simulate \n"
38  " --input INPUT_OPTS INPUT_OPTS can be a combination of the following options, separated by comma:\n"
39  " type \n"
40  " base-directory \n"
41  " tile-level \n"
42  " cache-size \n"
43  " file \n"
44  " interpolation-method one of \"integer\", \"nearest-neighbor\" (default), \"average\" or \"bilinear\"\n";
45 }
46 
47 MapSourceType parseType( char const * const value )
48 {
49  MapSourceType result = UnknownMapSource;
50  if ( !value )
51  qFatal("Suboption 'type' does not have a value.");
52  if ( strcmp( value, "NasaWW") == 0 )
53  result = NasaWorldWindMap;
54  else if ( strcmp( value, "Bathymetry" ) == 0 )
55  result = BathymetryMap;
56  else
57  qFatal("Suboption 'type': Unrecognized value '%s'.", value );
58  return result;
59 }
60 
61 QString parseString( char const * const value )
62 {
63  QString result;
64  if ( !value )
65  qFatal("Suboption does not have a value.");
66  result = value;
67  return result;
68 }
69 
70 int parseInt( char const * const value )
71 {
72  if ( !value )
73  qFatal("Suboption does not have a value.");
74  QString str( value );
75  bool ok;
76  int const result = str.toInt( &ok );
77  if ( !ok )
78  qFatal("Suboption does not have an integer value.");
79  return result;
80 }
81 
82 EInterpolationMethod parseInterpolationMethod( char const * const value )
83 {
84  EInterpolationMethod result = UnknownInterpolationMethod;
85  if ( !value )
86  qFatal("Suboption 'interpolation-method' does not have a value.");
87  if ( strcmp( value, "integer") == 0 )
88  result = IntegerInterpolationMethod;
89  if ( strcmp( value, "nearest-neighbor") == 0 )
90  result = NearestNeighborInterpolationMethod;
91  if ( strcmp( value, "average") == 0 )
92  result = AverageInterpolationMethod;
93  else if ( strcmp( value, "bilinear" ) == 0 )
94  result = BilinearInterpolationMethod;
95  else
96  qFatal("Suboption 'interpolation-method': Unrecognized value '%s'.", value );
97  return result;
98 }
99 
100 ReadOnlyMapDefinition parseInput( char * subopts )
101 {
102  if ( !subopts )
103  qFatal("Missing argument for '--input'");
104 
105  enum
106  {
107  TypeOption = 0,
108  BaseDirectoryOption,
109  FileOption,
110  TileLevelOption,
111  InterpolationOption,
112  CacheSizeOption,
113  TheEnd
114  };
115 
116  char * const input_opts[] =
117  {
118  "type",
119  "base-directory",
120  "file",
121  "tile-level",
122  "interpolation-method",
123  "cache-size",
124  NULL
125  };
126 
127  ReadOnlyMapDefinition mapDefinition;
128 
129  char * value;
130  while ( *subopts != '\0' ) {
131  switch ( getsubopt( &subopts, input_opts, &value )) {
132 
133  case TypeOption:
134  mapDefinition.setMapType( parseType( value ));
135  break;
136 
137  case BaseDirectoryOption:
138  mapDefinition.setBaseDirectory( parseString( value ));
139  break;
140 
141  case FileOption:
142  mapDefinition.setFileName( parseString( value ));
143  break;
144 
145  case TileLevelOption:
146  mapDefinition.setTileLevel( parseInt( value ));
147  break;
148 
149  case InterpolationOption:
150  mapDefinition.setInterpolationMethod( parseInterpolationMethod( value ));
151  break;
152 
153  case CacheSizeOption:
154  mapDefinition.setCacheSizeBytes( parseInt( value ));
155  break;
156 
157  default:
158  qFatal("Unrecognized input suboption.");
159  }
160  }
161  return mapDefinition;
162 }
163 
164 
165 int main( int argc, char *argv[] )
166 {
167  QCoreApplication app( argc, argv );
168 
169  // --interpolation-method=NearestNeighbor|Bilinear
170 
171  QString outputDirectory;
172  int outputTileLevel = -1;
173 
174  int threadCount = QThread::idealThreadCount();
175  int clusterSize = 0; // cluster size 0 makes no sense
176  bool onlySimulate = false;
177 
178  QVector<ReadOnlyMapDefinition> mapSources;
179 
180  // input: type, tile-level, base-dir|file
181  // --input,type=NasaWW,tile-level=8,base-directory=<dir>,interpolation-method=Bilinear
182  // --input,type=Image,file=<file>
183 
184  enum { HelpOption = 1,
185  InputOption,
186  OutputDirectoryOption,
187  OutputTileLevelOption,
188  JobsOption,
189  ClusterSizeOption,
190  SimulateOption };
191 
192  static struct option long_options[] = {
193  {"help", no_argument, NULL, HelpOption },
194  {"input", required_argument, NULL, InputOption },
195  {"output-directory", required_argument, NULL, OutputDirectoryOption },
196  {"output-tile-level", required_argument, NULL, OutputTileLevelOption },
197  {"jobs", required_argument, NULL, JobsOption },
198  {"cluster-size", required_argument, NULL, ClusterSizeOption },
199  {"simulate", no_argument, NULL, SimulateOption },
200  {0, 0, 0, 0 }
201  };
202 
203  while ( true ) {
204  int option_index = 0;
205 
206  int const opt = getopt_long( argc, argv, "", long_options, &option_index );
207  if ( opt == -1 )
208  break;
209 
210  switch ( opt ) {
211 
212  case HelpOption:
213  printUsage();
214  exit( EXIT_SUCCESS );
215 
216  case InputOption:
217  mapSources.push_back( parseInput( optarg ));
218  break;
219 
220  case OutputDirectoryOption:
221  outputDirectory = parseString( optarg );
222  break;
223 
224  case OutputTileLevelOption:
225  outputTileLevel = parseInt( optarg );
226  break;
227 
228  case JobsOption:
229  threadCount = parseInt( optarg );
230  break;
231 
232  case ClusterSizeOption:
233  clusterSize = parseInt( optarg );
234  break;
235 
236  case SimulateOption:
237  onlySimulate = true;
238  break;
239 
240  case '?':
241  break;
242  }
243  }
244 
245  qDebug() << "\noutput directory:" << outputDirectory
246  << "\noutput tile level:" << outputTileLevel
247  << "\ncluster size:" << clusterSize
248  << "\nthreads:" << threadCount
249  << "\ninputs:" << mapSources;
250 
251  if (onlySimulate)
252  exit( EXIT_SUCCESS );
253 
254  NasaWorldWindToOpenStreetMapConverter converter;
255  converter.setMapSources( mapSources );
256  converter.setOsmBaseDirectory( QDir( outputDirectory ));
257  converter.setOsmTileLevel( outputTileLevel );
258  converter.setOsmTileClusterEdgeLengthTiles( clusterSize );
259  converter.setThreadCount( threadCount );
260 
261  QObject::connect( &converter, SIGNAL(finished()), &app, SLOT(quit()));
262 
263  QVector<QPair<Thread*, OsmTileClusterRenderer*> > renderThreads = converter.start();
264  app.exec();
265 
266  QVector<QPair<Thread*, OsmTileClusterRenderer*> >::iterator pos = renderThreads.begin();
267  QVector<QPair<Thread*, OsmTileClusterRenderer*> >::iterator const end = renderThreads.end();
268  for (; pos != end; ++pos ) {
269  (*pos).first->stop();
270  (*pos).first->wait();
271  delete (*pos).second;
272  }
273 
274  return EXIT_SUCCESS;
275 }
ReadOnlyMapDefinition::setFileName
void setFileName(QString const &fileName)
Definition: ReadOnlyMapDefinition.h:63
ReadOnlyMapDefinition::setTileLevel
void setTileLevel(int const tileLevel)
Definition: ReadOnlyMapDefinition.h:73
OsmTileClusterRenderer.h
NasaWorldWindToOpenStreetMapConverter::setThreadCount
void setThreadCount(int const threadCount)
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:48
EInterpolationMethod
EInterpolationMethod
Definition: mapreproject.h:4
NasaWorldWindToOpenStreetMapConverter
Definition: NasaWorldWindToOpenStreetMapConverter.h:22
NasaWorldWindToOpenStreetMapConverter::setOsmTileLevel
void setOsmTileLevel(int const level)
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:43
parseInput
ReadOnlyMapDefinition parseInput(char *subopts)
Definition: tools/mapreproject/main.cpp:100
NasaWorldWindMap
Definition: mapreproject.h:11
ReadOnlyMapDefinition::setInterpolationMethod
void setInterpolationMethod(EInterpolationMethod const interpolationMethod)
Definition: ReadOnlyMapDefinition.h:58
NasaWorldWindToOpenStreetMapConverter::start
QVector< QPair< Thread *, OsmTileClusterRenderer * > > start()
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:53
NearestNeighborInterpolationMethod
Definition: mapreproject.h:6
IntegerInterpolationMethod
Definition: mapreproject.h:5
Thread.h
ReadOnlyMapDefinition::setMapType
void setMapType(MapSourceType const mapType)
Definition: ReadOnlyMapDefinition.h:68
parseString
QString parseString(char const *const value)
Definition: tools/mapreproject/main.cpp:61
NearestNeighborInterpolation.h
main
int main(int argc, char *argv[])
Definition: tools/mapreproject/main.cpp:165
UnknownMapSource
Definition: mapreproject.h:10
UnknownInterpolationMethod
Definition: mapreproject.h:4
ReadOnlyMapDefinition::setCacheSizeBytes
void setCacheSizeBytes(int const cacheSizeBytes)
Definition: ReadOnlyMapDefinition.h:53
BilinearInterpolation.h
NasaWorldWindToOpenStreetMapConverter.h
QCoreApplication
mapreproject.h
NasaWorldWindToOpenStreetMapConverter::setOsmBaseDirectory
void setOsmBaseDirectory(QDir const &nwwBaseDirectory)
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:29
printUsage
void printUsage()
Definition: tools/mapreproject/main.cpp:29
BathymetryMap
Definition: mapreproject.h:12
parseInterpolationMethod
EInterpolationMethod parseInterpolationMethod(char const *const value)
Definition: tools/mapreproject/main.cpp:82
ReadOnlyMapDefinition
Definition: ReadOnlyMapDefinition.h:12
parseInt
int parseInt(char const *const value)
Definition: tools/mapreproject/main.cpp:70
ReadOnlyMapDefinition::setBaseDirectory
void setBaseDirectory(QString const &baseDirectory)
Definition: ReadOnlyMapDefinition.h:48
NasaWorldWindToOpenStreetMapConverter::setMapSources
void setMapSources(QVector< ReadOnlyMapDefinition > const &mapSources)
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:24
BilinearInterpolationMethod
Definition: mapreproject.h:8
MapSourceType
MapSourceType
Definition: mapreproject.h:10
parseType
MapSourceType parseType(char const *const value)
Definition: tools/mapreproject/main.cpp:47
NasaWorldWindToOpenStreetMapConverter::setOsmTileClusterEdgeLengthTiles
void setOsmTileClusterEdgeLengthTiles(int const clusterEdgeLengthTiles)
Definition: NasaWorldWindToOpenStreetMapConverter.cpp:38
ReadOnlyMapDefinition.h
AverageInterpolationMethod
Definition: mapreproject.h:7
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 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