bool ProjectorData::approximateSrcRowCol( int destRow, int destCol, int *srcRow, int *srcCol ) { int myMatrixRow = matrixRow( destRow ); int myMatrixCol = matrixCol( destCol ); if ( myMatrixRow > mHelperTopRow ) { // TODO: make it more robust (for random, not sequential reading) nextHelper(); } double myDestY = mDestExtent.yMaximum() - ( destRow + 0.5 ) * mDestYRes; // See the schema in javax.media.jai.WarpGrid doc (but up side down) // TODO: use some kind of cache of values which can be reused double myDestXMin, myDestYMin, myDestXMax, myDestYMax; destPointOnCPMatrix( myMatrixRow + 1, myMatrixCol, &myDestXMin, &myDestYMin ); destPointOnCPMatrix( myMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax ); double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin ); QgsPointXY &myTop = pHelperTop[destCol]; QgsPointXY &myBot = pHelperBottom[destCol]; // 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; 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; if ( !mExtent.contains( QgsPointXY( mySrcX, mySrcY ) ) ) { return false; } // TODO: check again cell selection (coor is in the middle) *srcRow = static_cast< int >( std::floor( ( mSrcExtent.yMaximum() - mySrcY ) / mSrcYRes ) ); *srcCol = static_cast< int >( std::floor( ( mySrcX - mSrcExtent.xMinimum() ) / mSrcXRes ) ); // For now silently correct limits to avoid crashes // TODO: review // should not happen if ( *srcRow >= mSrcRows ) return false; if ( *srcRow < 0 ) return false; if ( *srcCol >= mSrcCols ) return false; if ( *srcCol < 0 ) return false; return true; }
void QgsRasterProjector::approximateSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol ) { int myMatrixRow = matrixRow( theDestRow ); int myMatrixCol = matrixCol( theDestCol ); if ( myMatrixRow > mHelperTopRow ) { // TODO: make it more robust (for random, not sequential reading) nextHelper(); } double myDestY = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes; // See the schema in javax.media.jai.WarpGrid doc (but up side down) // TODO: use some kind of cache of values which can be reused double myDestXMin, myDestYMin, myDestXMax, myDestYMax; destPointOnCPMatrix( myMatrixRow + 1, myMatrixCol, &myDestXMin, &myDestYMin ); destPointOnCPMatrix( myMatrixRow, myMatrixCol + 1, &myDestXMax, &myDestYMax ); double yfrac = ( myDestY - myDestYMin ) / ( myDestYMax - myDestYMin ); QgsPoint &myTop = pHelperTop[theDestCol]; QgsPoint &myBot = pHelperBottom[theDestCol]; // 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; 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; // TODO: check again cell selection (coor is in the middle) *theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - mySrcY ) / mSrcYRes ); *theSrcCol = ( int ) floor(( mySrcX - mSrcExtent.xMinimum() ) / mSrcXRes ); // For now silently correct limits to avoid crashes // TODO: review if ( *theSrcRow >= mSrcRows ) *theSrcRow = mSrcRows - 1; if ( *theSrcRow < 0 ) *theSrcRow = 0; if ( *theSrcCol >= mSrcCols ) *theSrcCol = mSrcCols - 1; if ( *theSrcCol < 0 ) *theSrcCol = 0; Q_ASSERT( *theSrcRow < mSrcRows ); Q_ASSERT( *theSrcCol < mSrcCols ); }
//Define matrix base class constructor Matrix::Matrix(int rows, int columns) { if (rows <= 0 || columns <= 0) { throw std::invalid_argument("Rows and columns must be non-zero and positive"); } this->numberOfRows = rows; this->numberOfColumns = columns; this->matrixRows = std::unique_ptr<matrixRow[]>(new matrixRow[rows]); for (int rowCounter = 0; rowCounter < this->numberOfRows; ++rowCounter) { this->matrixRows[rowCounter] = matrixRow(new _int64[columns]); } }