[QGIS Commit] r15268 - branches/raster-providers/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Feb 27 10:05:00 EST 2011


Author: rblazek
Date: 2011-02-27 07:05:00 -0800 (Sun, 27 Feb 2011)
New Revision: 15268

Modified:
   branches/raster-providers/src/core/qgsrasterdataprovider.cpp
   branches/raster-providers/src/core/qgsrasterprojector.cpp
   branches/raster-providers/src/core/qgsrasterprojector.h
Log:
more projector optimisation

Modified: branches/raster-providers/src/core/qgsrasterdataprovider.cpp
===================================================================
--- branches/raster-providers/src/core/qgsrasterdataprovider.cpp	2011-02-27 10:22:25 UTC (rev 15267)
+++ branches/raster-providers/src/core/qgsrasterdataprovider.cpp	2011-02-27 15:05:00 UTC (rev 15268)
@@ -69,6 +69,7 @@
     }
   }
   QgsDebugMsg( QString( "reproject block time  (ms): %1" ).arg( time.elapsed() ) );
+  //std::cerr << "reproject block time  (ms): " << time.elapsed() << std::endl;
 
   free( mySrcData );
 };

Modified: branches/raster-providers/src/core/qgsrasterprojector.cpp
===================================================================
--- branches/raster-providers/src/core/qgsrasterprojector.cpp	2011-02-27 10:22:25 UTC (rev 15267)
+++ branches/raster-providers/src/core/qgsrasterprojector.cpp	2011-02-27 15:05:00 UTC (rev 15268)
@@ -99,16 +99,10 @@
   mSrcYRes = mSrcExtent.width() / mSrcCols;
 
   // init helper points 
-  //mHelperTop.resize ( mDestCols );
-  //mHelperBottom.resize ( mDestCols );
-  for ( int i = 0; i < mDestCols; i++) {
-    mHelperTop.append ( QgsPoint() );
-    mHelperBottom.append ( QgsPoint() );
-  }
-  pHelperTop = &mHelperTop;
-  pHelperBottom = &mHelperBottom;
-  calcHelper ( 0, &mHelperTop );
-  calcHelper ( 1, &mHelperBottom );
+  pHelperTop = new QgsPoint[mDestCols];
+  pHelperBottom = new QgsPoint[mDestCols];
+  calcHelper ( 0, pHelperTop );
+  calcHelper ( 1, pHelperBottom );
   mHelperTopRow = 0;
 }
 
@@ -138,6 +132,7 @@
   }
   // Expand a bit to avoid possible approx coords falling out because of representation error
   //mSrcExtent.setXMinimum();
+
   QgsDebugMsg(  "mSrcExtent = " + mSrcExtent.toString() );
 }
 
@@ -223,7 +218,8 @@
 }
 
 
-void QgsRasterProjector::calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints )
+//void QgsRasterProjector::calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints )
+void QgsRasterProjector::calcHelper ( int theMatrixRow, QgsPoint *thePoints )
 {
   // TODO?: should we also precalc dest cell center coordinates for x and y?
   for ( int myDestCol = 0; myDestCol < mDestCols; myDestCol++) {
@@ -243,40 +239,36 @@
 
     double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
 
-    //QgsPoint *mySrcPoint0 = &(mCPMatrix[theMatrixRow+1][myMatrixCol]);
-    //QgsPoint *mySrcPoint1 = &(mCPMatrix[theMatrixRow+1][myMatrixCol+1]);
-    //QgsPoint *mySrcPoint2 = &(mCPMatrix[theMatrixRow][myMatrixCol]);
-    //QgsPoint *mySrcPoint3 = &(mCPMatrix[theMatrixRow][myMatrixCol+1]);
-
-    //QgsPoint *mySrcPoint0 = &(mCPMatrix[theMatrixRow][myMatrixCol]);
-    //QgsPoint *mySrcPoint1 = &(mCPMatrix[theMatrixRow][myMatrixCol+1]);
-    //double s = mySrcPoint0->x() + ( mySrcPoint1->x() - mySrcPoint0->x() ) * xfrac;
-    //double t = mySrcPoint0->y() + ( mySrcPoint1->y() - mySrcPoint0->y() ) * xfrac; 
-    QgsPoint mySrcPoint0 = mCPMatrix[theMatrixRow][myMatrixCol];
-    QgsPoint mySrcPoint1 = mCPMatrix[theMatrixRow][myMatrixCol+1];
+    QgsPoint &mySrcPoint0 = mCPMatrix[theMatrixRow][myMatrixCol];
+    QgsPoint &mySrcPoint1 = mCPMatrix[theMatrixRow][myMatrixCol+1];
     double s = mySrcPoint0.x() + ( mySrcPoint1.x() - mySrcPoint0.x() ) * xfrac;
     double t = mySrcPoint0.y() + ( mySrcPoint1.y() - mySrcPoint0.y() ) * xfrac; 
 
     //QgsDebugMsg( QString("s = %1 t = %2").arg(s).arg(t) );
-    //double u = mySrcPoint2->x() + ( mySrcPoint3->x() - mySrcPoint2->x() ) * xfrac;
-    //double v = mySrcPoint2->y() + ( mySrcPoint3->y() - mySrcPoint2->y() ) * xfrac; 
 
     //QgsDebugMsg( QString("thePoints = %1").arg ( (long)thePoints ) );
-    (*thePoints)[myDestCol].setX ( s );
-    (*thePoints)[myDestCol].setY ( t );
-    //thePoints->at(myDestCol).setX ( s );
-    //thePoints->at(myDestCol).setY ( t );
+
+    thePoints[myDestCol].setX ( s );
+    thePoints[myDestCol].setY ( t );
+
     //QgsDebugMsg( QString("thePoints[myDestCol] = %1").arg( (*thePoints)[myDestCol].toString() ) );
   }
 }
 void QgsRasterProjector::nextHelper ()
 {
   //QgsDebugMsg( QString("mHelperTopRow = %1").arg(mHelperTopRow) );
+  /*
   QList <QgsPoint> *tmp;
   tmp = pHelperTop;
   pHelperTop = pHelperBottom;
   pHelperBottom = tmp;
   calcHelper ( mHelperTopRow+2, pHelperBottom );
+  */
+  QgsPoint *tmp;
+  tmp = pHelperTop;
+  pHelperTop = pHelperBottom;
+  pHelperBottom = tmp;
+  calcHelper ( mHelperTopRow+2, pHelperBottom );
   mHelperTopRow++;
 }
 
@@ -286,11 +278,16 @@
   int myMatrixRow = matrixRow ( theDestRow );
   int myMatrixCol = matrixCol ( theDestCol );
 
+  //int myMatrixRow = 0;
+  //int myMatrixCol = 0;
+  *theSrcRow = 0; // debug
+  *theSrcCol = 0;
+
   if ( myMatrixRow > mHelperTopRow ) {
+    // TODO: make it more robust (for random, not sequential reading)
     nextHelper ();
   }
 
-  //double myDestX = mDestExtent.xMinimum() + ( theDestCol + 0.5 ) * mDestXRes;
   double myDestY = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
 
   //QgsDebugMsg( QString("myDestX = %1 myDestY = %2").arg( myDestX ).arg( myDestY) );
@@ -304,51 +301,38 @@
   destPointOnCPMatrix ( myMatrixRow + 1, myMatrixCol, &myDestXMin, &myDestYMin );
   destPointOnCPMatrix ( myMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax );
 
-  //QgsDebugMsg( "myDestLL = " + myDestLL.toString() + " myDestUR = " + myDestUR.toString() );
-
-  QgsPoint *mySrcPoint0 = &(mCPMatrix[myMatrixRow+1][myMatrixCol]);
-  QgsPoint *mySrcPoint1 = &(mCPMatrix[myMatrixRow+1][myMatrixCol+1]);
-  QgsPoint *mySrcPoint2 = &(mCPMatrix[myMatrixRow][myMatrixCol]);
-  QgsPoint *mySrcPoint3 = &(mCPMatrix[myMatrixRow][myMatrixCol+1]);
-
   //QgsDebugMsg( "mySrcPoint : " + mySrcPoint0.toString() + " " + mySrcPoint1.toString() + " " +mySrcPoint2.toString() + " " + mySrcPoint3.toString() + " " );
 
-  //double xfrac = ( myDestX - myDestXMin ) / ( myDestXMax - myDestXMin );
   double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin );
-  //QgsDebugMsg( QString("xfrac = %1 yfrac = %2").arg(xfrac).arg(yfrac) );
-  //assert ( xfrac >= 0 );
+  //QgsDebugMsg( QString("yfrac = %2").arg(yfrac) );
   //assert ( yfrac >= 0 );
   
-  //double s = mySrcPoint0->x() + ( mySrcPoint1->x() - mySrcPoint0->x() ) * xfrac;
-  //double t = mySrcPoint0->y() + ( mySrcPoint1->y() - mySrcPoint0->y() ) * xfrac; 
+  QgsPoint &myTop = pHelperTop[theDestCol];
+  QgsPoint &myBot = pHelperBottom[theDestCol];
 
-  //double u = mySrcPoint2->x() + ( mySrcPoint3->x() - mySrcPoint2->x() ) * xfrac;
-  //double v = mySrcPoint2->y() + ( mySrcPoint3->y() - mySrcPoint2->y() ) * xfrac; 
+  // Warning: this is very SLOW compared to the following code!:
+  //double mySrcX = myBot.x() + (myTop.x() - myBot.x()) * yfrac;
+  //double mySrcY = myBot.y() + (myTop.y() - myBot.y()) * yfrac;
 
-  //QgsDebugMsg( QString("s = %1 t = %2").arg(s).arg(t) );
-  //QgsDebugMsg( QString("u = %1 v = %2").arg(u).arg(v) );
+  double tx = myTop.x();
+  double ty = myTop.y();
+  double bx = myBot.x();
+  double by = myBot.y();
+  double mySrcX = bx + (tx - bx) * yfrac;
+  double mySrcY = by + (ty - by) * yfrac;
 
-  QgsPoint *myTop = &((*pHelperTop)[theDestCol]);
-  QgsPoint *myBot = &((*pHelperBottom)[theDestCol]);
-
-  //QgsDebugMsg( QString("s = %1 t = %2 myTop = %3").arg(s).arg(t).arg ( myTop->toString() ) );
-  //QgsDebugMsg( QString("u = %1 v = %2 myBot = %3").arg(u).arg(v).arg ( myBot->toString() ) );
-  
-  //double mySrcX = s + (u - s) * yfrac;
-  //double mySrcY = t + (v - t) * yfrac;
-
-  double mySrcX = myBot->x() + (myTop->x() - myBot->x()) * yfrac;
-  double mySrcY = myBot->y() + (myTop->y() - myBot->y()) * yfrac;
-
-
   //QgsDebugMsg( QString("mySrcX = %1 mySrcY = %2").arg(mySrcX).arg(mySrcY) );
 
   // TODO: check again cell selection (coor is in the middle)
 
   //QgsDebugMsg( QString("mSrcExtent.yMaximum() = %1 mySrcY = %2").arg(mSrcExtent.yMaximum()).arg(mySrcY)) ;
+
   *theSrcRow = (int) floor ( ( mSrcExtent.yMaximum() - mySrcY ) / mSrcXRes );
   *theSrcCol =  (int) floor ( ( mySrcX - mSrcExtent.xMinimum() ) / mSrcYRes );
 
+  //*theSrcRow = 0; // debug
+  //*theSrcCol = 0;
+
   //QgsDebugMsg( QString("( mSrcExtent.yMaximum() - mySrcY ) / ( mSrcExtent.height() / mSrcRows ) = %1") .arg( ( mSrcExtent.yMaximum() - mySrcY ) / ( mSrcExtent.height() / mSrcRows )  ) );
   //QgsDebugMsg( QString("mySrcY = %1 yMaximum = %2").arg(mySrcY).arg(mSrcExtent.yMaximum()) );
   

Modified: branches/raster-providers/src/core/qgsrasterprojector.h
===================================================================
--- branches/raster-providers/src/core/qgsrasterprojector.h	2011-02-27 10:22:25 UTC (rev 15267)
+++ branches/raster-providers/src/core/qgsrasterprojector.h	2011-02-27 15:05:00 UTC (rev 15268)
@@ -107,7 +107,8 @@
     bool checkRows ();
 
     /** Calculate array of src helper points */
-    void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
+    //void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
+    void calcHelper ( int theMatrixRow, QgsPoint *thePoints );
 
     /** Calc / switch helper */
     void nextHelper();
@@ -181,12 +182,14 @@
     //QList< QList<double *> > mCPMatrix;
 
     /** Array of source points for each destination column on top of current CPMatrix grid row */
-    QList <QgsPoint> mHelperTop;
-    QList <QgsPoint> *pHelperTop;
+    /* Warning: using QList is slow on access */
+    //QList <QgsPoint> mHelperTop;
+    QgsPoint *pHelperTop;
 
     /** Array of source points for each destination column on bottom of current CPMatrix grid row */
-    QList <QgsPoint> mHelperBottom;
-    QList <QgsPoint> *pHelperBottom;
+    /* Warning: using QList is slow on access */
+    //QList <QgsPoint> mHelperBottom;
+    QgsPoint *pHelperBottom;
 
     /** Current mHelperTop matrix row */
     int mHelperTopRow;



More information about the QGIS-commit mailing list