From b876c3efc5b917622a23b68fc17819d4540690b9 Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Thu, 18 Nov 2010 10:36:51 +0100
Subject: [PATCH] Add otbComplexToVectorImageCastFilter class + tests

---
 .../otbComplexToVectorImageCastFilter.h       | 107 ++++++++++++++++++
 Testing/Code/BasicFilters/CMakeLists.txt      |  15 +++
 .../BasicFilters/otbBasicFiltersTests13.cxx   |   2 +
 .../otbComplexToVectorImageCastFilter.cxx     |  69 +++++++++++
 4 files changed, 193 insertions(+)
 create mode 100644 Code/BasicFilters/otbComplexToVectorImageCastFilter.h
 create mode 100644 Testing/Code/BasicFilters/otbComplexToVectorImageCastFilter.cxx

diff --git a/Code/BasicFilters/otbComplexToVectorImageCastFilter.h b/Code/BasicFilters/otbComplexToVectorImageCastFilter.h
new file mode 100644
index 0000000000..dac095af3f
--- /dev/null
+++ b/Code/BasicFilters/otbComplexToVectorImageCastFilter.h
@@ -0,0 +1,107 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+#ifndef __otbComplexToVectorImageCastFilter_h
+#define __otbComplexToVectorImageCastFilter_h
+
+#include "otbUnaryFunctorImageFilter.h"
+#include "vnl/vnl_math.h"
+
+namespace otb
+{
+  
+/** \class ComplexToVectorImageCastFilter
+ * \brief Transfomr a complex image into a 2 channels vector image.
+ * The first channel is the real part, the second the imaginary one.
+ * 
+ * 
+ * \sa ComplexToImaginaryImageFilter
+ * \sa ComplexToRealImageFilter
+ */
+namespace Functor {  
+  
+template< class TInput, class TOutput>
+class ComplexToVector
+{
+public:
+  typedef typename TOutput::ValueType OutputValueType;
+
+ ComplexToVector() {}
+  ~ComplexToVector() {}
+
+  // This is an obligation to use the functor in otbUnaryFunctorImageFilter
+  unsigned int GetOutputSize()
+    {
+      return 2;
+    }
+
+  inline TOutput operator()( const TInput & A ) const
+    {
+      TOutput output;
+      output.SetSize(2);
+      
+      output[0] = static_cast<OutputValueType>(A.real());
+      output[1] = static_cast<OutputValueType>(A.imag()); 
+      
+      return output;
+    }
+}; 
+}
+
+template <class TInputImage, class TOutputImage>
+class ITK_EXPORT ComplexToVectorImageCastFilter :
+    public
+otb::UnaryFunctorImageFilter<TInputImage,TOutputImage, 
+                        Functor::ComplexToVector< 
+  typename TInputImage::PixelType, 
+  typename TOutputImage::PixelType>   >
+{
+public:
+  /** Standard class typedefs. */
+  typedef ComplexToVectorImageCastFilter  Self;
+  typedef otb::UnaryFunctorImageFilter<
+    TInputImage,TOutputImage, 
+    Functor::ComplexToVector< typename TInputImage::PixelType, 
+    typename TOutputImage::PixelType> >                        Superclass;
+  typedef itk::SmartPointer<Self>             Pointer;
+  typedef itk::SmartPointer<const Self>       ConstPointer;
+
+  /** Method for creation through the object factory. */
+  itkNewMacro(Self);
+
+  /** Runtime information support. */
+  itkTypeMacro(ComplexToVectorImageCastFilter, 
+               otb::UnaryFunctorImageFilter);
+
+  typedef typename TInputImage::PixelType    InputPixelType;
+  typedef typename TOutputImage::PixelType   OutputPixelType;
+
+
+protected:
+  ComplexToVectorImageCastFilter() {}
+  virtual ~ComplexToVectorImageCastFilter() {}
+
+private:
+  ComplexToVectorImageCastFilter(const Self&); //purposely not implemented
+  void operator=(const Self&); //purposely not implemented
+
+};
+
+} // end namespace otb
+
+
+#endif
diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt
index ba96a7cf7c..a00f93edc2 100644
--- a/Testing/Code/BasicFilters/CMakeLists.txt
+++ b/Testing/Code/BasicFilters/CMakeLists.txt
@@ -1800,6 +1800,20 @@ ADD_TEST(bfTvImaginaryImageToComplexImageFilterTest ${BASICFILTERS_TESTS13}
   ${INPUTDATA}/GomaAvant.png
 )
 
