Skip to content

Commit

Permalink
-Fixed problem restoring min max values from project file
Browse files Browse the repository at this point in the history
-Closes ticket #945
-Added ability choose in the GUI to load estimated or actual min max values from the band
-Cleaned and reorganized raster properties gui a little
-Added a set default constrast enhancement option in gui that is persistent between sessions
-Closes ticket #1055 and #778

git-svn-id: http://svn.osgeo.org/qgis/trunk@8398 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
ersts committed May 6, 2008
1 parent 759fb39 commit ce7c48f
Show file tree
Hide file tree
Showing 6 changed files with 1,195 additions and 733 deletions.
6 changes: 6 additions & 0 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -260,6 +260,12 @@ public:

void setMaximumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true);

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(int theBand, double* theMinMax);

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax);

QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand);

//
Expand Down
129 changes: 111 additions & 18 deletions src/app/qgsrasterlayerproperties.cpp
Expand Up @@ -42,7 +42,7 @@
#include <QPolygonF>
#include <QColorDialog>
#include <QList>

#include <QSettings>

#include <iostream>

Expand Down Expand Up @@ -298,6 +298,7 @@ mRasterLayer( dynamic_cast<QgsRasterLayer*>(lyr) )
pbnDefaultValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionCopySelected.png")));
pbnImportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileOpen.png")));
pbnExportTransparentPixelValues->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));
pbtnMakeContrastEnhancementAlgorithmDefault->setIcon(QIcon(QPixmap(myThemePath + "/mActionFileSave.png")));

// Only do pyramids if dealing directly with GDAL.
if (mRasterLayerIsGdal)
Expand Down Expand Up @@ -613,11 +614,6 @@ void QgsRasterLayerProperties::sync()
cboxInvertColorMap->setChecked(false);
}

//set the transparency slider
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
//update the transparency percentage label
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());

//set the combos to the correct values
cboRed->setCurrentText(mRasterLayer->getRedBandName());
cboGreen->setCurrentText(mRasterLayer->getGreenBandName());
Expand Down Expand Up @@ -712,13 +708,45 @@ void QgsRasterLayerProperties::sync()
{
cboxContrastEnhancementAlgorithm->setCurrentText(tr("No Scaling"));
}

//Display the current default contrast enhancement algorithm
QSettings myQSettings;
QString myDefaultAlgorithm = myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString();
if(myDefaultAlgorithm == "NO_STRETCH")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
}
if(myDefaultAlgorithm == "STRETCH_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch To MinMax"));
}
else if(myDefaultAlgorithm == "STRETCH_AND_CLIP_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Stretch And Clip To MinMax"));
}
else if(myDefaultAlgorithm == "CLIP_TO_MINMAX")
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("Clip To MinMax"));
}
else
{
labelDefaultContrastEnhancementAlgorithm->setText(tr("No Scaling"));
}



#ifdef QGISDEBUG
QgsDebugMsg("QgsRasterLayerProperties::sync populate transparency tab");
#endif
/*
* Transparent Pixel Tab
*/

//set the transparency slider
sliderTransparency->setValue(255 - mRasterLayer->getTransparency());
//update the transparency percentage label
sliderTransparency_valueChanged(255 - mRasterLayer->getTransparency());

int myIndex = cboxTransparencyLayer->findText(mRasterLayer->getTransparentLayerName());
if(-1 != myIndex)
{
Expand Down Expand Up @@ -2697,22 +2725,87 @@ void QgsRasterLayerProperties::on_pbtnLoadMinMax_clicked()
if(rbtnThreeBand->isChecked())
{
rbtnThreeBandMinMax->setChecked(true);
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
leRedMin->setText(QString::number(myRasterBandStats.minVal));
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));

