Skip to content
Permalink
Browse files

avoid creating a histogram without range (fixes #10832)

  • Loading branch information
jef-n committed Oct 15, 2014
1 parent c90d810 commit 962a7d9f789543e0ca3bf1416ff419bfef8748e6
@@ -512,7 +512,7 @@ void QgsRasterLayerProperties::setRendererWidget( const QString& rendererName )
QgsDebugMsg( "renderer has widgetCreateFunction" );
// Current canvas extent (used to calc min/max) in layer CRS
QgsRectangle myExtent = mMapCanvas->mapSettings().outputExtentToLayerExtent( mRasterLayer, mMapCanvas->extent() );
mRendererWidget = ( *rendererEntry.widgetCreateFunction )( mRasterLayer, myExtent );
mRendererWidget = rendererEntry.widgetCreateFunction( mRasterLayer, myExtent );
mRendererStackedWidget->addWidget( mRendererWidget );
if ( oldWidget )
{
@@ -50,7 +50,7 @@ class CORE_EXPORT QgsRasterBandStats
{
statsGathered = None;
minimumValue = std::numeric_limits<double>::max();
maximumValue = std::numeric_limits<double>::min();
maximumValue = -std::numeric_limits<double>::max();
range = 0.0;
mean = 0.0;
sumOfSquares = 0.0;
@@ -273,7 +273,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &theHistogram,
// We need statistics -> avoid histogramDefaults in hasHistogram if possible
// TODO: use approximated statistics if aproximated histogram is requested
// (theSampleSize > 0)
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
theHistogram.minimum = stats.minimumValue;
}
}
@@ -285,7 +285,7 @@ void QgsRasterInterface::initHistogram( QgsRasterHistogram &theHistogram,
}
else
{
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Max, theExtent, theSampleSize );
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Max, theExtent, theSampleSize );
theHistogram.maximum = stats.maximumValue;
}
}
@@ -518,7 +518,7 @@ void QgsRasterInterface::cumulativeCut( int theBandNo,
int mySrcDataType = srcDataType( theBandNo );

//get band stats to specify real histogram min/max (fix #9793 Byte bands)
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
QgsRasterBandStats stats = bandStatistics( theBandNo, QgsRasterBandStats::Min, theExtent, theSampleSize );
// for byte bands make sure bin count == actual range
int myBinCount = ( mySrcDataType == QGis::Byte ) ? int( ceil( stats.maximumValue - stats.minimumValue + 1 ) ) : 0;
QgsRasterHistogram myHistogram = histogram( theBandNo, myBinCount, stats.minimumValue, stats.maximumValue, theExtent, theSampleSize );
@@ -606,53 +606,65 @@ void QgsRasterHistogramWidget::refreshHistogram()
QgsDebugMsg( QString( "computed histo min = %1 max = %2" ).arg( mHistoMin ).arg( mHistoMax ) );
myFirstIteration = false;
}
// for x axis use band pixel values rather than gdal hist. bin values
// subtract -0.5 to prevent rounding errors
// see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8
// fix x range for non-Byte data
mpPlot->setAxisScale( QwtPlot::xBottom,
mHistoMin - myBinXStep / 2,
mHistoMax + myBinXStep / 2 );

mpPlot->replot();
if ( mHistoMin < mHistoMax )
{
// for x axis use band pixel values rather than gdal hist. bin values
// subtract -0.5 to prevent rounding errors
// see http://www.gdal.org/classGDALRasterBand.html#3f8889607d3b2294f7e0f11181c201c8
// fix x range for non-Byte data
mpPlot->setAxisScale( QwtPlot::xBottom,
mHistoMin - myBinXStep / 2,
mHistoMax + myBinXStep / 2 );
mpPlot->setEnabled( true );
mpPlot->replot();

// histo plot markers
// memory leak?
mHistoMarkerMin = new QwtPlotMarker();
mHistoMarkerMin->attach( mpPlot );
mHistoMarkerMax = new QwtPlotMarker();
mHistoMarkerMax->attach( mpPlot );
updateHistoMarkers();
// histo plot markers
// memory leak?
mHistoMarkerMin = new QwtPlotMarker();
mHistoMarkerMin->attach( mpPlot );
mHistoMarkerMax = new QwtPlotMarker();
mHistoMarkerMax->attach( mpPlot );
updateHistoMarkers();

// histo picker
if ( ! mHistoPicker )
{
mHistoPicker = new QwtPlotPicker( mpPlot->canvas() );
// mHistoPicker->setTrackerMode( QwtPicker::ActiveOnly );
mHistoPicker->setTrackerMode( QwtPicker::AlwaysOff );
mHistoPicker->setRubberBand( QwtPicker::VLineRubberBand );
mHistoPicker->setEnabled( false );
// histo picker
if ( !mHistoPicker )
{
mHistoPicker = new QwtPlotPicker( mpPlot->canvas() );
// mHistoPicker->setTrackerMode( QwtPicker::ActiveOnly );
mHistoPicker->setTrackerMode( QwtPicker::AlwaysOff );
mHistoPicker->setRubberBand( QwtPicker::VLineRubberBand );
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
mHistoPicker->setStateMachine( new QwtPickerDragPointMachine );
connect( mHistoPicker, SIGNAL( selected( const QPointF & ) ), this, SLOT( histoPickerSelected( const QPointF & ) ) );
mHistoPicker->setStateMachine( new QwtPickerDragPointMachine );
connect( mHistoPicker, SIGNAL( selected( const QPointF & ) ), this, SLOT( histoPickerSelected( const QPointF & ) ) );
#else
mHistoPicker->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::DragSelection );
connect( mHistoPicker, SIGNAL( selected( const QwtDoublePoint & ) ), this, SLOT( histoPickerSelectedQwt5( const QwtDoublePoint & ) ) );
mHistoPicker->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::DragSelection );
connect( mHistoPicker, SIGNAL( selected( const QwtDoublePoint & ) ), this, SLOT( histoPickerSelectedQwt5( const QwtDoublePoint & ) ) );
#endif
}
}
mHistoPicker->setEnabled( false );

// plot zoomer
if ( ! mHistoZoomer )
{
mHistoZoomer = new QwtPlotZoomer( mpPlot->canvas() );
// plot zoomer
if ( !mHistoZoomer )
{
mHistoZoomer = new QwtPlotZoomer( mpPlot->canvas() );
#if defined(QWT_VERSION) && QWT_VERSION>=0x060000
mHistoZoomer->setStateMachine( new QwtPickerDragRectMachine );
mHistoZoomer->setStateMachine( new QwtPickerDragRectMachine );
#else
mHistoZoomer->setSelectionFlags( QwtPicker::RectSelection | QwtPicker::DragSelection );
mHistoZoomer->setSelectionFlags( QwtPicker::RectSelection | QwtPicker::DragSelection );
#endif
mHistoZoomer->setTrackerMode( QwtPicker::AlwaysOff );
mHistoZoomer->setTrackerMode( QwtPicker::AlwaysOff );
}
mHistoZoomer->setEnabled( true );
}
else
{
mpPlot->setDisabled( true );
if ( mHistoPicker )
mHistoPicker->setEnabled( false );
if ( mHistoZoomer )
mHistoZoomer->setEnabled( false );
}

disconnect( mRasterLayer, SIGNAL( progressUpdate( int ) ), mHistogramProgress, SLOT( setValue( int ) ) );
stackedWidget2->setCurrentIndex( 0 );
@@ -1397,7 +1397,7 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
myMinVal -= dfHalfBucket;
myMaxVal += dfHalfBucket;

/*
#if 0
const char* pszPixelType = GDALGetMetadataItem( myGdalBand, "PIXELTYPE", "IMAGE_STRUCTURE" );
int bSignedByte = ( pszPixelType != NULL && EQUAL( pszPixelType, "SIGNEDBYTE" ) );

@@ -1420,7 +1420,7 @@ QgsRasterHistogram QgsGdalProvider::histogram( int theBandNo,
myMinVal -= dfHalfBucket;
myMaxVal += dfHalfBucket;
}
*/
#endif

int *myHistogramArray = new int[myHistogram.binCount];
CPLErr myError = GDALGetRasterHistogram( myGdalBand, myMinVal, myMaxVal,

0 comments on commit 962a7d9

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