From c1a29d343f3e55cb4d141fe7eba7723dcd5d2f6a Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Fri, 30 Jan 2009 11:08:21 +0100
Subject: [PATCH] ADD: Class KeyPointDensityImage filter & tests

---
 Code/BasicFilters/otbCountImageFilter.txx     | 128 ------------------
 ...lter.h => otbKeyPointDensityImageFilter.h} |  62 ++++-----
 .../otbKeyPointDensityImageFilter.txx         | 121 +++++++++++++++++
 Testing/Code/BasicFilters/CMakeLists.txt      |  22 +--
 .../BasicFilters/otbBasicFiltersTests11.cxx   |   3 +-
 ...x => otbKeyPointDensityImageFilterNew.cxx} |  22 ++-
 .../otbPointSetDensityFunctionTest.cxx        |   2 +-
 7 files changed, 166 insertions(+), 194 deletions(-)
 delete mode 100644 Code/BasicFilters/otbCountImageFilter.txx
 rename Code/BasicFilters/{otbCountImageFilter.h => otbKeyPointDensityImageFilter.h} (59%)
 create mode 100644 Code/BasicFilters/otbKeyPointDensityImageFilter.txx
 rename Testing/Code/BasicFilters/{otbCountImageFilterNew.cxx => otbKeyPointDensityImageFilterNew.cxx} (56%)

diff --git a/Code/BasicFilters/otbCountImageFilter.txx b/Code/BasicFilters/otbCountImageFilter.txx
deleted file mode 100644
index d03536bbef..0000000000
--- a/Code/BasicFilters/otbCountImageFilter.txx
+++ /dev/null
@@ -1,128 +0,0 @@
-/*=========================================================================
-
-Program:   ORFEO Toolbox
-Language:  C++
-Date:      $Date$
-Version:   $Revision$
-
-
-Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
-See OTBCopyright.txt for details.
-
-Copyright (c) CS systèmes d'information. All rights reserved.
-See CSCopyright.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 "otbCountImageFilter.h"
-#include "itkImageRegionIterator.h"
-
-
-namespace otb
-{
-  /**---------------------------------------------------------
-   * Constructor
-   ----------------------------------------------------------*/
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  CountImageFilter<TInputImage , TDetector, TCount, TOutputImage>
-  ::CountImageFilter()
-  {
-    this->SetNumberOfRequiredInputs( 1 );
-    m_CountImageFunction = CountImageFunctionType::New();
-    m_NeighborhoodRadius = 1;
-  }
-
-
- /*---------------------------------------------------------
-  * Destructor.c
-  ----------------------------------------------------------*/
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  CountImageFilter<TInputImage, TDetector, TCount, TOutputImage >
-  ::~CountImageFilter()
-  {}
-
-  /**
-   * threaded Generate Data
-   */
-
-  /**
- * ThreadedGenerateData Performs the pixel-wise addition
- */
-template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-void
-CountImageFilter<TInputImage, TDetector, TCount, TOutputImage >
-::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, int threadId )
-{
-  typename Superclass::OutputImagePointer      outputImage = this->GetOutput();
-  InputImagePointerType ptr = const_cast<InputImageType *>(this->GetInput());
-
-      /** Update the radius for the CountImageFunction */
-    m_CountImageFunction->SetInputImage(ptr);
-    m_CountImageFunction->SetNeighborhoodRadius(m_NeighborhoodRadius);
-    
-    
-    itk::ImageRegionIterator<InputImageType> 
-                       itInput(ptr, ptr->GetLargestPossibleRegion());
-    
-    itk::ImageRegionIterator<OutputImageType> 
-                       itOutput(outputImage, outputImage->GetLargestPossibleRegion());
-    
-    itInput.GoToBegin();
-    itOutput.GoToBegin();
-    
-    while(!itInput.IsAtEnd() && !itOutput.IsAtEnd())
-      {
-	IndexType index = itInput.GetIndex();
-	itOutput.Set(m_CountImageFunction->EvaluateAtIndex(index));
-	
-	++itInput;
-	++itOutput;
-      }
-  
-  
-}
-
-
-  /**
-   * Set Detector 
-   */
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  void
-  CountImageFilter<TInputImage, TDetector, TCount, TOutputImage >
-  ::SetDetector(DetectorType* detector)
-  {
-    m_CountImageFunction->SetDetector(detector);
-  }
-  
-  
-  /**
-   * Get Detector 
-   */
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  typename CountImageFilter< TInputImage ,  TDetector,  TCount,  TOutputImage >
-  ::DetectorType *
-  CountImageFilter< TInputImage , TDetector, TCount, TOutputImage >
-  ::GetDetector()
-  {
-    return m_CountImageFunction->GetDetector();
-  }
-  
-
-
-  /*----------------------------------------------------------------
-    PrintSelf
-    -----------------------------------------------------------------*/
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  void
-  CountImageFilter< TInputImage ,  TDetector,  TCount,  TOutputImage >
-  ::PrintSelf(std::ostream& os, itk::Indent indent) const
-  {
-    Superclass::PrintSelf(os, indent);
-    os << indent << "Neighborhood Radius " << m_NeighborhoodRadius   << std::endl;
-  }
-
-}/** end namesapce otb*/
diff --git a/Code/BasicFilters/otbCountImageFilter.h b/Code/BasicFilters/otbKeyPointDensityImageFilter.h
similarity index 59%
rename from Code/BasicFilters/otbCountImageFilter.h
rename to Code/BasicFilters/otbKeyPointDensityImageFilter.h
index df4905853b..445abdd0e9 100644
--- a/Code/BasicFilters/otbCountImageFilter.h
+++ b/Code/BasicFilters/otbKeyPointDensityImageFilter.h
@@ -17,33 +17,33 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the above copyright notices for more information.
 
 =========================================================================*/
