• 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
  • examples
  • cpp
  • animation-video
examples/cpp/animation-video/main.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 2013 Dennis Nienhüser <earthwings@gentoo.org>
9 // Loosely based on MarblePhysics.cpp
10 //
11 
17 #include <marble/MarbleWidget.h>
18 #include <GeoDataCoordinates.h>
19 #include <GeoDataLineString.h>
20 #include <marble/RenderPlugin.h>
21 #include <marble/Quaternion.h>
22 
23 #include <opencv2/highgui/highgui.hpp>
24 #include <opencv2/imgproc/imgproc.hpp>
25 
26 #include <QTimeLine>
27 #include <qmath.h>
28 #include <QApplication>
29 
30 #include <cstdio>
31 
32 using namespace Marble;
33 using namespace cv;
34 
35 namespace {
36  // Some stuff you might want to change
37 
38  // The map theme in use
39  QString const mapTheme = "earth/mapquest-open-aerial/mapquest-open-aerial.dgml";
40 
41  // Enabled plugins. Everything else will be disabled
42  QStringList const features = QStringList() << "stars" << "atmosphere";
43 
44  // Camera starting point: Position and zoom level
45  GeoDataCoordinates const source( 8.40314, 49.01302, 0.0, GeoDataCoordinates::Degree);
46  double const sourceZoomLevel = 11;
47 
48  // Camera destination point: Position and zoom level
49  GeoDataCoordinates const destination( -101.36631, 43.13718, 0.0, GeoDataCoordinates::Degree);
50  double const destinationZoomLevel = 14;
51 
52  // Minimum zoom level (in the middle of the animation)
53  double const jumpZoomLevel = 5.5;
54 
55  // Length of the video
56  QTimeLine timeLine( 20 * 1000 );
57 
58  // Frames per second
59  int const fps = 30;
60 
61  // Target video file name
62  std::string const videoFile = "marble-animated-zoom.avi";
63 
64  // Video resolution
65  Size frameSize( 1280, 720 );
66 }
67 
68 void interpolate( MarbleWidget* widget, qreal value )
69 {
70  GeoDataCoordinates coordinates;
71  qreal lon, lat;
72  Quaternion::slerp( source.quaternion(), destination.quaternion(), value ).getSpherical( lon, lat );
73  coordinates.setLongitude( lon );
74  coordinates.setLatitude( lat );
75  widget->centerOn( coordinates );
76  widget->setRadius( exp(jumpZoomLevel) + (value < 0.5 ? exp(sourceZoomLevel*(1.0-2*value)) : exp(destinationZoomLevel*(2*value-1.0))) );
77 }
78 
79 void animatedFlight( MarbleWidget *mapWidget )
80 {
81  mapWidget->resize( frameSize.width, frameSize.height );
82  VideoWriter videoWriter( videoFile, CV_FOURCC('D','I','V','X'), fps, frameSize );
83  Mat buffer;
84  buffer.create(frameSize, CV_8UC3);
85  timeLine.setCurveShape( QTimeLine::EaseInOutCurve );
86  int const frameTime = qRound( 1000.0 / fps );
87  for ( int i=1; i<=timeLine.duration(); i+=frameTime ) {
88  printf("[%i%% done]\r", cvRound( (100.0*i)/timeLine.duration() ) );
89  fflush(stdout);
90  interpolate( mapWidget, timeLine.valueForTime( i ) );
91  QImage screenshot = QPixmap::grabWidget( mapWidget ).toImage().convertToFormat( QImage::Format_RGB888 );
92  Mat converter( frameSize, CV_8UC3 );
93  converter.data = screenshot.bits();
94  cvtColor( converter, buffer, CV_RGB2BGR );
95  videoWriter.write( buffer );
96  }
97  for ( int i=0; i<fps; ++i ) {
98  videoWriter.write( buffer ); // one second stand-still at end
99  }
100  printf("Wrote %s\n", videoFile.c_str());
101 }
102 
103 int main(int argc, char** argv)
104 {
105  QApplication app(argc,argv);
106  MarbleWidget *mapWidget = new MarbleWidget;
107  mapWidget->setMapThemeId(mapTheme);
108  foreach( RenderPlugin* plugin, mapWidget->renderPlugins() ) {
109  if ( !features.contains( plugin->nameId() ) ) {
110  plugin->setEnabled( false );
111  }
112  }
113 
114  animatedFlight( mapWidget );
115  return 0;
116 }
GeoDataCoordinates.h
Quaternion.h
interpolate
void interpolate(MarbleWidget *widget, qreal value)
Definition: examples/cpp/animation-video/main.cpp:68
QImage::convertToFormat
QImage convertToFormat(Format format, QFlags< Qt::ImageConversionFlag > flags) const
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
main
int main(int argc, char **argv)
Definition: examples/cpp/animation-video/main.cpp:103
QApplication
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::MarbleWidget
A widget class that displays a view of the earth.
Definition: MarbleWidget.h:104
Marble::MarbleWidget::setMapThemeId
void setMapThemeId(const QString &maptheme)
Set a new map theme.
Definition: MarbleWidget.cpp:759
QWidget::resize
void resize(int w, int h)
Marble::Quaternion::slerp
static Quaternion slerp(const Quaternion &q1, const Quaternion &q2, qreal t)
Definition: Quaternion.cpp:201
GeoDataLineString.h
QString
QStringList
Marble::RenderPlugin::nameId
QString nameId
Definition: RenderPlugin.h:48
Marble::MarbleWidget::centerOn
void centerOn(const qreal lon, const qreal lat, bool animated=false)
Center the view on a geographical point.
Definition: MarbleWidget.cpp:549
Marble::MarbleWidget::setRadius
void setRadius(int radius)
Set the radius of the globe in pixels.
Definition: MarbleWidget.cpp:330
Marble::GeoDataCoordinates::setLatitude
void setLatitude(qreal lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:699
QImage
animatedFlight
void animatedFlight(MarbleWidget *mapWidget)
Definition: examples/cpp/animation-video/main.cpp:79
Marble::GeoDataCoordinates::setLongitude
void setLongitude(qreal lon, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
set the longitude in a GeoDataCoordinates object
Definition: GeoDataCoordinates.cpp:679
Marble::RenderPlugin::setEnabled
void setEnabled(bool enabled)
settting enabled
Definition: RenderPlugin.cpp:139
RenderPlugin.h
QPixmap::grabWidget
QPixmap grabWidget(QWidget *widget, const QRect &rectangle)
QTimeLine
MarbleWidget.h
This file contains the headers for MarbleWidget.
QPixmap::toImage
QImage toImage() const
Marble::RenderPlugin
The abstract class that creates a renderable item.
Definition: RenderPlugin.h:43
Marble::MarbleWidget::renderPlugins
QList< RenderPlugin * > renderPlugins() const
Returns a list of all RenderPlugins on the widget, this includes float items.
Definition: MarbleWidget.cpp:1107
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:40 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