Quantum GIS API Documentation
1.7.4
|
00001 /* ************************************************************************** 00002 qgsfreakoutshader.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 "qgsfreakoutshader.h" 00024 00025 QgsFreakOutShader::QgsFreakOutShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue ) 00026 { 00027 setClassBreaks(); 00028 } 00029 00030 void QgsFreakOutShader::setClassBreaks() 00031 { 00032 //set up the three class breaks for pseudocolor mapping 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 //double check that myInt >= min and <= max 00070 //this is relevant if we are plotting within stddevs 00071 if ( myPixelValue < mMinimumValue ) 00072 { 00073 myPixelValue = mMinimumValue; 00074 } 00075 if ( myPixelValue > mMaximumValue ) 00076 { 00077 myPixelValue = mMaximumValue; 00078 } 00079 00080 //check if we are in the first class break 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 //check if we are in the second class break 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 //otherwise we must be in the third classbreak 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 }