Skip to content
Permalink
Browse files

[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
  • Loading branch information
timlinux
timlinux committed Mar 11, 2011
1 parent e05c419 commit e49a1482c5a003c624bdeb78cad7079043a7c912
@@ -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>
@@ -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>
@@ -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>
Binary file not shown.
@@ -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

@@ -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" ) );
@@ -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();
@@ -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
@@ -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 ) );
@@ -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 );

@@ -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">
@@ -357,6 +357,7 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionFullHistogramStretch"/>
<addaction name="mActionLocalHistogramStretch"/>
</widget>
<widget class="QToolBar" name="mLabelToolBar">
@@ -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"/>

0 comments on commit e49a148

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