+ADD_TEST(bfTuComplexToVectorImageCastFilterNew ${BASICFILTERS_TESTS13}
+  otbComplexToVectorImageCastFilterNew
+)
+
+ADD_TEST(bfTuComplexToVectorImageCastFilterTest ${BASICFILTERS_TESTS13}
+  --compare-image ${NOTOL}
+  ${TEMP}/bfTvComplexToVectorImageCastFilterTest.tif
+  ${BASELINE}/bfTvComplexToVectorImageCastFilterTest.tif
+  otbComplexToVectorImageCastFilterTest
+    ${INPUTDATA}/RSAT_imagery_HH.tif
+    ${TEMP}/bfTvComplexToVectorImageCastFilterTest.tif
+)
+
+
 
 # A enrichir
 SET(BasicFilters_SRCS1
@@ -2052,6 +2066,7 @@ otbComplexToIntensityFilterTest.cxx
 otbRealAndImaginaryImageToComplexImageFilterTest.cxx
 otbRealImageToComplexImageFilterTest.cxx
 otbImaginaryImageToComplexImageFilterTest.cxx
+otbComplexToVectorImageCastFilter.cxx
 )
 
 
diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx
index d6bdf233b8..615c791a9c 100644
--- a/Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx
+++ b/Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx
@@ -33,4 +33,6 @@ void RegisterTests()
   REGISTER_TEST(otbRealAndImaginaryImageToComplexImageFilterTest);
   REGISTER_TEST(otbRealImageToComplexImageFilterTest);
   REGISTER_TEST(otbImaginaryImageToComplexImageFilterTest);
+  REGISTER_TEST(otbComplexToVectorImageCastFilterNew);
+  REGISTER_TEST(otbComplexToVectorImageCastFilterTest);
 }
diff --git a/Testing/Code/BasicFilters/otbComplexToVectorImageCastFilter.cxx b/Testing/Code/BasicFilters/otbComplexToVectorImageCastFilter.cxx
new file mode 100644
index 0000000000..73b7745264
--- /dev/null
+++ b/Testing/Code/BasicFilters/otbComplexToVectorImageCastFilter.cxx
@@ -0,0 +1,69 @@
+/*=========================================================================
+
+  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 "itkExceptionObject.h"
+
+#include "otbComplexToVectorImageCastFilter.h"
+#include "otbVectorImage.h"
+#include "otbImage.h"
+#include "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+
+
+int otbComplexToVectorImageCastFilterNew(int argc, char * argv[])
+{
+  typedef std::complex<float>        ComplexType;
+  typedef otb::Image<ComplexType, 2> CplxImageType;
+  typedef otb::VectorImage<float, 2> VectorImageType;
+
+  typedef otb::ComplexToVectorImageCastFilter<CplxImageType, VectorImageType> FilterType;
+
+  // Instantiating object
+  FilterType::Pointer caster = FilterType::New();
+
+
+  return EXIT_SUCCESS;
+}
+
+int otbComplexToVectorImageCastFilterTest(int argc, char * argv[])
+{
+  const char * infname      = argv[1];
+  const char * outfname     = argv[2];
+  
+  typedef std::complex<float>        ComplexType;
+  typedef otb::Image<ComplexType, 2> CplxImageType;
+  typedef otb::VectorImage<float, 2> VectorImageType;
+
+  typedef otb::ComplexToVectorImageCastFilter<CplxImageType, VectorImageType> FilterType;
+  typedef otb::ImageFileReader<CplxImageType>                                 ReaderType;
+  typedef otb::ImageFileWriter<VectorImageType>                               WriterType;
+ 
+
+   // Instantiating objects
+  ReaderType::Pointer reader = ReaderType::New();
+  WriterType::Pointer writer = WriterType::New();
+  FilterType::Pointer caster = FilterType::New();
+
+  reader->SetFileName(argv[1]);
+  caster->SetInput(reader->GetOutput());
+  writer->SetFileName(argv[2]);
+  writer->SetInput( caster->GetOutput());
+
+  writer->Update();
+
+  return EXIT_SUCCESS;
+}
-- 
GitLab