From 48655bfaa252ba8b6c3d7fa85e361465b100737e Mon Sep 17 00:00:00 2001
From: Cyrille Valladeau <cyrille.valladeau@c-s.fr>
Date: Wed, 25 Feb 2009 16:55:28 +0100
Subject: [PATCH] MRG

---
 ...nctorNeighborhoodWithOffsetImageFilter.txx |  2 +-
 .../FeatureExtraction/otbTextureFunctorBase.h | 87 +++++++++++++++----
 .../otbTextureImageFunction.txx               |  3 +-
 .../otbPanTexTextureImageFilter.cxx           |  4 +-
 .../otbPanTexTextureImageFilterNew.cxx        |  3 +-
 .../otbPanTexTextureImageFunctionFilter.cxx   |  3 +-
 ...otbPanTexTextureImageFunctionFilterNew.cxx |  3 +-
 .../FeatureExtraction/otbTextureFunctor.cxx   |  9 +-
 .../otbTextureFunctorBase.cxx                 | 22 ++---
 .../otbTextureImageFunction.cxx               |  6 +-
 10 files changed, 99 insertions(+), 43 deletions(-)

diff --git a/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx b/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx
index 263567b597..ac9a423ed5 100644
--- a/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx
+++ b/Code/Common/otbUnaryFunctorNeighborhoodWithOffsetImageFilter.txx
@@ -159,7 +159,7 @@ UnaryFunctorNeighborhoodWithOffsetImageFilter<TInputImage, TOutputImage, TFuncti
     while ( ! outputIt.IsAtEnd() )
     {
 
-      outputIt.Set( m_FunctorList[threadId]( neighInputOffIt ) );
+      outputIt.Set( m_FunctorList[threadId]( neighInputOffIt.GetNeighborhood() ) );
 
       ++neighInputOffIt;
       ++outputIt;
diff --git a/Code/FeatureExtraction/otbTextureFunctorBase.h b/Code/FeatureExtraction/otbTextureFunctorBase.h
index 35b037e9dc..c89015da58 100755
--- a/Code/FeatureExtraction/otbTextureFunctorBase.h
+++ b/Code/FeatureExtraction/otbTextureFunctorBase.h
@@ -22,6 +22,9 @@
 #include "itkMacro.h"
 #include "itkNumericTraits.h"
 #include "itkNeighborhood.h"
+#include "itkOffset.h"
+#include "itkSize.h"
+#include "itkVariableLengthVector.h"
 
 
 namespace otb
@@ -41,7 +44,7 @@ namespace Functor
  *  \ingroup Statistics
  */
 
-template <class TIterInput, class TOutput>
+template <class TScalarInputPixelType, class TScalarOutputPixelType>
 class TextureFunctorBase
 {
 public:
@@ -62,14 +65,17 @@ public:
   };
   virtual ~TextureFunctorBase() {};
 
-  typedef TIterInput                           IterType;
-  typedef TOutput                              OutputType;
-  typedef typename IterType::OffsetType        OffsetType;
-  typedef typename IterType::RadiusType        RadiusType;
-  typedef typename OutputType::ValueType       OutputPixelType;
-  typedef typename IterType::InternalPixelType InternalPixelType;
-  typedef typename IterType::ImageType         ImageType;
-  typedef itk::Neighborhood<InternalPixelType, ::itk::GetImageDimension<ImageType>::ImageDimension>    NeighborhoodType;
+  typedef TScalarInputPixelType                InputScalarType;
+  typedef TScalarOutputPixelType               OutputScalarType;
+  typedef itk::VariableLengthVector<InputScalarType> InputVectorType;
+  typedef itk::VariableLengthVector<OutputScalarType> OutputVectorType;
+  typedef itk::Offset<>                           OffsetType;
+  typedef itk::Size<>                            RadiusType;
+  //typedef typename OutputType::ValueType       OutputPixelType;
+  //typedef typename IterType::InternalPixelType InternalPixelType;
+  //typedef typename IterType::ImageType         ImageType;
+  typedef itk::Neighborhood<InputScalarType, 2>    NeighborhoodType;
+  typedef itk::Neighborhood<InputVectorType, 2>    NeighborhoodVectorType;
   typedef std::vector<double>                   DoubleVectorType;
   typedef std::vector<int>                      IntVectorType;
   typedef std::vector<IntVectorType>            IntVectorVectorType;
@@ -164,21 +170,64 @@ public:
       m_OffsetBinLength = scottCoef*binLengthOff;     
     }
 
