[QGIS Commit] r14535 - in branches/raster-providers/src: core core/raster providers/grass

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Nov 8 17:24:35 EST 2010


Author: rblazek
Date: 2010-11-08 14:24:35 -0800 (Mon, 08 Nov 2010)
New Revision: 14535

Modified:
   branches/raster-providers/src/core/qgsrasterdataprovider.h
   branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
   branches/raster-providers/src/core/raster/qgsrasterviewport.h
   branches/raster-providers/src/providers/grass/qgis.d.rast.c
   branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
Log:
data type fixed

Modified: branches/raster-providers/src/core/qgsrasterdataprovider.h
===================================================================
--- branches/raster-providers/src/core/qgsrasterdataprovider.h	2010-11-08 12:02:17 UTC (rev 14534)
+++ branches/raster-providers/src/core/qgsrasterdataprovider.h	2010-11-08 22:24:35 UTC (rev 14535)
@@ -159,7 +159,7 @@
       return QgsRasterDataProvider::UnknownDataType;
     }
 
-    int dataTypeSize ( int dataType ) const
+    int typeSize ( int dataType ) const
     {
       // modified copy from GDAL
       switch( dataType )
@@ -189,6 +189,10 @@
           return 0;
       }
     }
+    int dataTypeSize ( int bandNo ) const
+    {
+      return typeSize ( dataType ( bandNo ) );
+    }
 
     /** Get numbur of bands */
     virtual int bandCount() const {

Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.cpp	2010-11-08 12:02:17 UTC (rev 14534)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.cpp	2010-11-08 22:24:35 UTC (rev 14535)
@@ -752,7 +752,7 @@
   myNYBlocks = ( mDataProvider->ySize() + myYBlockSize - 1 ) / myYBlockSize;
 
   //void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( GDALGetDataTypeSize( myDataType ) / 8 ) );
-  void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( mDataProvider->dataTypeSize( myDataType ) / 8 ) );
+  void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( mDataProvider->dataTypeSize(theBandNo ) / 8 ) );
 
   // unfortunately we need to make two passes through the data to calculate stddev
   bool myFirstIterationFlag = true;
@@ -1975,7 +1975,7 @@
       //GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, i );
       //GDALDataType type = GDALGetRasterDataType( gdalBand );
       //int size = GDALGetDataTypeSize( type ) / 8;
-      int size = mDataProvider->dataTypeSize(mDataProvider->dataType(i))/8;
+      int size = mDataProvider->dataTypeSize(i)/8;
       void *data = CPLMalloc( size );
 
       // TODO
@@ -5427,7 +5427,7 @@
 {
  // GDALDataType type = GDALGetRasterDataType( gdalBand );
   //int size = GDALGetDataTypeSize( type ) / 8;
-  int size = mDataProvider->dataTypeSize(mDataProvider->dataType(bandNo))/8;
+  int size = mDataProvider->dataTypeSize(bandNo)/8;
 
   QgsDebugMsg( "calling RasterIO with " +
                QString( ", source NW corner: " ) + QString::number( viewPort->rectXOffset ) +
@@ -5926,7 +5926,7 @@
   }
   //GDALDataType type = GDALGetRasterDataType( mRasterBand );
   //int size = GDALGetDataTypeSize( type ) / 8;
-  int size = mDataProvider->dataTypeSize(mDataProvider->dataType(mBandNo))/8;
+  int size = mDataProvider->dataTypeSize(mBandNo)/8;
   *rasterScanLine = ( unsigned char * )mCurrentGDALData + mCurrentPartImageRow * mViewPort->drawableAreaXDim * size;
 
   ++mCurrentPartImageRow;
@@ -5973,10 +5973,10 @@
           imageY = static_cast<int>( mViewPort->topLeftPoint.y() + 0.5 +  fabs( mGeoTransform[5] ) * mCurrentPartRasterMin / mMapToPixel->mapUnitsPerPixel() );
         }
 
-        mPainter->drawImage( imageX,
+        mPainter->drawImage( imageX, //the top-left point in the paint device
                              imageY,
                              *mCurrentImage,
-                             paintXoffset,
+                             paintXoffset, //specifies the top-left point in image
                              paintYoffset );
       }
     }
@@ -6005,11 +6005,12 @@
   //read GDAL image data
   //GDALDataType type = GDALGetRasterDataType( mRasterBand );
   //int size = GDALGetDataTypeSize( type ) / 8;
-  int size = mDataProvider->dataTypeSize ( mDataProvider->dataType(mBandNo) ) / 8 ;
+  int size = mDataProvider->dataTypeSize ( mBandNo ) / 8 ;
+  QgsDebugMsg( "type = " + QString::number( mDataProvider->dataType(mBandNo) ) );
+  QgsDebugMsg( "size = " + QString::number(size) );
   int xSize = mViewPort->drawableAreaXDim;
   int ySize = mViewPort->drawableAreaYDim;
 
-  //TODO: clean up - most should be thrown out
   //make the raster tiles overlap at least 2 pixels to avoid white stripes
   int overlapRows = 0;
   if ( mMapToPixel )
@@ -6040,6 +6041,7 @@
     return false;
   }
   mNumCurrentImageRows = ySize;
+  QgsDebugMsg( "alloc " + QString::number( size * xSize * ySize) );
   mCurrentGDALData = VSIMalloc( size * xSize * ySize );
   //CPLErr myErr = GDALRasterIO( mRasterBand, GF_Read, mViewPort->rectXOffset,
   //                             mViewPort->rectYOffset + mCurrentRow, mViewPort->clippedWidth, rasterYSize,
@@ -6047,8 +6049,8 @@
 
 
   // TODO !!! get correct extent
-  double yMin = mViewPort->mDrawnExtent.yMaximum() - mCurrentPartRasterMax ;
-  double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentPartRasterMin;
+  double yMax = mViewPort->mDrawnExtent.yMaximum() - mCurrentRow * mMapToPixel->mapUnitsPerPixel();
+  double yMin = yMax - ySize * mMapToPixel->mapUnitsPerPixel();
 
   QgsDebugMsg( QString("mCurrentRow = %1 yMaximum = %2 ySize = %3 mapUnitsPerPixel = %4").arg(mCurrentRow).arg(mViewPort->mDrawnExtent.yMaximum()).arg(ySize).arg(mMapToPixel->mapUnitsPerPixel()) );
   QgsRectangle partExtent ( mViewPort->mDrawnExtent.xMinimum(), yMin,

Modified: branches/raster-providers/src/core/raster/qgsrasterviewport.h
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterviewport.h	2010-11-08 12:02:17 UTC (rev 14534)
+++ branches/raster-providers/src/core/raster/qgsrasterviewport.h	2010-11-08 22:24:35 UTC (rev 14535)
@@ -30,6 +30,7 @@
 
 struct QgsRasterViewPort
 {
+  // RASTER SPACE
   /** \brief  The offset from the left hand edge of the raster for the rectangle that will be drawn to screen.
    * TODO Check this explanation is correc!*/
   int   rectXOffset;
@@ -38,6 +39,8 @@
    * TODO Check this explanation is correc!*/
   int   rectYOffset;
   float rectYOffsetFloat;
+
+  // RASTER SPACE
   /** \brief Lower left X dimension of clipped raster image in raster pixel space.
    *  RasterIO will do the scaling for us, so for example, if the user is zoomed in a long way, there may only
    *  be e.g. 5x5 pixels retrieved from the raw raster data, but rasterio will seamlessly scale the up to
@@ -62,6 +65,8 @@
   int clippedWidth;
   /** \brief Distance in pixels from clippedYMin to clippedYMax  */
   int clippedHeight;
+
+  // NOT IN MAP SPACE BUT DEVICE SPACE
   /** \brief Coordinate (in geographic coordinate system) of top left corner of the part of the raster that
    * is to be rendered.*/
   QgsPoint topLeftPoint;
@@ -70,6 +75,8 @@
   QgsPoint bottomRightPoint;
   /** \brief Distance in map units from left edge to right edge for the part of the raster that
    * is to be rendered.*/
+
+  
   int drawableAreaXDim;
   /** \brief Distance in map units from bottom edge to top edge for the part of the raster that
    * is to be rendered.*/

Modified: branches/raster-providers/src/providers/grass/qgis.d.rast.c
===================================================================
--- branches/raster-providers/src/providers/grass/qgis.d.rast.c	2010-11-08 12:02:17 UTC (rev 14534)
+++ branches/raster-providers/src/providers/grass/qgis.d.rast.c	2010-11-08 22:24:35 UTC (rev 14535)
@@ -33,6 +33,7 @@
   struct Option *win;
   struct Option *format;
   struct Cell_head window;
+  RASTER_MAP_TYPE raster_type;
 
   /* Initialize the GIS calls */
   G_gisinit( argv[0] );
@@ -79,13 +80,16 @@
   G_adjust_Cell_head( &window, 1, 1 );
   G_set_window( &window );
 
+  raster_type = G_raster_map_type ( name, "" );
   fp = G_raster_map_is_fp( name, mapset );
 
   /* use DCELL even if the map is FCELL */
-  if ( fp )
-    display( name, mapset, DCELL_TYPE, format->answer );
-  else
-    display( name, mapset, CELL_TYPE, format->answer );
+  // Why? It would break dataType in provider.
+  //if ( fp )
+  //  display( name, mapset, DCELL_TYPE, format->answer );
+  //else
+  //  display( name, mapset, CELL_TYPE, format->answer );
+  display( name, mapset, raster_type, format->answer );
 
   exit( EXIT_SUCCESS );
 }
@@ -156,6 +160,8 @@
   fo = fdopen( fileno( stdout ), "wb" );
 
   raster_size = G_raster_size( data_type );
+  //fprintf( fo, "%d %d", data_type, raster_size );
+  //exit(0);
   /* loop for array rows */
   for ( row = 0; row < nrows; row++ )
   {

Modified: branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp	2010-11-08 12:02:17 UTC (rev 14534)
+++ branches/raster-providers/src/providers/grass/qgsgrassrasterprovider.cpp	2010-11-08 22:24:35 UTC (rev 14535)
@@ -188,9 +188,7 @@
   QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
   // byteCount() in Qt >= 4.6
   //int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
-  // TODO : data type size
-  int typeSize = 4;
-  int size = mCols * typeSize < data.size() ? mCols * typeSize : data.size();
+  int size = mCols * dataTypeSize(bandNo) < data.size() ? mCols * dataTypeSize(bandNo) : data.size();
   memcpy( block, data.data(), size );
 }
 
@@ -230,9 +228,7 @@
   QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
   // byteCount() in Qt >= 4.6
   //int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
-  // TODO : data type size
-  int typeSize = 4;
-  int size = pixelWidth * pixelHeight * typeSize < data.size() ? pixelWidth * pixelHeight * typeSize : data.size();
+  int size = pixelWidth * pixelHeight * dataTypeSize(bandNo) < data.size() ? pixelWidth * pixelHeight * dataTypeSize(bandNo) : data.size();
   memcpy( block, data.data(), size );
 }
 
@@ -333,14 +329,13 @@
 {
   switch ( mGrassDataType ) {
     case CELL_TYPE:
-      return QgsGrassRasterProvider::Int32;
+      return QgsRasterDataProvider::Int32;
       break;
     case FCELL_TYPE:
-      return QgsGrassRasterProvider::Float32;
+      return QgsRasterDataProvider::Float32;
       break;
     case DCELL_TYPE:
-      return QgsGrassRasterProvider::Int32;
-      return QgsGrassRasterProvider::Float64;
+      return QgsRasterDataProvider::Float64;
       break;
   }
   return QgsRasterDataProvider::UnknownDataType;



More information about the QGIS-commit mailing list