if(rbtnActualMinMax->isChecked())
{
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboRed->currentText()));
leRedMin->setText(QString::number(myRasterBandStats.minVal));
leRedMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGreen->currentText()));
leGreenMin->setText(QString::number(myRasterBandStats.minVal));
leGreenMax->setText(QString::number(myRasterBandStats.maxVal));
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboBlue->currentText()));
leBlueMin->setText(QString::number(myRasterBandStats.minVal));
leBlueMax->setText(QString::number(myRasterBandStats.maxVal));
}
else
{
rbtnEstimateMinMax->setChecked(true);
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboRed->currentText()), myMinimumMaximum);
leRedMin->setText(QString::number(myMinimumMaximum[0]));
leRedMax->setText(QString::number(myMinimumMaximum[1]));
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGreen->currentText()), myMinimumMaximum);
leGreenMin->setText(QString::number(myMinimumMaximum[0]));
leGreenMax->setText(QString::number(myMinimumMaximum[1]));
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboBlue->currentText()), myMinimumMaximum);
leBlueMin->setText(QString::number(myMinimumMaximum[0]));
leBlueMax->setText(QString::number(myMinimumMaximum[1]));
}

}
else
{
rbtnSingleBandMinMax->setChecked(true);
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
if(rbtnActualMinMax->isChecked())
{
myRasterBandStats = mRasterLayer->getRasterBandStats(mRasterLayer->getRasterBandNumber(cboGray->currentText()));
leGrayMin->setText(QString::number(myRasterBandStats.minVal));
leGrayMax->setText(QString::number(myRasterBandStats.maxVal));
}
else
{
rbtnEstimateMinMax->setChecked(true);
double myMinimumMaximum[2];
mRasterLayer->computeMinimumMaximumEstimates(mRasterLayer->getRasterBandNumber(cboGray->currentText()), myMinimumMaximum);
leGrayMin->setText(QString::number(myMinimumMaximum[0]));
leGrayMax->setText(QString::number(myMinimumMaximum[1]));
}
}
}
}

void QgsRasterLayerProperties::on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked()
{
//Like some of the other functionality in the raster properties GUI this deviated a little from the
//best practice of GUI design as this pressing cancel will not undo setting the default
//contrast enhancement algorithm
if(cboxContrastEnhancementAlgorithm->currentText() != tr("User Defined"))
{
QSettings myQSettings;
if(cboxContrastEnhancementAlgorithm->currentText() == tr("No Stretch"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Stretch And Clip To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "STRETCH_AND_CLIP_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else if(cboxContrastEnhancementAlgorithm->currentText() == tr("Clip To MinMax"))
{
myQSettings.setValue("/Raster/defaultContrastEnhancementAlgorithm", "CLIP_TO_MINMAX");
labelDefaultContrastEnhancementAlgorithm->setText(cboxContrastEnhancementAlgorithm->currentText());
}
else
{
//do nothing
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/qgsrasterlayerproperties.h
Expand Up @@ -108,7 +108,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/**Callback for double clicks on the colormap entry widget*/
void handleColormapTreeWidgetDoubleClick(QTreeWidgetItem* item, int column);
/**This slot loads the minimum and maximum values from the raster band and updates the gui*/
void on_pbtnLoadMinMax_clicked();
void on_pbtnLoadMinMax_clicked();
/**This slot save the current contrast enhancement algorithm as the default algorithm */
void on_pbtnMakeContrastEnhancementAlgorithmDefault_clicked();


signals:
Expand Down
48 changes: 46 additions & 2 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -60,7 +60,7 @@ email : tim at linfiniti.com
#include <QPixmap>
#include <QRegExp>
#include <QSlider>

#include <QSettings>
// workaround for MSVC compiler which already has defined macro max
// that interferes with calling std::numeric_limits<int>::max
#ifdef _MSC_VER
Expand Down Expand Up @@ -592,7 +592,9 @@ bool QgsRasterLayer::readFile( QString const & fileName )
}

//defaults - Needs to be set after the Contrast list has been build
setContrastEnhancementAlgorithm(QgsContrastEnhancement::STRETCH_TO_MINMAX);
//Try to read the default contrast enhancement from the config file
QSettings myQSettings;
setContrastEnhancementAlgorithm(myQSettings.value("/Raster/defaultContrastEnhancementAlgorithm", "NO_STRETCH").toString());

//decide what type of layer this is...
//note that multiband images can have one or more 'undefindd' bands,
Expand Down Expand Up @@ -4320,6 +4322,16 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
myElement = snode.toElement();
setStdDevsToPlot(myElement.text().toDouble());

snode = mnl.namedItem("mUserDefinedRGBMinMaxFlag");
myElement = snode.toElement();
myQVariant = (QVariant) myElement.attribute("boolean");
setUserDefinedRGBMinMax(myQVariant.toBool());

snode = mnl.namedItem("mUserDefinedGrayMinMaxFlag");
myElement = snode.toElement();
myQVariant = (QVariant) myElement.attribute("boolean");
setUserDefinedGrayMinMax(myQVariant.toBool());

snode = mnl.namedItem("mContrastEnhancementAlgorithm");
myElement = snode.toElement();
setContrastEnhancementAlgorithm(myElement.text(), false);
Expand Down Expand Up @@ -4659,6 +4671,34 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )

rasterPropertiesElement.appendChild( mStandardDeviationsElement );

// <mUserDefinedRGBMinMaxFlag>
QDomElement userDefinedRGBMinMaxFlag = document.createElement( "mUserDefinedRGBMinMaxFlag" );

if ( getUserDefinedRGBMinMax() )
{
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "true" );
}
else
{
userDefinedRGBMinMaxFlag.setAttribute( "boolean", "false" );
}

rasterPropertiesElement.appendChild( userDefinedRGBMinMaxFlag );

// <mUserDefinedGrayMinMaxFlag>
QDomElement userDefinedGrayMinMaxFlag = document.createElement( "mUserDefinedGrayMinMaxFlag" );

if ( getUserDefinedGrayMinMax() )
{
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "true" );
}
else
{
userDefinedGrayMinMaxFlag.setAttribute( "boolean", "false" );
}

rasterPropertiesElement.appendChild( userDefinedGrayMinMaxFlag );

// <contrastEnhancementAlgorithm>
QDomElement contrastEnhancementAlgorithmElement = document.createElement( "mContrastEnhancementAlgorithm" );
QDomText contrastEnhancementAlgorithmText = document.createTextNode( getContrastEnhancementAlgorithmAsQString() );
Expand Down Expand Up @@ -5391,4 +5431,8 @@ void QgsRasterLayer::setContrastEnhancementAlgorithm(QString theAlgorithm, bool
{
setContrastEnhancementAlgorithm(QgsContrastEnhancement::USER_DEFINED, theGenerateLookupTableFlag);
}
else
{
setContrastEnhancementAlgorithm(QgsContrastEnhancement::NO_STRETCH, theGenerateLookupTableFlag);
}
}
24 changes: 24 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -463,6 +463,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

// Accessor and mutator for minimum maximum values
//TODO: Move these out of the header file...
/** \brief Accessor for minimum value user for contrast enhancement */
double getMinimumValue(unsigned int theBand)
{
if(0 < theBand && theBand <= getBandCount())
Expand All @@ -473,11 +474,13 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
return 0.0;
}

/** \brief Accessor for minimum value user for contrast enhancement */
double getMinimumValue(QString theBand)
{
return getMinimumValue(getRasterBandNumber(theBand));
}

/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(0 < theBand && theBand <= getBandCount())
Expand All @@ -486,6 +489,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
}
}

