From b537cc2566eebe5c1101cc0371e8ce8cb9cfa942 Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Mon, 6 Sep 2010 18:55:37 +0200
Subject: [PATCH] ENH : tests for Optimized Resample Image Filter

---
 Testing/Code/Projections/CMakeLists.txt       |  25 +++++
 .../Projections/otbOptResampleImageFilter.cxx | 105 ++++++++++++++++++
 .../otbOptResampleImageFilterNew.cxx          |  39 +++++++
 .../Code/Projections/otbProjectionsTests4.cxx |  31 ++++++
 4 files changed, 200 insertions(+)
 create mode 100644 Testing/Code/Projections/otbOptResampleImageFilter.cxx
 create mode 100644 Testing/Code/Projections/otbOptResampleImageFilterNew.cxx
 create mode 100644 Testing/Code/Projections/otbProjectionsTests4.cxx

diff --git a/Testing/Code/Projections/CMakeLists.txt b/Testing/Code/Projections/CMakeLists.txt
index b43b7c73e1..ebab0ef270 100644
--- a/Testing/Code/Projections/CMakeLists.txt
+++ b/Testing/Code/Projections/CMakeLists.txt
@@ -18,6 +18,7 @@ SET(EPSILON_6 0.000001)
 SET(PROJECTIONS_TESTS1 ${CXX_TEST_PATH}/otbProjectionsTests1)
 SET(PROJECTIONS_TESTS2 ${CXX_TEST_PATH}/otbProjectionsTests2)
 SET(PROJECTIONS_TESTS3 ${CXX_TEST_PATH}/otbProjectionsTests3)
+SET(PROJECTIONS_TESTS4 ${CXX_TEST_PATH}/otbProjectionsTests4)
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbPROJECTIONS_TESTS1 ~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -578,6 +579,23 @@ ADD_TEST(prTvVectorDataExtractROIandProjection ${PROJECTIONS_TESTS3}
 )
 ENDIF(OTB_DATA_USE_LARGEINPUT)
 
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbPROJECTIONS_TESTS4 ~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ADD_TEST(prTuOptResampleImageFilterNew ${PROJECTIONS_TESTS4}
+  otbOptResampleImageFilterNew
+  )
+
+IF(OTB_DATA_USE_LARGEINPUT)
+ADD_TEST(prTvOptResampleImageFilter ${PROJECTIONS_TESTS4}
+  otbOptResampleImageFilter
+  ${LARGEINPUT}/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF
+  500
+  ${TEMP}/prTvotbOptResampledImage.tif
+  )
+ENDIF(OTB_DATA_USE_LARGEINPUT)
+
 
 
 
@@ -627,8 +645,15 @@ otbVectorDataExtractROIandProjection.cxx
 )
 
 
+SET(Projections_SRCS4
+otbProjectionsTests4.cxx
+otbOptResampleImageFilterNew.cxx
+otbOptResampleImageFilter.cxx
+)
+
 OTB_ADD_EXECUTABLE(otbProjectionsTests1 "${Projections_SRCS1}" "OTBProjections;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbProjectionsTests2 "${Projections_SRCS2}" "OTBProjections;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbProjectionsTests3 "${Projections_SRCS3}" "OTBProjections;OTBIO;OTBTesting")
+OTB_ADD_EXECUTABLE(otbProjectionsTests4 "${Projections_SRCS4}" "OTBProjections;OTBIO;OTBTesting")
 
 ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
