From a9ea9612f77169636900104112b3c2561ebf9e0d Mon Sep 17 00:00:00 2001
From: Manuel Grizonnet <manuel.grizonnet@orfeo-toolbox.org>
Date: Wed, 12 Oct 2011 17:05:54 +0200
Subject: [PATCH] ENH:new hyperspectral unmixing example (not added yet in
 OTB-Documents -> extract of aviris data to big for the OTB-Data repository)

---
 Examples/Hyperspectral/CMakeLists.txt         | 21 ++++++++++++++-----
 .../HyperspectralUnmixingExample.cxx          |  9 ++++----
 .../otbHyperspectralExamplesTests.cxx         |  2 +-
 3 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/Examples/Hyperspectral/CMakeLists.txt b/Examples/Hyperspectral/CMakeLists.txt
index cd15a3b55c..da575fe359 100644
--- a/Examples/Hyperspectral/CMakeLists.txt
+++ b/Examples/Hyperspectral/CMakeLists.txt
@@ -5,37 +5,48 @@
 PROJECT(HyperspectralExamples)
 INCLUDE_REGULAR_EXPRESSION("^.*$")
 
-ADD_EXECUTABLE(HyperspectralUnmixingExample HyperspectralUnmixing.cxx )
+ADD_EXECUTABLE(HyperspectralUnmixingExample HyperspectralUnmixingExample.cxx )
 TARGET_LINK_LIBRARIES(HyperspectralUnmixingExample OTBCommon OTBIO OTBHyperspectral)
 
 
 IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
 
-SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Hyperspctral)
+SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Hyperspectral)
 SET(BASELINE_IMAGES_OTB ${OTB_DATA_ROOT}/Baseline/OTB/Images)
 
 SET(INPUTDATA_EXAMPLES ${OTB_DATA_ROOT}/Examples)
 SET(INPUTDATA ${OTB_DATA_ROOT}/Input)
 SET(TEMP ${OTB_BINARY_DIR}/Testing/Temporary)
 
+IF(OTB_DATA_USE_LARGEINPUT)
+  SET(IMAGEDATA ${OTB_DATA_LARGEINPUT_ROOT} )
+ENDIF(OTB_DATA_USE_LARGEINPUT)
+
 SET(EXE_TESTS ${CXX_TEST_PATH}/otbHyperspectralExamplesTests)
 
 SET(TOL 0.0)
 
 # tests#
 # ------- HyperspectralUnmixingExampleTest ----------
+IF(OTB_DATA_USE_LARGEINPUT)
 
 ADD_TEST(siTvHyperspectralExampleTest ${EXE_TESTS}
-     #--compare-image ${TOL} ${BASELINE}/siTvUnmixingExampleTest.txt
-     #              ${TEMP}/siTvUnmixingExampleTest.txt
+     --compare-n-images ${TOL} 3
+     ${BASELINE}/siTvHyperspectralUnmixingExampleTestBand1.png
+     ${TEMP}/siTvHyperspectralUnmixingExampleTestBand1.png
+     ${BASELINE}/siTvHyperspectralUnmixingExampleTestBand2.png
+     ${TEMP}/siTvHyperspectralUnmixingExampleTestBand2.png
+     ${BASELINE}/siTvHyperspectralUnmixingExampleTestBand3.png
+     ${TEMP}/siTvHyperspectralUnmixingExampleTestBand3.png
      HyperspectralUnmixingExample
-     ${INPUTDATA_EXAMPLES}/Indian_pines_corrected.tif
+     ${IMAGEDATA}/AVIRIS/Indian_pines_corrected.tif
      ${TEMP}/siTvHyperspectralUnmixingExampleTest.tif
      ${TEMP}/siTvHyperspectralUnmixingExampleTestBand1.png
      ${TEMP}/siTvHyperspectralUnmixingExampleTestBand2.png
      ${TEMP}/siTvHyperspectralUnmixingExampleTestBand3.png
      16
 )
+ENDIF(OTB_DATA_USE_LARGEINPUT)
 
 INCLUDE_DIRECTORIES(${OTB_SOURCE_DIR}/Testing/Code)
 
diff --git a/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx b/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx
index 26476ec34b..29fc6e21e7 100644
--- a/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx
+++ b/Examples/Hyperspectral/HyperspectralUnmixingExample.cxx
@@ -18,7 +18,6 @@
 #include "otbVectorImage.h"
 #include "otbImageFileReader.h"
 #include "otbImageFileWriter.h"
-#include "otbStreamingStatisticsVectorImageFilter.h"
 #include "otbVectorRescaleIntensityImageFilter.h"
 #include "otbVectorImageToMatrixImageFilter.h"
 #include "itkRescaleIntensityImageFilter.h"
@@ -45,6 +44,7 @@
 #include "otbVcaImageFilter.h"
 #include "otbUnConstrainedLeastSquareImageFilter.h"
 // Software Guide : EndCodeSnippet
+
 int main(int argc, char * argv[])
 {
   if (argc != 7)
@@ -83,8 +83,7 @@ int main(int argc, char * argv[])
 
   typedef vnl_vector<double> VectorType;
   typedef vnl_matrix<double> MatrixType;
-
-  // Software Guide : EndCodeSnippet
+  
   // Software Guide : BeginLatex
   //
   // We instantiate now the image reader and we set the image file name.
@@ -106,7 +105,6 @@ int main(int argc, char * argv[])
   // \doxygen{otb}{VectorRescaleIntensityImageFilter}.
   //
   // Software Guide : EndLatex
-  //rescale input image between 0 and 1
  
   // Software Guide : BeginCodeSnippet
   RescalerType::Pointer         rescaler = RescalerType::New();
@@ -199,6 +197,7 @@ int main(int argc, char * argv[])
   // \end{figure}
   //
   //  Software Guide : EndLatex
+
   typedef otb::Image<PixelType, Dimension>                        MonoImageType;
   typedef otb::MultiToMonoChannelExtractROI<PixelType, PixelType> ExtractROIFilterType;
   typedef otb::Image<unsigned char, 2>                            OutputImageType;
@@ -225,4 +224,4 @@ int main(int argc, char * argv[])
     }
 
   return EXIT_SUCCESS;
-} // end main
+}
diff --git a/Examples/Hyperspectral/otbHyperspectralExamplesTests.cxx b/Examples/Hyperspectral/otbHyperspectralExamplesTests.cxx
index 8a7b0fcd2a..05cc817d17 100644
--- a/Examples/Hyperspectral/otbHyperspectralExamplesTests.cxx
+++ b/Examples/Hyperspectral/otbHyperspectralExamplesTests.cxx
@@ -27,5 +27,5 @@ void RegisterTests()
 }
 
 #undef main
-#define main Unmixing
+#define main HyperspectralUnmixingExample
 #include "HyperspectralUnmixingExample.cxx"
-- 
GitLab