Quantum GIS API Documentation
1.7.4
|
00001 /* ************************************************************************** 00002 qgspseudocolorshader.cpp - description 00003 ------------------- 00004 begin : Fri Dec 28 2007 00005 copyright : (C) 2007 by Peter J. Ersts 00006 email : ersts@amnh.org 00007 00008 This class contains code that was originally part of the larger QgsRasterLayer 00009 class originally created circa 2004 by T.Sutton, Gary E.Sherman, Steve Halasz 00010 ****************************************************************************/ 00011 00012 /* ************************************************************************** 00013 * * 00014 * This program is free software; you can redistribute it and/or modify * 00015 * it under the terms of the GNU General Public License as published by * 00016 * the Free Software Foundation; either version 2 of the License, or * 00017 * (at your option) any later version. * 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 //double check that myInt >= min and <= max 00036 //this is relevant if we are plotting within stddevs 00037 if ( myPixelValue < mMinimumValue ) 00038 { 00039 myPixelValue = mMinimumValue; 00040 } 00041 if ( myPixelValue > mMaximumValue ) 00042 { 00043 myPixelValue = mMaximumValue; 00044 } 00045 00046 //check if we are in the first class break 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 //check if we are in the second class break 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 //otherwise we must be in the third classbreak 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 //set up the three class breaks for pseudocolor mapping 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 }