[Marble-commits] KDE/kdeedu/marble/src/lib

Bernhard Beschow bbeschow at cs.tu-berlin.de
Fri Jul 30 19:30:15 CEST 2010


SVN commit 1157325 by beschow:

remove AbstractScanlineTextureMapper::resizeMap() and the therein updated members

According to the single point of truth principle, calculate the respective values dynamically rather than relying on an external entity to keep them synchronized to the
view parameters.
The performance impact should not be dramatic since they are computed once before an expensive operation.

 M  +16 -23    AbstractScanlineTextureMapper.cpp  
 M  +1 -7      AbstractScanlineTextureMapper.h  
 M  +10 -8     EquirectScanlineTextureMapper.cpp  
 M  +0 -3      MarbleModel.cpp  
 M  +11 -9     MercatorScanlineTextureMapper.cpp  
 M  +17 -15    SphericalScanlineTextureMapper.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/AbstractScanlineTextureMapper.cpp #1157324:1157325
@@ -28,8 +28,6 @@
     : QObject( parent ),
       m_maxGlobalX( 0 ),
       m_maxGlobalY( 0 ),
-      m_imageHeight( 0 ),
-      m_imageWidth( 0 ),
       m_prevLat( 0.0 ),
       m_prevLon( 0.0 ),
       m_toTileCoordinatesLon( 0.0 ),
@@ -118,25 +116,6 @@
 }
 
 
-void AbstractScanlineTextureMapper::resizeMap(int width, int height)
-{
-    m_imageHeight = height;
-    m_imageWidth  = width;
-
-    // Find the optimal interpolation interval m_nBest for the 
-    // current image canvas width
-    m_nBest = 2;
-
-    int  nEvalMin = m_imageWidth - 1;
-    for ( int it = 1; it < 48; ++it ) {
-        int nEval = ( m_imageWidth - 1 ) / it + ( m_imageWidth - 1 ) % it;
-        if ( nEval < nEvalMin ) {
-            nEvalMin = nEval;
-            m_nBest = it; 
-        }
-    }
-}
-
 void AbstractScanlineTextureMapper::pixelValueF(qreal lon,
                                                qreal lat, 
                                                QRgb* scanLine )
@@ -480,7 +459,7 @@
 }
 
 
-int AbstractScanlineTextureMapper::interpolationStep( ViewParams *viewParams ) const
+int AbstractScanlineTextureMapper::interpolationStep( ViewParams *viewParams )
 {
     if ( viewParams->mapQuality() == PrintQuality ) {
         return 1;    // Don't interpolate for print quality.
@@ -490,10 +469,24 @@
         return 8;
     }
 
-    return m_nBest;
+    // Find the optimal interpolation interval m_nBest for the 
+    // current image canvas width
+    const int width = viewParams->canvasImage()->width();
+
+    int nBest = 2;
+    int nEvalMin = width - 1;
+    for ( int it = 1; it < 48; ++it ) {
+        int nEval = ( width - 1 ) / it + ( width - 1 ) % it;
+        if ( nEval < nEvalMin ) {
+            nEvalMin = nEval;
+            nBest = it; 
 }
+    }
 
+    return nBest;
+}
 
+
 void AbstractScanlineTextureMapper::nextTile( int &posX, int &posY )
 {
     // Move from tile coordinates to global texture coordinates 
--- trunk/KDE/kdeedu/marble/src/lib/AbstractScanlineTextureMapper.h #1157324:1157325
@@ -41,7 +41,6 @@
 
     virtual void mapTexture( ViewParams *viewParams ) = 0;
 
-    virtual void resizeMap( int width, int height );
     bool interlaced() const;
     void setInterlaced( bool enabled );
     int tileZoomLevel() const;
@@ -65,7 +64,7 @@
     void pixelValueApprox(const qreal& lon, const qreal& lat,
                           QRgb *scanLine, int n );
 
-    int interpolationStep( ViewParams *viewParams ) const;
+    static int interpolationStep( ViewParams *viewParams );
 
     // method for fast integer calculation
     void nextTile( int& posx, int& posy );
@@ -100,9 +99,6 @@
     int     m_maxGlobalX;
     int     m_maxGlobalY; // could be private also
 
-    int     m_imageHeight;
-    int     m_imageWidth;
-
     // Previous coordinates
     qreal  m_prevLat;
     qreal  m_prevLon;
@@ -135,8 +131,6 @@
     StackedTile *m_tile;
     int         m_previousRadius;
 
-    int         m_nBest;
-
     int         m_tileLevel;
     int         m_maxTileLevel;
     int         m_globalWidth;
--- trunk/KDE/kdeedu/marble/src/lib/EquirectScanlineTextureMapper.cpp #1157324:1157325
@@ -41,6 +41,8 @@
 void EquirectScanlineTextureMapper::mapTexture( ViewParams *viewParams )
 {
     QImage       *canvasImage = viewParams->canvasImage();
+    const int imageHeight = canvasImage->height();
+    const int imageWidth  = canvasImage->width();
     const qint64  radius      = viewParams->radius();
 
     const bool highQuality  = ( viewParams->mapQuality() == HighQuality
@@ -85,17 +87,17 @@
 
     // Calculate y-range the represented by the center point, yTop and
     // what actually can be painted
-    yPaintedTop    = yTop = m_imageHeight / 2 - radius + yCenterOffset;
-    yPaintedBottom = m_imageHeight / 2 + radius + yCenterOffset;
+    yPaintedTop    = yTop = imageHeight / 2 - radius + yCenterOffset;
+    yPaintedBottom = imageHeight / 2 + radius + yCenterOffset;
  
     if (yPaintedTop < 0)                yPaintedTop = 0;
-    if (yPaintedTop > m_imageHeight)    yPaintedTop = m_imageHeight;
+    if (yPaintedTop > imageHeight)    yPaintedTop = imageHeight;
     if (yPaintedBottom < 0)             yPaintedBottom = 0;
-    if (yPaintedBottom > m_imageHeight) yPaintedBottom = m_imageHeight;
+    if (yPaintedBottom > imageHeight) yPaintedBottom = imageHeight;
 
     const qreal pixel2Rad = 1.0/rad2Pixel;
 
-    qreal leftLon = + centerLon - ( m_imageWidth / 2 * pixel2Rad );
+    qreal leftLon = + centerLon - ( imageWidth / 2 * pixel2Rad );
     while ( leftLon < -M_PI ) leftLon += 2 * M_PI;
     while ( leftLon >  M_PI ) leftLon -= 2 * M_PI;
 
@@ -149,7 +151,7 @@
                 scanLine += ( n - 1 );
             }
 
-            if ( x < m_imageWidth ) {
+            if ( x < imageWidth ) {
                 if ( highQuality )
                     pixelValueF( lon, lat, scanLine );
                 else
@@ -165,7 +167,7 @@
         // copy scanline to improve performance
         if ( interlaced && y + 1 < yPaintedBottom ) { 
 
-            int pixelByteSize = canvasImage->bytesPerLine() / m_imageWidth;
+            int pixelByteSize = canvasImage->bytesPerLine() / imageWidth;
 
             memcpy( canvasImage->scanLine( y + 1 ) + xLeft * pixelByteSize, 
                     canvasImage->scanLine( y ) + xLeft * pixelByteSize, 
@@ -176,7 +178,7 @@
 
     // Remove unused lines
     const int clearStart = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? yPaintedBottom : 0;
-    const int clearStop  = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? m_imageHeight  : yTop;
+    const int clearStop  = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? imageHeight  : yTop;
 
     QRgb * const clearBegin = (QRgb*)( canvasImage->scanLine( clearStart ) );
     QRgb * const clearEnd = (QRgb*)( canvasImage->scanLine( clearStop ) );
--- trunk/KDE/kdeedu/marble/src/lib/MarbleModel.cpp #1157324:1157325
@@ -543,9 +543,6 @@
 
 void MarbleModelPrivate::resize( int width, int height )
 {
-    if ( m_mapTheme->map()->hasTextureLayers() ) {
-        m_texmapper->resizeMap( width, height );
-    }
     if ( m_veccomposer ) {
         m_veccomposer->resizeMap( width, height );
     }
--- trunk/KDE/kdeedu/marble/src/lib/MercatorScanlineTextureMapper.cpp #1157324:1157325
@@ -43,6 +43,8 @@
 void MercatorScanlineTextureMapper::mapTexture( ViewParams *viewParams )
 {
     QImage       *canvasImage = viewParams->canvasImage();
+    const int imageHeight = canvasImage->height();
+    const int imageWidth  = canvasImage->width();
     const qint64  radius      = viewParams->radius();
 
     const bool highQuality  = ( viewParams->mapQuality() == HighQuality
@@ -89,17 +91,17 @@
 
     // Calculate y-range the represented by the center point, yTop and
     // what actually can be painted
-    yPaintedTop    = yTop = m_imageHeight / 2 - 2 * radius + yCenterOffset;
-    yPaintedBottom        = m_imageHeight / 2 + 2 * radius + yCenterOffset;
+    yPaintedTop    = yTop = imageHeight / 2 - 2 * radius + yCenterOffset;
+    yPaintedBottom        = imageHeight / 2 + 2 * radius + yCenterOffset;
  
     if (yPaintedTop < 0)                yPaintedTop = 0;
-    if (yPaintedTop > m_imageHeight)    yPaintedTop = m_imageHeight;
+    if (yPaintedTop > imageHeight)    yPaintedTop = imageHeight;
     if (yPaintedBottom < 0)             yPaintedBottom = 0;
-    if (yPaintedBottom > m_imageHeight) yPaintedBottom = m_imageHeight;
+    if (yPaintedBottom > imageHeight) yPaintedBottom = imageHeight;
 
     const qreal pixel2Rad = 1.0/rad2Pixel;
 
-    qreal leftLon = + centerLon - ( m_imageWidth / 2 * pixel2Rad );
+    qreal leftLon = + centerLon - ( imageWidth / 2 * pixel2Rad );
     while ( leftLon < -M_PI ) leftLon += 2 * M_PI;
     while ( leftLon >  M_PI ) leftLon -= 2 * M_PI;
 
@@ -127,7 +129,7 @@
         int  xIpRight = n * (int)( xRight / n - 1 ) + 1; 
 
         lon = leftLon;
-        lat = atan( sinh( ( (m_imageHeight / 2 + yCenterOffset) - y )
+        lat = atan( sinh( ( (imageHeight / 2 + yCenterOffset) - y )
                     * pixel2Rad ) );
 
         for ( int x = xLeft; x < xRight; ++x ) {
@@ -154,7 +156,7 @@
                 scanLine += ( n - 1 );
             }
 
-            if ( x < m_imageWidth ) {
+            if ( x < imageWidth ) {
                 if ( highQuality )
                     pixelValueF( lon, lat, scanLine );
                 else
@@ -170,7 +172,7 @@
         // copy scanline to improve performance
         if ( interlaced && y + 1 < yPaintedBottom ) { 
 
-            int pixelByteSize = canvasImage->bytesPerLine() / m_imageWidth;
+            int pixelByteSize = canvasImage->bytesPerLine() / imageWidth;
 
             memcpy( canvasImage->scanLine( y + 1 ) + xLeft * pixelByteSize, 
                     canvasImage->scanLine( y ) + xLeft * pixelByteSize, 
@@ -181,7 +183,7 @@
 
     // Remove unused lines
     const int clearStart = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? yPaintedBottom : 0;
-    const int clearStop  = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? m_imageHeight  : yTop;
+    const int clearStop  = ( yPaintedTop - m_oldYPaintedTop <= 0 ) ? imageHeight  : yTop;
 
     QRgb * const clearBegin = (QRgb*)( canvasImage->scanLine( clearStart ) );
     QRgb * const clearEnd = (QRgb*)( canvasImage->scanLine( clearStop ) );
--- trunk/KDE/kdeedu/marble/src/lib/SphericalScanlineTextureMapper.cpp #1157324:1157325
@@ -38,6 +38,8 @@
 void SphericalScanlineTextureMapper::mapTexture( ViewParams *viewParams )
 {
     QImage       *canvasImage = viewParams->canvasImage();
+    const int imageHeight = canvasImage->height();
+    const int imageWidth  = canvasImage->width();
     const qint64  radius      = viewParams->radius();
 
     const bool highQuality  = ( viewParams->mapQuality() == HighQuality
@@ -80,22 +82,22 @@
     int skip = interlaced ? 1 : 0;
 
     // Calculate the actual y-range of the map on the screen 
-    const int yTop = ( ( m_imageHeight / 2 - radius < 0 )
-                       ? 0 : m_imageHeight / 2 - radius );
+    const int yTop = ( ( imageHeight / 2 - radius < 0 )
+                       ? 0 : imageHeight / 2 - radius );
     const int yBottom = ( (yTop == 0)
-                          ? m_imageHeight - skip
+                          ? imageHeight - skip
                           : yTop + radius + radius - skip );
 
     for ( int y = yTop; y < yBottom ; ++y ) {
 
         // Evaluate coordinates for the 3D position vector of the current pixel
-        const qreal qy = inverseRadius * (qreal)( m_imageHeight / 2 - y );
+        const qreal qy = inverseRadius * (qreal)( imageHeight / 2 - y );
         const qreal qr = 1.0 - qy * qy;
 
         // rx is the radius component in x direction
         int rx = (int)sqrt( (qreal)( radius * radius 
-                                      - ( ( y - m_imageHeight / 2 )
-                                          * ( y - m_imageHeight / 2 ) ) ) );
+                                      - ( ( y - imageHeight / 2 )
+                                          * ( y - imageHeight / 2 ) ) ) );
 
         // Calculate the actual x-range of the map within the current scanline.
         // 
@@ -109,9 +111,9 @@
         // In that situation xLeft equals zero.
         // For xRight the situation is similar.
 
-        const int xLeft  = ( ( m_imageWidth / 2 - rx > 0 )
-                             ? m_imageWidth / 2 - rx : 0 ); 
-        const int xRight = ( ( m_imageWidth / 2 - rx > 0 )
+        const int xLeft  = ( ( imageWidth / 2 - rx > 0 )
+                             ? imageWidth / 2 - rx : 0 ); 
+        const int xRight = ( ( imageWidth / 2 - rx > 0 )
                              ? xLeft + rx + rx : canvasImage->width() );
 
         QRgb * scanLine = (QRgb*)( canvasImage->scanLine( y ) ) + xLeft;
@@ -119,14 +121,14 @@
         int  xIpLeft  = 1;
         int  xIpRight = n * (int)( xRight / n - 1 ) + 1; 
 
-        if ( m_imageWidth / 2 - rx > 0 ) {
+        if ( imageWidth / 2 - rx > 0 ) {
             xIpLeft  = n * (int)( xLeft  / n + 1 );
             xIpRight = n * (int)( xRight / n - 1 );
         }
 
         // Decrease pole distortion due to linear approximation ( y-axis )
         bool crossingPoleArea = false;
-        int northPoleY = m_imageHeight / 2 - (int)( radius * northPole.v[Q_Y] );
+        int northPoleY = imageHeight / 2 - (int)( radius * northPole.v[Q_Y] );
         if ( northPole.v[Q_Z] > 0
              && northPoleY - ( n * 0.75 ) <= y
              && northPoleY + ( n * 0.75 ) >= y ) 
@@ -145,7 +147,7 @@
             if ( x >= xIpLeft && x <= xIpRight ) {
 
                 // Decrease pole distortion due to linear approximation ( x-axis )
-                int northPoleX = m_imageWidth / 2 + (int)( radius * northPole.v[Q_X] );
+                int northPoleX = imageWidth / 2 + (int)( radius * northPole.v[Q_X] );
 
 //                mDebug() << QString("NorthPole X: %1, LeftInterval: %2").arg( northPoleX ).arg( leftInterval );
                 if ( crossingPoleArea
@@ -166,7 +168,7 @@
 
             // Evaluate more coordinates for the 3D position vector of
             // the current pixel.
-            const qreal qx = (qreal)( x - m_imageWidth / 2 ) * inverseRadius;
+            const qreal qx = (qreal)( x - imageWidth / 2 ) * inverseRadius;
 
             const qreal qr2z = qr - qx * qx;
             const qreal qz = ( qr2z > 0.0 ) ? sqrt( qr2z ) : 0.0;
@@ -197,7 +199,7 @@
 //          rendering around north pole:
 
 //            if ( !crossingPoleArea )
-            if ( x < m_imageWidth ) {
+            if ( x < imageWidth ) {
                 if ( highQuality )
                     pixelValueF( lon, lat, scanLine );
                 else
@@ -212,7 +214,7 @@
         // copy scanline to improve performance
         if ( interlaced && y + 1 < yBottom ) { 
 
-            int pixelByteSize = canvasImage->bytesPerLine() / m_imageWidth;
+            int pixelByteSize = canvasImage->bytesPerLine() / imageWidth;
 
             memcpy( canvasImage->scanLine( y + 1 ) + xLeft * pixelByteSize, 
                     canvasImage->scanLine( y ) + xLeft * pixelByteSize, 


More information about the Marble-commits mailing list