Skip to content

Commit

Permalink
raster cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Apr 29, 2013
1 parent e755815 commit 33d13cc
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 153 deletions.
10 changes: 0 additions & 10 deletions python/core/raster/qgsrasteriterator.sip
Expand Up @@ -4,16 +4,6 @@ class QgsRasterIterator
#include <qgsrasteriterator.h>
%End
public:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterBlock *block;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterIterator( QgsRasterInterface* input );
~QgsRasterIterator();
Expand Down
6 changes: 3 additions & 3 deletions python/core/raster/qgsrasternuller.sip
Expand Up @@ -21,10 +21,10 @@ class QgsRasterNuller : QgsRasterInterface

QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) / Factory /;

void setNoData( QList<QgsRasterNuller::NoData> noData );
void setNoData( int bandNo, QgsRasterRangeList noData );

QList<QgsRasterNuller::NoData> noData() const;
QgsRasterRangeList noData( int bandNo ) const;

/** \brief Set output no data value. */
void setOutputNoData( double noData );
void setOutputNoDataValue( int bandNo, double noData );
};
15 changes: 0 additions & 15 deletions python/core/raster/qgsrasterprojector.sip
Expand Up @@ -50,21 +50,6 @@ class QgsRasterProjector : QgsRasterInterface
/** \brief set maximum source resolution */
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes );

/** get source extent */
QgsRectangle srcExtent();

/** get/set source width/height */
int srcRows();
int srcCols();
void setSrcRows( int theRows );
void setSrcCols( int theCols );

/** \brief Get source row and column indexes for current source extent and resolution */
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

int dstRows() const;
int dstCols() const;

QgsRasterBlock *block( int bandNo, const QgsRectangle & extent, int width, int height ) / Factory /;
};

33 changes: 16 additions & 17 deletions python/core/raster/qgsrasterviewport.sip
Expand Up @@ -4,28 +4,27 @@ struct QgsRasterViewPort
%TypeHeaderCode
#include <qgsrasterviewport.h>
%End
/** \brief Coordinate (in output device coordinate system) of top left corner
* of the part of the raster that is to be rendered.*/
QgsPoint mTopLeftPoint;
/** \brief Coordinate (in output device coordinate system) of bottom right corner
* of the part of the raster that is to be rendered.*/
QgsPoint mBottomRightPoint;

// 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;
/** \brief Coordinate (in geographic coordinate system) of bottom right corner of the part of the raster that
* is to be rendered.*/
QgsPoint bottomRightPoint;
/** \brief Distance in map units from left edge to right edge for the part of the raster that
* is to be rendered.*/
/** \brief Width, number of columns to be rendered */
int mWidth;
/** \brief Distance in map units from bottom edge to top edge for the part of
* the raster that is to be rendered.*/
/** \brief Height, number of rows to be rendered */
int mHeight;

int drawableAreaXDim;
/** \brief Distance in map units from bottom edge to top edge for the part of the raster that
* is to be rendered.*/
int drawableAreaYDim;

// intersection of current map extent and layer extent
/** \brief Intersection of current map extent and layer extent */
QgsRectangle mDrawnExtent;

// Source coordinate system
/** \brief Source coordinate system */
QgsCoordinateReferenceSystem mSrcCRS;

// Target coordinate system
/** \brief Target coordinate system */
QgsCoordinateReferenceSystem mDestCRS;

};
2 changes: 1 addition & 1 deletion python/gui/qgsrasterlayersaveasdialog.sip
Expand Up @@ -46,7 +46,7 @@ class QgsRasterLayerSaveAsDialog : QDialog
QgsCoordinateReferenceSystem outputCrs();
QStringList createOptions() const;
QgsRectangle outputRectangle() const;
QList<QgsRasterNuller::NoData> noData() const;
QgsRasterRangeList noData() const;

QList< int > pyramidsList() const;
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const;
Expand Down
5 changes: 4 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -4295,7 +4295,10 @@ void QgisApp::saveAsRasterFile()
}

