From 2a642ac04abb58c0cc99ea69e20e5aef87ab38ef Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Thu, 29 Jan 2009 17:50:23 +0100
Subject: [PATCH] ADD : Add validation test for PointSetToDensityImageFilter

---
 .../otbPointSetToDensityImageFilter.h         | 62 ++++++++-------
 .../otbPointSetToDensityImageFilter.txx       | 54 +++++++++++++
 Testing/Code/BasicFilters/CMakeLists.txt      | 11 +++
 .../BasicFilters/otbBasicFiltersTests11.cxx   |  3 +-
 .../otbPointSetToDensityImageFilterTest.cxx   | 75 +++++++++++++++++++
 ...KeyPointSetFilterOutputDescriptorAscii.cxx |  1 -
 6 files changed, 177 insertions(+), 29 deletions(-)
 create mode 100644 Testing/Code/BasicFilters/otbPointSetToDensityImageFilterTest.cxx

diff --git a/Code/BasicFilters/otbPointSetToDensityImageFilter.h b/Code/BasicFilters/otbPointSetToDensityImageFilter.h
index f6c224f1f4..9a7e0f0bd6 100644
--- a/Code/BasicFilters/otbPointSetToDensityImageFilter.h
+++ b/Code/BasicFilters/otbPointSetToDensityImageFilter.h
@@ -23,29 +23,11 @@ PURPOSE.  See the above copyright notices for more information.
 #include "itkProcessObject.h"
 #include "itkPointSet.h"
 #include "itkPointSetToImageFilter.h"
-
+#include "otbPointSetDensityFunction.h"
+#include "itkPoint.h"
 
 /** \class PointSetToDensityImageFilter
- *  \brief This class extracts key points from an image through a pyramidal gaussian based decomposition
- *
- * This class implements the SURF Key point detector proposed by Tuytelaars and Vangool from the university
- * of Leuven, 2005
- *
- * \li Gaussian Second order derivative Hessian images are computed in each
- *     level and each octave for the input image.
- * \li For each octave, an extremum search is launched on each 3 adjacent scales.
- * \li The Key points detected are the ones extremum in the current , previous and
- *     next scale of reserach. 3 scales are needed for the computation (NumberOfScales >=3).
- * \li Orientation and descriptors are computed for each key point detected.
  *
- * Selected Key Points are stored in an itk::PointSet structure.
- * Points contains the coordinate of the detected point.
- * DataPoints contain the values of the 64 element descriptor for each key point
- * detected through the pyramidal analysis.
- *
- * Orientation is expressed in degree in the range of [0,360]
- *
- *  \sa otb::ImageToDeterminantHessianImage
  */
 
 namespace otb
@@ -59,7 +41,7 @@ namespace otb
 
     /** Standard class typedefs. */
       typedef PointSetToDensityImageFilter                                Self;
-      typedef itk::PointSetToImageFilter<TInputPointSet, TOutputImage>   Superclass;
+      typedef itk::PointSetToImageFilter<TInputPointSet, TOutputImage>    Superclass;
       typedef itk::SmartPointer<Self>                                     Pointer;
       typedef itk::SmartPointer<const Self>                               ConstPointer;
 
@@ -68,12 +50,31 @@ namespace otb
 
       /** Run-time type information (and related methods). */
       itkTypeMacro(PointSetToDensityImageFilter,itk::PointSetToImageFilter);
-
-
-      /** Template parameters typedefs*/
-
-
-
+      
+      
+
+      /**   typedefs parameters support */
+      typedef TInputPointSet                          PointSetType;
+      
+      typedef TOutputImage                            OutputImageType;
+      typedef typename  OutputImageType::PixelType    PixelType;
+      typedef typename  OutputImageType::IndexType    IndexType;
+
+      /**   typedef filter support*/
+      typedef otb::PointSetDensityFunction<PointSetType , PixelType>   PointSetDensityFunctionType;
+      typedef typename PointSetDensityFunctionType::InputType          InputType;
+      typedef typename PointSetDensityFunctionType::Pointer            PointSetDensityFunctionPointerType;
+      
+
+      /** Set/Get Radius*/
+      itkGetMacro(Radius, unsigned int);
+      itkSetMacro(Radius, unsigned int);
+      
+      /** PointSet Set/Get*/
+      //     itkSetObjectMacro(PointSet,PointSetType);
+      //itkGetObjectMacro(PointSet,PointSetType);
+
+      
     protected:
 
       /**
@@ -92,12 +93,19 @@ namespace otb
        * Main computation method.
        */
       virtual void  GenerateData();