-#ifndef __otbCountImageFilter_h
-#define __otbCountImageFilter_h
+#ifndef __otbKeyPointDensityImageFilter_h
+#define __otbKeyPointDensityImageFilter_h
 
 
 #include "itkImageToImageFilter.h"
 #include "itkProcessObject.h"
-#include "otbCountImageFunction.h"
+#include "otbPointSetToDensityImageFilter.h"
 #include "itkNumericTraits.h"
 
 
-/** \class CountImageFilter
- *  \brief This class extracts key points from an image through a pyramidal gaussian based decomposition
+/** \class KeyPointDensityImageFilter
+ *  \brief 
 
  *
  */
 
 namespace otb
 {
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-    class ITK_EXPORT CountImageFilter
+  template <class TInputImage , class TDetector, class TOutputImage>
+    class ITK_EXPORT KeyPointDensityImageFilter
     : public itk::ImageToImageFilter<TInputImage, TOutputImage>
     {
 
     public:
 
     /** Standard class typedefs. */
-      typedef CountImageFilter                                            Self;
+      typedef KeyPointDensityImageFilter                                            Self;
       typedef itk::ImageToImageFilter<TInputImage,TOutputImage>           Superclass ;
       typedef itk::SmartPointer<Self>                                     Pointer;
       typedef itk::SmartPointer<const Self>                               ConstPointer;
@@ -52,32 +52,25 @@ namespace otb
       itkNewMacro(Self);
 
       /** Run-time type information (and related methods). */
-      itkTypeMacro(CountImageFilter,itk::ImageToImageFilter);
+      itkTypeMacro(KeyPointDensityImageFilter,itk::ImageToImageFilter);
 
 
       /** Template parameters typedefs*/
       typedef TInputImage                                  InputImageType;
       typedef typename InputImageType::Pointer             InputImagePointerType;
-      typedef typename InputImageType::IndexType           IndexType;
-
+  
       /** OutputImageType typedef support*/
-      typedef typename Superclass::OutputImageType         OutputImageType;
+      typedef TOutputImage                                 OutputImageType;
       typedef typename OutputImageType::Pointer            OutputImagePointerType;
-      typedef typename OutputImageType::RegionType  OutputImageRegionType;
-      typedef typename OutputImageType::PixelType          OutputPixelType; 
-      
-      typedef typename itk::NumericTraits< OutputPixelType>::RealType  OutputRealType;
-
+  
       /** Detector typedef Support*/
-      typedef TDetector                                    DetectorType;
+      typedef TDetector                                      DetectorType;
+      typedef typename DetectorType::OutputPointSetType      PointSetType;
+      typedef typename DetectorType::Pointer                 DetectorPointerType;
       
-      /** Count Function typedef Support*/
-      typedef TCount                                       CountMethodType;
-      
-      /** CountImageFunction support*/
-      typedef otb::CountImageFunction<InputImageType,DetectorType, 
-	            CountMethodType >                     CountImageFunctionType;
-      typedef typename CountImageFunctionType::Pointer    CountImageFunctionTypePointer;
+      /** PointSetToDensityImageFilter support*/
+      typedef otb::PointSetToDensityImageFilter<PointSetType, OutputImageType> PointSetToDensityImageType;
+      typedef typename PointSetToDensityImageType::Pointer                     PointSetToDensityImagePointerType;
       
       /** Get/Set the radius of the neighborhood over which the
 	  statistics are evaluated */
@@ -94,11 +87,11 @@ namespace otb
       /**
        * Constructor.
        */
-      CountImageFilter();
+      KeyPointDensityImageFilter();
       /**
        * Destructor.
        */
-      virtual ~CountImageFilter();
+      virtual ~KeyPointDensityImageFilter();
       /**
        * Standard PrintSelf method.
        */
@@ -106,20 +99,21 @@ namespace otb
       /**
        * Main computation method.
        */
-      virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
-
+      //virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+      virtual void GenerateData( );
+	    
   private:
 
-      CountImageFilter(const Self&); //purposely not implemented
+      KeyPointDensityImageFilter(const Self&); //purposely not implemented
       void operator=(const Self&); //purposely not implemented
       
-      CountImageFunctionTypePointer m_CountImageFunction;
-
-      unsigned int m_NeighborhoodRadius;
+      DetectorPointerType                m_Detector;
+      PointSetToDensityImagePointerType  m_PointSetToDensityImageFilter;
+      unsigned int                       m_NeighborhoodRadius;
     };
 }
 #ifndef OTB_MANUAL_INSTANTIATION
-#include "otbCountImageFilter.txx"
+#include "otbKeyPointDensityImageFilter.txx"
 #endif
 
 #endif
diff --git a/Code/BasicFilters/otbKeyPointDensityImageFilter.txx b/Code/BasicFilters/otbKeyPointDensityImageFilter.txx
new file mode 100644
index 0000000000..8ceca6e8b3
--- /dev/null
+++ b/Code/BasicFilters/otbKeyPointDensityImageFilter.txx
@@ -0,0 +1,121 @@
+/*=========================================================================
+
+Program:   ORFEO Toolbox
+Language:  C++
+Date:      $Date$
+Version:   $Revision$
+
+
+Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+See OTBCopyright.txt for details.
+
+Copyright (c) CS systèmes d'information. All rights reserved.
+See CSCopyright.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 "otbKeyPointDensityImageFilter.h"
+#include "itkImageRegionIterator.h"
+
+
+namespace otb
+{
+  /**---------------------------------------------------------
+   * Constructor
+   ----------------------------------------------------------*/
+  template <class TInputImage , class TDetector, class TOutputImage>
+  KeyPointDensityImageFilter<TInputImage , TDetector,  TOutputImage>
+  ::KeyPointDensityImageFilter()
+  {
+    this->SetNumberOfRequiredInputs( 1 );
+    m_NeighborhoodRadius = 1;
+    m_Detector =  DetectorType::New();
+    m_PointSetToDensityImageFilter = PointSetToDensityImageType::New();
+  }
+
+
+ /*---------------------------------------------------------
+  * Destructor.c
+  ----------------------------------------------------------*/
+  template <class TInputImage , class TDetector, class TOutputImage>
+  KeyPointDensityImageFilter<TInputImage, TDetector, TOutputImage >
+  ::~KeyPointDensityImageFilter()
+  {}
+
+  /**
+   * threaded Generate Data
+   */
+
+  /**
+ * ThreadedGenerateData Performs the pixel-wise addition
+ */
+template <class TInputImage , class TDetector,  class TOutputImage>
+void
+KeyPointDensityImageFilter<TInputImage, TDetector, TOutputImage >
+::GenerateData()
+//::GenerateData( const OutputImageRegionType &outputRegionForThread, int threadId )
+{
+  typename Superclass::OutputImagePointer      outputImage = this->GetOutput();
+  InputImagePointerType ptr = const_cast<InputImageType *>(this->GetInput());
+  if(!ptr)
+    return ;
+
+  /** Detector*/
+  m_Detector->SetInput(ptr);
+  
+  /** Applying the pointsetTodensityImageFilter*/
+  m_PointSetToDensityImageFilter->SetInput(m_Detector->GetOutput());
+  m_PointSetToDensityImageFilter->SetRadius(m_NeighborhoodRadius);
+  m_PointSetToDensityImageFilter->SetSpacing(ptr->GetSpacing());
+  m_PointSetToDensityImageFilter->SetSize(ptr->GetLargestPossibleRegion().GetSize());
+  m_PointSetToDensityImageFilter->SetOrigin(ptr->GetOrigin());
+  m_PointSetToDensityImageFilter->Update();
+  
+  /** updating the output*/
+  this->GraftOutput(m_PointSetToDensityImageFilter->GetOutput());
+}
+
+
+  /**
+   * Set Detector 
+   */
+  template <class TInputImage , class TDetector, class TOutputImage>
+  void
+  KeyPointDensityImageFilter<TInputImage, TDetector, TOutputImage >
+  ::SetDetector(DetectorType* detector)
+  {
+    m_Detector = detector;
+  }
+  
+  
+  /**
+   * Get Detector 
+   */
+  template <class TInputImage , class TDetector, class TOutputImage>
+  typename KeyPointDensityImageFilter< TInputImage ,  TDetector,  TOutputImage >
+  ::DetectorType *
+  KeyPointDensityImageFilter< TInputImage , TDetector, TOutputImage >
+  ::GetDetector()
+  {
+    return m_Detector;
+  }
+  
+
+
+  /*----------------------------------------------------------------
+    PrintSelf
+    -----------------------------------------------------------------*/
+  template <class TInputImage , class TDetector, class TOutputImage>
+  void
+  KeyPointDensityImageFilter< TInputImage ,  TDetector,  TOutputImage >
+  ::PrintSelf(std::ostream& os, itk::Indent indent) const
+  {
+    Superclass::PrintSelf(os, indent);
+    os << indent << "Neighborhood Radius " << m_NeighborhoodRadius   << std::endl;
+  }
+
+}/** end namesapce otb*/
diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt
index 39aa54877e..4194ebcab7 100644
--- a/Testing/Code/BasicFilters/CMakeLists.txt
+++ b/Testing/Code/BasicFilters/CMakeLists.txt
@@ -1164,20 +1164,11 @@ ADD_TEST(bfTvImagePCAShapeModelEstimatorTest ${BASICFILTERS_TESTS11}
     ${TEMP}/imagePCAShapeModelEstimatorTest_eigen_vectors1.tif
     ${TEMP}/imagePCAShapeModelEstimatorTest_eigen_vectors2.tif
 )
