267 changes: 175 additions & 92 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
#include "qgslogger.h"
#include "qgsapplication.h"
#include "qgisapp.h"
#include "qgsbilinearrasterresampler.h"
#include "qgscubicrasterresampler.h"
#include "qgscoordinatetransform.h"
#include "qgsrasterlayerproperties.h"
#include "qgsrasterrenderer.h"
#include "qgsgenericprojectionselector.h"
#include "qgsproject.h"
#include "qgsrasterbandstats.h"
Expand Down Expand Up @@ -284,6 +287,48 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
}
tableTransparency->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
tableTransparency->horizontalHeader()->setResizeMode( 1, QHeaderView::Stretch );

//resampling
const QgsRasterRenderer* renderer = mRasterLayer->renderer();
mZoomedInResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedInResamplingComboBox->insertItem( 1, tr( "Bilinear" ) );
mZoomedInResamplingComboBox->insertItem( 2, tr( "Cubic" ) );
mZoomedOutResamplingComboBox->insertItem( 0, tr( "Nearest neighbour" ) );
mZoomedOutResamplingComboBox->insertItem( 1, tr( "Average" ) );
//set combo boxes to current resampling types
if ( renderer )
{
const QgsRasterResampler* zoomedInResampler = renderer->zoomedInResampler();
if ( zoomedInResampler )
{
if ( zoomedInResampler->type() == "bilinear" )
{
mZoomedInResamplingComboBox->setCurrentIndex( 1 );
}
else if ( zoomedInResampler->type() == "cubic" )
{
mZoomedInResamplingComboBox->setCurrentIndex( 2 );
}
}
else
{
mZoomedInResamplingComboBox->setCurrentIndex( 0 );
}

const QgsRasterResampler* zoomedOutResampler = renderer->zoomedOutResampler();
if ( zoomedOutResampler )
{
if ( zoomedOutResampler->type() == "bilinear" ) //bilinear resampler does averaging when zooming out
{
mZoomedOutResamplingComboBox->setCurrentIndex( 1 );
}
}
else
{
mZoomedOutResamplingComboBox->setCurrentIndex( 0 );
}
mMaximumOversamplingSpinBox->setValue( renderer->maxOversampling() );
}
} // QgsRasterLayerProperties ctor


Expand Down Expand Up @@ -975,98 +1020,6 @@ void QgsRasterLayerProperties::apply()
/*
* Symbology Tab
*/
//set the appropriate render style
if ( rbtnSingleBand->isChecked() )
{
//
// Grayscale
//
if ( mRasterLayer->rasterType() == QgsRasterLayer::GrayOrUndefined )
{

if ( cboxColorMap->currentText() != tr( "Grayscale" ) )
{
QgsDebugMsg( "Raster Drawing Style to :: SingleBandPseudoColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::SingleBandPseudoColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: SingleBandGray" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::SingleBandGray );
}
}
//
// Paletted Image
//
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Palette )
{
if ( cboxColorMap->currentText() == tr( "Grayscale" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedSingleBandGray" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" )
.arg( cboGray->currentText() ).arg( mRasterLayer->grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedSingleBandGray );
}
else if ( cboxColorMap->currentText() == tr( "Colormap" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedColor" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedSingleBandPseudoColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedSingleBandPseudoColor );
}

}
//
// Mutltiband
//
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Multiband )
{
if ( cboxColorMap->currentText() != tr( "Grayscale" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to ::MultiBandSingleBandPseudoColor " );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandPseudoColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: MultiBandSingleBandGray" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandGray );

}
}
} //end of grayscale box enabled and rbtnsingleband checked
else //assume that rbtnThreeBand is checked and render in rgb color
{
//set the grayscale color table type if the groupbox is enabled

if ( mRasterLayer->rasterType() == QgsRasterLayer::Palette )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedMultiBandColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedMultiBandColor );
}
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Multiband )
{

QgsDebugMsg( "Setting Raster Drawing Style to :: MultiBandColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandColor );
}

}

//set whether the layer histogram should be inverted
mRasterLayer->setInvertHistogram( cboxInvertColorMap->isChecked() );
Expand Down Expand Up @@ -1444,6 +1397,136 @@ void QgsRasterLayerProperties::apply()
pixmapLegend->setScaledContents( true );
pixmapLegend->repaint();

