Skip to content
Snippets Groups Projects
Commit a22e3302 authored by Patrick Imbo's avatar Patrick Imbo
Browse files

PathListToHistogramGenerator : implémentation de la classe et des testing

parent e97bdff8
Branches
Tags
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
FILE(GLOB OTBCommon_SRCS "*.cxx" ) FILE(GLOB OTBCommon_SRCS "*.cxx" )
ADD_LIBRARY(OTBCommon ${OTBCommon_SRCS}) ADD_LIBRARY(OTBCommon ${OTBCommon_SRCS})
TARGET_LINK_LIBRARIES (OTBCommon ITKCommon) TARGET_LINK_LIBRARIES (OTBCommon ITKStatistics ITKCommon)
INSTALL_TARGETS(/lib/otb OTBCommon ) INSTALL_TARGETS(/lib/otb OTBCommon )
INSTALL_FILES(/include/otb/Common "(\\.h|\\.txx)$") INSTALL_FILES(/include/otb/Common "(\\.h|\\.txx)$")
/*=========================================================================
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
/*=========================================================================
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
...@@ -213,6 +213,13 @@ ADD_TEST(coTuDrawLineSpatialObjectList ${COMMON_TESTS} ...@@ -213,6 +213,13 @@ ADD_TEST(coTuDrawLineSpatialObjectList ${COMMON_TESTS}
ADD_TEST(coTuImageToLineSpatialObjectListNew ${COMMON_TESTS} ADD_TEST(coTuImageToLineSpatialObjectListNew ${COMMON_TESTS}
otbImageToLineSpatialObjectListNew) otbImageToLineSpatialObjectListNew)
# ------- otb::PathListToHistogramGenerator ---------------------------
ADD_TEST(coTuPathListToHistogramGeneratorNew ${COMMON_TESTS}
otbPathListToHistogramGeneratorNew)
ADD_TEST(coTuPathListToHistogramGenerator ${COMMON_TESTS}
otbPathListToHistogramGenerator)
# ------- Fichiers sources CXX ----------------------------------- # ------- Fichiers sources CXX -----------------------------------
SET(BasicCommon_SRCS SET(BasicCommon_SRCS
...@@ -235,6 +242,8 @@ otbDrawLineSpatialObject.cxx ...@@ -235,6 +242,8 @@ otbDrawLineSpatialObject.cxx
otbDrawLineSpatialObjectListNew.cxx otbDrawLineSpatialObjectListNew.cxx
otbDrawLineSpatialObjectList.cxx otbDrawLineSpatialObjectList.cxx
otbImageToLineSpatialObjectListNew.cxx otbImageToLineSpatialObjectListNew.cxx
otbPathListToHistogramGeneratorNew.cxx
otbPathListToHistogramGenerator.cxx
) )
...@@ -243,7 +252,7 @@ INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") ...@@ -243,7 +252,7 @@ INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
# ${TIFF_LIBRARY} # ${TIFF_LIBRARY}
ADD_EXECUTABLE(otbCommonTests otbCommonTests.cxx ${BasicCommon_SRCS}) 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 ) ADD_EXECUTABLE(otbTestExtractROI otbTestExtractROI.cxx )
TARGET_LINK_LIBRARIES(otbTestExtractROI OTBIO OTBCommon gdal ITKIO ITKCommon) TARGET_LINK_LIBRARIES(otbTestExtractROI OTBIO OTBCommon gdal ITKIO ITKCommon)
......
...@@ -45,4 +45,6 @@ REGISTER_TEST(otbDrawLineSpatialObject); ...@@ -45,4 +45,6 @@ REGISTER_TEST(otbDrawLineSpatialObject);
REGISTER_TEST(otbDrawLineSpatialObjectListNew); REGISTER_TEST(otbDrawLineSpatialObjectListNew);
REGISTER_TEST(otbDrawLineSpatialObjectList); REGISTER_TEST(otbDrawLineSpatialObjectList);
REGISTER_TEST(otbImageToLineSpatialObjectListNew); REGISTER_TEST(otbImageToLineSpatialObjectListNew);
REGISTER_TEST(otbPathListToHistogramGeneratorNew);
REGISTER_TEST(otbPathListToHistogramGenerator);
} }
/*=========================================================================
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;
}
/*=========================================================================
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;
}
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#pragma warning ( disable : 4786 ) #pragma warning ( disable : 4786 )
#endif #endif
#include "otbImageFileReader.h"
#include "otbFlusserPathFunction.h" #include "otbFlusserPathFunction.h"
#include "itkPolyLineParametricPath.h" #include "itkPolyLineParametricPath.h"
#include "itkExceptionObject.h" #include "itkExceptionObject.h"
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#pragma warning ( disable : 4786 ) #pragma warning ( disable : 4786 )
#endif #endif
#include "otbImageFileReader.h"
#include "otbHuPathFunction.h" #include "otbHuPathFunction.h"
#include "itkPolyLineParametricPath.h" #include "itkPolyLineParametricPath.h"
#include "itkExceptionObject.h" #include "itkExceptionObject.h"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment