• 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
  • graphicsitem
GeoPhotoGraphicsItem.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 2012 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "GeoPhotoGraphicsItem.h"
12 
13 #include "GeoPainter.h"
14 #include "ViewportParams.h"
15 
16 #include <QImageReader>
17 
18 #include <QDebug>
19 
20 namespace Marble
21 {
22 
23 GeoPhotoGraphicsItem::GeoPhotoGraphicsItem( const GeoDataFeature *feature )
24  : GeoGraphicsItem( feature )
25 {
26 }
27 
28 void GeoPhotoGraphicsItem::setPhoto( const QImage &photo )
29 {
30  m_photo = photo;
31 }
32 
33 QImage GeoPhotoGraphicsItem::photo() const
34 {
35  return m_photo;
36 }
37 
38 void GeoPhotoGraphicsItem::setPhotoFile( const QString &filename )
39 {
40  m_photoPath = filename;
41 }
42 
43 QString GeoPhotoGraphicsItem::photoPath() const
44 {
45  return m_photoPath;
46 }
47 
48 void GeoPhotoGraphicsItem::paint( GeoPainter* painter, const ViewportParams* viewport )
49 {
51  qreal const planetRadius = EARTH_RADIUS;
53  qreal const viewAngle = 110.0;
54  qreal const cameraDistance = 1000 * planetRadius * 0.4 / viewport->radius() / tan( 0.5 * viewAngle * DEG2RAD );
56  qreal const near = 200.0;
57 
58  /* The code below loads the image lazily (only
59  * when it will actually be displayed). Once it was
60  * loaded but moves out of the viewport, it is unloaded
61  * again. Otherwise memory consumption gets quite high
62  * for a large set of photos
63  */
64  bool unloadImage = true;
65 
66  if ( cameraDistance > m_point.coordinates().altitude() ) {
67  QSizeF size;
68  if ( m_photo.isNull() && !m_photoPath.isEmpty() ) {
69  QImageReader reader( m_photoPath );
70  size = reader.size(); // Image is not loaded yet
71  } else {
72  size = m_photo.size(); // Image loaded or invalid
73  }
74  size *= (m_point.coordinates().altitude() + near) / cameraDistance;
75  if ( size.width() * size.height() > 256 ) {
76  // The image gets displayed if the observer is above it and if it covers a certain minimum area
77  qreal x(0.0), y( 0.0 );
78  viewport->screenCoordinates( m_point.coordinates(), x, y );
79  QRectF position( QPointF( x, y ), size );
80  position.moveCenter( QPointF( x, y ) );
81 
82  QRectF displayed = position & QRectF( QPointF( 0, 0 ), viewport->size() );
83  if( !displayed.isEmpty() ) {
84  if ( m_photo.isNull() ) {
86  m_photo = QImage( m_photoPath );
87  }
88  unloadImage = false;
89  painter->drawImage( position, m_photo );
90  }
91  }
92  }
93 
94  if ( unloadImage && !m_photoPath.isEmpty() ) {
95  // No unloading if no path is known
96  m_photo = QImage();
97  }
98 }
99 
100 const GeoDataLatLonAltBox& GeoPhotoGraphicsItem::latLonAltBox() const
101 {
102  return m_point.latLonAltBox();
103 }
104 
105 void GeoPhotoGraphicsItem::setPoint( const GeoDataPoint &point )
106 {
107  m_point = point;
108 }
109 
110 GeoDataPoint GeoPhotoGraphicsItem::point() const
111 {
112  return m_point;
113 }
114 
115 }
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
Marble::GeoPhotoGraphicsItem::m_photo
QImage m_photo
Definition: GeoPhotoGraphicsItem.h:47
Marble::ViewportParams::size
QSize size() const
Definition: ViewportParams.cpp:260
Marble::GeoPhotoGraphicsItem::setPhoto
void setPhoto(const QImage &photo)
Definition: GeoPhotoGraphicsItem.cpp:28
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::GeoPhotoGraphicsItem::GeoPhotoGraphicsItem
GeoPhotoGraphicsItem(const GeoDataFeature *feature)
Definition: GeoPhotoGraphicsItem.cpp:23
Marble::GeoGraphicsItem
Definition: GeoGraphicsItem.h:30
QImage::isNull
bool isNull() const
Marble::GeoPhotoGraphicsItem::m_point
GeoDataPoint m_point
Definition: GeoPhotoGraphicsItem.h:45
QPointF
Marble::GeoDataCoordinates::altitude
qreal altitude() const
return the altitude of the Point in meters
Definition: GeoDataCoordinates.cpp:1197
Marble::GeoPhotoGraphicsItem::paint
virtual void paint(GeoPainter *painter, const ViewportParams *viewport)
Paints the item using the given GeoPainter.
Definition: GeoPhotoGraphicsItem.cpp:48
Marble::EARTH_RADIUS
const qreal EARTH_RADIUS
Definition: MarbleGlobal.h:257
Marble::GeoPhotoGraphicsItem::setPoint
void setPoint(const GeoDataPoint &point)
Definition: GeoPhotoGraphicsItem.cpp:105
QString::isEmpty
bool isEmpty() const
Marble::GeoPhotoGraphicsItem::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the bounding box covered by the item.
Definition: GeoPhotoGraphicsItem.cpp:100
QImageReader::size
QSize size() const
Marble::ViewportParams::screenCoordinates
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
Definition: ViewportParams.cpp:357
GeoPhotoGraphicsItem.h
QImageReader
QString
GeoPainter.h
Marble::DEG2RAD
const qreal DEG2RAD
Definition: MarbleGlobal.h:219
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
QRectF::moveCenter
void moveCenter(const QPointF &position)
Marble::GeoPainter::drawImage
void drawImage(const GeoDataCoordinates &centerPosition, const QImage &image)
Draws an image at the given position. The image is placed with its center located at the given center...
Definition: GeoPainter.cpp:428
QRectF::isEmpty
bool isEmpty() const
ViewportParams.h
This file contains the headers for ViewportParams.
QImage
QSizeF
Marble::ViewportParams::radius
int radius() const
Definition: ViewportParams.cpp:195
QRectF
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:57
Marble::GeoPhotoGraphicsItem::photo
QImage photo() const
Definition: GeoPhotoGraphicsItem.cpp:33
Marble::GeoPhotoGraphicsItem::photoPath
QString photoPath() const
Definition: GeoPhotoGraphicsItem.cpp:43
QImage::size
QSize size() const
Marble::GeoDataPoint::coordinates
const GeoDataCoordinates & coordinates() const
Definition: GeoDataPoint.cpp:81
Marble::GeoPhotoGraphicsItem::point
GeoDataPoint point() const
Definition: GeoPhotoGraphicsItem.cpp:110
Marble::GeoDataGeometry::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Definition: GeoDataGeometry.cpp:122
QSizeF::height
qreal height() const
Marble::GeoPhotoGraphicsItem::m_photoPath
QString m_photoPath
Definition: GeoPhotoGraphicsItem.h:49
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
QSizeF::width
qreal width() const
Marble::GeoPhotoGraphicsItem::setPhotoFile
void setPhotoFile(const QString &filename)
Definition: GeoPhotoGraphicsItem.cpp:38
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