QgsRasterNuller *nuller = new QgsRasterNuller();
nuller->setNoData( d.noData() );
for ( int band = 1; band <= rasterLayer->dataProvider()->bandCount(); band ++ )
{
nuller->setNoData( band, d.noData() );
}
if ( !pipe->insert( 1, nuller ) )
{
QgsDebugMsg( "Cannot set pipe nuller" );
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterblock.cpp
Expand Up @@ -360,7 +360,7 @@ bool QgsRasterBlock::setValue( int row, int column, double value )

bool QgsRasterBlock::setColor( int row, int column, QRgb color )
{
return setColor(( size_t )row*column, color );
return setColor(( size_t )row*mWidth + column, color );
}

bool QgsRasterBlock::setColor( size_t index, QRgb color )
Expand All @@ -385,7 +385,7 @@ bool QgsRasterBlock::setColor( size_t index, QRgb color )

bool QgsRasterBlock::setIsNoData( int row, int column )
{
return setIsNoData(( size_t )row*column );
return setIsNoData(( size_t )row*mWidth + column );
}

bool QgsRasterBlock::setIsNoData( size_t index )
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterdrawer.cpp
Expand Up @@ -41,7 +41,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM

// last pipe filter has only 1 band
int bandNumber = 1;
mIterator->startRasterRead( bandNumber, viewPort->drawableAreaXDim, viewPort->drawableAreaYDim, viewPort->mDrawnExtent );
mIterator->startRasterRead( bandNumber, viewPort->mWidth, viewPort->mHeight, viewPort->mDrawnExtent );

//number of cols/rows in output pixels
int nCols = 0;
Expand Down Expand Up @@ -89,7 +89,7 @@ void QgsRasterDrawer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const
}

//top left position in device coords
QPoint tlPoint = QPoint( viewPort->topLeftPoint.x() + topLeftCol, viewPort->topLeftPoint.y() + topLeftRow );
QPoint tlPoint = QPoint( viewPort->mTopLeftPoint.x() + topLeftCol, viewPort->mTopLeftPoint.y() + topLeftRow );
p->save();
p->setRenderHint( QPainter::Antialiasing, false );
p->drawImage( tlPoint, img );
Expand Down
8 changes: 5 additions & 3 deletions src/core/raster/qgsrasterfilewriter.cpp
Expand Up @@ -189,10 +189,10 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
destNoDataValue = srcProvider->srcNoDataValue( bandNo );
destHasNoDataValue = true;
}
else if ( nuller && nuller->noData().size() > 0 )
else if ( nuller && nuller->noData( bandNo ).size() > 0 )
{
// Use one user defined no data value
destNoDataValue = nuller->noData().value( 0 ).min;
destNoDataValue = nuller->noData( bandNo ).value( 0 ).min();
destHasNoDataValue = true;
}
else
Expand Down Expand Up @@ -232,7 +232,9 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeDataRaster( const Qgs
}

if ( nuller && destHasNoDataValue )
nuller->setOutputNoData( destNoDataValue );
{
nuller->setOutputNoDataValue( bandNo, destNoDataValue );
}

QgsDebugMsg( QString( "bandNo = %1 destDataType = %2 destHasNoDataValue = %3 destNoDataValue = %4" ).arg( bandNo ).arg( destDataType ).arg( destHasNoDataValue ).arg( destNoDataValue ) );
destDataTypeList.append( destDataType );
Expand Down
10 changes: 1 addition & 9 deletions src/core/raster/qgsrasteriterator.cpp
Expand Up @@ -44,14 +44,12 @@ void QgsRasterIterator::startRasterRead( int bandNumber, int nCols, int nRows, c
pInfo.nRows = nRows;
pInfo.currentCol = 0;
pInfo.currentRow = 0;
pInfo.block = 0;
pInfo.prj = 0;
mRasterPartInfos.insert( bandNumber, pInfo );
}

bool QgsRasterIterator::readNextRasterPart( int bandNumber,
int& nCols, int& nRows,
//void** rasterData,
QgsRasterBlock **block,
int& topLeftCol, int& topLeftRow )
{
Expand All @@ -73,9 +71,6 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
}

//remove last data block
// TODO: block is released somewhere else (check)
//delete pInfo.block;
pInfo.block = 0;
delete pInfo.prj;
pInfo.prj = 0;

