diff --git a/Code/Common/CMakeLists.txt b/Code/Common/CMakeLists.txt index 97d1e116803462e680bd8147db9ee26feaaf0787..daa67e7beeca9bc32e0885f6d8d599e3312f2f3d 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 0000000000000000000000000000000000000000..6779002de3ba42e1790e851b5dd479630112f398 --- /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 0000000000000000000000000000000000000000..62da6121edc84dbd3001898a51c076b56a84e69d --- /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 fc1fae62bbb3f5d46871a8fd5363d302f1b84daf..f727ef686de5e440bd6803491f5b17e387b9389d 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 e24dab82f6a99f7423aae2a4bf17cafcf468bc6c..834b4c5dea3557d6fe44c005ea242e839a71b8a5 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 0000000000000000000000000000000000000000..018f6fd93e6d07bfce45ae45d24274b39c1a3bde --- /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 0000000000000000000000000000000000000000..b755577d5a5c7c4afbbbeb56a4412796c39869a6 --- /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 06875b092dbd3641d23e33fefcad9f51949aa68f..293f1210cc1581f5184ff3e15686cf74a5d0b692 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 8f83aedbafd754cb893c8cb8d332b248d9bdd67b..69526fd642cb8ccb806501b62f2cd16616ed8c7c 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"