00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <QDebug>
00022
00023 #include "qgspseudocolorshader.h"
00024
00025 QgsPseudoColorShader::QgsPseudoColorShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
00026 {
00027 setClassBreaks();
00028 }
00029
00030
00031 bool QgsPseudoColorShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
00032 {
00033 double myPixelValue = theValue;
00034
00035
00036
00037 if ( myPixelValue < mMinimumValue )
00038 {
00039 myPixelValue = mMinimumValue;
00040 }
00041 if ( myPixelValue > mMaximumValue )
00042 {
00043 myPixelValue = mMaximumValue;
00044 }
00045
00046
00047 if (( myPixelValue >= mClassBreakMin1 ) && ( myPixelValue < mClassBreakMax1 ) )
00048 {
00049 *theReturnRedValue = 0;
00050 *theReturnGreenValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * ( myPixelValue - mClassBreakMin1 ) ) * 3 );
00051 *theReturnBlueValue = 255;
00052 }
00053
00054 else if (( myPixelValue >= mClassBreakMin2 ) && ( myPixelValue < mClassBreakMax2 ) )
00055 {
00056 *theReturnRedValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 );
00057 *theReturnGreenValue = 255;
00058 *theReturnBlueValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 ) );
00059 }
00060
00061 else
00062 {
00063 *theReturnRedValue = 255;
00064 *theReturnGreenValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin3 ) / 1 ) * 3 ) ) );
00065 *theReturnBlueValue = 0;
00066 }
00067
00068 return true;
00069 }
00070
00071 bool QgsPseudoColorShader::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
00072 {
00073 *theReturnRedValue = 0;
00074 *theReturnGreenValue = 0;
00075 *theReturnBlueValue = 0;
00076
00077 return false;
00078 }
00079
00080 void QgsPseudoColorShader::setClassBreaks()
00081 {
00082
00083 mBreakSize = mMinimumMaximumRange / 3;
00084 mClassBreakMin1 = mMinimumValue;
00085 mClassBreakMax1 = mClassBreakMin1 + mBreakSize;
00086 mClassBreakMin2 = mClassBreakMax1;
00087 mClassBreakMax2 = mClassBreakMin2 + mBreakSize;
00088 mClassBreakMin3 = mClassBreakMax2;
00089 }
00090
00096 void QgsPseudoColorShader::setMaximumValue( double theValue )
00097 {
00098 mMaximumValue = theValue;
00099 mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00100 setClassBreaks();
00101 }
00102
00108 void QgsPseudoColorShader::setMinimumValue( double theValue )
00109 {
00110 mMinimumValue = theValue;
00111 mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00112 setClassBreaks();
00113 }