Skip to content
Permalink
Browse files

add raster histogram tests

  • Loading branch information
etiennesky committed Jul 17, 2012
1 parent 29c8ef7 commit d1b7e8bac368e933f370fd4af3c3aef98572721a
Showing with 360 additions and 20 deletions.
  1. +24 −12 src/gui/raster/qgsrasterhistogramwidget.cpp
  2. +7 −1 src/gui/raster/qgsrasterhistogramwidget.h
  3. +8 −0 src/providers/gdal/qgsgdalprovider.cpp
  4. +11 −6 tests/src/core/qgsrenderchecker.cpp
  5. +7 −1 tests/src/core/qgsrenderchecker.h
  6. +8 −0 tests/src/gui/CMakeLists.txt
  7. +295 −0 tests/src/gui/testqgsrasterhistogram.cpp
  8. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_gray1/expected_histo_gray1.png
  9. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_gray2/expected_histo_gray2.png
  10. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_gray2/expected_histo_rgb2.png
  11. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_pseudo1/expected_histo_pseudo1.png
  12. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_rgb1/expected_histo_rgb1.png
  13. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_rgb2/expected_histo_rgb2.png
  14. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_rgb3/expected_histo_rgb3.png
  15. BIN tests/testdata/control_images/histogram_qwt5/expected_histo_rgb4/expected_histo_rgb4.png
  16. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_gray1/expected_histo_gray1.png
  17. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_gray2/expected_histo_gray2.png
  18. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_pseudo1/expected_histo_pseudo1.png
  19. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_rgb1/expected_histo_rgb1.png
  20. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_rgb2/expected_histo_rgb2.png
  21. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_rgb3/expected_histo_rgb3.png
  22. BIN tests/testdata/control_images/histogram_qwt6/expected_histo_rgb4/expected_histo_rgb4.png
@@ -522,19 +522,21 @@ void QgsRasterHistogramWidget::on_mSaveAsImageButton_clicked()
}
}

void QgsRasterHistogramWidget::histoSaveAsImage( const QString& theFilename )
bool QgsRasterHistogramWidget::histoSaveAsImage( const QString& theFilename,
int width, int height, int quality )
{
// make sure dir. exists
QDir myDir( QFileInfo( theFilename ).dir() );
QFileInfo myInfo( theFilename );
QDir myDir( myInfo.dir() );
if ( ! myDir.exists() )
{
QgsDebugMsg( QString( "Error, directory %1 non-existent (theFilename = %2)" ).arg( myDir.absolutePath() ).arg( theFilename ) );
return;
return false;
}

// prepare the pixmap
QPixmap myPixmap( 600, 600 );
QRect myQRect( 5, 5, 590, 590 ); // leave a 5px border on all sides
QPixmap myPixmap( width, height );
QRect myQRect( 5, 5, width - 10, height - 10 ); // leave a 5px border on all sides
myPixmap.fill( Qt::white ); // Qt::transparent ?

#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
@@ -566,10 +568,15 @@ void QgsRasterHistogramWidget::histoSaveAsImage( const QString& theFilename )
#endif

// save pixmap to file
myPixmap.save( theFilename );
myPixmap.save( theFilename, 0, quality );

#if defined(QWT_VERSION) && QWT_VERSION<0x060000
#endif
// should do more error checking
return true;
}

void QgsRasterHistogramWidget::setSelectedBand( int theBandNo )
{
cboHistoBand->setCurrentIndex( theBandNo - 1 );
}

void QgsRasterHistogramWidget::on_cboHistoBand_currentIndexChanged( int index )
@@ -610,16 +617,21 @@ void QgsRasterHistogramWidget::histoActionTriggered( QAction* action )
{
if ( ! action )
return;
histoAction( action->data().toString(), action->isChecked() );
}

// this approach is a bit of a hack, but this way we don't have to define slots for each action
QString actionName = action->data().toString();
void QgsRasterHistogramWidget::histoAction( const QString actionName, bool actionFlag )
{
if ( actionName == "" )
return;

// this approach is a bit of a hack, but this way we don't have to define slots for each action
QgsDebugMsg( QString( "band = %1 action = %2" ).arg( cboHistoBand->currentIndex() + 1 ).arg( actionName ) );

// checkeable actions
if ( actionName == "Show markers" )
{
mHistoShowMarkers = action->isChecked();
mHistoShowMarkers = actionFlag;
updateHistoMarkers();
return;
}
@@ -643,7 +655,7 @@ void QgsRasterHistogramWidget::histoActionTriggered( QAction* action )
}
else if ( actionName == "Load apply all" )
{
mHistoLoadApplyAll = action->isChecked();
mHistoLoadApplyAll = actionFlag;
return;
}
// Load actions
@@ -43,7 +43,7 @@ class QgsRasterHistogramWidget : public QWidget, private Ui::QgsRasterHistogramW
~QgsRasterHistogramWidget();

/** Save the histogram as an image to disk */
void histoSaveAsImage( const QString& theFilename );
bool histoSaveAsImage( const QString& theFilename, int width = 600, int height = 600, int quality = -1 );

/** Set the renderer widget (or just its name if there is no widget) */
void setRendererWidget( const QString& name, QgsRasterRendererWidget* rendererWidget = NULL );
@@ -54,6 +54,12 @@ class QgsRasterHistogramWidget : public QWidget, private Ui::QgsRasterHistogramW
/** \brief Compute the histogram on demand. */
bool computeHistogram( bool forceComputeFlag );

/** Apply a histoActionTriggered() event. */
void histoAction( const QString actionName, bool actionFlag = true );

/** Apply a histoActionTriggered() event. */
void setSelectedBand( int index );

public slots:
/** \brief slot executed when user wishes to refresh raster histogramwidget */
void refreshHistogram();
@@ -1498,7 +1498,10 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & the
double dfHalfBucket = 0;
eErr = GDALGetRasterStatistics( myGdalBand, TRUE, TRUE, &myMinVal, &myMaxVal, NULL, NULL );
if ( eErr != CE_None )
{
delete [] myHistogramArray;
return;
}
dfHalfBucket = ( myMaxVal - myMinVal ) / ( 2 * theBinCount );
myMinVal -= dfHalfBucket;
myMaxVal += dfHalfBucket;
@@ -1509,7 +1512,10 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & the
theIgnoreOutOfRangeFlag, theHistogramEstimatedFlag, progressCallback,
&myProg ); //this is the arg for our custom gdal progress callback
if ( myError != CE_None )
{
delete [] myHistogramArray;
return;
}

#endif

@@ -1526,6 +1532,8 @@ void QgsGdalProvider::populateHistogram( int theBandNo, QgsRasterBandStats & the
// QgsDebugMsg( "Added " + QString::number( myHistogramArray[myBin] ) + " to histogram vector" );
}
}
delete [] myHistogramArray;


}
QgsDebugMsg( ">>>>> Histogram vector now contains " + QString::number( theBandStats.histogramVector->size() ) +
@@ -15,7 +15,6 @@

#include "qgsrenderchecker.h"

#include <QDir>
#include <QColor>
#include <QPainter>
#include <QImage>
@@ -33,16 +32,17 @@ QgsRenderChecker::QgsRenderChecker( ) :
mMatchTarget( 0 ),
mElapsedTime( 0 ),
mElapsedTimeTarget( 0 ),
mpMapRenderer( NULL )
mpMapRenderer( NULL ),
mControlPathPrefix( "" )
{

}

QString QgsRenderChecker::controlImagePath() const
{
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
QString myControlImageDir = myDataDir + QDir::separator() + "control_images"
+ QDir::separator() ;
QString myControlImageDir = myDataDir + QDir::separator() + "control_images" +
QDir::separator() + mControlPathPrefix;
return myControlImageDir;
}

@@ -167,7 +167,8 @@ bool QgsRenderChecker::runTest( QString theTestName,


bool QgsRenderChecker::compareImages( QString theTestName,
unsigned int theMismatchCount )
unsigned int theMismatchCount,
QString theRenderedImageFile )
{
if ( mExpectedImageFile.isEmpty() )
{
@@ -178,6 +179,10 @@ bool QgsRenderChecker::compareImages( QString theTestName,
"Image File not set.</td></tr></table>\n";
return false;
}
if ( ! theRenderedImageFile.isEmpty() )
{
mRenderedImageFile = theRenderedImageFile;
}
if ( mRenderedImageFile.isEmpty() )
{
qDebug( "QgsRenderChecker::runTest failed - Rendered Image File not set." );
@@ -327,7 +332,7 @@ bool QgsRenderChecker::compareImages( QString theTestName,
"\" type=\"text/text\">" + myMessage +
" If you feel the difference image should be considered an anomaly "
"you can do something like this\n"
"cp " + myDiffImageFile + "../tests/testdata/control_images/" + theTestName +
"cp " + myDiffImageFile + " ../tests/testdata/control_images/" + theTestName +
"/<imagename>.png"
"</DartMeasurement>";
qDebug() << myMeasureMessage;
@@ -16,6 +16,7 @@
#ifndef QGSRENDERCHECKER_H
#define QGSRENDERCHECKER_H

#include <QDir>
#include <QString>
#include <qgsmaprenderer.h>
class QImage;
@@ -52,6 +53,10 @@ class QgsRenderChecker
* controlImagePath + '/' + mControlName + '/' + mControlName + '.png'
*/
void setControlName( const QString theName );
/** Prefix where the control images are kept.
* This will be appended to controlImagePath
*/
void setControlPathPrefix( const QString theName ) { mControlPathPrefix = theName + QDir::separator(); }
/** Get an md5 hash that uniquely identifies an image */
QString imageToHash( QString theImageFile );

@@ -79,7 +84,7 @@ class QgsRenderChecker
* for that by providing a tolerance.
* @note: make sure to call setExpectedImage and setRenderedImage first.
*/
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0 );
bool compareImages( QString theTestName, unsigned int theMismatchCount = 0, QString theRenderedImageFile = "" );
/** Get a list of all teh anomalies. An anomaly is a rendered difference
* file where there is some red pixel content (indicating a render check
* mismatch), but where the output was still acceptible. If the render
@@ -100,6 +105,7 @@ class QgsRenderChecker
int mElapsedTime;
int mElapsedTimeTarget;
QgsMapRenderer * mpMapRenderer;
QString mControlPathPrefix;

}; // class QgsRenderChecker

@@ -11,13 +11,15 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../core #for render checker class
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui/symbology-ng
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui/raster
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/symbology-ng
${QT_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
${PROJ_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${QWT_INCLUDE_DIR}
)

#############################################################
@@ -37,6 +39,10 @@ IF (WIN32)
SET(PLATFORM_LIBRARIES wsock32)
ENDIF (WIN32)

IF(WIN32)
ADD_DEFINITIONS(-DQWT_DLL)
ENDIF(WIN32)

# Since the tests are not actually installed, but rather
# run directly from the build/src/tests dir we need to
# ensure the omg libs can be found.
@@ -93,6 +99,7 @@ MACRO (ADD_QGIS_TEST testname testsrc)
${PROJ_LIBRARY}
${GEOS_LIBRARY}
${GDAL_LIBRARY}
${QWT_LIBRARY}
qgis_core
qgis_gui)
ADD_TEST(qgis_${testname} ${CMAKE_CURRENT_BINARY_DIR}/../../../output/bin/qgis_${testname})
@@ -110,4 +117,5 @@ ADD_QGIS_TEST(zoomtest testqgsmaptoolzoom.cpp)
#QT4_WRAP_CPP(rendererv2gui_MOC_SRCS ${rendererv2gui_HDRS})
#ADD_EXECUTABLE(qgis_rendererv2gui ${rendererv2gui_SRCS} ${rendererv2gui_MOC_SRCS})

ADD_QGIS_TEST(histogramtest testqgsrasterhistogram.cpp)

0 comments on commit d1b7e8b

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