Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsfreakoutshader.cpp
Go to the documentation of this file.
1 /* **************************************************************************
2  qgsfreakoutshader.cpp - description
3  -------------------
4 begin : Fri Dec 28 2007
5 copyright : (C) 2007 by Peter J. Ersts
6 email : ersts@amnh.org
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 "qgsfreakoutshader.h"
24 
25 QgsFreakOutShader::QgsFreakOutShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
26 {
28 }
29 
31 {
32  //set up the three class breaks for pseudocolor mapping
39 }
40 
46 void QgsFreakOutShader::setMaximumValue( double theValue )
47 {
48  mMaximumValue = theValue;
51 }
52 
58 void QgsFreakOutShader::setMinimumValue( double theValue )
59 {
60  mMinimumValue = theValue;
63 }
64 
65 bool QgsFreakOutShader::shade( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
66 {
67  double myPixelValue = theValue;
68 
69  //double check that myInt >= min and <= max
70  //this is relevant if we are plotting within stddevs
71  if ( myPixelValue < mMinimumValue )
72  {
73  myPixelValue = mMinimumValue;
74  }
75  if ( myPixelValue > mMaximumValue )
76  {
77  myPixelValue = mMaximumValue;
78  }
79 
80  //check if we are in the first class break
81  if (( myPixelValue >= mClassBreakMin1 ) && ( myPixelValue < mClassBreakMax1 ) )
82  {
83  *theReturnRedValue = 0;
84  *theReturnGreenValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * ( myPixelValue - mClassBreakMin1 ) ) * 3 );
85  *theReturnBlueValue = 255;
86 
87  *theReturnRedValue = 255 - *theReturnGreenValue;
88  }
89  //check if we are in the second class break
90  else if (( myPixelValue >= mClassBreakMin2 ) && ( myPixelValue < mClassBreakMax2 ) )
91  {
92  *theReturnRedValue = static_cast < int >((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 );
93  *theReturnGreenValue = 255;
94  *theReturnBlueValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin2 ) / 1 ) ) * 3 ) );
95 
96  *theReturnGreenValue = *theReturnBlueValue;
97  }
98  //otherwise we must be in the third classbreak
99  else
100  {
101  *theReturnGreenValue = 255;
102  *theReturnGreenValue = static_cast < int >( 255 - ((( 255 / mMinimumMaximumRange ) * (( myPixelValue - mClassBreakMin3 ) / 1 ) * 3 ) ) );
103  *theReturnBlueValue = 0;
104 
105  *theReturnRedValue = *theReturnGreenValue;
106  *theReturnGreenValue = 255 - *theReturnGreenValue;
107  }
108 
109  return true;
110 }
111 
112 bool QgsFreakOutShader::shade( double theRedValue, double theGreenValue, double theBlueValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
113 {
114  *theReturnRedValue = 0;
115  *theReturnGreenValue = 0;
116  *theReturnBlueValue = 0;
117 
118  return false;
119 }