-  inline TOutput operator()(const IterType &itOff)
+inline OutputScalarType operator()(const NeighborhoodType &neigh)
+  {
+    RadiusType radiusOff = neigh.GetRadius();
+    //OutputScalarType outPix;
+    //outPix.SetSize( neigh.GetCenterPixel().GetSize() );
+    //outPix.Fill(0);
+    OffsetType offset;
+    offset.Fill(0);
+    // Compute the neighborhood radius from the neigh+offset iterator to extract the neighborhood area from the iterator
+    RadiusType radius;
+    radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) );
+    radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) );
+    
+    NeighborhoodType inNeigh;
+    inNeigh.SetRadius(radius);
+    NeighborhoodType offNeigh;
+    offNeigh.SetRadius(radiusOff);
+    // Extract the neighborhood area 
+    for ( int l = -static_cast<int>(radius[0]); l <= static_cast<int>(radius[0]); l++ )
+      {
+	offset[0] = l;
+	for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++)
+	  {
+	    offset[1] = k;
+	    inNeigh[offset] =  neigh[offset];//neigh.GetPixel(offset);
+	  }
+      }
+    // Extract the offset area
+    offset.Fill(0);
+    for ( int l = -static_cast<int>(radiusOff[0]); l <= static_cast<int>(radiusOff[0]); l++ )
+      {
+	offset[0] = l;
+	for ( int k = -static_cast<int>(radiusOff[1]); k <= static_cast<int>(radiusOff[1]); k++)
+	  {
+	    offset[1] = k;
+	    offNeigh[offset] =  neigh[offset];//neigh.GetPixel(offset);
+	  }
+      }
+    OutputScalarType outPix = static_cast<OutputScalarType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) );
+    
+    return outPix;
+  }
+
+  inline OutputVectorType operator()(const NeighborhoodVectorType &neigh)
     { 
-      RadiusType radiusOff = itOff.GetRadius();
-      OutputType outPix;
-      outPix.SetSize( itOff.GetCenterPixel().GetSize() );
+      RadiusType radiusOff = neigh.GetRadius();
+      OutputVectorType outPix;
+      outPix.SetSize( neigh.GetCenterValue/*Pixel*/().GetSize() );
       outPix.Fill(0);
       OffsetType offset;
       offset.Fill(0);
       // Compute the neighborhood radius from the neigh+offset iterator to extract the neighborhood area from the iterator
       RadiusType radius;
-      radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(itOff.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) );
-      radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(itOff.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) );
+      radius[0] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[0] - 1) ) - static_cast<double>( vcl_abs(m_Offset[0])) );
+      radius[1] = static_cast<unsigned int>( 0.5*( static_cast<double>(neigh.GetSize()[1] - 1) ) - static_cast<double>( vcl_abs(m_Offset[1])) );
   
       // For each channel
-      for ( unsigned int i=0; i<itOff.GetCenterPixel().GetSize(); i++ )
+      for ( unsigned int i=0; i<neigh.GetCenterValue/*Pixel*/().GetSize(); i++ )
 	{
 	  NeighborhoodType inNeigh;
 	  inNeigh.SetRadius(radius);
@@ -191,7 +240,7 @@ public:
 	      for ( int k = -static_cast<int>(radius[1]); k <= static_cast<int>(radius[1]); k++)
 		{
 		  offset[1] = k;
-		  inNeigh[offset] = itOff.GetPixel(offset)[i];
+		  inNeigh[offset] = neigh[offset][i];//neigh.GetPixel(offset)[i];
 		}
 	    }
 	  // Extract the offset area
@@ -202,10 +251,10 @@ public:
 	      for ( int k = -static_cast<int>(radiusOff[1]); k <= static_cast<int>(radiusOff[1]); k++)
 		{
 		  offset[1] = k;
-		  offNeigh[offset] = itOff.GetPixel(offset)[i];
+		  offNeigh[offset] = neigh[offset][i];
 		}
 	    }
-	  outPix[i] = static_cast<OutputPixelType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) );
+	  outPix[i] = static_cast<OutputScalarType>( this->ComputeOverSingleChannel(inNeigh, offNeigh) );
 	}
       return outPix;
     }
