From badc6fb4750d482ffad32d04e5be3b06f1b312b4 Mon Sep 17 00:00:00 2001
From: Patrick Imbo <patrick.imbo@c-s.fr>
Date: Mon, 22 Nov 2010 15:12:15 +0100
Subject: [PATCH] ADD: new SarRadiometricCalibration comparaison test

---
 Testing/Code/Radiometry/CMakeLists.txt        |  8 ++
 .../Code/Radiometry/otbRadiometryTests9.cxx   |  1 +
 ...ricCalibrationToImageFilterCompareTest.cxx | 93 +++++++++++++++++++
 3 files changed, 102 insertions(+)
 create mode 100644 Testing/Code/Radiometry/otbSarRadiometricCalibrationToImageFilterCompareTest.cxx

diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt
index 054d1e9136..52a141d1cd 100644
--- a/Testing/Code/Radiometry/CMakeLists.txt
+++ b/Testing/Code/Radiometry/CMakeLists.txt
@@ -1504,6 +1504,13 @@ ADD_TEST(raTvSarRadiometricCalibrationToImageWithComplexPixelFilter_TSX_PANGKALA
 	    1000 1000 250 250 # Extract
 )
 
+ADD_TEST(raTvSarRadiometricCalibrationToImageCompareFilter_TSX_PANGKALANBUUN  ${RADIOMETRY_TESTS9}
+        otbSarRadiometricCalibrationToImageFilterCompareTest
+	    ${LARGEINPUT}/TERRASARX/PANGKALANBUUN/IMAGEDATA/IMAGE_HH_SRA_stripFar_008.cos
+	    1000 1000 250 250 # Extract
+)
+
+
 ADD_TEST(raTvSarRadiometricCalibrationToImageWithComplexPixelFilter_TSX_TORONTO ${RADIOMETRY_TESTS9}
     --compare-image ${EPSILON_12}  
                 ${BASELINE}/raTvSarRadiometricCalibrationToImageFilter_TSX_TORONTO.tif
@@ -1676,6 +1683,7 @@ otbSarBrightnessFunctor.cxx
 otbSarBrightnessFunction.cxx
 otbSarBrightnessToImageFilterTest.cxx
 otbTestVNLMinimize.cxx
+otbSarRadiometricCalibrationToImageFilterCompareTest.cxx
 )
 
 
diff --git a/Testing/Code/Radiometry/otbRadiometryTests9.cxx b/Testing/Code/Radiometry/otbRadiometryTests9.cxx
index 2feacadd2a..74c345a8df 100644
--- a/Testing/Code/Radiometry/otbRadiometryTests9.cxx
+++ b/Testing/Code/Radiometry/otbRadiometryTests9.cxx
@@ -44,4 +44,5 @@ void RegisterTests()
   REGISTER_TEST(otbSarBrightnessFunction);
   REGISTER_TEST(otbSarBrightnessToImageFilterTest);
   REGISTER_TEST(otbTestVNLMinimize);
+  REGISTER_TEST(otbSarRadiometricCalibrationToImageFilterCompareTest);
 }
diff --git a/Testing/Code/Radiometry/otbSarRadiometricCalibrationToImageFilterCompareTest.cxx b/Testing/Code/Radiometry/otbSarRadiometricCalibrationToImageFilterCompareTest.cxx
new file mode 100644
index 0000000000..973ef954f3
--- /dev/null
+++ b/Testing/Code/Radiometry/otbSarRadiometricCalibrationToImageFilterCompareTest.cxx
@@ -0,0 +1,93 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+#include "otbImage.h"
+#include "otbSarRadiometricCalibrationToImageFilter.h"
+#include "otbImageFileReader.h"
+#include "otbExtractROI.h"
+#include "itkComplexToModulusImageFilter.h"
+#include  "otbStreamingCompareImageFilter.h"
+
+int otbSarRadiometricCalibrationToImageFilterCompareTest(int argc, char * argv[])
+{
+  const unsigned int Dimension = 2;
+  typedef float                                                                         RealType;
+  typedef std::complex<RealType>                                                        PixelType;
+  typedef otb::Image<PixelType, Dimension>                                              InputImageType;
+  typedef otb::Image<RealType, Dimension>                                               OutputImageType;
+  typedef otb::ImageFileReader<InputImageType>                                          ReaderType;
+  typedef otb::SarRadiometricCalibrationToImageFilter<InputImageType, OutputImageType>  FilterComplexType;
+  typedef otb::SarRadiometricCalibrationToImageFilter<OutputImageType, OutputImageType> FilterRealType;
+  typedef otb::ExtractROI<RealType, RealType>                                   ExtractorType;
+  typedef itk::ComplexToModulusImageFilter<InputImageType, OutputImageType>             ModulusType;
+  typedef otb::StreamingCompareImageFilter<OutputImageType>                             CompareFilterType;
+
+  // Instantiating object
+  FilterComplexType::Pointer filterComplex = FilterComplexType::New();
+  FilterRealType::Pointer filterReal = FilterRealType::New();
+  ReaderType::Pointer reader = ReaderType::New();
+  ExtractorType::Pointer extractorComplex = ExtractorType::New();
+  ExtractorType::Pointer extractorReal = ExtractorType::New();
+  ModulusType::Pointer modulus = ModulusType::New();
+  CompareFilterType::Pointer compare = CompareFilterType::New();
+
+  reader->SetFileName(argv[1]);
+  filterComplex->SetInput(reader->GetOutput());
+
+  modulus->SetInput(reader->GetOutput());
+  filterReal->SetInput(modulus->GetOutput());
+
+  filterComplex->UpdateOutputInformation();
+  filterReal->UpdateOutputInformation();
+
+  if (argc > 2)
+    {
+    // Generate an extract from the large input
+    OutputImageType::RegionType region;
+    OutputImageType::IndexType  id;
+    id[0] = atoi(argv[2]);   id[1] = atoi(argv[3]);
+    OutputImageType::SizeType size;
+    size[0] = atoi(argv[4]);   size[1] = atoi(argv[5]);
+    region.SetIndex(id);
+    region.SetSize(size);
+
+    extractorComplex->SetExtractionRegion(region);
+    extractorComplex->SetInput(filterComplex->GetOutput());
+
+    extractorReal->SetExtractionRegion(region);
+    extractorReal->SetInput(filterReal->GetOutput());
+
+    compare->SetInput1(extractorComplex->GetOutput());
+    compare->SetInput2(extractorReal->GetOutput());
+    }
+  else
+    {
+    compare->SetInput1(filterComplex->GetOutput());
+    compare->SetInput2(filterReal->GetOutput());
+    }
+
+  compare->Update();
+  if(compare->GetMAE() > 0.00000001)
+    {
+    std::cout << "MAE : " << compare->GetMAE() << std::endl;
+    return EXIT_FAILURE;
+    }
+
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab