Skip to content

Commit e49a148

Browse files
author
timlinux
committed
[FEATURE] Added histogram stretch to full dataset icon to raster toolbar
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15432 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e05c419 commit e49a148

File tree

7 files changed

+107
-4
lines changed

7 files changed

+107
-4
lines changed

images/images.qrc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<RCC>
2-
<qresource prefix="/images" >
2+
<qresource prefix="/images">
33
<file>icons/qgis-icon-16x16.png</file>
44
<file>icons/qgis-icon-60x60.png</file>
55
<file>north_arrows/gpsarrow2.svg</file>
@@ -74,6 +74,7 @@
7474
<file>themes/default/mActionFolder.png</file>
7575
<file>themes/default/mActionFormAnnotation.png</file>
7676
<file>themes/default/mActionFromSelectedFeature.png</file>
77+
<file>themes/default/mActionFullHistogramStretch.png</file>
7778
<file>themes/default/mActionGroupItems.png</file>
7879
<file>themes/default/mActionHelpAbout.png</file>
7980
<file>themes/default/mActionHelpAPI.png</file>
@@ -402,7 +403,7 @@
402403
<file>themes/newgis/mIconPolygonLayer.png</file>
403404
<file>themes/newgis/mIconTableLayer.png</file>
404405
</qresource>
405-
<qresource prefix="/images/tips" >
406+
<qresource prefix="/images/tips">
406407
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
407408
</qresource>
408409
</RCC>
Loading

src/app/qgisapp.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ void QgisApp::createActions()
839839

840840
// Raster toolbar items
841841
connect( mActionLocalHistogramStretch, SIGNAL( triggered() ), this, SLOT( localHistogramStretch() ) );
842+
connect( mActionFullHistogramStretch, SIGNAL( triggered() ), this, SLOT( fullHistogramStretch() ) );
842843

843844
// Help Menu Items
844845

@@ -1354,6 +1355,7 @@ void QgisApp::setTheme( QString theThemeName )
13541355
mActionConfigureShortcuts->setIcon( getThemeIcon( "/mActionOptions.png" ) );
13551356
mActionHelpContents->setIcon( getThemeIcon( "/mActionHelpContents.png" ) );
13561357
mActionLocalHistogramStretch->setIcon( getThemeIcon( "/mActionLocalHistogramStretch.png" ) );
1358+
mActionFullHistogramStretch->setIcon( getThemeIcon( "/mActionFullHistogramStretch.png" ) );
13571359
mActionQgisHomePage->setIcon( getThemeIcon( "/mActionQgisHomePage.png" ) );
13581360
mActionAbout->setIcon( getThemeIcon( "/mActionHelpAbout.png" ) );
13591361
mActionSponsors->setIcon( getThemeIcon( "/mActionHelpSponsors.png" ) );
@@ -4838,6 +4840,49 @@ void QgisApp::options()
48384840
delete optionsDialog;
48394841
}
48404842

4843+
void QgisApp::fullHistogramStretch()
4844+
{
4845+
QgsMapLayer * layer = mMapLegend->currentLayer();
4846+
4847+
if ( !layer )
4848+
{
4849+
QMessageBox::information( this,
4850+
tr( "No Layer Selected" ),
4851+
tr( "To perform a full histogram stretch, you need to have a raster layer selected." ) );
4852+
return;
4853+
}
4854+
4855+
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
4856+
if ( !rlayer )
4857+
{
4858+
QMessageBox::information( this,
4859+
tr( "No Raster Layer Selected" ),
4860+
tr( "To perform a full histogram stretch, you need to have a raster layer selected." ) );
4861+
return;
4862+
}
4863+
if ( rlayer->drawingStyle() == QgsRasterLayer::SingleBandGray ||
4864+
rlayer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray ||
4865+
rlayer->drawingStyle() == QgsRasterLayer::MultiBandColor
4866+
)
4867+
{
4868+
rlayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
4869+
rlayer->setMinimumMaximumUsingDataset();
4870+
rlayer->setCacheImage( NULL );
4871+
//refreshLayerSymbology( rlayer->getLayerID() );
4872+
mMapCanvas->refresh();
4873+
return;
4874+
}
4875+
else
4876+
{
4877+
QMessageBox::information( this,
4878+
tr( "No Valid Raster Layer Selected" ),
4879+
tr( "To perform a local histogram stretch, you need to have a grayscale "
4880+
"or multiband (multiband single layer, singleband grayscale or multiband color) "
4881+
" raster layer selected." ) );
4882+
return;
4883+
}
4884+
}
4885+
48414886
void QgisApp::localHistogramStretch()
48424887
{
48434888
QgsMapLayer * layer = mMapLegend->currentLayer();

src/app/qgisapp.h

+2
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
495495
void zoomActualSize();
496496
//! perform a local histogram stretch on the active raster layer (stretch based on pixel values in view extent)
497497
void localHistogramStretch();
498+
//! perform a full histogram stretch on the active raster layer (stretch based on pixels values in full dataset)
499+
void fullHistogramStretch();
498500
//! plugin manager
499501
void showPluginManager();
500502
//! load python support if possible

src/core/raster/qgsrasterlayer.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -2730,6 +2730,42 @@ void QgsRasterLayer::setMinimumMaximumUsingLastExtent()
27302730
}
27312731
}
27322732

