1 Index: marble-0.85+svn1207808/src/lib/AbstractScanlineTextureMapper.cpp
2 ===================================================================
3 --- marble-0.85+svn1207808.orig/src/lib/AbstractScanlineTextureMapper.cpp 2010-12-19 16:51:17.000000000 -0500
4 +++ marble-0.85+svn1207808/src/lib/AbstractScanlineTextureMapper.cpp 2010-12-19 16:51:30.000000000 -0500
6 m_tileLoader( tileLoader ),
9 - m_textureLayer( textureLayer ),
10 m_tileSize( textureLayer->tileSize() ), // cache tile size
11 + m_textureLayer( textureLayer ),
13 m_previousRadius( 0 ),
15 Index: marble-0.85+svn1207808/src/lib/AbstractScanlineTextureMapper.h
16 ===================================================================
17 --- marble-0.85+svn1207808.orig/src/lib/AbstractScanlineTextureMapper.h 2010-12-19 16:51:17.000000000 -0500
18 +++ marble-0.85+svn1207808/src/lib/AbstractScanlineTextureMapper.h 2010-12-19 16:51:30.000000000 -0500
23 + /// size of the tiles of of the current texture layer
24 + QSize const m_tileSize;
27 + uint m_mapThemeIdHash;
30 Q_DISABLE_COPY( AbstractScanlineTextureMapper )
31 void initGlobalWidth();
32 void initGlobalHeight();
34 GeoSceneTexture const * const m_textureLayer;
35 - /// size of the tiles of of the current texture layer
36 - QSize const m_tileSize;
44 qreal m_normGlobalWidth;
45 qreal m_normGlobalHeight;
46 - uint m_mapThemeIdHash;
49 inline bool AbstractScanlineTextureMapper::interlaced() const
50 Index: marble-0.85+svn1207808/src/lib/CMakeLists.txt
51 ===================================================================
52 --- marble-0.85+svn1207808.orig/src/lib/CMakeLists.txt 2010-12-19 16:51:17.000000000 -0500
53 +++ marble-0.85+svn1207808/src/lib/CMakeLists.txt 2010-12-19 16:51:30.000000000 -0500
55 SphericalScanlineTextureMapper.cpp
56 EquirectScanlineTextureMapper.cpp
57 MercatorScanlineTextureMapper.cpp
58 + FastMercatorTextureMapper.cpp
62 Index: marble-0.85+svn1207808/src/lib/FastMercatorTextureMapper.cpp
63 ===================================================================
64 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
65 +++ marble-0.85+svn1207808/src/lib/FastMercatorTextureMapper.cpp 2010-12-19 16:51:30.000000000 -0500
68 +// This file is part of the Marble Virtual Globe.
70 +// This program is free software licensed under the GNU LGPL. You can
71 +// find a copy of this license in LICENSE.txt in the top directory of
74 +// Copyright 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
79 +#include"FastMercatorTextureMapper.h"
85 +#include <QtCore/qmath.h>
86 +#include <QtGui/QImage>
87 +#include <QtGui/QPainter>
90 +#include "StackedTileLoader.h"
91 +#include "ViewParams.h"
92 +#include "TileLoaderHelper.h"
93 +#include "StackedTile.h"
94 +#include "MathHelper.h"
96 +using namespace Marble;
98 +FastMercatorTextureMapper::FastMercatorTextureMapper( GeoSceneTexture *textureLayer,
99 + StackedTileLoader *tileLoader,
101 + : AbstractScanlineTextureMapper( textureLayer, tileLoader, parent ),
102 + m_oldYPaintedTop( 0 )
107 +void FastMercatorTextureMapper::mapTexture( ViewParams *viewParams )
109 + QImage *canvasImage = viewParams->canvasImage();
110 + const int imageHeight = canvasImage->height();
111 + const int imageWidth = canvasImage->width();
112 + const qint64 radius = viewParams->radius();
114 + m_tilePosX = 65535;
115 + m_tilePosY = 65535;
116 + m_toTileCoordinatesLon = (qreal)(globalWidth() / 2 - m_tilePosX);
117 + m_toTileCoordinatesLat = (qreal)(globalHeight() / 2 - m_tilePosY);
120 + m_tileLoader->resetTilehash();
121 + selectTileLevel( viewParams );
123 + // Calculate translation of center point
124 + qreal centerLon, centerLat;
126 + viewParams->centerCoordinates( centerLon, centerLat );
128 + const qreal xNormalizedCenter = 0.5 + 0.5 * centerLon / M_PI;
129 + const int numTilesX = globalWidth() / m_tileSize.width();
130 + const int minTileX = qFloor( numTilesX * ( xNormalizedCenter - imageWidth/( 8.0 * radius ) ) );
131 + const int maxTileX = numTilesX * ( xNormalizedCenter + imageWidth/( 8.0 * radius ) );
133 + const qreal yNormalizedCenter = 0.5 - 0.5 * asinh( tan( centerLat ) ) / M_PI;
134 + const int numTilesY = globalHeight() / m_tileSize.height();
135 + const int minTileY = qMax( numTilesY * ( yNormalizedCenter - imageHeight/( 8.0 * radius ) ), 0.0 );
136 + const int maxTileY = qMin( numTilesY * ( yNormalizedCenter + imageHeight/( 8.0 * radius ) ), numTilesY - 1.0 );
138 + QPainter painter( canvasImage );
140 + for ( int tileY = minTileY; tileY <= maxTileY; ++tileY ) {
141 + for ( int tileX = minTileX; tileX <= maxTileX; ++tileX ) {
142 + const int xLeft = ( 4.0 * radius ) * ( ( tileX ) / (qreal)numTilesX - xNormalizedCenter + imageWidth/( 8.0 * radius ) );
143 + const int xRight = ( 4.0 * radius ) * ( ( tileX + 1 ) / (qreal)numTilesX - xNormalizedCenter + imageWidth/( 8.0 * radius ) ) - 1;
144 + const int yTop = ( 4.0 * radius ) * ( ( tileY ) / (qreal)numTilesY - yNormalizedCenter + imageHeight/( 8.0 * radius ) );
145 + const int yBottom = ( 4.0 * radius ) * ( ( tileY + 1 ) / (qreal)numTilesY - yNormalizedCenter + imageHeight/( 8.0 * radius ) ) - 1;
147 + const QRect rect = QRect( QPoint( xLeft, yTop ), QPoint( xRight, yBottom ) );
148 + const TileId id = TileId( m_mapThemeIdHash, m_tileLevel, ( ( tileX % numTilesX ) + numTilesX ) % numTilesX, tileY );
149 + StackedTile *const tile = m_tileLoader->loadTile( id, DownloadBrowse );
151 + painter.drawImage( rect, *tile->resultTile() );
159 + int yPaintedBottom;
161 + // Calculate y-range the represented by the center point, yTop and
162 + // what actually can be painted
163 + yPaintedTop = yTop = ( - yNormalizedCenter ) * ( 4 * radius ) + imageHeight / 2;
164 + yPaintedBottom = ( 1.0 - yNormalizedCenter ) * ( 4 * radius ) + imageHeight / 2;
166 + if (yPaintedTop < 0) yPaintedTop = 0;
167 + if (yPaintedTop > imageHeight) yPaintedTop = imageHeight;
168 + if (yPaintedBottom < 0) yPaintedBottom = 0;
169 + if (yPaintedBottom > imageHeight) yPaintedBottom = imageHeight;
171 + // Remove unused lines
172 + const int clearStart = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? yPaintedBottom : 0;
173 + const int clearStop = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? imageHeight : yTop;
175 + QRgb * const clearBegin = (QRgb*)( canvasImage->scanLine( clearStart ) );
176 + QRgb * const clearEnd = (QRgb*)( canvasImage->scanLine( clearStop ) );
178 + QRgb * it = clearBegin;
180 + for ( ; it < clearEnd; ++it ) {
184 + m_oldYPaintedTop = yPaintedTop;
186 + m_tileLoader->cleanupTilehash();
190 +#include "FastMercatorTextureMapper.moc"
191 Index: marble-0.85+svn1207808/src/lib/FastMercatorTextureMapper.h
192 ===================================================================
193 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
194 +++ marble-0.85+svn1207808/src/lib/FastMercatorTextureMapper.h 2010-12-19 16:51:30.000000000 -0500
197 +// This file is part of the Marble Virtual Globe.
199 +// This program is free software licensed under the GNU LGPL. You can
200 +// find a copy of this license in LICENSE.txt in the top directory of
203 +// Copyright 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
206 +#ifndef MARBLE_FASTMERCATORTEXTUREMAPPER_H
207 +#define MARBLE_FASTMERCATORTEXTUREMAPPER_H
210 +#include "AbstractScanlineTextureMapper.h"
215 +class FastMercatorTextureMapper : public AbstractScanlineTextureMapper
220 + FastMercatorTextureMapper( GeoSceneTexture *textureLayer, StackedTileLoader *tileLoader,
221 + QObject *parent = 0 );
222 + void mapTexture( ViewParams *viewParams );
225 + int m_oldYPaintedTop;
231 Index: marble-0.85+svn1207808/src/lib/TextureLayer.cpp
232 ===================================================================
233 --- marble-0.85+svn1207808.orig/src/lib/TextureLayer.cpp 2010-12-19 16:51:17.000000000 -0500
234 +++ marble-0.85+svn1207808/src/lib/TextureLayer.cpp 2010-12-19 16:51:30.000000000 -0500
236 #include "SphericalScanlineTextureMapper.h"
237 #include "EquirectScanlineTextureMapper.h"
238 #include "MercatorScanlineTextureMapper.h"
239 +#include "FastMercatorTextureMapper.h"
240 #include "GeoPainter.h"
241 #include "GeoSceneDocument.h"
242 #include "GeoSceneFilter.h"
247 - d->m_texmapper = new MercatorScanlineTextureMapper( d->textureLayer(), &d->m_tileLoader,
248 + if ( d->textureLayer()->projection() == GeoSceneTexture::Mercator ) {
249 + d->m_texmapper = new FastMercatorTextureMapper( d->textureLayer(), &d->m_tileLoader,
252 + d->m_texmapper = new MercatorScanlineTextureMapper( d->textureLayer(), &d->m_tileLoader,