[QGIS Commit] r10271 - trunk/qgis/src/core/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Wed Mar 11 18:32:49 EDT 2009
Author: ersts
Date: 2009-03-11 18:32:49 -0400 (Wed, 11 Mar 2009)
New Revision: 10271
Modified:
trunk/qgis/src/core/raster/qgscolorrampshader.cpp
Log:
-Fixed issue with color ramp shader and doubles
-Closes ticket #1497
Modified: trunk/qgis/src/core/raster/qgscolorrampshader.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgscolorrampshader.cpp 2009-03-11 11:30:27 UTC (rev 10270)
+++ trunk/qgis/src/core/raster/qgscolorrampshader.cpp 2009-03-11 22:32:49 UTC (rev 10271)
@@ -17,11 +17,14 @@
* (at your option) any later version. *
* *
***************************************************************************/
+#define REALLY_SMALL 0.0000001
#include "qgslogger.h"
#include "qgscolorrampshader.h"
+#include <math.h>
+
QgsColorRampShader::QgsColorRampShader( double theMinimumValue, double theMaximumValue ) : QgsRasterShaderFunction( theMinimumValue, theMaximumValue )
{
QgsDebugMsg( "called." );
@@ -54,17 +57,19 @@
return false;
}
+ double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
- else if ( theValue <= myColorRampItem.value )
+ else if ( theValue <= myColorRampItem.value || myTinyDiff <= REALLY_SMALL )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
@@ -94,12 +99,14 @@
return false;
}
+ double myTinyDiff = 0.0;
QgsColorRampShader::ColorRampItem myColorRampItem;
while ( mCurrentColorRampItemIndex >= 0 && mCurrentColorRampItemIndex < myColorRampItemCount )
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
- if ( theValue == myColorRampItem.value )
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
+ if ( theValue == myColorRampItem.value || myTinyDiff <= REALLY_SMALL )
{
*theReturnRedValue = myColorRampItem.color.red();
*theReturnGreenValue = myColorRampItem.color.green();
@@ -133,13 +140,13 @@
bool QgsColorRampShader::interpolatedColor( double theValue, int* theReturnRedValue, int* theReturnGreenValue, int* theReturnBlueValue )
{
-
int myColorRampItemCount = mColorRampItemList.count();
if ( myColorRampItemCount <= 0 )
{
return false;
}
+ double myTinyDiff = 0.0;
double myCurrentRampRange; //difference between two consecutive entry values
double myOffsetInRange; //difference between the previous entry value and value
QgsColorRampShader::ColorRampItem myColorRampItem;
@@ -147,12 +154,13 @@
{
//Start searching from the last index - assumtion is that neighboring pixels tend to be similar values
myColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex );
+ myTinyDiff = fabs( theValue - myColorRampItem.value );
//If the previous entry is less, then search closer to the top of the list (assumes mColorRampItemList is sorted)
if ( mCurrentColorRampItemIndex != 0 && theValue <= mColorRampItemList.at( mCurrentColorRampItemIndex - 1 ).value )
{
mCurrentColorRampItemIndex--;
}
- else if ( mCurrentColorRampItemIndex != 0 && theValue <= myColorRampItem.value )
+ else if ( mCurrentColorRampItemIndex != 0 && ( theValue <= myColorRampItem.value || myTinyDiff <= REALLY_SMALL ) )
{
QgsColorRampShader::ColorRampItem myPreviousColorRampItem = mColorRampItemList.value( mCurrentColorRampItemIndex - 1 );
myCurrentRampRange = myColorRampItem.value - myPreviousColorRampItem.value;
More information about the QGIS-commit
mailing list