From a22e330276dc2d2402bcbc33a5e23a4a2c97b617 Mon Sep 17 00:00:00 2001
From: Patrick Imbo <patrick.imbo@c-s.fr>
Date: Tue, 29 Aug 2006 13:26:53 +0000
Subject: [PATCH] =?UTF-8?q?PathListToHistogramGenerator=20:=20impl=C3=A9me?=
 =?UTF-8?q?ntation=20de=20la=20classe=20et=20des=20testing?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 Code/Common/CMakeLists.txt                    |   2 +-
 Code/Common/otbPathListToHistogramGenerator.h | 134 ++++++++++++++++++
 .../otbPathListToHistogramGenerator.txx       | 129 +++++++++++++++++
 Testing/Code/Common/CMakeLists.txt            |  11 +-
 Testing/Code/Common/otbCommonTests.cxx        |   2 +
 .../otbPathListToHistogramGenerator.cxx       | 108 ++++++++++++++
 .../otbPathListToHistogramGeneratorNew.cxx    |  57 ++++++++
 .../Code/FeatureExtraction/otbFlusserPath.cxx |   1 -
 Testing/Code/FeatureExtraction/otbHuPath.cxx  |   1 -
 9 files changed, 441 insertions(+), 4 deletions(-)
 create mode 100644 Code/Common/otbPathListToHistogramGenerator.h
 create mode 100644 Code/Common/otbPathListToHistogramGenerator.txx
 create mode 100644 Testing/Code/Common/otbPathListToHistogramGenerator.cxx
 create mode 100644 Testing/Code/Common/otbPathListToHistogramGeneratorNew.cxx

diff --git a/Code/Common/CMakeLists.txt b/Code/Common/CMakeLists.txt
index 97d1e11680..daa67e7bee 100644
--- a/Code/Common/CMakeLists.txt
+++ b/Code/Common/CMakeLists.txt
@@ -3,7 +3,7 @@
 FILE(GLOB OTBCommon_SRCS "*.cxx" )
 
 ADD_LIBRARY(OTBCommon ${OTBCommon_SRCS})
-TARGET_LINK_LIBRARIES (OTBCommon ITKCommon)
+TARGET_LINK_LIBRARIES (OTBCommon ITKStatistics ITKCommon)
 
 INSTALL_TARGETS(/lib/otb OTBCommon )
 INSTALL_FILES(/include/otb/Common "(\\.h|\\.txx)$")
