Skip to content
Permalink
Browse files

rasterprojector in pipe

  • Loading branch information
blazek committed Jul 1, 2012
1 parent 3f227c4 commit 82f6739c38a31ff81c36212db448c53f59fbb7dd
@@ -241,7 +241,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}
mMaximumOversamplingSpinBox->setValue( renderer->maxOversampling() );
mMaximumOversamplingSpinBox->setValue( resampleFilter->maxOversampling() );
}

//transparency band
@@ -37,6 +37,36 @@ QgsRasterProjector::QgsRasterProjector(
QgsDebugMsg( "Entered" );
QgsDebugMsg( "theDestExtent = " + theDestExtent.toString() );

calc();
}

QgsRasterProjector::QgsRasterProjector(
QgsCoordinateReferenceSystem theSrcCRS,
QgsCoordinateReferenceSystem theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mExtent( theExtent )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
{
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::~QgsRasterProjector()
{
//delete mCoordinateTransform;
//delete pHelperTop;
//delete pHelperBottom;
}

void QgsRasterProjector::calc()
{
mCPMatrix.clear();
//delete pHelperTop;
//delete pHelperBottom;

mDestXRes = mDestExtent.width() / ( mDestCols );
mDestYRes = mDestExtent.height() / ( mDestRows );

@@ -110,11 +140,6 @@ QgsRasterProjector::QgsRasterProjector(
mHelperTopRow = 0;
}

QgsRasterProjector::~QgsRasterProjector()
{
//delete mCoordinateTransform;
}

void QgsRasterProjector::calcSrcExtent()
{
/* Run around the mCPMatrix and find source extent */
@@ -508,3 +533,62 @@ bool QgsRasterProjector::checkRows()
}
return true;
}

void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
QgsDebugMsg( "Entered" );
if ( !mInput ) return 0;

int bandNumber = 0;
if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
{
return mInput->readBlock( bandNumber, extent, width, height );
}

mDestExtent = extent;
mDestRows = height;
mDestCols = width;
calc();

QgsDebugMsg( QString( "srcExtent:\n%1" ).arg( srcExtent().toString() ) );
QgsDebugMsg( QString( "srcCols = %1 srcRows = %1" ).arg( srcCols() ).arg( srcRows() ) );

// If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
if ( srcRows() <= 0 || srcCols() <= 0 )
{
return 0;
}

void * inputData = mInput->readBlock( bandNumber, srcExtent(), srcCols(), srcRows() );

if ( !inputData ) return 0;

// ARGB32 only for now
int pixelSize = 4;

int inputSize = pixelSize * srcCols() * srcRows();

int outputSize = width * height * pixelSize;
void * outputData = malloc( outputSize );

// TODO: fill by transparent

int srcRow, srcCol;
for ( int i = 0; i < height; ++i )
{
for ( int j = 0; j < width; ++j )
{
srcRowCol( i, j, &srcRow, &srcCol );
int srcIndex = pixelSize * ( srcRow * mSrcCols + srcCol );
int destIndex = pixelSize * ( i * width + j );

if ( srcIndex >= inputSize || destIndex >= outputSize ) continue; // should not happen

memcpy(( char* )outputData + destIndex, ( char* )inputData + srcIndex, pixelSize );
}
}

free( inputData );

return outputData;
}
@@ -30,14 +30,15 @@
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransform.h"
#include "qgsrasterface.h"

#include <cmath>

//class QgsRectangle;
class QgsPoint;

//class CORE_EXPORT QgsRasterProjector
class QgsRasterProjector
class QgsRasterProjector : public QgsRasterFace
{
// Q_OBJECT
public:
@@ -53,11 +54,16 @@ class QgsRasterProjector
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent
);
QgsRasterProjector(
QgsCoordinateReferenceSystem theSrcCRS,
QgsCoordinateReferenceSystem theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent
);

/** \brief The destructor */
~QgsRasterProjector();


/** \brief get destination point for _current_ destination position */
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );

@@ -77,6 +83,9 @@ class QgsRasterProjector
/** \brief Get source row and column indexes for current source extent and resolution */
void srcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol );

/** \brief Calculate matrix */
void calc();

/** \brief insert rows to matrix */
void insertRows();

@@ -128,6 +137,8 @@ class QgsRasterProjector
int dstRows() const { return mDestRows; }
int dstCols() const { return mDestCols; }

void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );

private:
/** Source CRS */
QgsCoordinateReferenceSystem mSrcCRS;
@@ -40,12 +40,14 @@ email : tim at linfiniti.com
#include "qgscolorrampshader.h"

//renderers
//#include "qgspalettedrasterrenderer.h"
//#include "qgsmultibandcolorrenderer.h"
//#include "qgssinglebandcolordatarenderer.h"
//#include "qgssinglebandpseudocolorrenderer.h"
#include "qgspalettedrasterrenderer.h"
#include "qgsmultibandcolorrenderer.h"
#include "qgssinglebandcolordatarenderer.h"
#include "qgssinglebandpseudocolorrenderer.h"
#include "qgssinglebandgrayrenderer.h"

#include "qgsrasterprojector.h"

#include <cstdio>
#include <cmath>
#include <limits>
@@ -825,17 +827,24 @@ void QgsRasterLayer::draw( QPainter * theQPainter,

if ( mRenderer )
{
//mRenderer->draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
//if ( mResampleFilter )
//{
QgsRasterDrawer drawer( mResampleFilter );
//QgsRasterDrawer drawer( mRenderer );
//QgsRasterDrawer drawer( mResampleFilter );

double maxSrcXRes = 0;
double maxSrcYRes = 0;

if ( mDataProvider->capabilities() & QgsRasterDataProvider::ExactResolution )
{
maxSrcXRes = mDataProvider->extent().width() / mDataProvider->xSize();
maxSrcYRes = mDataProvider->extent().height() / mDataProvider->ySize();
}

QgsRasterProjector projector( theRasterViewPort->mSrcCRS, theRasterViewPort->mDestCRS, maxSrcXRes, maxSrcYRes, mDataProvider->extent() );

projector.setInput( mResampleFilter );

QgsRasterDrawer drawer( &projector );
drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
//}
//else
//{
// QgsRasterDrawer drawer( mRenderer );
// drawer.draw( theQPainter, theRasterViewPort, theQgsMapToPixel );
//}
}

QgsDebugMsg( QString( "raster draw time (ms): %1" ).arg( time.elapsed() ) );

0 comments on commit 82f6739

Please sign in to comment.
You can’t perform that action at this time.