//set the appropriate render style
if ( rbtnSingleBand->isChecked() )
{
//
// Grayscale
//
if ( mRasterLayer->rasterType() == QgsRasterLayer::GrayOrUndefined )
{

if ( cboxColorMap->currentText() != tr( "Grayscale" ) )
{
QgsDebugMsg( "Raster Drawing Style to :: SingleBandPseudoColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::SingleBandPseudoColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: SingleBandGray" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::SingleBandGray );
}
}
//
// Paletted Image
//
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Palette )
{
if ( cboxColorMap->currentText() == tr( "Grayscale" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedSingleBandGray" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" )
.arg( cboGray->currentText() ).arg( mRasterLayer->grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedSingleBandGray );
}
else if ( cboxColorMap->currentText() == tr( "Colormap" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedColor" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedSingleBandPseudoColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedSingleBandPseudoColor );
}

}
//
// Mutltiband
//
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Multiband )
{
if ( cboxColorMap->currentText() != tr( "Grayscale" ) )
{
QgsDebugMsg( "Setting Raster Drawing Style to ::MultiBandSingleBandPseudoColor " );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandPseudoColor );
}
else
{
QgsDebugMsg( "Setting Raster Drawing Style to :: MultiBandSingleBandGray" );
QgsDebugMsg( QString( "Combo value : %1 GrayBand Mapping : %2" ).arg( cboGray->currentText() ).arg( mRasterLayer->
grayBandName() ) );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandSingleBandGray );

}
}
} //end of grayscale box enabled and rbtnsingleband checked
else //assume that rbtnThreeBand is checked and render in rgb color
{
//set the grayscale color table type if the groupbox is enabled

if ( mRasterLayer->rasterType() == QgsRasterLayer::Palette )
{
QgsDebugMsg( "Setting Raster Drawing Style to :: PalettedMultiBandColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::PalettedMultiBandColor );
}
else if ( mRasterLayer->rasterType() == QgsRasterLayer::Multiband )
{

QgsDebugMsg( "Setting Raster Drawing Style to :: MultiBandColor" );

mRasterLayer->setDrawingStyle( QgsRasterLayer::MultiBandColor );
}
}
//set render style finished


//resampling
QgsRasterRenderer* rasterRenderer = mRasterLayer->renderer();
QgsRasterResampler* zoomedInResampler = 0;
QString zoomedInResamplingMethod = mZoomedInResamplingComboBox->currentText();
if ( zoomedInResamplingMethod == tr( "Bilinear" ) )
{
zoomedInResampler = new QgsBilinearRasterResampler();
}
else if ( zoomedInResamplingMethod == tr( "Cubic" ) )
{
zoomedInResampler = new QgsCubicRasterResampler();
}

if ( rasterRenderer )
{
rasterRenderer->setZoomedInResampler( zoomedInResampler );
}

QgsRasterResampler* zoomedOutResampler = 0;
QString zoomedOutResamplingMethod = mZoomedOutResamplingComboBox->currentText();
if ( zoomedOutResamplingMethod == tr( "Average" ) )
{
zoomedOutResampler = new QgsBilinearRasterResampler();
}

if ( rasterRenderer )
{
rasterRenderer->setZoomedOutResampler( zoomedOutResampler );
}

if ( rasterRenderer )
{
rasterRenderer->setMaxOversampling( mMaximumOversamplingSpinBox->value() );
}


//get the thumbnail for the layer
QPixmap myQPixmap = QPixmap( pixmapThumbnail->width(), pixmapThumbnail->height() );
mRasterLayer->thumbnailAsPixmap( &myQPixmap );
Expand Down
9 changes: 9 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ SET(QGIS_CORE_SRCS
raster/qgsrastershader.cpp
raster/qgsrastershaderfunction.cpp

raster/qgsrasterrenderer.cpp
raster/qgsbilinearrasterresampler.cpp
raster/qgscubicrasterresampler.cpp
raster/qgspalettedrasterrenderer.cpp
raster/qgsmultibandcolorrenderer.cpp
raster/qgssinglebandcolordatarenderer.cpp
raster/qgssinglebandgrayrenderer.cpp
raster/qgssinglebandpseudocolorrenderer.cpp

renderer/qgscontinuouscolorrenderer.cpp
renderer/qgsgraduatedsymbolrenderer.cpp
renderer/qgsrenderer.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
unsigned int getTransparency();

/** Mutator for transparency level. Should be between 0 and 255 */
void setTransparency( unsigned int );
virtual void setTransparency( unsigned int );

/**
* If an operation returns 0 (e.g. draw()), this function
Expand Down
3 changes: 3 additions & 0 deletions src/core/qgsrasterprojector.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ class QgsRasterProjector
/** get mCPMatrix as string */
QString cpToString();

int dstRows() const { return mDestRows; }
int dstCols() const { return mDestCols; }

private:
/** Source CRS */
QgsCoordinateReferenceSystem mSrcCRS;
Expand Down
33 changes: 33 additions & 0 deletions src/core/raster/qgsbilinearrasterresampler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***************************************************************************
qgsbilinearrasterresampler.cpp
------------------------------
begin : December 2011
copyright : (C) 2011 by Marco Hugentobler
email : marco at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsbilinearrasterresampler.h"
#include <QImage>
#include <cmath>

QgsBilinearRasterResampler::QgsBilinearRasterResampler()
{
}

QgsBilinearRasterResampler::~QgsBilinearRasterResampler()
{
}

void QgsBilinearRasterResampler::resample( const QImage& srcImage, QImage& dstImage )
{
dstImage = srcImage.scaled( dstImage.width(), dstImage.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
Loading