• 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
GeoGraphicsScene.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 Konstantin Oblaukhov <oblaukhov.konstantin@gmail.com>
9 //
10 
11 #include "GeoGraphicsScene.h"
12 
13 #include "GeoDataFeature.h"
14 #include "GeoDataGroundOverlay.h"
15 #include "GeoDataLatLonBox.h"
16 #include "GeoDataPhotoOverlay.h"
17 #include "GeoDataPlacemark.h"
18 #include "GeoDataTypes.h"
19 #include "GeoGraphicsItem.h"
20 #include "TileId.h"
21 #include "TileCoordsPyramid.h"
22 #include "MarbleDebug.h"
23 #include <QMap>
24 
25 namespace Marble
26 {
27 
28 bool zValueLessThan( GeoGraphicsItem* i1, GeoGraphicsItem* i2 )
29 {
30  return i1->zValue() < i2->zValue();
31 }
32 
33 class GeoGraphicsScenePrivate
34 {
35 public:
36 
37  void addItems(const TileId &tileId, QList<GeoGraphicsItem*> &result, int maxZoomLevel ) const;
38 
39  QMap<TileId, QList<GeoGraphicsItem*> > m_items;
40  QMultiHash<const GeoDataFeature*, TileId> m_features;
41 };
42 
43 GeoGraphicsScene::GeoGraphicsScene( QObject* parent ): QObject( parent ), d( new GeoGraphicsScenePrivate() )
44 {
45 
46 }
47 
48 GeoGraphicsScene::~GeoGraphicsScene()
49 {
50  delete d;
51 }
52 
53 void GeoGraphicsScene::eraseAll()
54 {
55  for( QMap< TileId, QList< GeoGraphicsItem* > >::const_iterator i = d->m_items.constBegin();
56  i != d->m_items.constEnd(); ++i )
57  {
58  qDeleteAll(*i);
59  }
60  d->m_items.clear();
61  d->m_features.clear();
62 }
63 
64 QList< GeoGraphicsItem* > GeoGraphicsScene::items( const GeoDataLatLonBox &box, int zoomLevel ) const
65 {
66  if ( box.west() > box.east() ) {
67  // Handle boxes crossing the IDL by splitting it into two separate boxes
68  GeoDataLatLonBox left;
69  left.setWest( -M_PI );
70  left.setEast( box.east() );
71  left.setNorth( box.north() );
72  left.setSouth( box.south() );
73 
74  GeoDataLatLonBox right;
75  right.setWest( box.west() );
76  right.setEast( M_PI );
77  right.setNorth( box.north() );
78  right.setSouth( box.south() );
79 
80  QList< GeoGraphicsItem* > allItems = items( left, zoomLevel );
81  foreach( GeoGraphicsItem* item, items( right, zoomLevel ) ) {
82  if ( !allItems.contains( item ) ) {
83  allItems << item;
84  }
85  }
86  return allItems;
87  }
88 
89  QList< GeoGraphicsItem* > result;
90  QRect rect;
91  qreal north, south, east, west;
92  box.boundaries( north, south, east, west );
93  TileId key;
94 
95  key = TileId::fromCoordinates( GeoDataCoordinates(west, north, 0), zoomLevel );
96  rect.setLeft( key.x() );
97  rect.setTop( key.y() );
98 
99  key = TileId::fromCoordinates( GeoDataCoordinates(east, south, 0), zoomLevel );
100  rect.setRight( key.x() );
101  rect.setBottom( key.y() );
102 
103  TileCoordsPyramid pyramid( 0, zoomLevel );
104  pyramid.setBottomLevelCoords( rect );
105 
106  for ( int level = pyramid.topLevel(); level <= pyramid.bottomLevel(); ++level ) {
107  QRect const coords = pyramid.coords( level );
108  int x1, y1, x2, y2;
109  coords.getCoords( &x1, &y1, &x2, &y2 );
110  for ( int x = x1; x <= x2; ++x ) {
111  for ( int y = y1; y <= y2; ++y ) {
112  d->addItems( TileId ( 0, level, x, y ), result, zoomLevel );
113  }
114  }
115  }
116  return result;
117 }
118 
119 void GeoGraphicsScene::removeItem( const GeoDataFeature* feature )
120 {
121  QList<TileId> keys = d->m_features.values( feature );
122  foreach( TileId key, keys ) {
123  QList< GeoGraphicsItem* >& tileList = d->m_items[key];
124  foreach( GeoGraphicsItem* item, tileList ) {
125  if( item->feature() == feature ) {
126  d->m_features.remove( feature );
127  tileList.removeAll( item );
128  break;
129  }
130  }
131  }
132 }
133 
134 void GeoGraphicsScene::clear()
135 {
136  d->m_items.clear();
137 }
138 
139 void GeoGraphicsScene::addItem( GeoGraphicsItem* item )
140 {
141  // Select zoom level so that the object fit in single tile
142  int zoomLevel;
143  qreal north, south, east, west;
144  item->latLonAltBox().boundaries( north, south, east, west );
145  for(zoomLevel = item->minZoomLevel(); zoomLevel >= 0; zoomLevel--)
146  {
147  if( TileId::fromCoordinates( GeoDataCoordinates(west, north, 0), zoomLevel ) ==
148  TileId::fromCoordinates( GeoDataCoordinates(east, south, 0), zoomLevel ) )
149  break;
150  }
151 
152  const TileId key = TileId::fromCoordinates( GeoDataCoordinates(west, north, 0), zoomLevel ); // same as GeoDataCoordinates(east, south, 0), see above
153 
154  QList< GeoGraphicsItem* >& tileList = d->m_items[key];
155  QList< GeoGraphicsItem* >::iterator position = qLowerBound( tileList.begin(), tileList.end(), item, zValueLessThan );
156  tileList.insert( position, item );
157  d->m_features.insert( item->feature(), key );
158 }
159 
160 void GeoGraphicsScenePrivate::addItems( const TileId &tileId, QList<GeoGraphicsItem *> &result, int maxZoomLevel ) const
161 {
162  const QList< GeoGraphicsItem* > &objects = m_items.value(tileId);
163  QList< GeoGraphicsItem* >::iterator before = result.begin();
164  QList< GeoGraphicsItem* >::const_iterator currentItem = objects.constBegin();
165  while( currentItem != objects.end() ) {
166  while( ( currentItem != objects.end() )
167  && ( ( before == result.end() ) || ( (*currentItem)->zValue() < (*before)->zValue() ) ) ) {
168  if( (*currentItem)->minZoomLevel() <= maxZoomLevel && (*currentItem)->visible() ) {
169  before = result.insert( before, *currentItem );
170  }
171  ++currentItem;
172  }
173  if ( before != result.end() ) {
174  ++before;
175  }
176  }
177 }
178 
179 }
180 
181 #include "GeoGraphicsScene.moc"
QRect::setBottom
void setBottom(int y)
TileId.h
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataLatLonBox::setNorth
void setNorth(const qreal north, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:101
TileCoordsPyramid.h
Marble::GeoDataLatLonBox::boundaries
void boundaries(qreal &north, qreal &south, qreal &east, qreal &west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Definition: GeoDataLatLonBox.cpp:198
GeoDataGroundOverlay.h
Marble::GeoGraphicsScene::removeItem
void removeItem(const GeoDataFeature *feature)
Remove all concerned items from the GeoGraphicsScene Removes all items which are associated with obje...
Definition: GeoGraphicsScene.cpp:119
Marble::GeoGraphicsItem::minZoomLevel
int minZoomLevel() const
Returns the minim zoom level on which item will be active.
Definition: GeoGraphicsItem.cpp:107
Marble::TileId::y
int y() const
Definition: TileId.h:67
QRect::getCoords
void getCoords(int *x1, int *y1, int *x2, int *y2) const
QMap
Marble::TileCoordsPyramid::coords
QRect coords(int const level) const
Definition: TileCoordsPyramid.cpp:82
Marble::GeoGraphicsItem
Definition: GeoGraphicsItem.h:30
Marble::GeoGraphicsItem::feature
const GeoDataFeature * feature() const
Returns the placemark for that item.
Definition: GeoGraphicsItem.cpp:62
Marble::GeoDataLatLonBox::setSouth
void setSouth(const qreal south, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:122
Marble::TileCoordsPyramid::bottomLevel
int bottomLevel() const
Definition: TileCoordsPyramid.cpp:72
Marble::GeoDataLatLonBox::setWest
void setWest(const qreal west, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:164
MarbleDebug.h
Marble::zValueLessThan
bool zValueLessThan(GeoGraphicsItem *i1, GeoGraphicsItem *i2)
Definition: GeoGraphicsScene.cpp:28
QList::const_iterator
Marble::GeoGraphicsItem::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the bounding box covered by the item.
Definition: GeoGraphicsItem.cpp:67
QList::value
T value(int i) const
Marble::GeoDataLatLonBox::north
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:93
Marble::GeoDataLatLonBox::east
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:135
QRect
Marble::TileCoordsPyramid
Definition: TileCoordsPyramid.h:23
GeoDataFeature.h
Marble::GeoGraphicsScene::GeoGraphicsScene
GeoGraphicsScene(QObject *parent=0)
Creates a new instance of GeoGraphicsScene.
Definition: GeoGraphicsScene.cpp:43
Marble::GeoGraphicsItem::zValue
qreal zValue() const
Returns the z value of the item.
Definition: GeoGraphicsItem.cpp:87
QObject
QRect::setTop
void setTop(int y)
QList::removeAll
int removeAll(const T &value)
QList
GeoDataPlacemark.h
QList::iterator
Marble::TileId::x
int x() const
Definition: TileId.h:62
QList::end
iterator end()
Marble::GeoGraphicsScene::items
QList< GeoGraphicsItem * > items(const GeoDataLatLonBox &box, int maxZoomLevel) const
Get the list of items in the specified Box.
Definition: GeoGraphicsScene.cpp:64
Marble::GeoGraphicsScene::eraseAll
void eraseAll()
Get all items in the GeoGraphicsScene Returns all items in the GeoGraphicsScene.
Definition: GeoGraphicsScene.cpp:53
QList::contains
bool contains(const T &value) const
GeoGraphicsItem.h
Marble::GeoGraphicsScene::clear
void clear()
Remove all items from the GeoGraphicsScene Removes all items from the GeoGraphicsScene.
Definition: GeoGraphicsScene.cpp:134
GeoDataLatLonBox.h
QRect::setRight
void setRight(int x)
Marble::GeoDataLatLonBox::west
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:156
Marble::TileId
Definition: TileId.h:27
QList::insert
void insert(int i, const T &value)
Marble::TileId::fromCoordinates
static TileId fromCoordinates(const GeoDataCoordinates &coords, int popularity)
Definition: TileId.cpp:62
Marble::TileCoordsPyramid::topLevel
int topLevel() const
Definition: TileCoordsPyramid.cpp:67
Marble::GeoDataFeature
A base class for all geodata features.
Definition: GeoDataFeature.h:57
Marble::GeoDataLatLonBox::south
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
Definition: GeoDataLatLonBox.cpp:114
Marble::TileCoordsPyramid::setBottomLevelCoords
void setBottomLevelCoords(QRect const &coords)
Definition: TileCoordsPyramid.cpp:77
M_PI
#define M_PI
Definition: GeoDataCoordinates.h:26
GeoGraphicsScene.h
GeoDataTypes.h
QList::constBegin
const_iterator constBegin() const
Marble::GeoGraphicsScene::addItem
void addItem(GeoGraphicsItem *item)
Add an item to the GeoGraphicsScene Adds the item item to the GeoGraphicsScene.
Definition: GeoGraphicsScene.cpp:139
GeoDataPhotoOverlay.h
QRect::setLeft
void setLeft(int x)
Marble::GeoGraphicsScene::~GeoGraphicsScene
~GeoGraphicsScene()
Definition: GeoGraphicsScene.cpp:48
QList::begin
iterator begin()
QMultiHash
Marble::GeoDataLatLonBox
A class that defines a 2D bounding box for geographic data.
Definition: GeoDataLatLonBox.h:51
Marble::GeoDataLatLonBox::setEast
void setEast(const qreal east, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian)
Definition: GeoDataLatLonBox.cpp:143
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