Skip to content
Permalink
Browse files

re enabled resampling, clean up

  • Loading branch information
blazek committed Jul 1, 2012
1 parent db7f9a5 commit 71f3cfe881a29d8d6fe785eefd5ed972f47eb2ac
@@ -40,7 +40,6 @@ class QByteArray;

#define TINY_VALUE std::numeric_limits<double>::epsilon() * 20


/** \ingroup core
* Base class for raster data providers.
*
@@ -105,6 +104,7 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast

virtual ~QgsRasterDataProvider() {};

QgsRasterInterface * srcInput() { return this; }

/**
* Add the list of WMS layer names to be rendered by this server
@@ -34,6 +34,7 @@ QgsRasterProjector::QgsRasterProjector(
, mExtent( theExtent )
, mDestRows( theDestRows ), mDestCols( theDestCols )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
, pHelperTop( 0 ), pHelperBottom( 0 )
{
QgsDebugMsg( "Entered" );
QgsDebugMsg( "theDestExtent = " + theDestExtent.toString() );
@@ -52,21 +53,22 @@ QgsRasterProjector::QgsRasterProjector(
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mExtent( theExtent )
, mMaxSrcXRes( theMaxSrcXRes ), mMaxSrcYRes( theMaxSrcYRes )
, pHelperTop( 0 ), pHelperBottom( 0 )
{
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
, pHelperTop( 0 ), pHelperBottom( 0 )
{
QgsDebugMsg( "Entered" );
}

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

void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
@@ -79,9 +81,12 @@ void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoor

void QgsRasterProjector::calc()
{
QgsDebugMsg( "Entered" );
mCPMatrix.clear();
//delete pHelperTop;
//delete pHelperBottom;
delete pHelperTop;
pHelperTop = 0;
delete pHelperBottom;
pHelperBottom = 0;

mDestXRes = mDestExtent.width() / ( mDestCols );
mDestYRes = mDestExtent.height() / ( mDestRows );
@@ -328,6 +333,7 @@ void QgsRasterProjector::calcHelper( int theMatrixRow, QgsPoint *thePoints )
}
void QgsRasterProjector::nextHelper()
{
// We just switch pHelperTop and pHelperBottom, memory is not lost
QgsPoint *tmp;
tmp = pHelperTop;
pHelperTop = pHelperBottom;
@@ -345,23 +351,33 @@ void QgsRasterProjector::srcRowCol( int theDestRow, int theDestCol, int *theSrcR

void QgsRasterProjector::preciseSrcRowCol( int theDestRow, int theDestCol, int *theSrcRow, int *theSrcCol )
{
//QgsDebugMsg( QString( "theDestRow = %1" ).arg(theDestRow) );
//QgsDebugMsg( QString( "theDestRow = %1 mDestExtent.yMaximum() = %2 mDestYRes = %3" ).arg(theDestRow).arg(mDestExtent.yMaximum()).arg(mDestYRes) );
#ifdef QGISDEBUG
QgsDebugMsgLevel( QString( "theDestRow = %1" ).arg( theDestRow ), 5 );
QgsDebugMsgLevel( QString( "theDestRow = %1 mDestExtent.yMaximum() = %2 mDestYRes = %3" ).arg( theDestRow ).arg( mDestExtent.yMaximum() ).arg( mDestYRes ), 5 );
#endif

// Get coordinate of center of destination cell
double x = mDestExtent.xMinimum() + ( theDestCol + 0.5 ) * mDestXRes;
double y = mDestExtent.yMaximum() - ( theDestRow + 0.5 ) * mDestYRes;
double z = 0;

//QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );
#ifdef QGISDEBUG
QgsDebugMsgLevel( QString( "x = %1 y = %2" ).arg( x ).arg( y ), 5 );
#endif

mCoordinateTransform.transformInPlace( x, y, z );
//QgsDebugMsg( QString( "x = %1 y = %2" ).arg(x).arg(y) );

#ifdef QGISDEBUG
QgsDebugMsgLevel( QString( "x = %1 y = %2" ).arg( x ).arg( y ), 5 );
#endif

// Get source row col
*theSrcRow = ( int ) floor(( mSrcExtent.yMaximum() - y ) / mSrcYRes );
*theSrcCol = ( int ) floor(( x - mSrcExtent.xMinimum() ) / mSrcXRes );
//QgsDebugMsg( QString( "mSrcExtent.yMaximum() = %1 mSrcYRes = %2" ).arg(mSrcExtent.yMaximum()).arg(mSrcYRes) );
//QgsDebugMsg( QString( "theSrcRow = %1 theSrcCol = %2" ).arg(*theSrcRow).arg(*theSrcCol) );
#ifdef QGISDEBUG
QgsDebugMsgLevel( QString( "mSrcExtent.yMaximum() = %1 mSrcYRes = %2" ).arg( mSrcExtent.yMaximum() ).arg( mSrcYRes ), 5 );
QgsDebugMsgLevel( QString( "theSrcRow = %1 theSrcCol = %2" ).arg( *theSrcRow ).arg( *theSrcCol ), 5 );
#endif

// With epsg 32661 (Polar Stereographic) it was happening that *theSrcCol == mSrcCols
// For now silently correct limits to avoid crashes
@@ -555,10 +571,10 @@ void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent,
QgsDebugMsg( "Entered" );
if ( !mInput ) return 0;

int bandNumber = 1;
if ( ! mSrcCRS.isValid() || ! mDestCRS.isValid() || mSrcCRS == mDestCRS )
{
return mInput->block( bandNumber, extent, width, height );
QgsDebugMsg( "No projection necessary" );
return mInput->block( bandNo, extent, width, height );
}

mDestExtent = extent;
@@ -575,7 +591,7 @@ void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent,
return 0;
}

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

if ( !inputData ) return 0;

@@ -26,21 +26,17 @@
#include <QVector>
#include <QList>


#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgscoordinatetransform.h"
#include "qgsrasterinterface.h"

#include <cmath>

//class QgsRectangle;
class QgsPoint;

//class CORE_EXPORT QgsRasterProjector
class QgsRasterProjector : public QgsRasterInterface
class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
{
// Q_OBJECT
public:
/** \brief QgsRasterProjector implements approximate projection support for
* it calculates grid of points in source CRS for target CRS + extent
@@ -126,7 +122,6 @@ class QgsRasterProjector : public QgsRasterInterface
bool checkRows();

/** Calculate array of src helper points */
//void calcHelper ( int theMatrixRow, QList<QgsPoint> *thePoints );
void calcHelper( int theMatrixRow, QgsPoint *thePoints );

