Skip to content

Commit

Permalink
pipe in properties dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Jul 1, 2012
1 parent d937dbb commit db7f9a5
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 21 deletions.
40 changes: 40 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include <limits>
#include <typeinfo>

#include "qgsmaptopixel.h"
#include "qgsmapcanvas.h"
Expand Down Expand Up @@ -294,6 +295,8 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
}
}
on_mRenderTypeComboBox_currentIndexChanged( mRenderTypeComboBox->currentIndex() );

updatePipeList();
} // QgsRasterLayerProperties ctor


Expand Down Expand Up @@ -1600,3 +1603,40 @@ void QgsRasterLayerProperties::toggleBuildPyramidsButton()
}
}

void QgsRasterLayerProperties::updatePipeList()
{
QgsDebugMsg("Entered");

mPipeTreeWidget->setColumnCount( 3 );
//mPipeTreeWidget->header()->setResizeMode(0, QHeaderView::Stretch);
mPipeTreeWidget->header()->setResizeMode( QHeaderView::ResizeToContents );

QStringList labels;
labels << tr( "Filter" ) << tr("Bands") << tr( "Tot time" ) << tr( "Avg time" );
mPipeTreeWidget->setHeaderLabels( labels );

QgsRasterPipe *pipe = mRasterLayer->pipe();
for ( int i = 0; i < pipe->size(); i++ )
{
QgsRasterInterface * filter = pipe->at(i);
QStringList texts;
QString name;
// Unfortunately at this moment not all filters inherits from QObject
QObject *o = dynamic_cast<QObject*>( filter);
if ( o )
{
//name = o->objectName(); // gives empty with provider
name = o->metaObject()->className();
}
else
{
name = QString(typeid(*filter).name()).replace ( QRegExp(".*Qgs"), "Qgs" );
}

texts << name << QString("%1").arg( filter->bandCount() );
texts << QString("%1 ms").arg( filter->time(0) ) << QString("%1 ms").arg( filter->avgTime(), 0, 'd' );
QTreeWidgetItem *item = new QTreeWidgetItem( texts );

mPipeTreeWidget->addTopLevelItem ( item );
}
}
3 changes: 3 additions & 0 deletions src/app/qgsrasterlayerproperties.h
Expand Up @@ -151,6 +151,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
qreal mGradientHeight;
qreal mGradientWidth;

/** Update pipe tab - filters list */
void updatePipeList();

QgsMapCanvas* mMapCanvas;
QgsMapToolEmitPoint* mPixelSelectorTool;
};
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsrasterprojector.cpp
Expand Up @@ -555,10 +555,10 @@ void * QgsRasterProjector::readBlock( int bandNo, QgsRectangle const & extent,
QgsDebugMsg( "Entered" );
if ( !mInput ) return 0;

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

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

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

if ( !inputData ) return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgsmultibandcolorrenderer.cpp
Expand Up @@ -176,7 +176,7 @@ void * QgsMultiBandColorRenderer::readBlock( int bandNo, QgsRectangle const & e
bandIt = bands.constBegin();
for ( ; bandIt != bands.constEnd(); ++bandIt )
{
bandData[*bandIt] = mInput->readBlock( *bandIt, extent, width, height );
bandData[*bandIt] = mInput->block( *bandIt, extent, width, height );
if ( !bandData[*bandIt] ) return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -95,7 +95,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e
}

QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBandNumber );
void* rasterData = mInput->readBlock( bandNo, extent, width, height );
void* rasterData = mInput->block( bandNo, extent, width, height );
double currentOpacity = mOpacity;

//rendering is faster without considering user-defined transparency
Expand All @@ -104,7 +104,7 @@ void * QgsPalettedRasterRenderer::readBlock( int bandNo, QgsRectangle const & e

if ( mAlphaBand > 0 && mAlphaBand != mBandNumber )
{
transparencyData = mInput->readBlock( mAlphaBand, extent, width, height );
transparencyData = mInput->block( mAlphaBand, extent, width, height );
}
else if ( mAlphaBand == mBandNumber )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterdrawer.cpp
Expand Up @@ -57,7 +57,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
}

// last pipe filter has only 1 band
int bandNumber = 0;
int bandNumber = 1;
startRasterRead( bandNumber, viewPort, theQgsMapToPixel );

//number of cols/rows in output pixels
Expand Down Expand Up @@ -167,7 +167,7 @@ bool QgsRasterDrawer::readNextRasterPart( int bandNumber, QgsRasterViewPort* vie
double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
QgsRectangle blockRect( xmin, ymin, xmax, ymax );

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

*rasterData = pInfo.data;
topLeftCol = pInfo.currentCol;
Expand Down
57 changes: 54 additions & 3 deletions src/core/raster/qgsrasterinterface.cpp
Expand Up @@ -19,10 +19,12 @@
#include "qgslogger.h"

#include <QByteArray>
#include <QTime>

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

Expand All @@ -43,3 +45,52 @@ QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format
uchar * data = ( uchar * ) malloc( size );
return new QImage( data, width, height, format );
}

void * QgsRasterInterface::block( int bandNo, QgsRectangle const & extent, int width, int height )
{
QTime time;
time.start();
void * b = readBlock( bandNo, extent, width, height );

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

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

double QgsRasterInterface::avgTime( )
{
// Not perfect because Qtime measures ms only and we dont count rendered bands
double t = 0;
int count = 0;
for ( int i = 1; i < mTime.size(); i++ )
{
t += mTime[i];
if ( mTime[i] > 0 ) count++;
}
return count > 0 ? t/count : 0;
}
21 changes: 20 additions & 1 deletion src/core/raster/qgsrasterinterface.h
Expand Up @@ -118,7 +118,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return UnknownDataType;
}

/** Get numbur of bands */
/** Get number of bands */
virtual int bandCount() const
{
return 1;
Expand All @@ -131,6 +131,13 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
* Returns pointer to data.
* Caller is responsible to free the memory returned.
*/
void * block( int bandNo, QgsRectangle const & extent, int width, int height );

/** 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.
*/
virtual void * readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
{
Q_UNUSED( bandNo ); Q_UNUSED( extent ); Q_UNUSED( width ); Q_UNUSED( height );
Expand All @@ -146,14 +153,26 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
*/
QImage * createImage( int width, int height, QImage::Format format );

// 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
double time( int bandNo );
double avgTime();

//protected:

Role mRole;

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

// Last rendering time
QVector<double> mTime;

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

#endif
Expand Down
3 changes: 3 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -364,6 +364,9 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
const QgsRasterResampleFilter* resampleFilter() const { return dynamic_cast<QgsRasterResampleFilter*>( mPipe.filter( QgsRasterInterface::ResamplerRole ) ); }
QgsRasterResampleFilter * resampleFilter() { return dynamic_cast<QgsRasterResampleFilter*>( mPipe.filter( QgsRasterInterface::ResamplerRole ) ); }

/** Get raster pipe */
QgsRasterPipe * pipe() { return &mPipe; }

/** \brief Accessor to find out how many standard deviations are being plotted */
double standardDeviations() const { return mStandardDeviations; }

Expand Down
2 changes: 2 additions & 0 deletions src/core/raster/qgsrasterpipe.h
Expand Up @@ -64,6 +64,8 @@ class CORE_EXPORT QgsRasterPipe //: public QObject
//QgsRasterInterface * filter ( QgsRasterInterface::Role role );
QgsRasterInterface * filter ( QgsRasterInterface::Role role ) const;

int size() { return mFilters.size(); }
QgsRasterInterface * at( int idx ) { return mFilters.at(idx); }
QgsRasterInterface * last() { return mFilters.last(); }

/** Delete all filters */
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgsrasterresamplefilter.cpp
Expand Up @@ -100,8 +100,8 @@ void * QgsRasterResampleFilter::readBlock( int bandNo, QgsRectangle const & ext
int resHeight = height * oversamplingY;

// At moment we know that we read rendered image
int bandNumber = 0;
void *rasterData = mInput->readBlock( bandNumber, extent, resWidth, resHeight );
int bandNumber = 1;
void *rasterData = mInput->block( bandNumber, extent, resWidth, resHeight );

//resample image
if (( mZoomedInResampler || mZoomedOutResampler ) && !doubleNear( oversamplingX, 1.0 ) && !doubleNear( oversamplingY, 1.0 ) )
Expand Down
2 changes: 1 addition & 1 deletion src/core/raster/qgssinglebandcolordatarenderer.cpp
Expand Up @@ -57,7 +57,7 @@ void * QgsSingleBandColorDataRenderer::readBlock( int bandNo, QgsRectangle cons

QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBand );

void* rasterData = mInput->readBlock( bandNo, extent, width, height );
void* rasterData = mInput->block( bandNo, extent, width, height );

currentRasterPos = 0;
QImage img( width, height, QImage::Format_ARGB32 );
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgssinglebandgrayrenderer.cpp
Expand Up @@ -74,7 +74,7 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e
alphaType = ( QgsRasterInterface::DataType )mInput->dataType( mAlphaBand );
}

void* rasterData = mInput->readBlock( mGrayBand, extent, width, height );
void* rasterData = mInput->block( mGrayBand, extent, width, height );
if ( !rasterData ) return 0;

void* alphaData = 0;
Expand All @@ -84,7 +84,7 @@ void * QgsSingleBandGrayRenderer::readBlock( int bandNo, QgsRectangle const & e

if ( mAlphaBand > 0 && mGrayBand != mAlphaBand )
{
alphaData = mInput->readBlock( mAlphaBand, extent, width, height );
alphaData = mInput->block( mAlphaBand, extent, width, height );
if ( !alphaData ) {
free ( rasterData );
return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Expand Up @@ -76,7 +76,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co
double currentOpacity = mOpacity;
QgsRasterInterface::DataType rasterType = ( QgsRasterInterface::DataType )mInput->dataType( mBand );

void* rasterData = mInput->readBlock( mBand, extent, width, height );
void* rasterData = mInput->block( mBand, extent, width, height );

int red, green, blue;
QRgb myDefaultColor = qRgba( 255, 255, 255, 0 );
Expand All @@ -86,7 +86,7 @@ void * QgsSingleBandPseudoColorRenderer::readBlock( int bandNo, QgsRectangle co

if ( mAlphaBand > 0 && mAlphaBand != mBand )
{
transparencyData = mInput->readBlock( mAlphaBand, extent, width, height );
transparencyData = mInput->block( mAlphaBand, extent, width, height );
}
else if ( mAlphaBand == mBand )
{
Expand Down
26 changes: 24 additions & 2 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>706</width>
<height>663</height>
<height>652</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -825,7 +825,7 @@
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;table border=&quot;0&quot; style=&quot;-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;border: none;&quot;&gt;
Expand Down Expand Up @@ -952,6 +952,28 @@ p, li { white-space: pre-wrap; }
</item>
</layout>
</widget>
<widget class="QWidget" name="tabPagePipe">
<attribute name="title">
<string>Pipe (debug)</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTreeWidget" name="mPipeTreeWidget">
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="2" column="0" colspan="4">
Expand Down

0 comments on commit db7f9a5

Please sign in to comment.