2733+
void QgsRasterLayer::setMinimumMaximumUsingDataset()
2734+
{
2735+
double myMinMax[2];
2736+
if ( rasterType() == QgsRasterLayer::GrayOrUndefined || drawingStyle() == QgsRasterLayer::SingleBandGray || drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray )
2737+
{
2738+
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mGrayBandName ) );
2739+
float myMin = myRasterBandStats.minimumValue;
2740+
float myMax = myRasterBandStats.maximumValue;
2741+
setMinimumValue( grayBandName(), myMin );
2742+
setMaximumValue( grayBandName(), myMax );
2743+
setUserDefinedGrayMinimumMaximum( false );
2744+
}
2745+
else if ( rasterType() == QgsRasterLayer::Multiband )
2746+
{
2747+
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mRedBandName ) );
2748+
float myMin = myRasterBandStats.minimumValue;
2749+
float myMax = myRasterBandStats.maximumValue;
2750+
setMinimumValue( redBandName(), myMin );
2751+
setMaximumValue( redBandName(), myMax );
2752+
2753+
myRasterBandStats = bandStatistics( bandNumber( mGreenBandName ) );
2754+
myMin = myRasterBandStats.minimumValue;
2755+
myMax = myRasterBandStats.maximumValue;
2756+
setMinimumValue( greenBandName(), myMin );
2757+
setMaximumValue( greenBandName(), myMax );
2758+
2759+
myRasterBandStats = bandStatistics( bandNumber( mGreenBandName ) );
2760+
myMin = myRasterBandStats.minimumValue;
2761+
myMax = myRasterBandStats.maximumValue;
2762+
setMinimumValue( greenBandName(), myMin );
2763+
setMaximumValue( greenBandName(), myMax );
2764+
2765+
setUserDefinedRGBMinimumMaximum( false );
2766+
}
2767+
}
2768+
27332769
void QgsRasterLayer::setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
27342770
{
27352771
QgsDebugMsg( "setMinimumValue theValue = " + QString::number( theValue ) );

src/core/raster/qgsrasterlayer.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -596,9 +596,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
596596
/** \brief Mutator for setting the maximum value for contrast enhancement */
597597
void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );
598598

599-
/** \brief Sets the minimum and maximum values for the band(s) currently being displayed using the only pixel values from the last/current extent */
599+
/** \brief Sets the minimum and maximum values for the band(s) currently
600+
* being displayed using the only pixel values from the last/current extent
601+
* */
600602
void setMinimumMaximumUsingLastExtent();
601603

604+
/** \brief Sets the minimum and maximum values for the band(s) currently
605+
* being displayed using the only pixel values from the dataset min/max */
606+
void setMinimumMaximumUsingDataset();
607+
602608
/** \brief Mutator for setting the minimum value for contrast enhancement */
603609
void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );
604610

src/ui/qgisapp.ui

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<x>0</x>
1818
<y>0</y>
1919
<width>717</width>
20-
<height>23</height>
20+
<height>24</height>
2121
</rect>
2222
</property>
2323
<widget class="QMenu" name="mEditMenu">
@@ -357,6 +357,7 @@
357357
<attribute name="toolBarBreak">
358358
<bool>true</bool>
359359
</attribute>
360+
<addaction name="mActionFullHistogramStretch"/>
360361
<addaction name="mActionLocalHistogramStretch"/>
361362
</widget>
362363
<widget class="QToolBar" name="mLabelToolBar">
@@ -1457,6 +1458,18 @@
14571458
<string>Python Console</string>
14581459
</property>
14591460
</action>
1461+
<action name="mActionFullHistogramStretch">
1462+
<property name="icon">
1463+
<iconset resource="../../images/images.qrc">
1464+
<normaloff>:/images/themes/default/mActionFullHistogramStretch.png</normaloff>:/images/themes/default/mActionFullHistogramStretch.png</iconset>
1465+
</property>
1466+
<property name="text">
1467+
<string>Full histogram stretch</string>
1468+
</property>
1469+
<property name="toolTip">
1470+
<string>Stretch histogram to full dataset</string>
1471+
</property>
1472+
</action>
14601473
</widget>
14611474
<resources>
14621475
<include location="../../images/images.qrc"/>

0 commit comments

Comments
 (0)