/** Calc / switch helper */
@@ -34,7 +34,6 @@ class CORE_EXPORT QgsMultiBandColorRenderer: public QgsRasterRenderer

static QgsRasterRenderer* create( const QDomElement& elem, QgsRasterInterface* input );

//void draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel );
void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height );

int redBand() const { return mRedBand; }
@@ -15,16 +15,16 @@
* *
***************************************************************************/

#include "qgsrasterinterface.h"
#include "qgslogger.h"

#include <QByteArray>
#include <QTime>

#include "qgslogger.h"
#include "qgsrasterinterface.h"

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input, Role role )
: mInput( input )
, mRole( role )
, mTimeMinSize(150)
: mInput( input )
, mRole( role )
, mTimeMinSize( 150 )
{
}

@@ -54,20 +54,21 @@ void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int

if ( width > mTimeMinSize && height > mTimeMinSize )
{
if ( mTime.size() <= bandNo )
if ( mTime.size() <= bandNo )
{
mTime.resize( bandNo+1 );
mTime.resize( bandNo + 1 );
}
// QTime counts only in miliseconds
mTime[bandNo] = time.elapsed();
QgsDebugMsg ( QString("mRole = %1 bandNo = %2 time = %3" ).arg(mRole).arg(bandNo).arg(mTime[bandNo]) );
QgsDebugMsg( QString( "mRole = %1 bandNo = %2 time = %3" ).arg( mRole ).arg( bandNo ).arg( mTime[bandNo] ) );
}
return b;
}

