Quantum GIS API Documentation  1.8
src/core/raster/qgspseudocolorshader.cpp
Go to the documentation of this file.
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   Q_UNUSED( theRedValue );
00074   Q_UNUSED( theGreenValue );
00075   Q_UNUSED( theBlueValue );
00076 
00077   *theReturnRedValue = 0;
00078   *theReturnGreenValue = 0;
00079   *theReturnBlueValue = 0;
00080 
00081   return false;
00082 }
00083 
00084 void QgsPseudoColorShader::setClassBreaks()
00085 {
00086   //set up the three class breaks for pseudocolor mapping
00087   mBreakSize = mMinimumMaximumRange / 3;
00088   mClassBreakMin1 = mMinimumValue;
00089   mClassBreakMax1 = mClassBreakMin1 + mBreakSize;
00090   mClassBreakMin2 = mClassBreakMax1;
00091   mClassBreakMax2 = mClassBreakMin2 + mBreakSize;
00092   mClassBreakMin3 = mClassBreakMax2;
00093 }
00094 
00100 void QgsPseudoColorShader::setMaximumValue( double theValue )
00101 {
00102   mMaximumValue = theValue;
00103   mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00104   setClassBreaks();
00105 }
00106 
00112 void QgsPseudoColorShader::setMinimumValue( double theValue )
00113 {
00114   mMinimumValue = theValue;
00115   mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00116   setClassBreaks();
00117 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines