28 #include <QDomDocument>
29 #include <QDomElement>
34 mContrastEnhancementFunction = 0;
35 mEnhancementDirty =
false;
37 mRasterDataType = theDataType;
41 mRasterDataTypeRange = mMaximumValue - mMinimumValue;
43 mLookupTableOffset = mMinimumValue * -1;
48 if ( mRasterDataTypeRange <= 65535.0 )
50 mLookupTable =
new int[static_cast <
int>( mRasterDataTypeRange+1 )];
58 mContrastEnhancementFunction = 0;
59 mEnhancementDirty =
true;
60 mRasterDataType = ce.mRasterDataType;
62 mMinimumValue = ce.mMinimumValue;
63 mMaximumValue = ce.mMaximumValue;
64 mRasterDataTypeRange = ce.mRasterDataTypeRange;
72 if ( mRasterDataTypeRange <= 65535.0 )
74 mLookupTable =
new int[static_cast <
int>( mRasterDataTypeRange+1 )];
80 delete [] mLookupTable;
81 delete mContrastEnhancementFunction;
94 switch ( theDataType )
143 switch ( theDataType )
200 if ( mEnhancementDirty )
202 generateLookupTable();
205 if ( mLookupTable &&
NoEnhancement != mContrastEnhancementAlgorithm )
207 return mLookupTable[static_cast <
int>( theValue + mLookupTableOffset )];
214 return mContrastEnhancementFunction->
enhance( theValue );
221 bool QgsContrastEnhancement::generateLookupTable()
223 mEnhancementDirty =
false;
225 if ( !mContrastEnhancementFunction )
235 QgsDebugMsg(
"***MinimumValue : " + QString::number( mMinimumValue ) );
236 QgsDebugMsg(
"***MaximumValue : " + QString::number( mMaximumValue ) );
237 QgsDebugMsg(
"***mLookupTableOffset : " + QString::number( mLookupTableOffset ) );
238 QgsDebugMsg(
"***mRasterDataTypeRange : " + QString::number( mRasterDataTypeRange ) );
240 for (
int myIterator = 0; myIterator <= mRasterDataTypeRange; myIterator++ )
242 mLookupTable[myIterator] = mContrastEnhancementFunction->
enhance((
double )myIterator - mLookupTableOffset );
256 if ( 0 != mContrastEnhancementFunction )
272 QgsDebugMsg(
"called algorithm: " + QString::number((
int )theAlgorithm ) +
" generate lookup table: " + QString::number((
int )generateTable ) );
274 if ( theAlgorithm != mContrastEnhancementAlgorithm )
276 switch ( theAlgorithm )
295 mEnhancementDirty =
true;
296 mContrastEnhancementAlgorithm = theAlgorithm;
300 generateLookupTable();
314 if ( 0 != theFunction )
316 mContrastEnhancementFunction = theFunction;
318 generateLookupTable();
330 QgsDebugMsg(
"called value: " + QString::number( theValue ) +
" generate lookup table: " + QString::number((
int )generateTable ) );
338 mMaximumValue = theValue;
341 if ( 0 != mContrastEnhancementFunction )
346 mEnhancementDirty =
true;
350 generateLookupTable();
362 QgsDebugMsg(
"called value: " + QString::number( theValue ) +
" generate lookup table: " + QString::number((
int )generateTable ) );
370 mMinimumValue = theValue;
373 if ( 0 != mContrastEnhancementFunction )
378 mEnhancementDirty =
true;
382 generateLookupTable();
389 QDomElement minElem = doc.createElement(
"minValue" );
390 QDomText minText = doc.createTextNode( QString::number( mMinimumValue ) );
391 minElem.appendChild( minText );
392 parentElem.appendChild( minElem );
395 QDomElement maxElem = doc.createElement(
"maxValue" );
396 QDomText maxText = doc.createTextNode( QString::number( mMaximumValue ) );
397 maxElem.appendChild( maxText );
398 parentElem.appendChild( maxElem );
401 QDomElement algorithmElem = doc.createElement(
"algorithm" );
403 algorithmElem.appendChild( algorithmText );
404 parentElem.appendChild( algorithmElem );
409 QDomElement minValueElem = elem.firstChildElement(
"minValue" );
410 if ( !minValueElem.isNull() )
412 mMinimumValue = minValueElem.text().toDouble();
414 QDomElement maxValueElem = elem.firstChildElement(
"maxValue" );
415 if ( !maxValueElem.isNull() )
417 mMaximumValue = maxValueElem.text().toDouble();
419 QDomElement algorithmElem = elem.firstChildElement(
"algorithm" );
420 if ( !algorithmElem.isNull() )
422 QString algorithmString = algorithmElem.text();
425 if ( algorithmString ==
"0" )
429 else if ( algorithmString ==
"1" )
433 else if ( algorithmString ==
"2" )
437 else if ( algorithmString ==
"3" )
441 else if ( algorithmString ==
"4" )
459 return "NoEnhancement";
461 return "StretchToMinimumMaximum";
463 return "StretchAndClipToMinimumMaximum";
465 return "ClipToMinimumMaximum";
467 return "UserDefinedEnhancement";
469 return "NoEnhancement";
474 if ( contrastEnhancementString ==
"StretchToMinimumMaximum" )
478 else if ( contrastEnhancementString ==
"StretchAndClipToMinimumMaximum" )
482 else if ( contrastEnhancementString ==
"ClipToMinimumMaximum" )
486 else if ( contrastEnhancementString ==
"UserDefinedEnhancement" )