/** \brief Mutator for setting the minimum value for contrast enhancement */
void setMinimumValue(QString theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(theBand != tr("Not Set"))
Expand All @@ -495,6 +499,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer

}

/** \brief Accessor for maximum value user for contrast enhancement */
double getMaximumValue(unsigned int theBand)
{
if(0 < theBand && theBand <= getBandCount())
Expand All @@ -505,6 +510,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
return 0.0;
}

/** \brief Accessor for maximum value user for contrast enhancement */
double getMaximumValue(QString theBand)
{
if(theBand != tr("Not Set"))
Expand All @@ -515,6 +521,7 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
return 0.0;
}

/** \brief Mutator for setting the maximum value for contrast enhancement */
void setMaximumValue(unsigned int theBand, double theValue, bool theGenerateLookupTableFlag=true)
{
if(0 < theBand && theBand <= getBandCount())
Expand All @@ -523,6 +530,7 @@ 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)
{
if(theBand != tr("Not Set"))
Expand All @@ -531,6 +539,22 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
}
}

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(int theBand, double* theMinMax)
{
if(0 < theBand && theBand <= getBandCount())
{
GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBand);
GDALComputeRasterMinMax( myGdalBand, 1, theMinMax );
}
}

/** \brief Wrapper for GDALComputeRasterMinMax with the estimate option */
void computeMinimumMaximumEstimates(QString theBand, double* theMinMax)
{
computeMinimumMaximumEstimates(getRasterBandNumber(theBand), theMinMax);
}

QgsContrastEnhancement* getContrastEnhancement(unsigned int theBand)
{
return &mContrastEnhancementList[theBand - 1];
Expand Down

0 comments on commit ce7c48f

Please sign in to comment.