diff --git a/Testing/Code/Projections/otbOptResampleImageFilter.cxx b/Testing/Code/Projections/otbOptResampleImageFilter.cxx
new file mode 100644
index 0000000000..7b21380a16
--- /dev/null
+++ b/Testing/Code/Projections/otbOptResampleImageFilter.cxx
@@ -0,0 +1,105 @@
+/*=========================================================================
+
+  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 "otbOptResampleImageFilter.h"
+#include "otbVectorImage.h"
+#include "itkVector.h"
+#include "otbImageFileReader.h"
+#include "otbStreamingImageFileWriter.h"
+#include "otbImageFileWriter.h"
+#include "otbImage.h"
+
+// Transform 
+#include "itkTransform.h"
+#include "itkAffineTransform.h"
+
+int otbOptResampleImageFilter(int argc, char* argv[])
+{
+  const char * infname = argv[1];
+  const char * outfname = argv[3];
+  unsigned int isize    = atoi(argv[2]);
+  
+  // Images definition
+  const unsigned int Dimension = 2;
+  typedef double                                      PixelType;
+  typedef otb::VectorImage<PixelType, Dimension>      ImageType;
+  typedef itk::Vector<PixelType, 2>                   DeformationValueType;
+  typedef otb::Image<DeformationValueType, Dimension> DeformationFieldType;
+
+  typedef itk::Transform<
+    PixelType, Dimension, Dimension>     TransformType;
+
+  typedef itk::AffineTransform<
+    PixelType, Dimension>              AffineTransformType;
+  
+  // 
+  typedef otb::OptResampleImageFilter<ImageType, ImageType, DeformationFieldType> ImageResamplerType;
+
+  typedef otb::ImageFileReader<ImageType>         ReaderType;
+
+  // Instantiate an affine transformation Pointer
+  AffineTransformType::Pointer affineTransform    = AffineTransformType::New();
+  // Istantiate a Resampler
+  ImageResamplerType::Pointer resampler = ImageResamplerType::New();
+  // Instanciate reader
+  ReaderType::Pointer reader = ReaderType::New();
+
+  // Get the image file
+  reader->SetFileName(infname);
+  reader->UpdateOutputInformation();
+  
+  /** Set the options. */
+  ImageResamplerType::OriginType centerOfRotation;
+  centerOfRotation[ 0 ] = -3.0; centerOfRotation[ 1 ] = -3.0;
+  affineTransform->SetCenter( centerOfRotation );
+  
+  /** Create and set parameters. */
+  AffineTransformType::ParametersType parameters( affineTransform->GetNumberOfParameters() );
+  parameters[ 0 ] =   1.1;
+  parameters[ 1 ] =   0.1;
+  parameters[ 2 ] =  -0.2;
+  parameters[ 3 ] =   0.9;
+  parameters[ 4 ] =  10.3;
+  parameters[ 5 ] = -33.8;
+  affineTransform->SetParameters( parameters );
+  
+  // Get the size specified by the user
+  ImageType::SizeType   size;
+  size.Fill(isize);
+  
+  /** Set the OptResampler Parameters*/
+  resampler->SetInput(reader->GetOutput());
+  resampler->SetTransform(affineTransform);
+  resampler->SetDeformationFieldSpacing(5.); // TODO : add the spacing
+                                             // it to the
+                                             // command line
+  resampler->SetOutputSize(size);
+  
+  // Write the resampled image
+  typedef otb::StreamingImageFileWriter<ImageType>    WriterType;
+  WriterType::Pointer writer= WriterType::New();
+  writer->SetTilingStreamDivisions();
+  // TODO : implement the WriteGeomFile in StreamingImageFileWriter
+  //writer->WriteGeomFileOn();
+  writer->SetFileName(outfname);
+  writer->SetInput(resampler->GetOutput());
+  writer->Update();
+
+
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/Projections/otbOptResampleImageFilterNew.cxx b/Testing/Code/Projections/otbOptResampleImageFilterNew.cxx
new file mode 100644
index 0000000000..7a5b99e94d
--- /dev/null
+++ b/Testing/Code/Projections/otbOptResampleImageFilterNew.cxx
@@ -0,0 +1,39 @@
+/*=========================================================================
+
+  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 "otbOptResampleImageFilter.h"
+#include "otbVectorImage.h"
+#include "itkVector.h"
+#include "otbImage.h"
+
+int otbOptResampleImageFilterNew(int argc, char* argv[])
+{
+  // Images definition
+  const unsigned int Dimension = 2;
+  typedef double                                      PixelType;
+  typedef otb::VectorImage<PixelType, Dimension>      ImageType;
+  typedef itk::Vector<PixelType, 2>                   DeformationValueType;
+  typedef otb::Image<DeformationValueType, Dimension> DeformationFieldType;
+
+  // 
+  typedef otb::OptResampleImageFilter<ImageType, ImageType, DeformationFieldType> ImageResamplerType;
+
+  // 
+  ImageResamplerType::Pointer resampler = ImageResamplerType::New();
+  return 0;
+}
diff --git a/Testing/Code/Projections/otbProjectionsTests4.cxx b/Testing/Code/Projections/otbProjectionsTests4.cxx
new file mode 100644
index 0000000000..9061dc8abe
--- /dev/null
+++ b/Testing/Code/Projections/otbProjectionsTests4.cxx
@@ -0,0 +1,31 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+
+// this file defines the otbProjectionsTest for the test driver
+// and all it expects is that you have a function called RegisterTests
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4786 )
+#endif
+
+#include "otbTestMain.h"
+
+void RegisterTests()
+{
+  REGISTER_TEST(otbOptResampleImageFilterNew);
+  REGISTER_TEST(otbOptResampleImageFilter);
+}
-- 
GitLab