diff --git a/Code/Common/otbPathListToHistogramGenerator.h b/Code/Common/otbPathListToHistogramGenerator.h
new file mode 100644
index 0000000000..6779002de3
--- /dev/null
+++ b/Code/Common/otbPathListToHistogramGenerator.h
@@ -0,0 +1,134 @@
+/*=========================================================================
+
+  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 __otbPathListToHistogramGenerator_h
+#define __otbPathListToHistogramGenerator_h
+
+
+#include "itkListSampleToHistogramGenerator.h"
+#include "itkObject.h"
+#include "itkListSample.h"
+#include "itkVector.h"
+#include "itkDenseFrequencyContainer.h"
+
+namespace otb {
+
+/** \class PathListToHistogramGenerator
+ *  \brief This class generates an histogram from a list of path.
+ *
+ *  The concept of Histogram in ITK is quite generic. It has been designed to
+ *  manage multiple components data. This class facilitates the computation of
+ *  an histogram from a list of path. Internally it creates a List that is feed into
+ *  the ListSampleToHistogramGenerator.
+ *
+ */
+  
+ 
+template< class TPath,class TFunction >
+class PathListToHistogramGenerator : public itk::Object
+{
+public:
+  /** Standard typedefs */
+  typedef PathListToHistogramGenerator   Self ;
+  typedef itk::Object                    Superclass;
+  typedef itk::SmartPointer<Self>        Pointer;
+  typedef itk::SmartPointer<const Self>  ConstPointer;
+
+  /** Run-time type information (and related methods). */
+  itkTypeMacro(PathListToHistogramGenerator, itk::Object) ;
+
+  /** standard New() method support */
+  itkNewMacro(Self) ;
+
+  typedef TPath                                   	  PathType;
+  typedef typename PathType::Pointer                      PathPointer;
+  typedef std::vector< PathPointer >   		          PathListType;
+
+  typedef PathListType *                                  PathListPointer;
+  typedef const PathListType *                            PathListConstPointer;
+
+  typedef TFunction                                       FunctionType;
+
+  typedef double                                                   MeasurementType;
+  typedef itk::Vector< MeasurementType , 1 >                       ListSampleVectorType ;
+  typedef itk::Statistics::ListSample< ListSampleVectorType >      ListSampleType ;
+  typedef ListSampleType::Pointer                                  ListSamplePointer;
+  typedef ListSampleType::ConstPointer                             ListSampleConstPointer;
+  
+  typedef itk::Statistics::DenseFrequencyContainer        FrequencyContainerType;
+
+
+  typedef itk::Statistics::ListSampleToHistogramGenerator< 
+                         ListSampleType, 
+			 MeasurementType,
+                         FrequencyContainerType,1>        GeneratorType;
+
+
+  typedef typename GeneratorType::Pointer                 GeneratorPointer;
+
+  typedef typename GeneratorType::HistogramType           HistogramType;
+  typedef typename HistogramType::Pointer                 HistogramPointer;
+  typedef typename HistogramType::ConstPointer            HistogramConstPointer;
+  typedef typename HistogramType::SizeType                SizeType;
+  typedef typename HistogramType::MeasurementVectorType   MeasurementVectorType;
+
+public:
+
+  /** Triggers the Computation of the histogram */
+  void Compute( void );
+
+  /** Connects the input PathList for which the histogram is going to be computed */
+  void SetInput( PathListPointer path);
+  
+  /** Return the histogram. o00
+   \warning This output is only valid after the Compute() method has been invoked 
+   \sa Compute */
+  const HistogramType * GetOutput() const;
+  
+  /** Set number of histogram bins */
+  void SetNumberOfBins( const SizeType & size );
+ 
+  /** Set marginal scale value to be passed to the histogram generator */
+  void SetMarginalScale( double marginalScale );
+  void SetHistogramMin(const MeasurementVectorType & histogramMin);
+  void SetHistogramMax(const MeasurementVectorType & histogramMax);
+  void SetAutoMinMax(bool autoMinMax);
+
+protected:
+  PathListToHistogramGenerator();
+  virtual ~PathListToHistogramGenerator() {};
+  void PrintSelf(std::ostream& os, itk::Indent indent) const;
+
+
+private:
+
+  PathListPointer     m_PathList;
+  GeneratorPointer    m_HistogramGenerator;
+
+
+
+};
+
+
+} // end of namespace OTB 
+
+#ifndef OTB_MANUAL_INSTANTIATION
+#include "otbPathListToHistogramGenerator.txx"
+#endif
+
+#endif
diff --git a/Code/Common/otbPathListToHistogramGenerator.txx b/Code/Common/otbPathListToHistogramGenerator.txx
new file mode 100644
index 0000000000..62da6121ed
--- /dev/null
+++ b/Code/Common/otbPathListToHistogramGenerator.txx
@@ -0,0 +1,129 @@
+/*=========================================================================
+
+  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 _otbPathListToHistogramGenerator_txx
+#define _itkPathListToHistogramGenerator_txx
+
+#include "otbPathListToHistogramGenerator.h"
+
+
+namespace otb { 
+
+
+template< class TPath,class TFunction >
+PathListToHistogramGenerator< TPath, TFunction >
+::PathListToHistogramGenerator() 
+{
+  m_HistogramGenerator = GeneratorType::New();
+}
+
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetInput( PathListPointer path ) 
+{
+  m_PathList = path ;
+}
+
+
+template< class TPath,class TFunction >
+const typename PathListToHistogramGenerator< TPath, TFunction >::HistogramType *
+PathListToHistogramGenerator< TPath, TFunction >
+::GetOutput() const
+{
+  return m_HistogramGenerator->GetOutput();
+}
+
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::Compute() 
+{
+ //TODO
+  m_HistogramGenerator->Update();
+}
+
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetNumberOfBins( const SizeType & size ) 
+{
+  m_HistogramGenerator->SetNumberOfBins( size );
+}
+
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetMarginalScale( double marginalScale )
+{
+  m_HistogramGenerator->SetMarginalScale( marginalScale );
+}
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetHistogramMin(const MeasurementVectorType & histogramMin)
+{
+  m_HistogramGenerator->SetHistogramMin(histogramMin);
+}
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetHistogramMax(const MeasurementVectorType & histogramMax)
+{
+  m_HistogramGenerator->SetHistogramMax(histogramMax);
+}
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::SetAutoMinMax(bool autoMinMax)
+{
+  m_HistogramGenerator->SetAutoMinMax(autoMinMax);
+}
+
+
+template< class TPath,class TFunction >
+void
+PathListToHistogramGenerator< TPath, TFunction >
+::PrintSelf(std::ostream& os, itk::Indent indent) const
+{
+  Superclass::PrintSelf(os,indent);
+  os << "PathList = " << m_PathList << std::endl;
+  os << "HistogramGenerator = " << m_HistogramGenerator << std::endl;
+}
+
+
+
+} // end of namespace otb
+
+#endif
+
+
diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt
index fc1fae62bb..f727ef686d 100644
--- a/Testing/Code/Common/CMakeLists.txt
+++ b/Testing/Code/Common/CMakeLists.txt
@@ -213,6 +213,13 @@ ADD_TEST(coTuDrawLineSpatialObjectList ${COMMON_TESTS}
 ADD_TEST(coTuImageToLineSpatialObjectListNew ${COMMON_TESTS} 
          otbImageToLineSpatialObjectListNew)
 	 
+# -------            otb::PathListToHistogramGenerator   ---------------------------
+
+ADD_TEST(coTuPathListToHistogramGeneratorNew ${COMMON_TESTS} 
+         otbPathListToHistogramGeneratorNew)  
+
+ADD_TEST(coTuPathListToHistogramGenerator ${COMMON_TESTS} 
+         otbPathListToHistogramGenerator)  
          
 # -------       Fichiers sources CXX -----------------------------------
 SET(BasicCommon_SRCS
@@ -235,6 +242,8 @@ otbDrawLineSpatialObject.cxx
 otbDrawLineSpatialObjectListNew.cxx
 otbDrawLineSpatialObjectList.cxx
 otbImageToLineSpatialObjectListNew.cxx
+otbPathListToHistogramGeneratorNew.cxx
+otbPathListToHistogramGenerator.cxx
 )
 
 
@@ -243,7 +252,7 @@ INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
 # ${TIFF_LIBRARY}
 
 ADD_EXECUTABLE(otbCommonTests otbCommonTests.cxx ${BasicCommon_SRCS})
-TARGET_LINK_LIBRARIES(otbCommonTests OTBIO OTBCommon gdal ITKIO ITKCommon)
+TARGET_LINK_LIBRARIES(otbCommonTests OTBIO OTBCommon gdal ITKIO ITKStatistics ITKCommon)
 
 ADD_EXECUTABLE(otbTestExtractROI otbTestExtractROI.cxx )
 TARGET_LINK_LIBRARIES(otbTestExtractROI OTBIO OTBCommon gdal ITKIO ITKCommon)
diff --git a/Testing/Code/Common/otbCommonTests.cxx b/Testing/Code/Common/otbCommonTests.cxx
index e24dab82f6..834b4c5dea 100644
--- a/Testing/Code/Common/otbCommonTests.cxx
+++ b/Testing/Code/Common/otbCommonTests.cxx
@@ -45,4 +45,6 @@ REGISTER_TEST(otbDrawLineSpatialObject);
 REGISTER_TEST(otbDrawLineSpatialObjectListNew);
 REGISTER_TEST(otbDrawLineSpatialObjectList);
 REGISTER_TEST(otbImageToLineSpatialObjectListNew);
+REGISTER_TEST(otbPathListToHistogramGeneratorNew);
+REGISTER_TEST(otbPathListToHistogramGenerator);
 }
diff --git a/Testing/Code/Common/otbPathListToHistogramGenerator.cxx b/Testing/Code/Common/otbPathListToHistogramGenerator.cxx
new file mode 100644
index 0000000000..018f6fd93e
--- /dev/null
+++ b/Testing/Code/Common/otbPathListToHistogramGenerator.cxx
@@ -0,0 +1,108 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4786 )
+#endif
+
+#define MAIN
+
+
+#include "itkExceptionObject.h"
+#include "itkPolyLineParametricPath.h"
+#include "otbOrientationPathFunction.h"
+#include "otbPathListToHistogramGenerator.h"
+
+int otbPathListToHistogramGenerator( int argc, char* argv[] )
+{
+  try 
+    {         
+        const   unsigned int        	                       Dimension = 2;
+	typedef itk::PolyLineParametricPath< Dimension >       PathType;
+        typedef PathType::Pointer                              PathPointer;
+        typedef std::vector< PathPointer >   		       PathListType;
+	
+	typedef otb::OrientationPathFunction<PathType>         FunctionType;
+
+        typedef otb::PathListToHistogramGenerator< PathType,FunctionType >   HistogramGeneratorType;
+	
+        PathType::ContinuousIndexType cindex;
+	int NbAngle = 100;
+	
+        /* build segments list */
+	PathListType*  PathList;
+        PathList->clear();
+	
+	for(int i = 0 ; i <NbAngle ; i++)
+	{
+	    PathPointer pathElt = PathType::New();        
+ 	    pathElt->Initialize();
+	    cindex[0]=30;
+            cindex[1]=30;
+            pathElt->AddVertex(cindex);
+	    
+	    float Theta = 2.0*acos(-1)*i/NbAngle;
+            cindex[0]= 30 + cos(Theta);
+            cindex[1]= 30 + sin(Theta);
+            pathElt->AddVertex(cindex);
+         
+	    PathList->push_back(pathElt); 
+	}
+
+	
+	HistogramGeneratorType::Pointer histogramGenerator = HistogramGeneratorType::New();
+
+        typedef HistogramGeneratorType::SizeType   HistogramSizeType;
+	HistogramSizeType hsize;
+        hsize[0] = 127;  // number of bins for the Red   channel
+	
+        histogramGenerator->SetInput(  PathList  );
+        histogramGenerator->SetNumberOfBins( hsize );
+        histogramGenerator->SetMarginalScale( 10.0 );
+        histogramGenerator->Compute();
+
+        typedef HistogramGeneratorType::HistogramType  HistogramType;
+
+        const HistogramType * histogram = histogramGenerator->GetOutput();
+
+        const unsigned int histogramSize = histogram->Size();
+        std::cout << "Histogram size " << histogramSize << std::endl;
+
+
+       for( unsigned int bin=0; bin < histogramSize; bin++ )
+       {
+            std::cout << "bin = " << bin << " frequency = ";
+            std::cout << histogram->GetFrequency( bin, 0 ) << std::endl;
+       }
+	
+        
+    } 
+  catch( itk::ExceptionObject & err ) 
+    { 
+    std::cout << "itk::ExceptionObject catch !" << std::endl; 
+    std::cout << err << std::endl; 
+    return EXIT_FAILURE;
+    } 
+  catch( ... ) 
+    { 
+    std::cout << "unknown Exception catch !" << std::endl; 
+    return EXIT_FAILURE;
+    } 
+  
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/Common/otbPathListToHistogramGeneratorNew.cxx b/Testing/Code/Common/otbPathListToHistogramGeneratorNew.cxx
new file mode 100644
index 0000000000..b755577d5a
--- /dev/null
+++ b/Testing/Code/Common/otbPathListToHistogramGeneratorNew.cxx
@@ -0,0 +1,57 @@
+/*=========================================================================
+
+  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.
+
+=========================================================================*/
+
+#if defined(_MSC_VER)
+#pragma warning ( disable : 4786 )
+#endif
+
+#define MAIN
+
+
+#include "itkExceptionObject.h"
+#include "itkPolyLineParametricPath.h"
+#include "otbOrientationPathFunction.h"
+#include "otbPathListToHistogramGenerator.h"
+
+int otbPathListToHistogramGeneratorNew( int argc, char* argv[] )
+{
+  try 
+    {         
+        const   unsigned int        	                       Dimension = 2;
+	typedef itk::PolyLineParametricPath< Dimension >       PathType;
+	typedef otb::OrientationPathFunction<PathType>         FunctionType;
+
+        typedef otb::PathListToHistogramGenerator< PathType,FunctionType >   GeneratorType;
+	
+        GeneratorType::Pointer histogram = GeneratorType::New();
+        
+    } 
+  catch( itk::ExceptionObject & err ) 
+    { 
+    std::cout << "itk::ExceptionObject catch !" << std::endl; 
+    std::cout << err << std::endl; 
+    return EXIT_FAILURE;
+    } 
+  catch( ... ) 
+    { 
+    std::cout << "unknown Exception catch !" << std::endl; 
+    return EXIT_FAILURE;
+    } 
+  
+  return EXIT_SUCCESS;
+}
diff --git a/Testing/Code/FeatureExtraction/otbFlusserPath.cxx b/Testing/Code/FeatureExtraction/otbFlusserPath.cxx
index 06875b092d..293f1210cc 100644
--- a/Testing/Code/FeatureExtraction/otbFlusserPath.cxx
+++ b/Testing/Code/FeatureExtraction/otbFlusserPath.cxx
@@ -20,7 +20,6 @@
 #pragma warning ( disable : 4786 )
 #endif
 
-#include "otbImageFileReader.h"
 #include "otbFlusserPathFunction.h"
 #include "itkPolyLineParametricPath.h"
 #include "itkExceptionObject.h"
diff --git a/Testing/Code/FeatureExtraction/otbHuPath.cxx b/Testing/Code/FeatureExtraction/otbHuPath.cxx
index 8f83aedbaf..69526fd642 100644
--- a/Testing/Code/FeatureExtraction/otbHuPath.cxx
+++ b/Testing/Code/FeatureExtraction/otbHuPath.cxx
@@ -20,7 +20,6 @@
 #pragma warning ( disable : 4786 )
 #endif
 
-#include "otbImageFileReader.h"
 #include "otbHuPathFunction.h"
 #include "itkPolyLineParametricPath.h"
 #include "itkExceptionObject.h"
-- 
GitLab