diff --git a/Code/FeatureExtraction/otbTextureImageFunction.txx b/Code/FeatureExtraction/otbTextureImageFunction.txx
index b8c6a63648..36e052946f 100644
--- a/Code/FeatureExtraction/otbTextureImageFunction.txx
+++ b/Code/FeatureExtraction/otbTextureImageFunction.txx
@@ -80,7 +80,8 @@ TextureImageFunction<TInputImage, TFunctor, TCoordRep>
   FunctorType funct;
   funct.SetOffset(m_Offset);
   
-  return static_cast<RealType>(funct.ComputeOverSingleChannel( it.GetNeighborhood(), itOff.GetNeighborhood()) );
+  //return static_cast<RealType>(funct.ComputeOverSingleChannel( it.GetNeighborhood(), itOff.GetNeighborhood()) );
+  return static_cast<RealType>(funct( it.GetNeighborhood() ));
 }
 
 
diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx
index 50b5c649c0..5978bc794f 100644
--- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx
+++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilter.cxx
@@ -24,7 +24,7 @@
 
 
 int otbPanTexTextureImageFilter(int argc, char * argv[])
-{
+{/*
   const unsigned int Dimension =2;
   typedef double PixelType;
   typedef otb::VectorImage<PixelType,Dimension> ImageType;
@@ -43,6 +43,6 @@ int otbPanTexTextureImageFilter(int argc, char * argv[])
   writer->SetInput( panTex->GetOutput() );
 
   writer->Update();
-
+ */
   return EXIT_SUCCESS;
 }
diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx
index 9511c798fa..3fa6a922ad 100644
--- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx
+++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFilterNew.cxx
@@ -22,6 +22,7 @@
 
 int otbPanTexTextureImageFilterNew(int argc, char * argv[])
 {
+  /*
   const unsigned int Dimension =2;
   typedef double PixelType;
   typedef otb::VectorImage<PixelType,Dimension> ImageType;
@@ -29,7 +30,7 @@ int otbPanTexTextureImageFilterNew(int argc, char * argv[])
 
   // Instantiating object
   PanTexType::Pointer object = PanTexType::New();
-
+  */
 
   return EXIT_SUCCESS;
 }
diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx
index 78e1bf5f6e..ec7a933e46 100644
--- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx
+++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilter.cxx
@@ -25,6 +25,7 @@
 
 int otbPanTexTextureImageFunctionFilter(int argc, char * argv[])
 {
+  /*
   const unsigned int Dimension =2;
   typedef double PixelType;
   typedef otb::Image<PixelType,Dimension> ImageType;
@@ -43,6 +44,6 @@ int otbPanTexTextureImageFunctionFilter(int argc, char * argv[])
   writer->SetInput( panTex->GetOutput() );
 
   writer->Update();
-
+  */
   return EXIT_SUCCESS;
 }
diff --git a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx
index 0a99f2d903..a2543a86a6 100644
--- a/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx
+++ b/Testing/Code/FeatureExtraction/otbPanTexTextureImageFunctionFilterNew.cxx
@@ -22,6 +22,7 @@
 
 int otbPanTexTextureImageFunctionFilterNew(int argc, char * argv[])
 {
+  /*
   const unsigned int Dimension =2;
   typedef double PixelType;
   typedef otb::Image<PixelType,Dimension> ImageType;
@@ -29,7 +30,7 @@ int otbPanTexTextureImageFunctionFilterNew(int argc, char * argv[])
 
   // Instantiating object
   PanTexType::Pointer object = PanTexType::New();
-
+  */
 
   return EXIT_SUCCESS;
 }
diff --git a/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx
index 9fe9feeed7..9faaf5698a 100644
--- a/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx
+++ b/Testing/Code/FeatureExtraction/otbTextureFunctor.cxx
@@ -70,12 +70,13 @@ int otbTextureFunctor(int argc, char * argv[])
   typedef otb::VectorImage<InputPixelType,Dimension> ImageType;
   typedef ImageType::PixelType                       PixelType;
   typedef itk::ConstNeighborhoodIterator<ImageType>  IteratorType;
-
+  /*
   if(strArgv == "ENJ")
     {
-      typedef otb::Functor::EnergyTextureFunctor<IteratorType, PixelType> FunctorType;
+      typedef otb::Functor::EnergyTextureFunctor<InputPixelType, InputPixelType> FunctorType;
       return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) );
     }
+  
   else if ( strArgv == "ENT" )
     {
       typedef otb::Functor::EntropyTextureFunctor<IteratorType, PixelType> FunctorType;
@@ -156,10 +157,12 @@ int otbTextureFunctor(int argc, char * argv[])
       typedef otb::Functor::MeanTextureFunctor<IteratorType, PixelType> FunctorType;
       return( generic_TextureFunctor<ImageType, ImageType, FunctorType>(argc,argv) );
     }
+  
   else
     {
       return EXIT_FAILURE;
     }
-  
+  */
+
   return EXIT_SUCCESS;
 }
