QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgspseudocolorshader.cpp
Go to the documentation of this file.
1 /* **************************************************************************
2  qgspseudocolorshader.cpp - description
3  -------------------
4 begin : Fri Dec 28 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : [email protected]
7 
8 This class contains code that was originally part of the larger QgsRasterLayer
9 class originally created circa 2004 by T.Sutton, Gary E.Sherman, Steve Halasz
10 ****************************************************************************/
11 
12 /* **************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 #include <QDebug>
22 
23 #include "qgspseudocolorshader.h"
24 
25 QgsPseudoColorShader::QgsPseudoColorShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
26 {
28 }
29 
30 
31 bool QgsPseudoColorShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
32 {
33  double myPixelValue = theValue;
34 
35  //double check that myInt >= min and <= max
36  //this is relevant if we are plotting within stddevs
37  if ( myPixelValue < mMinimumValue )
38  {
39  myPixelValue = mMinimumValue;
40  }
41  if ( myPixelValue > mMaximumValue )
42  {
43  myPixelValue = mMaximumValue;
44  }
45 
46  //check if we are in the first class break
47  if (( myPixelValue >= mClassBreakMin1 ) && ( myPixelValue < mClassBreakMax1 ) )
48  {
49  *theReturnRedValue = 0;
50  *theReturnGreenValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * ( myPixelValue - mClassBreakMin1 ) ) * 3 );
51  *theReturnBlueValue = 255;
52  }
53  //check if we are in the second class break
54  else if (( myPixelValue >= mClassBreakMin2 ) && ( myPixelValue < mClassBreakMax2 ) )
55  {
56  *theReturnRedValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 );
57  *theReturnGreenValue = 255;
58  *theReturnBlueValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 ) );
59  }
60  //otherwise we must be in the third classbreak
61  else
62  {
63  *theReturnRedValue = 255;
64  *theReturnGreenValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin3 ) / 1 ) * 3 ) ) );
65  *theReturnBlueValue = 0;
66  }
67 
68  return true;
69 }
70 
71 bool QgsPseudoColorShader::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
72 {
73  Q_UNUSED( theRedValue );
74  Q_UNUSED( theGreenValue );
75  Q_UNUSED( theBlueValue );
76 
77  *theReturnRedValue = 0;
78  *theReturnGreenValue = 0;
79  *theReturnBlueValue = 0;
80 
81  return false;
82 }
83 
85 {
86  //set up the three class breaks for pseudocolor mapping
93 }
94 
101 {
102  mMaximumValue = theValue;
104  setClassBreaks();
105 }
106 
113 {
114  mMinimumValue = theValue;
116  setClassBreaks();
117 }