Skip to content
Permalink
Browse files

-Added ability to load min max values for enhancement based on curren…

…t portion of the raster being displayed.

-GUI update and string changes.
-Closes enhancement ticket 2024
-Accomplished by caching the last QgsRasterViewPort, I see this as a bit of a work around rather than a real solution. The issue at hand is that the render context can only be provided by the map canvas so neither the layer itself nor an layer properties dialog has access to the render context.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12015 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts
ersts committed Nov 8, 2009
1 parent 99f0e1c commit 56540d63004fdb8f1b65bc217129c4ceedd9fe54
@@ -274,6 +274,12 @@ public:
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );

/** \brief Get a pointer to the contrast enhancement for the selected band */
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );

@@ -15,6 +15,8 @@
* *
***************************************************************************/

#include <QDebug>

#include "qgslogger.h"
#include "qgsapplication.h"
#include "qgisapp.h"
@@ -434,7 +436,7 @@ void QgsRasterLayerProperties::setMinimumMaximumEstimateWarning()

if ( myEstimatedValues )
{
lblMinMaxEstimateWarning->setText( tr( "Note: Minimum Maximum values are estimates or user defined" ) );
lblMinMaxEstimateWarning->setText( tr( "Note: Minimum Maximum values are estimates, user defined, or calculated from the current extent" ) );
}
else
{
@@ -1934,7 +1936,6 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
QgsDebugMsg( QString( "max %1" ).arg( myYAxisMax ) );
QgsDebugMsg( QString( "min %1" ).arg( myYAxisMin ) );


//create the image onto which graph and axes will be drawn
int myImageWidth = pixHistogram->width() - 2;
int myImageHeight = pixHistogram->height() - 2; //Take two pixels off to account for the boarder around the QLabel
@@ -2086,6 +2087,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
QgsDebugMsg( QString( "Band %1, bin %2, Hist Value : %3, Scaled Value : %4" ).arg( myIteratorInt ).arg( myBin ).arg( myBinValue ).arg( myY ) );
QgsDebugMsg( "myY = myGraphImageHeight - myY" );
QgsDebugMsg( QString( "myY = %1-%2" ).arg( myGraphImageHeight ).arg( myY ) );

if ( myGraphType == BAR_CHART )
{
//draw the bar
@@ -2136,6 +2138,7 @@ void QgsRasterLayerProperties::on_pbnHistRefresh_clicked()
myPolygon << QPointF( myX + myYGutterWidth, myY );
}
}

if ( myGraphType == LINE_CHART )
{
QLinearGradient myGradient;
@@ -2832,6 +2835,9 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
if ( mRasterLayerIsGdal && ( mRasterLayer->drawingStyle() == QgsRasterLayer::SingleBandGray || mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandSingleGandGray || mRasterLayer->drawingStyle() == QgsRasterLayer::MultiBandColor ) )
{
QgsRasterBandStats myRasterBandStats;
double myMinimumMaximum[2];
myMinimumMaximum[0] = 0;
myMinimumMaximum[1] = 0;
if ( rbtnThreeBand->isChecked() )
{
rbtnThreeBandMinMax->setChecked( true );
@@ -2849,10 +2855,22 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
leBlueMax->setText( QString::number( myRasterBandStats.maximumValue ) );
mRGBMinimumMaximumEstimated = false;
}
else if ( rbtnExtentMinMax->isChecked() )
{
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboRed->currentText() ), myMinimumMaximum );
leRedMin->setText( QString::number( myMinimumMaximum[0] ) );
leRedMax->setText( QString::number( myMinimumMaximum[1] ) );
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboGreen->currentText() ), myMinimumMaximum );
leGreenMin->setText( QString::number( myMinimumMaximum[0] ) );
leGreenMax->setText( QString::number( myMinimumMaximum[1] ) );
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboBlue->currentText() ), myMinimumMaximum );
leBlueMin->setText( QString::number( myMinimumMaximum[0] ) );
leBlueMax->setText( QString::number( myMinimumMaximum[1] ) );
mRGBMinimumMaximumEstimated = true;
}
else
{
rbtnEstimateMinMax->setChecked( true );
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates( mRasterLayer->bandNumber( cboRed->currentText() ), myMinimumMaximum );
leRedMin->setText( QString::number( myMinimumMaximum[0] ) );
leRedMax->setText( QString::number( myMinimumMaximum[1] ) );
@@ -2876,10 +2894,16 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
leGrayMax->setText( QString::number( myRasterBandStats.maximumValue ) );
mGrayMinimumMaximumEstimated = false;
}
else if ( rbtnExtentMinMax->isChecked() )
{
mRasterLayer->computeMinimumMaximumFromLastExtent( mRasterLayer->bandNumber( cboGray->currentText() ), myMinimumMaximum );
leGrayMin->setText( QString::number( myMinimumMaximum[0] ) );
leGrayMax->setText( QString::number( myMinimumMaximum[1] ) );
mGrayMinimumMaximumEstimated = true;
}
else
{
rbtnEstimateMinMax->setChecked( true );
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates( mRasterLayer->bandNumber( cboGray->currentText() ), myMinimumMaximum );
leGrayMin->setText( QString::number( myMinimumMaximum[0] ) );
leGrayMax->setText( QString::number( myMinimumMaximum[1] ) );
@@ -16,7 +16,6 @@ email : tim at linfiniti.com
***************************************************************************/
/* $Id$ */


#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
@@ -25,7 +24,6 @@ email : tim at linfiniti.com
#include "qgsrasterbandstats.h"
#include "qgsrasterlayer.h"
#include "qgsrasterpyramid.h"
#include "qgsrasterviewport.h"
#include "qgsrectangle.h"
#include "qgsrendercontext.h"
#include "qgscoordinatereferencesystem.h"
@@ -152,6 +150,20 @@ QgsRasterLayer::QgsRasterLayer(
}
}

//Initialize the last view port structure, should really be a class
mLastViewPort.rectXOffset = 0;
mLastViewPort.rectXOffsetFloat = 0.0;
mLastViewPort.rectYOffset = 0;
mLastViewPort.rectYOffsetFloat = 0.0;
mLastViewPort.clippedXMin = 0.0;
mLastViewPort.clippedXMax = 0.0;
mLastViewPort.clippedYMin = 0.0;
mLastViewPort.clippedYMax = 0.0;
mLastViewPort.clippedWidth = 0;
mLastViewPort.clippedHeight = 0;
mLastViewPort.drawableAreaXDim = 0;
mLastViewPort.drawableAreaYDim = 0;

} // QgsRasterLayer ctor

/**
@@ -1266,6 +1278,52 @@ void QgsRasterLayer::computeMinimumMaximumEstimates( QString theBand, double* th
computeMinimumMaximumEstimates( bandNumber( theBand ), theMinMax );
}

/**
* @param theBand The band (number) for which to calculate the min max values
* @param theMinMax Pointer to a double[2] which hold the estimated min max
*/
void QgsRasterLayer::computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax )
{
if ( 0 == theMinMax ) { return; }

GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBand );
GDALDataType myDataType = GDALGetRasterDataType( myGdalBand );
void* myGdalScanData = readData( myGdalBand, &mLastViewPort );

/* Check for out of memory error */
if ( myGdalScanData == NULL )
{
return;
}

if ( 0 < theBand && theBand <= ( int ) bandCount() )
{
float myMin = std::numeric_limits<float>::max();
float myMax = -1 * std::numeric_limits<float>::max();
float myValue = 0.0;
for ( int myRow = 0; myRow < mLastViewPort.drawableAreaYDim; ++myRow )
{
for ( int myColumn = 0; myColumn < mLastViewPort.drawableAreaXDim; ++myColumn )
{
myValue = readValue( myGdalScanData, myDataType, myRow * mLastViewPort.drawableAreaXDim + myColumn );
myMin = qMin( myMin, myValue );
myMax = qMax( myMax, myValue );
}
}
theMinMax[0] = myMin;
theMinMax[1] = myMax;
}
}

/**
* @param theBand The band (name) for which to calculate the min max values
* @param theMinMax Pointer to a double[2] which hold the estimated min max
*/
void QgsRasterLayer::computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax )
{
computeMinimumMaximumFromLastExtent( bandNumber( theBand ), theMinMax );
}

/**
* @param theBand The band (number) for which to get the contrast enhancement for
* @return Pointer to the contrast enhancement or 0 on failure
@@ -1498,6 +1556,7 @@ bool QgsRasterLayer::draw( QgsRenderContext& rendererContext )

// /\/\/\ - added to handle zoomed-in rasters

mLastViewPort = *myRasterViewPort;

// Provider mode: See if a provider key is specified, and if so use the provider instead

@@ -35,6 +35,7 @@
#include "qgis.h"
#include "qgspoint.h"
#include "qgsmaplayer.h"
#include "qgsrasterviewport.h"
#include "qgscontrastenhancement.h"
#include "qgsrastertransparency.h"
#include "qgsrastershader.h"
@@ -59,7 +60,6 @@ class QgsRectangle;
class QgsRasterBandStats;
class QgsRasterPyramid;
class QgsRasterLayerProperties;
struct QgsRasterViewPort;
class QImage;
class QPixmap;
class QSlider;
@@ -440,6 +440,12 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates( QString theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
void computeMinimumMaximumFromLastExtent( int theBand, double* theMinMax );

/** \brief Compute the actual minimum maximum pixel values based on the current (last) display extent */
void computeMinimumMaximumFromLastExtent( QString theBand, double* theMinMax );

/** \brief Get a pointer to the contrast enhancement for the selected band */
QgsContrastEnhancement* contrastEnhancement( unsigned int theBand );

@@ -828,6 +834,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** [ data provider interface ] Timestamp, the last modified time of the data source when the layer was created */
QDateTime mLastModified;

QgsRasterViewPort mLastViewPort;

/** [ data provider interface ] pointer for loading the provider library */
QLibrary* mLib;

0 comments on commit 56540d6

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