Skip to content
Permalink
Browse files

cumulative cut tools, raster stretching moved from qgisapp to raster …

…layer, unfortunately one control image has also be changed because stretching changed from GDALComputeRasterMinMax which gives for tests/testdata/landsat.tif 3. band min/max 57/157 to GDALComputeRasterStatistics which gives 51/172
  • Loading branch information
blazek committed Jul 29, 2012
1 parent ad9cb9d commit 80c251d2a92dcc87ca3056e2e05251fad401bf6a
@@ -79,6 +79,7 @@
<file>themes/default/mActionFormAnnotation.png</file>
<file>themes/default/mActionFreezeLabels.png</file>
<file>themes/default/mActionFromSelectedFeature.png</file>
<file>themes/default/mActionFullCumulativeCutStretch.png</file>
<file>themes/default/mActionFullHistogramStretch.png</file>
<file>themes/default/mActionGroupItems.png</file>
<file>themes/default/mActionHelpAbout.png</file>
@@ -91,6 +92,7 @@
<file>themes/default/mActionInvertSelection.png</file>
<file>themes/default/mActionLabeling.png</file>
<file>themes/default/mActionLabel.png</file>
<file>themes/default/mActionLocalCumulativeCutStretch.png</file>
<file>themes/default/mActionLocalHistogramStretch.png</file>
<file>themes/default/mActionLowerItems.png</file>
<file>themes/default/mActionMapTips.png</file>
Binary file not shown.
Binary file not shown.
@@ -963,6 +963,8 @@ void QgisApp::createActions()
// Raster toolbar items
connect( mActionLocalHistogramStretch, SIGNAL( triggered() ), this, SLOT( localHistogramStretch() ) );
connect( mActionFullHistogramStretch, SIGNAL( triggered() ), this, SLOT( fullHistogramStretch() ) );
connect( mActionLocalCumulativeCutStretch, SIGNAL( triggered() ), this, SLOT( localCumulativeCutStretch() ) );
connect( mActionFullCumulativeCutStretch, SIGNAL( triggered() ), this, SLOT( fullCumulativeCutStretch() ) );

// Help Menu Items

@@ -5461,142 +5463,53 @@ void QgisApp::options()

void QgisApp::fullHistogramStretch()
{
histogramStretch( false );
histogramStretch( false, QgsRasterLayer::ContrastEnhancementMinMax );
}

void QgisApp::histogramStretch( bool visibleAreaOnly )
void QgisApp::localHistogramStretch()
{
QgsMapLayer * layer = mMapLegend->currentLayer();
histogramStretch( true, QgsRasterLayer::ContrastEnhancementMinMax );
}

if ( !layer )
void QgisApp::fullCumulativeCutStretch()
{
histogramStretch( false, QgsRasterLayer::ContrastEnhancementCumulativeCut );
}

void QgisApp::localCumulativeCutStretch()
{
histogramStretch( true, QgsRasterLayer::ContrastEnhancementCumulativeCut );
}

void QgisApp::histogramStretch( bool visibleAreaOnly, QgsRasterLayer::ContrastEnhancementLimits theLimits )
{
QgsMapLayer * myLayer = mMapLegend->currentLayer();

if ( !myLayer )
{
QMessageBox::information( this,
tr( "No Layer Selected" ),
tr( "To perform a full histogram stretch, you need to have a raster layer selected." ) );
return;
}

QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
if ( !rlayer )
QgsRasterLayer* myRasterLayer = qobject_cast<QgsRasterLayer *>( myLayer );
if ( !myRasterLayer )
{
QMessageBox::information( this,
tr( "No Raster Layer Selected" ),
tr( "To perform a full histogram stretch, you need to have a raster layer selected." ) );
return;
}

QgsRasterDataProvider* provider = rlayer->dataProvider();
if ( !provider )
{
return;
}

//get renderer
QgsRasterRenderer* renderer = rlayer->renderer();
if ( !renderer )
{
return;
}

//singleband gray <-> multiband color
if ( renderer->type() == "singlebandgray" )
{
QgsSingleBandGrayRenderer* grayRenderer = static_cast<QgsSingleBandGrayRenderer*>( renderer );
if ( !grayRenderer )
{
return;
}

//create new contrast enhancements
int grayBand = grayRenderer->grayBand();
if ( grayBand == -1 )
{
return;
}

QgsContrastEnhancement* e = rasterContrastEnhancement( rlayer, grayBand, visibleAreaOnly );
if ( !e )
{
return;
}
grayRenderer->setContrastEnhancement( e );
}
else if ( renderer->type() == "multibandcolor" )
{
QgsMultiBandColorRenderer* colorRenderer = static_cast<QgsMultiBandColorRenderer*>( renderer );
if ( !colorRenderer )
{
return;
}
QgsRectangle myRectangle;
if ( visibleAreaOnly ) myRectangle = mMapCanvas->mapRenderer()->outputExtentToLayerExtent( myRasterLayer, mMapCanvas->extent() );

QgsContrastEnhancement* redEnhancement = rasterContrastEnhancement( rlayer, colorRenderer->redBand(), visibleAreaOnly );
if ( redEnhancement )
{
colorRenderer->setRedContrastEnhancement( redEnhancement );
}
QgsContrastEnhancement* greenEnhancement = rasterContrastEnhancement( rlayer, colorRenderer->greenBand(), visibleAreaOnly );
if ( greenEnhancement )
{
colorRenderer->setGreenContrastEnhancement( greenEnhancement );
}
QgsContrastEnhancement* blueEnhancement = rasterContrastEnhancement( rlayer, colorRenderer->blueBand(), visibleAreaOnly );
if ( blueEnhancement )
{
colorRenderer->setBlueContrastEnhancement( blueEnhancement );
}
}
else
{
return;
}
myRasterLayer->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum, theLimits, myRectangle );

