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 "qgsfreakoutshader.h"
00024
00025 QgsFreakOutShader::QgsFreakOutShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
00026 {
00027 setClassBreaks();
00028 }
00029
00030 void QgsFreakOutShader::setClassBreaks()
00031 {
00032
00033 mBreakSize = mMinimumMaximumRange / 3;
00034 mClassBreakMin1 = mMinimumValue;
00035 mClassBreakMax1 = mClassBreakMin1 + mBreakSize;
00036 mClassBreakMin2 = mClassBreakMax1;
00037 mClassBreakMax2 = mClassBreakMin2 + mBreakSize;
00038 mClassBreakMin3 = mClassBreakMax2;
00039 }
00040
00046 void QgsFreakOutShader::setMaximumValue( double theValue )
00047 {
00048 mMaximumValue = theValue;
00049 mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00050 setClassBreaks();
00051 }
00052
00058 void QgsFreakOutShader::setMinimumValue( double theValue )
00059 {
00060 mMinimumValue = theValue;
00061 mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00062 setClassBreaks();
00063 }
00064
00065 bool QgsFreakOutShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
00066 {
00067 double myPixelValue = theValue;
00068
00069
00070
00071 if ( myPixelValue < mMinimumValue )
00072 {
00073 myPixelValue = mMinimumValue;
00074 }
00075 if ( myPixelValue > mMaximumValue )
00076 {
00077 myPixelValue = mMaximumValue;
00078 }
00079
00080
00081 if (( myPixelValue >= mClassBreakMin1 ) && ( myPixelValue < mClassBreakMax1 ) )
00082 {
00083 *theReturnRedValue = 0;
00084 *theReturnGreenValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * ( myPixelValue - mClassBreakMin1 ) ) * 3 );
00085 *theReturnBlueValue = 255;
00086
00087 *theReturnRedValue = 255 - *theReturnGreenValue;
00088 }
00089
00090 else if (( myPixelValue >= mClassBreakMin2 ) && ( myPixelValue < mClassBreakMax2 ) )
00091 {
00092 *theReturnRedValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 );
00093 *theReturnGreenValue = 255;
00094 *theReturnBlueValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 ) );
00095
00096 *theReturnGreenValue = *theReturnBlueValue;
00097 }
00098
00099 else
00100 {
00101 *theReturnGreenValue = 255;
00102 *theReturnGreenValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin3 ) / 1 ) * 3 ) ) );
00103 *theReturnBlueValue = 0;
00104
00105 *theReturnRedValue = *theReturnGreenValue;
00106 *theReturnGreenValue = 255 - *theReturnGreenValue;
00107 }
00108
00109 return true;
00110 }
00111
00112 bool QgsFreakOutShader::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
00113 {
00114 *theReturnRedValue = 0;
00115 *theReturnGreenValue = 0;
00116 *theReturnBlueValue = 0;
00117
00118 return false;
00119 }