[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/marble
From:       Torsten Rahn <tackat () kde ! org>
Date:       2007-08-23 11:16:23
Message-ID: 1187867783.753086.31078.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 703808 by rahn:


	- More cleanup in TextureMapper classes and
	better code documentation. Now it should be
	possible for other people to fully 
	understand it.
	* src/lib/AbstractScanlineTextureMapper.{cpp,h}
	* src/lib/TileLoader.h
	* src/lib/GlobeScanlineTextureMapper.cpp
	* src/lib/FlatScanlineTextureMapper.cpp
	* ChangeLog



 M  +21 -0     ChangeLog  
 M  +38 -44    src/lib/AbstractScanlineTextureMapper.cpp  
 M  +21 -10    src/lib/AbstractScanlineTextureMapper.h  
 M  +4 -4      src/lib/FlatScanlineTextureMapper.cpp  
 M  +11 -12    src/lib/GlobeScanlineTextureMapper.cpp  
 M  +9 -0      src/lib/TileLoader.h  


--- trunk/KDE/kdeedu/marble/ChangeLog #703807:703808
@@ -1,3 +1,15 @@
+2007-08-23  Torsten Rahn  <rahn@kde.org>
+
+	- More cleanup in TextureMapper classes and
+	better code documentation. Now it should be
+	possible for other people to fully 
+	understand it.
+	* src/lib/AbstractScanlineTextureMapper.{cpp,h}
+	* src/lib/TileLoader.h
+	* src/lib/GlobeScanlineTextureMapper.cpp
+	* src/lib/FlatScanlineTextureMapper.cpp
+	* ChangeLog
+
 2007-08-23  Murad Tagirov  <tmurad@gmail.com>
 
     - Added new classes for basic kml styles support
@@ -17,6 +29,15 @@
 
 	* src/lib/MarbleWidget.h: Added some apidox
 
+2007-08-22  Torsten Rahn  <rahn@kde.org>
+
+	Cleaning up the TextureMapper classes a bit.
+	More to follow.
+
+	* src/lib/AbstractScanlineTextureMapper.cpp: Cleanup
+	* src/lib/GlobeScanlineTextureMapper.cpp: Cleanup
+	* src/lib/TileLoader.h: Introducing globalWidth()/Height()
+
 2007-08-22  Murad Tagirov  <tmurad@gmail.com>
 
     Display time spent to parse kml file.
--- trunk/KDE/kdeedu/marble/src/lib/AbstractScanlineTextureMapper.cpp #703807:703808
@@ -54,14 +54,10 @@
     m_tilePosX = 0;
     m_tilePosY = 0;
 
-    m_fullRangeLon = 0;
-    m_halfRangeLat = 0;
-    m_halfRangeLon = 0.0;
-    m_quatRangeLat = 0.0;
-    m_fullNormLon  = 0;
-    m_halfNormLat  = 0;
-    m_halfNormLon  = 0.0;
-    m_quatNormLat  = 0.0;
+    m_maxGlobalX  = 0;
+    m_maxGlobalY  = 0;
+    m_toTileCoordinatesLon  = 0.0;
+    m_toTileCoordinatesLat  = 0.0;
 
     m_rad2PixelX = 0.0;
     m_rad2PixelY = 0.0;
@@ -117,26 +113,24 @@
 
 void AbstractScanlineTextureMapper::tileLevelInit( int tileLevel )
 {
-    int ResolutionX = (int)( 1728000000.0
-			     / (double)( TileLoader::levelToColumn( tileLevel ) )
-			     / (double)( m_tileLoader->tileWidth() ) );
-    int ResolutionY = (int)( 864000000.0
-			     / (double)( TileLoader::levelToRow( tileLevel ) )
-			     / (double)( m_tileLoader->tileHeight() ) );
+    // rad2PixelY might later on evolve into a method to allow 
+    // Mercator as a source texture format. That's why we have it
+    // in addition to rad2PixelX.
+    m_rad2PixelX = (double)(m_tileLoader->globalWidth( tileLevel )) / (2.0 * M_PI);
+    m_rad2PixelY = (double)(m_tileLoader->globalHeight( tileLevel )) / M_PI;
 
-    m_rad2PixelX = ( 864000000.0 / M_PI / (double)(ResolutionX) );
-    m_rad2PixelY = ( 864000000.0 / M_PI / (double)(ResolutionY) );
+    m_maxGlobalX = m_tileLoader->globalWidth( m_tileLevel )  - 1;
+    m_maxGlobalY = m_tileLoader->globalHeight( m_tileLevel ) - 1;
 
-
-    m_fullRangeLon = (int)   ( 1728000000.0 / (double)(ResolutionX) ) - 1;
-    m_halfRangeLon = (double)( 864000000.0 / (double)(ResolutionX) );
-    m_quatRangeLat = (double)( 432000000.0 / (double)(ResolutionY) );
-    m_halfRangeLat = (int)   ( 2.0 * m_quatRangeLat ) - 1;
-
-    m_fullNormLon = m_fullRangeLon - m_tilePosX;
-    m_halfNormLon = m_halfRangeLon - m_tilePosX;
-    m_halfNormLat = m_halfRangeLat - m_tilePosY;
-    m_quatNormLat = m_quatRangeLat - m_tilePosY;
+    // These variables move the origin of global texture coordinates from 
+    // the center to the upper left corner and subtract the tile position 
+    // in that coordinate system. In total this equals a coordinate 
+    // transformation to tile coordinates.
+  
+    m_toTileCoordinatesLon = (double)(m_tileLoader->globalWidth( m_tileLevel ) 
+                             / 2 - m_tilePosX);
+    m_toTileCoordinatesLat = (double)(m_tileLoader->globalHeight( m_tileLevel ) 
+                             / 2 - m_tilePosY);
 }
 
 
@@ -154,11 +148,11 @@
                                                QRgb* scanLine)
 {
     // Convert the lon and lat coordinates of the position on the scanline
-    // measured in radiant to the pixel position of the requested 
+    // measured in radian to the pixel position of the requested 
     // coordinate on the current tile.
  
-    m_posX = (int)( m_halfNormLon + lon * m_rad2PixelX );
-    m_posY = (int)( m_quatNormLat + lat * m_rad2PixelY );
+    m_posX = (int)( m_toTileCoordinatesLon + lon * m_rad2PixelY );
+    m_posY = (int)( m_toTileCoordinatesLat + lat * m_rad2PixelY );
 
     // Most of the time while moving along the scanLine we'll stay on the 
     // same tile. However at the tile border we might "fall off". If that 
@@ -184,16 +178,16 @@
 
 void AbstractScanlineTextureMapper::nextTile()
 {
-    // Necessary to prevent e.g. crash if lon = -pi
-    if ( m_posX > m_fullNormLon ) m_posX = m_fullNormLon;
-    if ( m_posY > m_halfNormLat ) m_posY = m_halfNormLat;
+    // Move from tile coordinates to global texture coordinates 
+    // ( with origin in upper left corner, measured in pixel) 
 
-    // The origin (0, 0) is in the upper left corner
-    // lon: 360 deg = 1728000000 pixel
-    // lat: 180 deg = 864000000 pixel
-
     int lon = m_posX + m_tilePosX;
+    if ( lon > m_maxGlobalX ) lon -= m_maxGlobalX;
+    if ( lon < 0 ) lon += m_maxGlobalX;
+
     int lat = m_posY + m_tilePosY;
+    if ( lat > m_maxGlobalY ) lat -= m_maxGlobalY;
+    if ( lat < 0 ) lat += m_maxGlobalY;
 
     // tileCol counts the tile columns left from the current tile.
     // tileRow counts the tile rows on the top from the current tile.
@@ -203,19 +197,19 @@
 
     m_tile = m_tileLoader->loadTile( tileCol, tileRow, m_tileLevel );
 
-    // Recalculate some convenience variables for the new tile:
-    // m_tilePosX/Y stores the position of the tiles in pixels
+    // Update position variables:
+    // m_tilePosX/Y stores the position of the tiles in 
+    // global texture coordinates 
+    // ( origin upper left, measured in pixels )
 
     m_tilePosX = tileCol * m_tileLoader->tileWidth();
-
-    m_fullNormLon = m_fullRangeLon - m_tilePosX;
-    m_halfNormLon = m_halfRangeLon - m_tilePosX;
+    m_toTileCoordinatesLon = (double)(m_tileLoader->globalWidth( m_tileLevel ) 
+                             / 2 - m_tilePosX);
     m_posX = lon - m_tilePosX;
 
     m_tilePosY = tileRow * m_tileLoader->tileHeight();
-
-    m_halfNormLat = m_halfRangeLat - m_tilePosY;
-    m_quatNormLat = m_quatRangeLat - m_tilePosY;
+    m_toTileCoordinatesLat = (double)(m_tileLoader->globalHeight( m_tileLevel ) 
+                             / 2 - m_tilePosY);
     m_posY = lat - m_tilePosY;
 }
 
--- trunk/KDE/kdeedu/marble/src/lib/AbstractScanlineTextureMapper.h #703807:703808
@@ -56,29 +56,36 @@
 
     void tileLevelInit( int tileLevel );
 
+    // Coordinates on the tile
     int     m_posX;
     int     m_posY;
 
+    // maximum values for global texture coordinates
+    // ( with origin in upper left corner, measured in pixel) 
+    int     m_maxGlobalX;
+    int     m_maxGlobalY;
+
     int     m_imageHeight;
     int     m_imageWidth;
     int     m_imageRadius;
 
+    // Previous coordinates
     double  m_prevLat;
     double  m_prevLon;
 
-    int     m_fullRangeLon;
-    int     m_halfRangeLat;
-    double  m_halfRangeLon;
-    double  m_quatRangeLat;
+    // Coordinate transformations:
 
-    int     m_fullNormLon;
-    int     m_halfNormLat;
-    double  m_halfNormLon;
-    double  m_quatNormLat;
-
+    // Converts Radian to global texture coordinates 
+    // ( with origin in center, measured in pixel) 
     double  m_rad2PixelX;
     double  m_rad2PixelY;
 
+    // Converts global texture coordinates 
+    // ( with origin in center, measured in pixel) 
+    // to tile coordinates ( measured in pixel )
+    double  m_toTileCoordinatesLon;
+    double  m_toTileCoordinatesLat;
+
     bool m_interlaced;
 
     // ------------------------
@@ -86,10 +93,14 @@
     TileLoader  *m_tileLoader;
     QRgb        *m_scanLine;
 
-    int          m_maxTileLevel;
 
     TextureTile *m_tile;
+
     int          m_tileLevel;
+    int          m_maxTileLevel;
+
+    // Position of the tile in global Texture Coordinates
+    // ( with origin in upper left corner, measured in pixel) 
     int          m_tilePosX;
     int          m_tilePosY;
 };