mMapCanvas->refresh();
}

QgsContrastEnhancement* QgisApp::rasterContrastEnhancement( QgsRasterLayer* rlayer, int band,
bool visibleAreaOnly ) const
{
if ( !rlayer || band == -1 )
{
return 0;
}

QgsRasterDataProvider* provider = rlayer->dataProvider();
if ( !provider )
{
return 0;
}

QgsContrastEnhancement* e = new QgsContrastEnhancement(( QgsContrastEnhancement::QgsRasterDataType )(
provider->dataType( band ) ) );
double minValue = 0;
double maxValue = 0;

if ( visibleAreaOnly )
{
double minMax[2];
rlayer->computeMinimumMaximumFromLastExtent( band, minMax );
minValue = minMax[0];
maxValue = minMax[1];
}
else
{
QgsRasterBandStats rasterBandStats = rlayer->dataProvider()->bandStatistics( band );
minValue = rasterBandStats.minimumValue;
maxValue = rasterBandStats.maximumValue;
}

e->setMinimumValue( minValue );
e->setMaximumValue( maxValue );
e->setContrastEnhancementAlgorithm( QgsContrastEnhancement::StretchToMinimumMaximum );
return e;
}

void QgisApp::localHistogramStretch()
{
histogramStretch( true );
}

void QgisApp::helpContents()
{
openURL( "index.html" );
@@ -55,7 +55,6 @@ class QgsPalLabeling;
class QgsPoint;
class QgsProviderRegistry;
class QgsPythonUtils;
class QgsRasterLayer;
class QgsRectangle;
class QgsUndoWidget;
class QgsVectorLayer;
@@ -87,6 +86,7 @@ class QgsTileScaleWidget;
#include "qgsconfig.h"
#include "qgsfeature.h"
#include "qgspoint.h"
#include "qgsrasterlayer.h"
#include "qgssnappingdialog.h"

#include "ui_qgisapp.h"
@@ -548,6 +548,10 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
* Valid for non wms raster layers only.
* @note Added in QGIS 1.7 */
void fullHistogramStretch();
/** Perform a local cumulative cut stretch */
void localCumulativeCutStretch();
/** Perform a full extent cumulative cut stretch */
void fullCumulativeCutStretch();
//! plugin manager
void showPluginManager();
//! load python support if possible
@@ -992,10 +996,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void createDecorations();

/**Do histogram stretch for singleband gray / multiband color rasters*/
void histogramStretch( bool visibleAreaOnly = false );
/**Create raster enhancement object for a raster band*/
QgsContrastEnhancement* rasterContrastEnhancement( QgsRasterLayer* rlayer, int band,
bool visibleAreaOnly = false ) const;
void histogramStretch( bool visibleAreaOnly = false, QgsRasterLayer::ContrastEnhancementLimits theLimits = QgsRasterLayer::ContrastEnhancementMinMax );

// actions for menus and toolbars -----------------

@@ -435,7 +435,15 @@ void QgsRasterDataProvider::initStatistics( QgsRasterBandStats &theStatistics,
theStatistics.bandNumber = theBandNo;
theStatistics.statsGathered = theStats;

QgsRectangle myExtent = theExtent.isEmpty() ? extent() : theExtent;
QgsRectangle myExtent;
if ( theExtent.isEmpty() )
{
myExtent = extent();
}
else
{
myExtent = extent().intersect( &theExtent );
}
theStatistics.extent = myExtent;

if ( theSampleSize > 0 )
@@ -674,7 +682,15 @@ void QgsRasterDataProvider::initHistogram( QgsRasterHistogram &theHistogram,
}
}

QgsRectangle myExtent = theExtent.isEmpty() ? extent() : theExtent;
QgsRectangle myExtent;
if ( theExtent.isEmpty() )
{
myExtent = extent();
}
else
{
myExtent = extent().intersect( &theExtent );
}
theHistogram.extent = myExtent;

if ( theSampleSize > 0 )

0 comments on commit 80c251d

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