Expand All @@ -98,9 +93,7 @@ bool QgsRasterIterator::readNextRasterPart( int bandNumber,
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
QgsRectangle blockRect( xmin, ymin, xmax, ymax );

pInfo.block = mInput->block( bandNumber, blockRect, nCols, nRows );

*block = pInfo.block;
*block = mInput->block( bandNumber, blockRect, nCols, nRows );
topLeftCol = pInfo.currentCol;
topLeftRow = pInfo.currentRow;

Expand Down Expand Up @@ -129,7 +122,6 @@ void QgsRasterIterator::removePartInfo( int bandNumber )
if ( partIt != mRasterPartInfos.end() )
{
RasterPartInfo& pInfo = partIt.value();
delete pInfo.block;
delete pInfo.prj;
mRasterPartInfos.remove( bandNumber );
}
Expand Down
23 changes: 12 additions & 11 deletions src/core/raster/qgsrasteriterator.h
Expand Up @@ -30,16 +30,6 @@ struct QgsRasterViewPort;
class CORE_EXPORT QgsRasterIterator
{
public:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterBlock *block;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterIterator( QgsRasterInterface* input );
~QgsRasterIterator();
Expand All @@ -52,7 +42,8 @@ class CORE_EXPORT QgsRasterIterator
*/
void startRasterRead( int bandNumber, int nCols, int nRows, const QgsRectangle& extent );

/**Fetches next part of raster data
/**Fetches next part of raster data, caller takes ownership of the block and
caller should delete the block.
@param bandNumber band to read
@param nCols number of columns on output device
@param nRows number of rows on output device
Expand All @@ -76,6 +67,16 @@ class CORE_EXPORT QgsRasterIterator
int maximumTileHeight() const { return mMaximumTileHeight; }

private:
//Stores information about reading of a raster band. Columns and rows are in unsampled coordinates
struct RasterPartInfo
{
int currentCol;
int currentRow;
int nCols;
int nRows;
QgsRasterProjector* prj; //raster projector (or 0 if no reprojection is done)
};

QgsRasterInterface* mInput;
QMap<int, RasterPartInfo> mRasterPartInfos;
QgsRectangle mExtent;
Expand Down
51 changes: 25 additions & 26 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -367,8 +367,8 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
}

// get dimensions of clipped raster image in device coordinate space (this is the size of the viewport)
myRasterViewPort->topLeftPoint = theQgsMapToPixel.transform( myRasterExtent.xMinimum(), myRasterExtent.yMaximum() );
myRasterViewPort->bottomRightPoint = theQgsMapToPixel.transform( myRasterExtent.xMaximum(), myRasterExtent.yMinimum() );
myRasterViewPort->mTopLeftPoint = theQgsMapToPixel.transform( myRasterExtent.xMinimum(), myRasterExtent.yMaximum() );
myRasterViewPort->mBottomRightPoint = theQgsMapToPixel.transform( myRasterExtent.xMaximum(), myRasterExtent.yMinimum() );

// align to output device grid, i.e. floor/ceil to integers
// TODO: this should only be done if paint device is raster - screen, image
Expand All @@ -378,22 +378,22 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
// the provider anyway
if ( true )
{
myRasterViewPort->topLeftPoint.setX( floor( myRasterViewPort->topLeftPoint.x() ) );
myRasterViewPort->topLeftPoint.setY( floor( myRasterViewPort->topLeftPoint.y() ) );
myRasterViewPort->bottomRightPoint.setX( ceil( myRasterViewPort->bottomRightPoint.x() ) );
myRasterViewPort->bottomRightPoint.setY( ceil( myRasterViewPort->bottomRightPoint.y() ) );
myRasterViewPort->mTopLeftPoint.setX( floor( myRasterViewPort->mTopLeftPoint.x() ) );
myRasterViewPort->mTopLeftPoint.setY( floor( myRasterViewPort->mTopLeftPoint.y() ) );
myRasterViewPort->mBottomRightPoint.setX( ceil( myRasterViewPort->mBottomRightPoint.x() ) );
myRasterViewPort->mBottomRightPoint.setY( ceil( myRasterViewPort->mBottomRightPoint.y() ) );
// recalc myRasterExtent to aligned values
myRasterExtent.set(
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->topLeftPoint.x(),
myRasterViewPort->bottomRightPoint.y() ),
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->bottomRightPoint.x(),
myRasterViewPort->topLeftPoint.y() )
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mTopLeftPoint.x(),
myRasterViewPort->mBottomRightPoint.y() ),
theQgsMapToPixel.toMapCoordinatesF( myRasterViewPort->mBottomRightPoint.x(),
myRasterViewPort->mTopLeftPoint.y() )
);

}

myRasterViewPort->drawableAreaXDim = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->drawableAreaYDim = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->mWidth = static_cast<int>( qAbs(( myRasterExtent.width() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );
myRasterViewPort->mHeight = static_cast<int>( qAbs(( myRasterExtent.height() / theQgsMapToPixel.mapUnitsPerPixel() ) ) );

//the drawable area can start to get very very large when you get down displaying 2x2 or smaller, this is becasue
//theQgsMapToPixel.mapUnitsPerPixel() is less then 1,
Expand All @@ -407,20 +407,19 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )
QgsDebugMsgLevel( QString( "myRasterExtent.yMinimum() = %1" ).arg( myRasterExtent.yMinimum() ), 3 );
QgsDebugMsgLevel( QString( "myRasterExtent.yMaximum() = %1" ).arg( myRasterExtent.yMaximum() ), 3 );

QgsDebugMsgLevel( QString( "topLeftPoint.x() = %1" ).arg( myRasterViewPort->topLeftPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "bottomRightPoint.x() = %1" ).arg( myRasterViewPort->bottomRightPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "topLeftPoint.y() = %1" ).arg( myRasterViewPort->topLeftPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "bottomRightPoint.y() = %1" ).arg( myRasterViewPort->bottomRightPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "mTopLeftPoint.x() = %1" ).arg( myRasterViewPort->mTopLeftPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "mBottomRightPoint.x() = %1" ).arg( myRasterViewPort->mBottomRightPoint.x() ), 3 );
QgsDebugMsgLevel( QString( "mTopLeftPoint.y() = %1" ).arg( myRasterViewPort->mTopLeftPoint.y() ), 3 );
QgsDebugMsgLevel( QString( "mBottomRightPoint.y() = %1" ).arg( myRasterViewPort->mBottomRightPoint.y() ), 3 );

QgsDebugMsgLevel( QString( "drawableAreaXDim = %1" ).arg( myRasterViewPort->drawableAreaXDim ), 3 );
QgsDebugMsgLevel( QString( "drawableAreaYDim = %1" ).arg( myRasterViewPort->drawableAreaYDim ), 3 );
QgsDebugMsgLevel( QString( "mWidth = %1" ).arg( myRasterViewPort->mWidth ), 3 );
QgsDebugMsgLevel( QString( "mHeight = %1" ).arg( myRasterViewPort->mHeight ), 3 );

// /\/\/\ - added to handle zoomed-in rasters

mLastViewPort = *myRasterViewPort;

// Provider mode: See if a provider key is specified, and if so use the provider instead

// TODO: is it necessary? Probably WMS only?
mDataProvider->setDpi( rendererContext.rasterScaleFactor() * 25.4 * rendererContext.scaleFactor() );

draw( theQPainter, myRasterViewPort, &theQgsMapToPixel );
Expand Down Expand Up @@ -785,8 +784,8 @@ void QgsRasterLayer::init()
setDrawingStyle( QgsRasterLayer::UndefinedDrawingStyle );

//Initialize the last view port structure, should really be a class
mLastViewPort.drawableAreaXDim = 0;
mLastViewPort.drawableAreaYDim = 0;
mLastViewPort.mWidth = 0;
mLastViewPort.mHeight = 0;
}

void QgsRasterLayer::setDataProvider( QString const & provider )
Expand Down Expand Up @@ -1266,10 +1265,10 @@ QPixmap QgsRasterLayer::previewAsPixmap( QSize size, QColor bgColor )
double myPixelWidth = myExtent.width() / myMapUnitsPerPixel;
double myPixelHeight = myExtent.height() / myMapUnitsPerPixel;

myRasterViewPort->topLeftPoint = QgsPoint( myX, myY );
myRasterViewPort->bottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
myRasterViewPort->drawableAreaXDim = myQPixmap.width();
myRasterViewPort->drawableAreaYDim = myQPixmap.height();
myRasterViewPort->mTopLeftPoint = QgsPoint( myX, myY );
myRasterViewPort->mBottomRightPoint = QgsPoint( myPixelWidth, myPixelHeight );
myRasterViewPort->mWidth = myQPixmap.width();
myRasterViewPort->mHeight = myQPixmap.height();

myRasterViewPort->mDrawnExtent = myExtent;
myRasterViewPort->mSrcCRS = QgsCoordinateReferenceSystem(); // will be invalid
Expand Down

0 comments on commit 33d13cc

Please sign in to comment.