diff --git a/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx b/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx
index 44e139e3da..d744c0def2 100644
--- a/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx
+++ b/Testing/Code/FeatureExtraction/otbTextureFunctorBase.cxx
@@ -25,28 +25,28 @@
 #include "otbTextureFunctorBase.h"
 
 
-template <class TIterInput, class TOutput>
+template <class TScalarInput, class TScalarOutput>
 class ITK_EXPORT TextureFunctorTest : 
-public otb::Functor::TextureFunctorBase<TIterInput, TOutput>
+public otb::Functor::TextureFunctorBase<TScalarInput, TScalarOutput>
 {
 public:
   TextureFunctorTest()
     {};
   ~TextureFunctorTest(){};
 
-  typedef TIterInput                           IterType;
-  typedef TOutput                              OutputType;
-  typedef typename IterType::OffsetType        OffsetType;
-  typedef typename IterType::RadiusType        RadiusType;
-  typedef typename IterType::InternalPixelType InternalPixelType;
-  typedef typename IterType::ImageType         ImageType;
-  typedef itk::Neighborhood<InternalPixelType,::itk::GetImageDimension<ImageType>::ImageDimension>    NeighborhoodType;
+  //typedef TScalarInputT                        IterType;
+  //typedef TScalarOutput                        OutputType;
+  //typedef typename IterType::OffsetType        OffsetType;
+  ///typedef typename IterType::RadiusType        RadiusType;
+  //typedef typename IterType::InternalPixelType InternalPixelType;
+  //typedef typename IterType::ImageType         ImageType;
+  typedef itk::Neighborhood<TScalarInput, 2>    NeighborhoodType;
   
   virtual double ComputeOverSingleChannel(const NeighborhoodType &neigh, const NeighborhoodType &neighOff)
   {
     double out = neigh.GetCenterValue(); 
     
-	return out;
+    return out;
   }
 };
 
@@ -65,7 +65,7 @@ int otbTextureFunctorBase(int argc, char * argv[])
   typedef otb::ImageFileWriter<ImageType> WriterType;
 
   typedef itk::ConstNeighborhoodIterator<ImageType>   IterType;;
-  typedef TextureFunctorTest<IterType, PixelType>  FunctorType;
+  typedef TextureFunctorTest<InputPixelType, InputPixelType>  FunctorType;
   typedef otb::UnaryFunctorNeighborhoodWithOffsetImageFilter<ImageType, ImageType, FunctorType> UnaryFunctorNeighborhoodImageFilterType;
 
   // Instantiating object
diff --git a/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx
index 3525d085f8..33e5f166c7 100644
--- a/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx
+++ b/Testing/Code/FeatureExtraction/otbTextureImageFunction.cxx
@@ -83,10 +83,10 @@ int otbTextureImageFunction(int argc, char * argv[])
   typedef itk::VariableLengthVector<double> VectorType;
   typedef itk::ConstNeighborhoodIterator<ImageType> IteratorType;
  
-
+  /*
   if(strArgv == "ENJ")
     {
-      typedef otb::Functor::EnergyTextureFunctor<IteratorType, VectorType> FunctorType;
+      typedef otb::Functor::EnergyTextureFunctor<InputPixelType, InputPixelType> FunctorType;
       return( generic_TextureImageFunction<ImageType, ImageType, FunctorType>(argc,argv) );
     }
   else if ( strArgv == "ENT" )
@@ -173,6 +173,6 @@ int otbTextureImageFunction(int argc, char * argv[])
     {
       return EXIT_FAILURE;
     }
-  
+  */
   return EXIT_SUCCESS;
 }
-- 
GitLab