PageRenderTime 24ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/src/core/testcontrastenhancements.cpp

https://github.com/linz/Quantum-GIS
C++ | 107 lines | 62 code | 11 blank | 34 comment | 7 complexity | 2e8d67a1736d09961dade0ff79a2ded3 MD5 | raw file
  1. /***************************************************************************
  2. testcontrastenhancements.cpp
  3. --------------------------------------
  4. Date : Frida Nov 23 2007
  5. Copyright : (C) 2007 by Tim Sutton
  6. Email : tim@linfiniti.com
  7. ***************************************************************************
  8. * *
  9. * This program is free software; you can redistribute it and/or modify *
  10. * it under the terms of the GNU General Public License as published by *
  11. * the Free Software Foundation; either version 2 of the License, or *
  12. * (at your option) any later version. *
  13. * *
  14. ***************************************************************************/
  15. #include <QtTest>
  16. #include <QObject>
  17. #include <QApplication>
  18. #include <QDesktopServices>
  19. //qgis includes...
  20. #include <qgsrasterlayer.h>
  21. #include <qgscliptominmaxenhancement.h>
  22. #include <qgscontrastenhancement.h>
  23. #include <qgslinearminmaxenhancement.h>
  24. #include <qgslinearminmaxenhancementwithclip.h>
  25. /** \ingroup UnitTests
  26. * This is a unit test for the ContrastEnhancements contrast enhancement classes.
  27. */
  28. class TestContrastEnhancements: public QObject
  29. {
  30. Q_OBJECT;
  31. private slots:
  32. void initTestCase();// will be called before the first testfunction is executed.
  33. void cleanupTestCase();// will be called after the last testfunction was executed.
  34. void init() {};// will be called before each testfunction is executed.
  35. void cleanup() {};// will be called after every testfunction.
  36. void clipMinMaxEnhancementTest();
  37. void linearMinMaxEnhancementWithClipTest();
  38. void linearMinMaxEnhancementTest();
  39. private:
  40. QString mReport;
  41. };
  42. //runs before all tests
  43. void TestContrastEnhancements::initTestCase()
  44. {
  45. mReport += "<h1>Raster Contrast Enhancement Tests</h1>\n";
  46. }
  47. //runs after all tests
  48. void TestContrastEnhancements::cleanupTestCase()
  49. {
  50. QString myReportFile = QDir::tempPath() + QDir::separator() + "contrastenhancementest.html";
  51. QFile myFile( myReportFile );
  52. if ( myFile.open( QIODevice::WriteOnly ) )
  53. {
  54. QTextStream myQTextStream( &myFile );
  55. myQTextStream << mReport;
  56. myFile.close();
  57. QDesktopServices::openUrl( "file://" + myReportFile );
  58. }
  59. }
  60. void TestContrastEnhancements::clipMinMaxEnhancementTest()
  61. {
  62. //Clips 0 < x < 10, 240 < X < 256
  63. //Stretch no stretch is applied
  64. QgsClipToMinMaxEnhancement myEnhancement( QgsContrastEnhancement::QGS_Byte, 10.0, 240.0 );
  65. // Original pixel value 0.0 Should be out of range thus clipped
  66. QVERIFY( !myEnhancement.isValueInDisplayableRange( 0.0 ) );
  67. //Original pixel value of 10.0 should be scaled to 10.0
  68. QVERIFY( 10.0 == myEnhancement.enhance( 10.0 ) ) ;
  69. //Original pixel value of 240 should be scaled to 240
  70. QVERIFY( 240.0 == myEnhancement.enhance( 240.0 ) ) ;
  71. }
  72. void TestContrastEnhancements::linearMinMaxEnhancementWithClipTest()
  73. {
  74. //First clips 0 < x < 10, 240 < X < 256
  75. //Then stretch 10 = 0, 240 = 255 linearly distribute values 10 -> 240 between 0 -> 255
  76. QgsLinearMinMaxEnhancementWithClip myEnhancement( QgsContrastEnhancement::QGS_Byte, 10.0, 240.0 );
  77. // Original pixel value 0.0 Should be out of range thus clipped
  78. QVERIFY( !myEnhancement.isValueInDisplayableRange( 0.0 ) );
  79. //Original pixel value of 10.0 should be scaled to 0.0
  80. QVERIFY( 0.0 == myEnhancement.enhance( 10.0 ) ) ;
  81. //Original pixel value of 240 should be scaled to 255
  82. QVERIFY( 255.0 == myEnhancement.enhance( 240.0 ) ) ;
  83. }
  84. void TestContrastEnhancements::linearMinMaxEnhancementTest()
  85. {
  86. //Stretch 10 = 0, 240 = 255 linearly distribute values 10 -> 240 between 0 -> 255
  87. QgsLinearMinMaxEnhancement myEnhancement( QgsContrastEnhancement::QGS_Byte, 10.0, 240.0 );
  88. //0 should be scaled to 10 and not clipped
  89. QVERIFY( myEnhancement.isValueInDisplayableRange( 0.0 ) );
  90. //Original pixel value of 10.0 should be scaled to 0.0
  91. QVERIFY( 0.0 == myEnhancement.enhance( 10.0 ) ) ;
  92. //Original pixel value of 240 should be scaled to 255
  93. QVERIFY( 255.0 == myEnhancement.enhance( 240.0 ) ) ;
  94. }
  95. QTEST_MAIN( TestContrastEnhancements )
  96. #include "moc_testcontrastenhancements.cxx"