-#
-#ADD_TEST(bfTvCountImageFunction ${BASICFILTERS_TESTS11}
-#--compare-ascii ${TOL}
-#	    ${BASELINE_FILES}/bfTvCountImageFunctionOutputAscii.txt
-#	    ${TEMP}/bfTvCountImageFunctionOutputAscii.txt
-#	otbCountImageFunctionTest
-#	 ${INPUTDATA}/QB_Suburb.png
-#	 ${TEMP}/bfTvCountImageFunctionOutputAscii.txt
-#	 5 2
-#)
-# -------    otbCountImageFilter   ----------------------------
-#ADD_TEST(bfTuCountImageFilterNew ${BASICFILTERS_TESTS11}
-#	 otbCountImageFilterNew
-#	 )
+
+# -------    otbKeyPointDensityImageFilter   ----------------------------
+ADD_TEST(bfTuKeyPointDensityImageFilterNew ${BASICFILTERS_TESTS11}
+	 otbKeyPointDensityImageFilterNew
+	 )
 
 #ADD_TEST(bfTvCountImageFilterOutputImage ${BASICFILTERS_TESTS11}
 #--compare-image ${TOL}
@@ -1354,8 +1345,7 @@ otbPointSetDensityFunctionNew.cxx
 otbPointSetDensityFunctionTest.cxx
 otbPointSetToDensityImageFilterNew.cxx
 otbPointSetToDensityImageFilterTest.cxx	
-#otbCountImageFunctionTest.cxx	
-#otbCountImageFilterNew.cxx
+otbKeyPointDensityImageFilterNew.cxx
 #otbCountImageFilterTest.cxx	
 otbImagePCAShapeModelEstimatorTest.cxx
 )
diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
index 0f9f45df44..0ea3b67d42 100644
--- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
+++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
@@ -33,8 +33,7 @@ REGISTER_TEST(otbPointSetDensityFunctionNew);
 REGISTER_TEST(otbPointSetDensityFunctionTest);
 REGISTER_TEST(otbPointSetToDensityImageFilterNew);
 REGISTER_TEST(otbPointSetToDensityImageFilterTest); 
-//REGISTER_TEST(otbCountImageFunctionTest);
-//REGISTER_TEST(otbCountImageFilterNew); 
+REGISTER_TEST(otbKeyPointDensityImageFilterNew); 
 //REGISTER_TEST(otbCountImageFilterTest);  
 REGISTER_TEST(otbImagePCAShapeModelEstimatorTest);
 }
diff --git a/Testing/Code/BasicFilters/otbCountImageFilterNew.cxx b/Testing/Code/BasicFilters/otbKeyPointDensityImageFilterNew.cxx
similarity index 56%
rename from Testing/Code/BasicFilters/otbCountImageFilterNew.cxx
rename to Testing/Code/BasicFilters/otbKeyPointDensityImageFilterNew.cxx
index 7cb4c01fea..243f8c332c 100644
--- a/Testing/Code/BasicFilters/otbCountImageFilterNew.cxx
+++ b/Testing/Code/BasicFilters/otbKeyPointDensityImageFilterNew.cxx
@@ -18,29 +18,25 @@ PURPOSE.  See the above copyright notices for more information.
 
 #include <stdio.h>
 
-#include "otbCountImageFilter.h"
-#include "otbSiftFastImageFilter.h"
-#include "otbSimplePointCountStrategy.h"
+#include "otbKeyPointDensityImageFilter.h"
+#include "otbImageToSIFTKeyPointSetFilter.h"
 #include "itkPointSet.h"
 #include "itkVariableLengthVector.h"
 #include "otbImage.h"
 
-int otbCountImageFilterNew(int, char* [] )
+int otbKeyPointDensityImageFilterNew(int, char* [] )
 {
 
   const   unsigned int                                      Dimension = 2;
   typedef float                                             PixelType; 
 
-  typedef otb::Image< PixelType, Dimension >                ImageType;
-  typedef ImageType::IndexType                              IndexType;
-  typedef itk::VariableLengthVector<PixelType>              RealVectorType;
-  typedef itk::PointSet<RealVectorType,Dimension>           PointSetType;
-  typedef otb::SiftFastImageFilter<ImageType,PointSetType>  DetectorType;
+  typedef otb::Image< PixelType, Dimension >                                    ImageType;
+  typedef ImageType::IndexType                                                  IndexType;
+  typedef itk::VariableLengthVector<PixelType>                                  RealVectorType;
+  typedef itk::PointSet<RealVectorType,Dimension>                               PointSetType;
+  typedef otb::ImageToSIFTKeyPointSetFilter<ImageType,PointSetType>             DetectorType;
   
-  typedef otb::Count<PointSetType,unsigned int ,IndexType>  CounterType;
-  
-  typedef otb::CountImageFilter< ImageType,DetectorType,
-                                 CounterType,ImageType>   FilterType;
+  typedef otb::KeyPointDensityImageFilter< ImageType,DetectorType, ImageType>   FilterType;
   
   /**Instancitation of an object*/
   FilterType::Pointer    filter =     FilterType::New();
diff --git a/Testing/Code/BasicFilters/otbPointSetDensityFunctionTest.cxx b/Testing/Code/BasicFilters/otbPointSetDensityFunctionTest.cxx
index dd6f7d9c91..e8537b16ee 100644
--- a/Testing/Code/BasicFilters/otbPointSetDensityFunctionTest.cxx
+++ b/Testing/Code/BasicFilters/otbPointSetDensityFunctionTest.cxx
@@ -37,7 +37,7 @@ int otbPointSetDensityFunctionTest(int argc, char* argv[] )
   typedef otb::PointSetDensityFunction <PointSetType,PixelType>    FunctionType;
 
   
-  /**Instancitation of an object*/
+  /**Instancitation ofa Smart Pointer*/
   PointSetType::Pointer pointSet = PointSetType::New();
   FunctionType::Pointer     filter = FunctionType::New();
   std::ofstream outfile(outfname);
-- 
GitLab