double QgsRasterInterface::time( int bandNo )
{
double QgsRasterInterface::time( int bandNo )
{
double t = 0;
if ( bandNo == 0 )
if ( bandNo == 0 )
{
for ( int i = 1; i < mTime.size(); i++ )
{
@@ -76,13 +77,13 @@ double QgsRasterInterface::time( int bandNo )
}
else
{
t = mTime.value( bandNo );
t = mTime.value( bandNo );
}
QgsDebugMsg ( QString("mRole = %1 bandNo = %2 time = %3" ).arg(mRole).arg(bandNo).arg(t) );
QgsDebugMsg( QString( "mRole = %1 bandNo = %2 time = %3" ).arg( mRole ).arg( bandNo ).arg( t ) );
return t;
}

double QgsRasterInterface::avgTime( )
double QgsRasterInterface::avgTime( )
{
// Not perfect because Qtime measures ms only and we dont count rendered bands
double t = 0;
@@ -92,5 +93,5 @@ double QgsRasterInterface::avgTime( )
t += mTime[i];
if ( mTime[i] > 0 ) count++;
}
return count > 0 ? t/count : 0;
return count > 0 ? t / count : 0;
}
@@ -18,22 +18,21 @@
#ifndef QGSRASTERINTERFACE_H
#define QGSRASTERINTERFACE_H

#include <QObject>
#include <QImage>

#include "qgsrectangle.h"

/** \ingroup core
* Base class for processing modules.
*/
// TODO: inherit from QObject? QgsDataProvider inherits already from QObject, multiple inheritance from QObject is not allowed
class CORE_EXPORT QgsRasterInterface //: public QObject
// TODO: inherit from QObject? It would be probably better but QgsDataProvider inherits already from QObject and multiple inheritance from QObject is not allowed
class CORE_EXPORT QgsRasterInterface
{

//Q_OBJECT

public:

/** Role is used to identify certain type of interface in pipe and replace
* it with another of the same Role for example
*/
enum Role
{
UnknownRole = 0,
@@ -43,9 +42,9 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
ProjectorRole = 4
};

Role role() { return mRole; }

// This is modified copy of GDALDataType
/** Data types.
* This is modified and extended copy of GDALDataType.
*/
enum DataType
{
/*! Unknown or unspecified type */ UnknownDataType = 0,
@@ -68,9 +67,16 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
TypeCount = 14 /* maximum type # + 1 */
};

QgsRasterInterface( QgsRasterInterface * input = 0, Role role = UnknownRole );

virtual ~QgsRasterInterface();

/** Interface role */
Role role() { return mRole; }

int typeSize( int dataType ) const
{
// modified copy from GDAL
// Modified and extended copy from GDAL
switch ( dataType )
{
case Byte:
@@ -102,15 +108,12 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return 0;
}
}

int dataTypeSize( int bandNo ) const
{
return typeSize( dataType( bandNo ) );
}

QgsRasterInterface( QgsRasterInterface * input = 0, Role role = UnknownRole );

virtual ~QgsRasterInterface();

/** Returns data type for the band specified by number */
virtual int dataType( int bandNo ) const
{
@@ -124,7 +127,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return 1;
}

// TODO
/** Retruns value representing 'no data' (NULL) */
virtual double noDataValue() const { return 0; }

/** Read block of data using given extent and size.
@@ -133,7 +136,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
*/
void * block( int bandNo, QgsRectangle const & extent, int width, int height );

/** Read block of data using given extent and size.
/** Read block of data using given extent and size.
* Method to be implemented by subclasses.
* Returns pointer to data.
* Caller is responsible to free the memory returned.
@@ -148,30 +151,40 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
* Returns true if set correctly, false if cannot use that input */
virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }

/** Get source / raw input, the first in pipe, usually provider.
* It may be used to get info about original data, e.g. resolution to decide
* resampling etc.
*/
virtual QgsRasterInterface * srcInput() { return mInput ? mInput->srcInput() : 0; }

/** Create a new image with extraneous data, such data may be used
* after the image is destroyed. The memory is not initialized.
*/
QImage * createImage( int width, int height, QImage::Format format );

// Clear last rendering time
/** Clear last rendering time */
void clearTime() { mTime.clear(); if ( mInput ) mInput->clearTime(); }

// Last time consumed by block()
// Returns total time (for all bands) if bandNo is 0

/** Last time consumed by call to block()
* Returns total time (for all bands) if bandNo is 0
*/
double time( int bandNo );
double avgTime();

//protected:
/** Average time for all bands consumed by last calls to block() */
double avgTime();

protected:
// Role of interface
Role mRole;

// QgsRasterInterface from used as input, data are read from it
// QgsRasterInterface used as input
QgsRasterInterface* mInput;

// Last rendering time
private:
// Last rendering times, from index 1
QVector<double> mTime;

// minimum block size to record time (to ignore thumbnails etc)
// Minimum block size to record time (to ignore thumbnails etc)
int mTimeMinSize;
};

0 comments on commit 71f3cfe

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