+            /**
+       * Main computation method.
+       */
+      virtual void  GenerateOutputInformation();
+      
 
   private:
 
       PointSetToDensityImageFilter(const Self&); //purposely not implemented
       void operator=(const Self&); //purposely not implemented
 
+      unsigned int m_Radius;
+      typename PointSetType::Pointer m_PointSet;
     };
 }
 #ifndef OTB_MANUAL_INSTANTIATION
diff --git a/Code/BasicFilters/otbPointSetToDensityImageFilter.txx b/Code/BasicFilters/otbPointSetToDensityImageFilter.txx
index a9c2353b2a..b1c304410e 100644
--- a/Code/BasicFilters/otbPointSetToDensityImageFilter.txx
+++ b/Code/BasicFilters/otbPointSetToDensityImageFilter.txx
@@ -19,6 +19,7 @@ PURPOSE.  See the above copyright notices for more information.
 =========================================================================*/
 
 #include "otbPointSetToDensityImageFilter.h"
+#include "itkImageRegionIterator.h"
 
 
 namespace otb
@@ -30,6 +31,7 @@ namespace otb
   PointSetToDensityImageFilter<  TInputPointSet ,  TOutputImage  >
   ::PointSetToDensityImageFilter()
   {
+    m_Radius = 1;
   }
 
 
@@ -49,10 +51,62 @@ namespace otb
   PointSetToDensityImageFilter<  TInputPointSet ,  TOutputImage>
   ::GenerateData(void)
   {
+    this->AllocateOutputs();
+    
+    PointSetDensityFunctionPointerType densityComputeFunction = PointSetDensityFunctionType::New();
+    densityComputeFunction->SetPointSet(const_cast<PointSetType*>(this->GetInput()));
+    densityComputeFunction->SetRadius(m_Radius);
+      
+    /** Point*/
+    InputType   pCenter;
+    IndexType index;
+    itk::ImageRegionIterator<OutputImageType> itOut(this->GetOutput(),
+						    this->GetOutput()->GetLargestPossibleRegion());
+    itOut.GoToBegin();
 
+    while(!itOut.IsAtEnd())
+      {
+	index = itOut.GetIndex();
+	pCenter[0] = index[0];
+	pCenter[1] = index[1];
 
+	itOut.Set(densityComputeFunction->Evaluate(pCenter));
+	++itOut;
+      }
   }/** End of GenerateData()*/
 
+/*-------------------------------------------------------
+  * Generate Data
+  --------------------------------------------------------*/
+  template <class TInputPointSet , class TOutputImage  >
+  void
+  PointSetToDensityImageFilter<  TInputPointSet ,  TOutputImage>
+  ::GenerateOutputInformation(void)
+  {
+    //Superclass::GenerateOutputInformation();
+    typename  Superclass::OutputImagePointer outputPtr = this->GetOutput();
+
+    if ( !outputPtr )
+    {
+    return;
+    }
+    
+  typename OutputImageType::RegionType region;
+  IndexType start ;
+  start.Fill(0);
+  
+  region.SetSize(this->GetSize());
+  region.SetIndex(start);
+  
+  outputPtr->SetOrigin(this->GetOrigin());
+  outputPtr->SetSpacing(this->GetSpacing());
+  outputPtr->SetRegions( region );
+
+  
+  
+  }/** End of GenerateoutputInformation*/
+  
+
   /*----------------------------------------------------------------
     PrintSelf
     -----------------------------------------------------------------*/
diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt
index fdf2a941f9..eaf29f3e60 100644
--- a/Testing/Code/BasicFilters/CMakeLists.txt
+++ b/Testing/Code/BasicFilters/CMakeLists.txt
@@ -1144,6 +1144,16 @@ ADD_TEST(bfTuPointSetToDensityImageFilterNew ${BASICFILTERS_TESTS11}
 
 
 
+ADD_TEST(bfTvPointSetToDensityImageFilterTest ${BASICFILTERS_TESTS11}
+--compare-image ${TOL}
+	    ${BASELINE_FILES}/bfTvPointSetToDensityImageFilterOutputImage.tif
+	    ${TEMP}/bfTvPointSetToDensityImageFilterOutputImage.tif
+	    otbPointSetToDensityImageFilterTest
+	 ${INPUTDATA}/QB_Suburb.png
+	 ${TEMP}/bfTvPointSetToDensityImageFilterOutputImage.tif
+	 5 2
+)
+
 # -------    otbPCAShapeModelEstimatorTest   ----------------------------
 ADD_TEST(bfTvImagePCAShapeModelEstimatorTest ${BASICFILTERS_TESTS11}
     otbImagePCAShapeModelEstimatorTest
@@ -1343,6 +1353,7 @@ otbPointSetFunctionNew.cxx
 otbPointSetDensityFunctionNew.cxx
 otbPointSetDensityFunctionTest.cxx
 otbPointSetToDensityImageFilterNew.cxx
+otbPointSetToDensityImageFilterTest.cxx	
 #otbCountImageFunctionTest.cxx	
 #otbCountImageFilterNew.cxx
 #otbCountImageFilterTest.cxx	
diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
index ece89b214b..0f9f45df44 100644
--- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
+++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
@@ -31,7 +31,8 @@ REGISTER_TEST(otbExtractROIResample);
 REGISTER_TEST(otbPointSetFunctionNew); 
 REGISTER_TEST(otbPointSetDensityFunctionNew); 
 REGISTER_TEST(otbPointSetDensityFunctionTest);
-REGISTER_TEST(otbPointSetToDensityImageFilterNew); 
+REGISTER_TEST(otbPointSetToDensityImageFilterNew);
+REGISTER_TEST(otbPointSetToDensityImageFilterTest); 
 //REGISTER_TEST(otbCountImageFunctionTest);
 //REGISTER_TEST(otbCountImageFilterNew); 
 //REGISTER_TEST(otbCountImageFilterTest);  
diff --git a/Testing/Code/BasicFilters/otbPointSetToDensityImageFilterTest.cxx b/Testing/Code/BasicFilters/otbPointSetToDensityImageFilterTest.cxx
new file mode 100644
index 0000000000..d838f87cd9
--- /dev/null
+++ b/Testing/Code/BasicFilters/otbPointSetToDensityImageFilterTest.cxx
@@ -0,0 +1,75 @@
+/*=========================================================================
+
+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 <stdio.h>
+#include "itkPointSet.h"
+#include "otbImage.h"
+#include "otbPointSetToDensityImageFilter.h"
+#include "itkVariableLengthVector.h"
+#include "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+#include "otbSiftFastImageFilter.h"
+
+
+int otbPointSetToDensityImageFilterTest(int argc, char* argv[] )
+{
+
+  const char * infname = argv[1];
+  const char * outfname = argv[2];
+  const unsigned int scales = atoi(argv[3]);
+  const unsigned int radius = atoi(argv[4]);
+
+  const   unsigned int                                             Dimension = 2;
+  typedef float                                                    PixelType; 
+  
+  typedef otb::Image<PixelType , Dimension>                        ImageType;
+  typedef otb::ImageFileReader<ImageType>                          ReaderType;
+  typedef otb::ImageFileWriter<ImageType>                          WriterType;
+  typedef itk::VariableLengthVector<PixelType>                     RealVectorType;
+  typedef itk::PointSet<RealVectorType,Dimension>                  PointSetType;
+  typedef otb::SiftFastImageFilter<ImageType,PointSetType>         DetectorType;
+  
+  typedef otb::PointSetToDensityImageFilter <PointSetType,ImageType>    FunctionType;
+ 
+  /**Instancitation of an object*/
+  FunctionType::Pointer    filter = FunctionType::New();
+  DetectorType::Pointer    detector = DetectorType::New();
+  ReaderType::Pointer      reader = ReaderType::New();
+   
+  reader->SetFileName(infname);
+  reader->GenerateOutputInformation();
+ 
+  detector->SetInput(reader->GetOutput());
+  detector->SetNumberOfScales(scales);
+  
+  /** PointSetImageToDensity ImageFilter*/
+  filter->SetInput(detector->GetOutput());
+  filter->SetRadius(radius);
+  filter->SetSpacing(reader->GetOutput()->GetSpacing());
+  filter->SetSize(reader->GetOutput()->GetLargestPossibleRegion().GetSize());
+  filter->SetOrigin(reader->GetOutput()->GetOrigin());
+  
+  /** Writing the densty Image*/
+  WriterType::Pointer writer = WriterType::New();
+  writer->SetFileName(outfname);
+  writer->SetInput(filter->GetOutput());
+  writer->Update();
+  
+  return EXIT_SUCCESS;
+}
+
diff --git a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx
index 3af21c0257..e093f082f4 100644
--- a/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx
+++ b/Testing/Code/FeatureExtraction/otbImageToFastSIFTKeyPointSetFilterOutputDescriptorAscii.cxx
@@ -18,7 +18,6 @@ PURPOSE.  See the above copyright notices for more information.
 #include "otbSiftFastImageFilter.h"
 #include "otbImage.h"
 #include "otbImageFileReader.h"
-#include "otbImageFileWriter.h"
 #include "itkPointSet.h"
 #include "itkVariableLengthVector.h"
 #include "otbRationalQuotientResampleImageFilter.h"
-- 
GitLab