Skip to content

Commit

Permalink
[FEATURE] Added histogram stretch to full dataset icon to raster toolbar
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15432 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Mar 11, 2011
1 parent 2197b50 commit c1df06c
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 4 deletions.
5 changes: 3 additions & 2 deletions images/images.qrc
@@ -1,5 +1,5 @@
<RCC>
<qresource prefix="/images" >
<qresource prefix="/images">
<file>icons/qgis-icon-16x16.png</file>
<file>icons/qgis-icon-60x60.png</file>
<file>north_arrows/gpsarrow2.svg</file>
Expand Down Expand Up @@ -74,6 +74,7 @@
<file>themes/default/mActionFolder.png</file>
<file>themes/default/mActionFormAnnotation.png</file>
<file>themes/default/mActionFromSelectedFeature.png</file>
<file>themes/default/mActionFullHistogramStretch.png</file>
<file>themes/default/mActionGroupItems.png</file>
<file>themes/default/mActionHelpAbout.png</file>
<file>themes/default/mActionHelpAPI.png</file>
Expand Down Expand Up @@ -402,7 +403,7 @@
<file>themes/newgis/mIconPolygonLayer.png</file>
<file>themes/newgis/mIconTableLayer.png</file>
</qresource>
<qresource prefix="/images/tips" >
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
</qresource>
</RCC>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -839,6 +839,7 @@ void QgisApp::createActions()

// Raster toolbar items
connect( mActionLocalHistogramStretch, SIGNAL( triggered() ), this, SLOT( localHistogramStretch() ) );
connect( mActionFullHistogramStretch, SIGNAL( triggered() ), this, SLOT( fullHistogramStretch() ) );

// Help Menu Items

Expand Down Expand Up @@ -1354,6 +1355,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionConfigureShortcuts->setIcon( getThemeIcon( "/mActionOptions.png" ) );
mActionHelpContents->setIcon( getThemeIcon( "/mActionHelpContents.png" ) );
mActionLocalHistogramStretch->setIcon( getThemeIcon( "/mActionLocalHistogramStretch.png" ) );
mActionFullHistogramStretch->setIcon( getThemeIcon( "/mActionFullHistogramStretch.png" ) );
mActionQgisHomePage->setIcon( getThemeIcon( "/mActionQgisHomePage.png" ) );
mActionAbout->setIcon( getThemeIcon( "/mActionHelpAbout.png" ) );
mActionSponsors->setIcon( getThemeIcon( "/mActionHelpSponsors.png" ) );
Expand Down Expand Up @@ -4838,6 +4840,49 @@ void QgisApp::options()
delete optionsDialog;
}

void QgisApp::fullHistogramStretch()
{
QgsMapLayer * layer = mMapLegend->currentLayer();

if ( !layer )
{
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 )
{
QMessageBox::information( this,
tr( "No Raster Layer Selected" ),
tr( "To perform a full histogram stretch, you need to have a raster layer selected." ) );
return;
}
if ( rlayer->drawingStyle() == QgsRasterLayer::SingleBandGray ||
rlayer->drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray ||
rlayer->drawingStyle() == QgsRasterLayer::MultiBandColor
)
{
rlayer->setContrastEnhancementAlgorithm( "StretchToMinimumMaximum" );
rlayer->setMinimumMaximumUsingDataset();
rlayer->setCacheImage( NULL );
//refreshLayerSymbology( rlayer->getLayerID() );
mMapCanvas->refresh();
return;
}
else
{
QMessageBox::information( this,
tr( "No Valid Raster Layer Selected" ),
tr( "To perform a local histogram stretch, you need to have a grayscale "
"or multiband (multiband single layer, singleband grayscale or multiband color) "
" raster layer selected." ) );
return;
}
}

void QgisApp::localHistogramStretch()
{
QgsMapLayer * layer = mMapLegend->currentLayer();
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -495,6 +495,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
void zoomActualSize();
//! perform a local histogram stretch on the active raster layer (stretch based on pixel values in view extent)
void localHistogramStretch();
//! perform a full histogram stretch on the active raster layer (stretch based on pixels values in full dataset)
void fullHistogramStretch();
//! plugin manager
void showPluginManager();
//! load python support if possible
Expand Down
36 changes: 36 additions & 0 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -2730,6 +2730,42 @@ void QgsRasterLayer::setMinimumMaximumUsingLastExtent()
}
}

void QgsRasterLayer::setMinimumMaximumUsingDataset()
{
double myMinMax[2];
if ( rasterType() == QgsRasterLayer::GrayOrUndefined || drawingStyle() == QgsRasterLayer::SingleBandGray || drawingStyle() == QgsRasterLayer::MultiBandSingleBandGray )
{
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mGrayBandName ) );
float myMin = myRasterBandStats.minimumValue;
float myMax = myRasterBandStats.maximumValue;
setMinimumValue( grayBandName(), myMin );
setMaximumValue( grayBandName(), myMax );
setUserDefinedGrayMinimumMaximum( false );
}
else if ( rasterType() == QgsRasterLayer::Multiband )
{
QgsRasterBandStats myRasterBandStats = bandStatistics( bandNumber( mRedBandName ) );
float myMin = myRasterBandStats.minimumValue;
float myMax = myRasterBandStats.maximumValue;
setMinimumValue( redBandName(), myMin );
setMaximumValue( redBandName(), myMax );

myRasterBandStats = bandStatistics( bandNumber( mGreenBandName ) );
myMin = myRasterBandStats.minimumValue;
myMax = myRasterBandStats.maximumValue;
setMinimumValue( greenBandName(), myMin );
setMaximumValue( greenBandName(), myMax );

myRasterBandStats = bandStatistics( bandNumber( mGreenBandName ) );
myMin = myRasterBandStats.minimumValue;
myMax = myRasterBandStats.maximumValue;
setMinimumValue( greenBandName(), myMin );
setMaximumValue( greenBandName(), myMax );

setUserDefinedRGBMinimumMaximum( false );
}
}

void QgsRasterLayer::setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag )
{
QgsDebugMsg( "setMinimumValue theValue = " + QString::number( theValue ) );
Expand Down
8 changes: 7 additions & 1 deletion src/core/raster/qgsrasterlayer.h
Expand Up @@ -596,9 +596,15 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue( QString theBand, double theValue, bool theGenerateLookupTableFlag = true );

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

/** \brief Sets the minimum and maximum values for the band(s) currently
* being displayed using the only pixel values from the dataset min/max */
void setMinimumMaximumUsingDataset();

/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue( unsigned int theBand, double theValue, bool theGenerateLookupTableFlag = true );

Expand Down
15 changes: 14 additions & 1 deletion src/ui/qgisapp.ui
Expand Up @@ -17,7 +17,7 @@
<x>0</x>
<y>0</y>
<width>717</width>
<height>23</height>
<height>24</height>
</rect>
</property>
<widget class="QMenu" name="mEditMenu">
Expand Down Expand Up @@ -357,6 +357,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionFullHistogramStretch"/>
<addaction name="mActionLocalHistogramStretch"/>
</widget>
<widget class="QToolBar" name="mLabelToolBar">
Expand Down Expand Up @@ -1457,6 +1458,18 @@
<string>Python Console</string>
</property>
</action>
<action name="mActionFullHistogramStretch">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFullHistogramStretch.png</normaloff>:/images/themes/default/mActionFullHistogramStretch.png</iconset>
</property>
<property name="text">
<string>Full histogram stretch</string>
</property>
<property name="toolTip">
<string>Stretch histogram to full dataset</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>
Expand Down

0 comments on commit c1df06c

Please sign in to comment.