5f60db304086b21c2bb9e9202e7cc19ed71af98d
[marble] / packaging / debian / patches / fastmercator.diff
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
5 @@ -36,8 +36,8 @@
6        m_tileLoader( tileLoader ),
7        m_tilePosX( 0 ),
8        m_tilePosY( 0 ),
9 -      m_textureLayer( textureLayer ),
10        m_tileSize( textureLayer->tileSize() ),  // cache tile size
11 +      m_textureLayer( textureLayer ),
12        m_tile( 0 ),
13        m_previousRadius( 0 ),
14        m_tileLevel( 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
19 @@ -120,24 +120,26 @@
20      int          m_tilePosX;
21      int          m_tilePosY;
22  
23 +    /// size of the tiles of of the current texture layer
24 +    QSize const m_tileSize;
25 +
26 +    int         m_tileLevel;
27 +    uint        m_mapThemeIdHash;
28 +
29   private:
30      Q_DISABLE_COPY( AbstractScanlineTextureMapper )
31      void initGlobalWidth();
32      void initGlobalHeight();
33  
34      GeoSceneTexture const * const m_textureLayer;
35 -    /// size of the tiles of of the current texture layer
36 -    QSize const m_tileSize;
37      StackedTile *m_tile;
38      int         m_previousRadius;
39  
40 -    int         m_tileLevel;
41      int         m_maxTileLevel;
42      int         m_globalWidth;
43      int         m_globalHeight;
44      qreal       m_normGlobalWidth;
45      qreal       m_normGlobalHeight;
46 -    uint        m_mapThemeIdHash;
47  };
48  
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
54 @@ -130,6 +130,7 @@
55      SphericalScanlineTextureMapper.cpp
56      EquirectScanlineTextureMapper.cpp
57      MercatorScanlineTextureMapper.cpp
58 +    FastMercatorTextureMapper.cpp
59      DiscCache.cpp
60      ServerLayout.cpp
61      StoragePolicy.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
66 @@ -0,0 +1,124 @@
67 +//
68 +// This file is part of the Marble Virtual Globe.
69 +//
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
72 +// the source code.
73 +//
74 +// Copyright 2010      Bernhard Beschow <bbeschow@cs.tu-berlin.de>
75 +//
76 +
77 +
78 +// local
79 +#include"FastMercatorTextureMapper.h"
80 +
81 +// posix
82 +#include <cmath>
83 +
84 +// Qt
85 +#include <QtCore/qmath.h>
86 +#include <QtGui/QImage>
87 +#include <QtGui/QPainter>
88 +
89 +// Marble
90 +#include "StackedTileLoader.h"
91 +#include "ViewParams.h"
92 +#include "TileLoaderHelper.h"
93 +#include "StackedTile.h"
94 +#include "MathHelper.h"
95 +
96 +using namespace Marble;
97 +
98 +FastMercatorTextureMapper::FastMercatorTextureMapper( GeoSceneTexture *textureLayer,
99 +                                                      StackedTileLoader *tileLoader,
100 +                                                      QObject *parent )
101 +    : AbstractScanlineTextureMapper( textureLayer, tileLoader, parent ),
102 +      m_oldYPaintedTop( 0 )
103 +{
104 +}
105 +
106 +
107 +void FastMercatorTextureMapper::mapTexture( ViewParams *viewParams )
108 +{
109 +    QImage       *canvasImage = viewParams->canvasImage();
110 +    const int imageHeight = canvasImage->height();
111 +    const int imageWidth  = canvasImage->width();
112 +    const qint64  radius      = viewParams->radius();
113 +
114 +    m_tilePosX = 65535;
115 +    m_tilePosY = 65535;
116 +    m_toTileCoordinatesLon = (qreal)(globalWidth() / 2 - m_tilePosX);
117 +    m_toTileCoordinatesLat = (qreal)(globalHeight() / 2 - m_tilePosY);
118 +
119 +    // Reset backend
120 +    m_tileLoader->resetTilehash();
121 +    selectTileLevel( viewParams );
122 +
123 +    // Calculate translation of center point
124 +    qreal centerLon, centerLat;
125 +
126 +    viewParams->centerCoordinates( centerLon, centerLat );
127 +
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 ) );
132 +
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 );
137 +
138 +    QPainter painter( canvasImage );
139 +
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;
146 +
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 );
150 +
151 +            painter.drawImage( rect, *tile->resultTile() );
152 +        }
153 +    }
154 +
155 +    painter.end();
156 +
157 +    int yTop;
158 +    int yPaintedTop;
159 +    int yPaintedBottom;
160 +
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;
165 +
166 +    if (yPaintedTop < 0)                yPaintedTop = 0;
167 +    if (yPaintedTop > imageHeight)    yPaintedTop = imageHeight;
168 +    if (yPaintedBottom < 0)             yPaintedBottom = 0;
169 +    if (yPaintedBottom > imageHeight) yPaintedBottom = imageHeight;
170 +
171 +    // Remove unused lines
172 +    const int clearStart = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? yPaintedBottom : 0;
173 +    const int clearStop  = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? imageHeight  : yTop;
174 +
175 +    QRgb * const clearBegin = (QRgb*)( canvasImage->scanLine( clearStart ) );
176 +    QRgb * const clearEnd = (QRgb*)( canvasImage->scanLine( clearStop ) );
177 +
178 +    QRgb * it = clearBegin;
179 +
180 +    for ( ; it < clearEnd; ++it ) {
181 +        *(it) = 0;
182 +    }
183 +
184 +    m_oldYPaintedTop = yPaintedTop;
185 +
186 +    m_tileLoader->cleanupTilehash();
187 +}
188 +
189 +
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
195 @@ -0,0 +1,35 @@
196 +//
197 +// This file is part of the Marble Virtual Globe.
198 +//
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
201 +// the source code.
202 +//
203 +// Copyright 2010      Bernhard Beschow <bbeschow@cs.tu-berlin.de>
204 +//
205 +
206 +#ifndef MARBLE_FASTMERCATORTEXTUREMAPPER_H
207 +#define MARBLE_FASTMERCATORTEXTUREMAPPER_H
208 +
209 +
210 +#include "AbstractScanlineTextureMapper.h"
211 +
212 +namespace Marble
213 +{
214 +
215 +class FastMercatorTextureMapper : public AbstractScanlineTextureMapper
216 +{
217 +    Q_OBJECT
218 +
219 + public:
220 +    FastMercatorTextureMapper( GeoSceneTexture *textureLayer, StackedTileLoader *tileLoader,
221 +                               QObject *parent = 0 );
222 +    void mapTexture( ViewParams *viewParams );
223 +
224 +  private:
225 +    int m_oldYPaintedTop;
226 +};
227 +
228 +}
229 +
230 +#endif
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
235 @@ -18,6 +18,7 @@
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"
243 @@ -249,8 +250,13 @@
244                                                                  this );
245              break;
246          case Mercator:
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,
250                                                                  this );
251 +            } else {
252 +                d->m_texmapper = new MercatorScanlineTextureMapper( d->textureLayer(), &d->m_tileLoader,
253 +                                                                    this );
254 +            }
255              break;
256          default:
257              d->m_texmapper = 0;