Quantum GIS API Documentation
1.7.4
|
00001 /* ************************************************************************** 00002 qgscontrastenhancementfunction.cpp - description 00003 ------------------- 00004 begin : Fri Nov 16 2007 00005 copyright : (C) 2007 by Peter J. Ersts 00006 email : ersts@amnh.org 00007 00008 ****************************************************************************/ 00009 00010 /* ************************************************************************** 00011 * * 00012 * This program is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU General Public License as published by * 00014 * the Free Software Foundation; either version 2 of the License, or * 00015 * (at your option) any later version. * 00016 * * 00017 ***************************************************************************/ 00018 00019 #include "qgscontrastenhancementfunction.h" 00020 00021 QgsContrastEnhancementFunction::QgsContrastEnhancementFunction( QgsContrastEnhancement::QgsRasterDataType theDataType, double theMinimumValue, double theMaximumValue ) 00022 { 00023 mQgsRasterDataType = theDataType; 00024 mMaximumValue = theMaximumValue; 00025 mMinimumValue = theMinimumValue; 00026 mMinimumMaximumRange = mMaximumValue - mMinimumValue; 00027 } 00028 00029 00030 int QgsContrastEnhancementFunction::enhance( double theValue ) 00031 { 00032 if ( mQgsRasterDataType == QgsContrastEnhancement::QGS_Byte ) 00033 { 00034 return static_cast<int>( theValue ); 00035 } 00036 else 00037 { 00038 return static_cast<int>(((( theValue - QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) ) / ( QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) - QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) ) )*255.0 ) ); 00039 } 00040 } 00041 00042 bool QgsContrastEnhancementFunction::isValueInDisplayableRange( double theValue ) 00043 { 00044 //A default check is to see if the provided value is with the range for the data type 00045 if ( theValue < QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) || theValue > QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) ) 00046 { 00047 return false; 00048 } 00049 00050 return true; 00051 } 00052 00053 void QgsContrastEnhancementFunction::setMaximumValue( double theValue ) 00054 { 00055 if ( QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) < theValue ) 00056 { 00057 mMaximumValue = QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ); 00058 } 00059 else 00060 { 00061 mMaximumValue = theValue; 00062 } 00063 00064 mMinimumMaximumRange = mMaximumValue - mMinimumValue; 00065 } 00066 00067 void QgsContrastEnhancementFunction::setMinimumValue( double theValue ) 00068 { 00069 00070 if ( QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) > theValue ) 00071 { 00072 mMinimumValue = QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ); 00073 } 00074 else 00075 { 00076 mMinimumValue = theValue; 00077 } 00078 00079 mMinimumMaximumRange = mMaximumValue - mMinimumValue; 00080 }