--- trunk/KDE/kdeedu/marble/src/lib/FlatScanlineTextureMapper.cpp #703807:703808
@@ -41,10 +41,10 @@
     m_tilePosX = 65535;
     m_tilePosY = 65535;
 
-    m_fullNormLon = m_fullRangeLon - m_tilePosX;
-    m_halfNormLon = m_halfRangeLon - m_tilePosX;
-    m_halfNormLat = m_halfRangeLat - m_tilePosY;
-    m_quatNormLat = m_quatRangeLat - m_tilePosY;
+    m_toTileCoordinatesLon = (double)(m_tileLoader->globalWidth( m_tileLevel ) 
+                             / 2 - m_tilePosX);
+    m_toTileCoordinatesLat = (double)(m_tileLoader->globalHeight( m_tileLevel ) 
+                             / 2 - m_tilePosY);
 
     int yTop;
     int yBottom;
--- trunk/KDE/kdeedu/marble/src/lib/GlobeScanlineTextureMapper.cpp #703807:703808
@@ -90,12 +90,11 @@
 
     m_tilePosX = 65535;
     m_tilePosY = 65535;
+    m_toTileCoordinatesLon = (double)(m_tileLoader->globalWidth( m_tileLevel ) 
+                             / 2 - m_tilePosX);
+    m_toTileCoordinatesLat = (double)(m_tileLoader->globalHeight( m_tileLevel ) 
+                             / 2 - m_tilePosY);
 
-    m_fullNormLon = m_fullRangeLon - m_tilePosX;
-    m_halfNormLon = m_halfRangeLon - m_tilePosX;
-    m_halfNormLat = m_halfRangeLat - m_tilePosY;
-    m_quatNormLat = m_quatRangeLat - m_tilePosY;
-
     // Reset backend
     m_tileLoader->resetTilehash();
     selectTileLevel(radius);
@@ -263,7 +262,7 @@
     // we didn't cross the dateline.
 
     if ( fabs(stepLon) < M_PI ) {
-        const int itStepLon = (int)( stepLon * m_nInverse * m_rad2PixelX * 128.0 );
+        const int itStepLon = (int)( stepLon * m_nInverse * m_rad2PixelY * 128.0 );
         const int itStepLat = (int)( stepLat * m_nInverse * m_rad2PixelY * 128.0 );
 
         m_prevLon *= m_rad2PixelX;
@@ -273,8 +272,8 @@
         // AbstractScanlineTextureMapper::pixelValue(...) here and 
         // calculate the performance critical issues via integers
 
-        int itLon = (int)( ( m_prevLon + m_halfNormLon ) * 128.0 );
-        int itLat = (int)( ( m_prevLat + m_quatNormLat ) * 128.0 );
+        int itLon = (int)( ( m_prevLon + m_toTileCoordinatesLon ) * 128.0 );
+        int itLat = (int)( ( m_prevLat + m_toTileCoordinatesLat ) * 128.0 );
 
         if ( m_tile->depth() == 8 ) {
             for ( int j=1; j < m_n; ++j ) {
@@ -287,8 +286,8 @@
                    || m_posY < 0 )
                 {
                     nextTile();
-                    itLon = (int)( ( m_prevLon + m_halfNormLon ) * 128.0 );
-                    itLat = (int)( ( m_prevLat + m_quatNormLat ) * 128.0 );
+                    itLon = (int)( ( m_prevLon + m_toTileCoordinatesLon ) * 128.0 );
+                    itLat = (int)( ( m_prevLat + m_toTileCoordinatesLat ) * 128.0 );
                     m_posX = ( itLon + itStepLon * j ) >> 7;
                     m_posY = ( itLat + itStepLat * j ) >> 7;
                 }
@@ -308,8 +307,8 @@
                      || m_posY < 0 )
                 {
                     nextTile();
-                    itLon = (int)( ( m_prevLon + m_halfNormLon ) * 128.0 );
-                    itLat = (int)( ( m_prevLat + m_quatNormLat ) * 128.0 );
+                    itLon = (int)( ( m_prevLon + m_toTileCoordinatesLon ) * 128.0 );
+                    itLat = (int)( ( m_prevLat + m_toTileCoordinatesLat ) * 128.0 );
                     m_posX = ( itLon + itStepLon * j ) >> 7;
                     m_posY = ( itLat + itStepLat * j ) >> 7;
                 }
--- trunk/KDE/kdeedu/marble/src/lib/TileLoader.h #703807:703808
@@ -65,6 +65,15 @@
     int tileWidth()  const { return m_tileWidth; }
     int tileHeight() const { return m_tileHeight; }
 
+    int globalWidth( int level ) const 
+    {
+        return m_tileWidth * levelToColumn( level );
+    };
+    int globalHeight( int level ) const 
+    {
+        return m_tileHeight * levelToRow( level );
+    };
+
     static int levelToRow( int level );
     static int levelToColumn( int level );
     static int rowToLevel( int row );
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic