From ea04aa49420a461dec5bd0bd5c904eeb6f68352f Mon Sep 17 00:00:00 2001
From: Otmane Lahlou <otmane.lahlou@c-s.fr>
Date: Wed, 28 Jan 2009 11:29:18 +0100
Subject: [PATCH] ADD: Test of validation for CountImageFilter

---
 Code/BasicFilters/otbCountImageFilter.h       |  6 +-
 Code/BasicFilters/otbCountImageFilter.txx     | 44 ++++++----
 Testing/Code/BasicFilters/CMakeLists.txt      | 10 +++
 .../BasicFilters/otbBasicFiltersTests11.cxx   |  1 +
 .../BasicFilters/otbCountImageFilterTest.cxx  | 87 +++++++++++++++++++
 .../BasicFilters/otbCountImageFunction.cxx    | 50 -----------
 6 files changed, 126 insertions(+), 72 deletions(-)
 create mode 100644 Testing/Code/BasicFilters/otbCountImageFilterTest.cxx
 delete mode 100644 Testing/Code/BasicFilters/otbCountImageFunction.cxx

diff --git a/Code/BasicFilters/otbCountImageFilter.h b/Code/BasicFilters/otbCountImageFilter.h
index 22fb090710..df4905853b 100644
--- a/Code/BasicFilters/otbCountImageFilter.h
+++ b/Code/BasicFilters/otbCountImageFilter.h
@@ -61,8 +61,9 @@ namespace otb
       typedef typename InputImageType::IndexType           IndexType;
 
       /** OutputImageType typedef support*/
-      typedef TOutputImage                                 OutputImageType;
+      typedef typename Superclass::OutputImageType         OutputImageType;
       typedef typename OutputImageType::Pointer            OutputImagePointerType;
+      typedef typename OutputImageType::RegionType  OutputImageRegionType;
       typedef typename OutputImageType::PixelType          OutputPixelType; 
       
       typedef typename itk::NumericTraits< OutputPixelType>::RealType  OutputRealType;
@@ -105,8 +106,7 @@ namespace otb
       /**
        * Main computation method.
        */
-      virtual void  GenerateData();
-
+      virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
 
   private:
 
diff --git a/Code/BasicFilters/otbCountImageFilter.txx b/Code/BasicFilters/otbCountImageFilter.txx
index 0d5cfee76a..cb9363f911 100644
--- a/Code/BasicFilters/otbCountImageFilter.txx
+++ b/Code/BasicFilters/otbCountImageFilter.txx
@@ -31,6 +31,7 @@ namespace otb
   CountImageFilter<TInputImage , TDetector, TCount, TOutputImage>
   ::CountImageFilter()
   {
+    this->SetNumberOfRequiredInputs( 1 );
     m_CountImageFunction = CountImageFunctionType::New();
     m_NeighborhoodRadius = 1;
   }
@@ -44,21 +45,25 @@ namespace otb
   ::~CountImageFilter()
   {}
 
- /*-------------------------------------------------------
-  * Generate Data
-  --------------------------------------------------------*/
+  /**
+   * threaded Generate Data
+   */
 
-  template <class TInputImage , class TDetector, class TCount, class TOutputImage>
-  void
-  CountImageFilter<TInputImage, TDetector, TCount, TOutputImage >
-  ::GenerateData(void)
-  {
-    InputImagePointerType ptr = const_cast<InputImageType *>(this->GetInput());
-    
-    OutputImagePointerType outputImage = this->GetOutput();
+  /**
+ * 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);
     
-    /** Update the radius for the CountImageFunction */
-    m_CountImageFunction->SetNeighborhoodRadius(this->GetNeighborhoodRadius());
     
     itk::ImageRegionIterator<InputImageType> 
                        itInput(ptr, ptr->GetLargestPossibleRegion());
@@ -66,7 +71,7 @@ namespace otb
     itk::ImageRegionIterator<OutputImageType> 
                        itOutput(outputImage, outputImage->GetLargestPossibleRegion());
     
-    CountMethodType CountMethod;
+    CountMethodType    CountMethod;
     
     itInput.GoToBegin();
     itOutput.GoToBegin();
@@ -74,15 +79,16 @@ namespace otb
     while(!itInput.IsAtEnd() && !itOutput.IsAtEnd())
       {
 	IndexType index = itInput.GetIndex();
-	itOutput.Set(m_CountImageFunction->EvaluateAtIndex(index));
+	//std::cout <<"Index "<< index <<std::endl;
+	float value = 0.;//m_CountImageFunction->EvaluateAtIndex(index); 
+	itOutput.Set(value);
 	
 	++itInput;
 	++itOutput;
       }
-           
-
-  }/** End of GenerateData()*/
-
+  
+  
+}
 
 
   /**
diff --git a/Testing/Code/BasicFilters/CMakeLists.txt b/Testing/Code/BasicFilters/CMakeLists.txt
index 9a6ecc9303..4b57269e47 100644
--- a/Testing/Code/BasicFilters/CMakeLists.txt
+++ b/Testing/Code/BasicFilters/CMakeLists.txt
@@ -1134,6 +1134,15 @@ ADD_TEST(bfTuCountImageFilterNew ${BASICFILTERS_TESTS11}
 	 otbCountImageFilterNew
 	 )
 
+ADD_TEST(bfTvCountImageFilterOutputImage ${BASICFILTERS_TESTS11}
+--compare-image ${TOL}
+	    ${BASELINE_FILES}/bfTvCountImageFilterOutputImage.tif
+	    ${TEMP}/bfTvCountImageFilterOutputImage.tif
+	    otbCountImageFilterTest
+	 ${INPUTDATA}/QB_Suburb.png
+	 ${TEMP}/bfTvCountImageFilterOutputImage.tif
+	 5 2 
+)
 
 # A enrichir
 SET(BasicFilters_SRCS1
@@ -1298,6 +1307,7 @@ otbExtractROIResample.cxx
 otbCountImageFunctionNew.cxx
 otbCountImageFunctionTest.cxx	
 otbCountImageFilterNew.cxx
+otbCountImageFilterTest.cxx	
 )
 
 
diff --git a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
index 07396aa660..66c127df73 100644
--- a/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
+++ b/Testing/Code/BasicFilters/otbBasicFiltersTests11.cxx
@@ -31,4 +31,5 @@ REGISTER_TEST(otbExtractROIResample);
 REGISTER_TEST(otbCountImageFunctionNew); 
 REGISTER_TEST(otbCountImageFunctionTest);
 REGISTER_TEST(otbCountImageFilterNew); 
+REGISTER_TEST(otbCountImageFilterTest);  
 }
diff --git a/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx b/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx
new file mode 100644
index 0000000000..68711a0a8d
--- /dev/null
+++ b/Testing/Code/BasicFilters/otbCountImageFilterTest.cxx
@@ -0,0 +1,87 @@
+/*=========================================================================
+
+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 "otbImage.h"
+#include "otbImageFileReader.h"
+#include "otbImageFileWriter.h"
+
+#include <stdio.h>
+#include "otbCountImageFilter.h"
+#include "otbSiftFastImageFilter.h"
+#include "otbSimplePointCountStrategy.h"
+#include "itkPointSet.h"
+#include "itkVariableLengthVector.h"
+
+#include <iostream>
+
+int otbCountImageFilterTest(int argc, char* argv[] )
+{
+  const char *  infname = argv[1];            
+  const char * outfname = argv[2];
+  const unsigned char scales = atoi(argv[3]);
+  const unsigned char radius = atoi(argv[4]);
+  const   unsigned int                                      Dimension = 2;
+  typedef float                                             PixelType; 
+
+  typedef otb::Image< PixelType, Dimension >                ImageType;
+  typedef ImageType::IndexType                              IndexType;
+  
+  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::Count<PointSetType,unsigned int ,IndexType>  CounterType;
+  
+  typedef otb::CountImageFilter< ImageType,DetectorType,
+                                   CounterType, ImageType>  FilterType;
+
+
+  /** Instanciation of the reader */
+  ReaderType::Pointer reader = ReaderType::New();
+
+  reader->SetFileName(infname);
+  reader->Update();
+  
+  ImageType::SizeType                     size;
+  size = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
+  
+  /**Instancitation of an object*/
+  FilterType::Pointer    filter =     FilterType::New();
+  
+  /** Instanciation of the detector : */
+  DetectorType::Pointer detector = filter->GetDetector();
+  detector->SetNumberOfScales(scales);
+  
+
+  filter->SetInput(reader->GetOutput()); 
+  filter->SetNeighborhoodRadius(radius);
+  filter->SetDetector(detector);  /*Set the number of scales for the detector**/
+
+  
+  /** Output*/
+  WriterType::Pointer writer = WriterType::New();
+  writer->SetFileName(outfname);
+  writer->SetInput(filter->GetOutput());
+  writer->Update();
+
+  return EXIT_SUCCESS;
+}
+
diff --git a/Testing/Code/BasicFilters/otbCountImageFunction.cxx b/Testing/Code/BasicFilters/otbCountImageFunction.cxx
deleted file mode 100644
index 1edc301a42..0000000000
--- a/Testing/Code/BasicFilters/otbCountImageFunction.cxx
+++ /dev/null
@@ -1,50 +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.
-
-
-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 "otbCountImageFunction.h"
-#include "otbSiftFastImageFilter.h"
-#include "otbSimplePointCountStrategy.h"
-#include "itkPointSet.h"
-#include "itkVariableLengthVector.h"
-#include "otbImage.h"
-
-int otbCountImageFunctionNew(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::Count<PointSetType,unsigned int ,IndexType>  CounterType;
-  
-  typedef otb::CountImageFunction< ImageType,DetectorType,
-                                             CounterType>   FunctionType;
-  
-  /**Instancitation of an object*/
-  FunctionType::Pointer    filter =     FunctionType::New();
-
-  return EXIT_SUCCESS;
-}
-
-- 
GitLab