QGIS API Documentation  master-3f58142
src/core/raster/qgscontrastenhancementfunction.cpp
Go to the documentation of this file.
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( QGis::DataType theDataType, double theMinimumValue, double theMaximumValue )
00022 {
00023   mQgsRasterDataType = theDataType;
00024   mMaximumValue = theMaximumValue;
00025   mMinimumValue = theMinimumValue;
00026   mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00027 }
00028 
00029 QgsContrastEnhancementFunction::QgsContrastEnhancementFunction( const QgsContrastEnhancementFunction& f )
00030 {
00031   mQgsRasterDataType = f.mQgsRasterDataType;
00032   mMaximumValue = f.mMaximumValue;
00033   mMinimumValue = f.mMinimumValue;
00034   mMinimumMaximumRange = f.mMinimumMaximumRange;
00035 }
00036 
00037 int QgsContrastEnhancementFunction::enhance( double theValue )
00038 {
00039   if ( mQgsRasterDataType == QGis::Byte )
00040   {
00041     return static_cast<int>( theValue );
00042   }
00043   else
00044   {
00045     return static_cast<int>(((( theValue - QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) ) / ( QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) - QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) ) )*255.0 ) );
00046   }
00047 }
00048 
00049 bool QgsContrastEnhancementFunction::isValueInDisplayableRange( double theValue )
00050 {
00051   //A default check is to see if the provided value is with the range for the data type
00052   if ( theValue < QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) || theValue > QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) )
00053   {
00054     return false;
00055   }
00056 
00057   return true;
00058 }
00059 
00060 void QgsContrastEnhancementFunction::setMaximumValue( double theValue )
00061 {
00062   if ( QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType ) < theValue )
00063   {
00064     mMaximumValue = QgsContrastEnhancement::maximumValuePossible( mQgsRasterDataType );
00065   }
00066   else
00067   {
00068     mMaximumValue = theValue;
00069   }
00070 
00071   mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00072 }
00073 
00074 void QgsContrastEnhancementFunction::setMinimumValue( double theValue )
00075 {
00076 
00077   if ( QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType ) > theValue )
00078   {
00079     mMinimumValue = QgsContrastEnhancement::minimumValuePossible( mQgsRasterDataType );
00080   }
00081   else
00082   {
00083     mMinimumValue = theValue;
00084   }
00085 
00086   mMinimumMaximumRange = mMaximumValue - mMinimumValue;
00087 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines