Skip to content

Commit

Permalink
on/off rasterinterface switch
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent c987446 commit 7d14802
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/core/qgsrasterprojector.cpp
Expand Up @@ -72,6 +72,20 @@ QgsRasterProjector::~QgsRasterProjector()
delete[] pHelperBottom;
}

int QgsRasterProjector::bandCount() const
{
if ( mInput ) return mInput->bandCount();

return 0;
}

QgsRasterInterface::DataType QgsRasterProjector::dataType( int bandNo ) const
{
if ( mInput ) return mInput->dataType( bandNo );

return QgsRasterInterface::UnknownDataType;
}

void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
{
mSrcCRS = theSrcCRS;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsrasterprojector.h
Expand Up @@ -61,6 +61,10 @@ class CORE_EXPORT QgsRasterProjector : public QgsRasterInterface
/** \brief The destructor */
~QgsRasterProjector();

int bandCount() const;

QgsRasterInterface::DataType dataType( int bandNo ) const;

/** \brief set source and destination CRS */
void setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS );

Expand Down
8 changes: 8 additions & 0 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -25,6 +25,7 @@

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input )
: mInput( input )
, mOn( true )
, mStatsOn( false )
{
}
Expand Down Expand Up @@ -80,6 +81,13 @@ QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format

void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
{
if ( !mOn )
{
// Switched off, pass input data unchanged
if ( !mInput ) return 0;
return mInput->block( bandNo, extent, width, height );
}

QTime time;
time.start();
void * b = readBlock( bandNo, extent, width, height );
Expand Down
9 changes: 9 additions & 0 deletions src/core/raster/qgsrasterinterface.h
Expand Up @@ -142,6 +142,12 @@ class CORE_EXPORT QgsRasterInterface
* Returns true if set correctly, false if cannot use that input */
virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }

/** Is on/off */
virtual bool on( ) { return mOn; }

/** Set on/off */
virtual void setOn( bool on ) { mOn = on; }

/** 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.
Expand All @@ -166,6 +172,9 @@ class CORE_EXPORT QgsRasterInterface
// QgsRasterInterface used as input
QgsRasterInterface* mInput;

// On/off state, if off, it does not do anything, replicates input
bool mOn;

private:
// Last rendering cumulative (this and all preceding interfaces) times, from index 1
QVector<double> mTime;
Expand Down
6 changes: 5 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -2109,7 +2109,11 @@ void QgsRasterLayer::setResampleFilter( QgsRasterResampleFilter* resampleFilter
{
QgsDebugMsg( "Entered" );
if ( !resampleFilter ) { return; }
mPipe.set( resampleFilter );
if ( !mPipe.set( resampleFilter ) )
{
// TODO: somehow notify (and delete?)
QgsDebugMsg( "Cannot set resample filter." );
}
}

void QgsRasterLayer::showProgress( int theValue )
Expand Down
35 changes: 27 additions & 8 deletions src/core/raster/qgsrasterpipe.cpp
Expand Up @@ -77,10 +77,7 @@ bool QgsRasterPipe::insert( int idx, QgsRasterInterface* theInterface )
bool QgsRasterPipe::replace( int idx, QgsRasterInterface* theInterface )
{
QgsDebugMsg( QString( "replace by %1 at %2" ).arg( typeid( *theInterface ).name() ).arg( idx ) );
if ( idx < 0 || idx >= mInterfaces.size() )
{
return false;
}
if ( !checkBounds( idx ) ) return false;
if ( !theInterface ) return false;

// make a copy of pipe to test connection, we test the connections
Expand Down Expand Up @@ -216,10 +213,7 @@ bool QgsRasterPipe::remove( int idx )
{
QgsDebugMsg( QString( "remove at %1" ).arg( idx ) );

if ( idx < 0 || idx >= mInterfaces.size() )
{
return false;
}
if ( !checkBounds( idx ) ) return false;

// make a copy of pipe to test connection, we test the connections
// of the whole pipe, because the types and band numbers may change
Expand Down Expand Up @@ -247,3 +241,28 @@ bool QgsRasterPipe::remove( QgsRasterInterface * theInterface )

return remove( mInterfaces.indexOf( theInterface ) );
}

bool QgsRasterPipe::setOn( int idx, bool on )
{
if ( !checkBounds( idx ) ) return false;

// Because setting interface on/off may change its output we must check if
// connection is OK after such switch
bool onOrig = mInterfaces[idx]->on();

if ( onOrig == on ) return true;

mInterfaces[idx]->setOn( on );

if ( connect( mInterfaces ) ) return true;

mInterfaces[idx]->setOn( onOrig );
connect( mInterfaces );
return false;
}

bool QgsRasterPipe::checkBounds( int idx ) const
{
if ( idx < 0 || idx >= mInterfaces.size() ) return false;
return true;
}
7 changes: 7 additions & 0 deletions src/core/raster/qgsrasterpipe.h
Expand Up @@ -81,6 +81,10 @@ class CORE_EXPORT QgsRasterPipe
QgsRasterInterface * at( int idx ) { return mInterfaces.at( idx ); }
QgsRasterInterface * last() { return mInterfaces.last(); }

/** Set interface at index on/off
* Returns true on success */
bool setOn( int idx, bool on );

// Getters for special types of interfaces
QgsRasterDataProvider * provider() const;
QgsRasterRenderer * renderer() const;
Expand All @@ -104,6 +108,9 @@ class CORE_EXPORT QgsRasterPipe

// Unset role in mRoleMap
void unsetRole( QgsRasterInterface * theInterface );

// Check if index is in bounds
bool checkBounds( int idx ) const;
};

#endif
Expand Down
24 changes: 21 additions & 3 deletions src/core/raster/qgsrasterrenderer.cpp
Expand Up @@ -42,14 +42,32 @@ QgsRasterRenderer::~QgsRasterRenderer()
{
}

int QgsRasterRenderer::bandCount() const
{
if ( mOn ) return 1;

if ( mInput ) return mInput->bandCount();

return 0;
}

QgsRasterInterface::DataType QgsRasterRenderer::dataType( int bandNo ) const
{
if ( mOn ) return QgsRasterInterface::ARGB32_Premultiplied;

if ( mInput ) return mInput->dataType( bandNo );

return QgsRasterInterface::UnknownDataType;
}

bool QgsRasterRenderer::setInput( QgsRasterInterface* input )
{
// Renderer can only work with numerical values in at least 1 band
if ( !mInput ) return false;
if ( !input ) return false;

for ( int i = 1; i <= mInput->bandCount(); i++ )
for ( int i = 1; i <= input->bandCount(); i++ )
{
if ( typeIsNumeric( mInput->dataType( i ) ) )
if ( typeIsNumeric( input->dataType( i ) ) )
{
mInput = input;
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterrenderer.h
Expand Up @@ -37,6 +37,10 @@ class CORE_EXPORT QgsRasterRenderer : public QgsRasterInterface
QgsRasterRenderer( QgsRasterInterface* input = 0, const QString& type = "" );
virtual ~QgsRasterRenderer();

virtual int bandCount() const;

virtual QgsRasterInterface::DataType dataType( int bandNo ) const;

virtual QString type() const { return mType; }

virtual bool setInput( QgsRasterInterface* input );
Expand Down
34 changes: 31 additions & 3 deletions src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -45,15 +45,43 @@ QgsRasterResampleFilter::~QgsRasterResampleFilter()
delete mZoomedOutResampler;
}

int QgsRasterResampleFilter::bandCount() const
{
if ( mOn ) return 1;

if ( mInput ) return mInput->bandCount();

return 0;
}

QgsRasterInterface::DataType QgsRasterResampleFilter::dataType( int bandNo ) const
{
if ( mOn ) return QgsRasterInterface::ARGB32_Premultiplied;

if ( mInput ) return mInput->dataType( bandNo );

return QgsRasterInterface::UnknownDataType;
}

bool QgsRasterResampleFilter::setInput( QgsRasterInterface* input )
{
QgsDebugMsg( "Entered" );
// Resampler can only work with single band ARGB32_Premultiplied
if ( !mInput ) return false;
if ( !input ) return false;

if ( mInput->bandCount() < 1 ) return false;
if ( input->bandCount() < 1 )
{
QgsDebugMsg( "No input band" );
return false;
}

if ( mInput->dataType( 1 ) != QgsRasterInterface::ARGB32_Premultiplied ) return false;
if ( input->dataType( 1 ) != QgsRasterInterface::ARGB32_Premultiplied )
{
return false;
QgsDebugMsg( "Unknown input data type" );
}

mInput = input;
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgsrasterresamplefilter.h
Expand Up @@ -31,6 +31,10 @@ class QgsRasterResampleFilter : public QgsRasterInterface
QgsRasterResampleFilter( QgsRasterInterface* input = 0 );
~QgsRasterResampleFilter();

int bandCount() const;

QgsRasterInterface::DataType dataType( int bandNo ) const;

bool setInput( QgsRasterInterface* input );

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

0 comments on commit 7d14802

Please sign in to comment.