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

PathListToHistogramGenerator : implémentation de la classe et des testing

parent a22e3302
Branches
Tags
No related merge requests found
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
namespace otb { namespace otb {
/** \class PathListToHistogramGenerator /** \class PathListToHistogramGenerator
* \brief This class generates an histogram from a list of path. * \brief This class generates an histogram from a list of path.
* *
...@@ -64,11 +66,13 @@ public: ...@@ -64,11 +66,13 @@ public:
typedef TFunction FunctionType; typedef TFunction FunctionType;
typedef double MeasurementType; typedef typename TFunction::OutputType RealType;
typedef itk::Vector< MeasurementType , 1 > ListSampleVectorType ;
typedef RealType MeasurementType;
typedef itk::Vector< MeasurementType ,1 > ListSampleVectorType ;
typedef itk::Statistics::ListSample< ListSampleVectorType > ListSampleType ; typedef itk::Statistics::ListSample< ListSampleVectorType > ListSampleType ;
typedef ListSampleType::Pointer ListSamplePointer; typedef typename ListSampleType::Pointer ListSamplePointer;
typedef ListSampleType::ConstPointer ListSampleConstPointer; typedef typename ListSampleType::ConstPointer ListSampleConstPointer;
typedef itk::Statistics::DenseFrequencyContainer FrequencyContainerType; typedef itk::Statistics::DenseFrequencyContainer FrequencyContainerType;
......
...@@ -58,8 +58,28 @@ void ...@@ -58,8 +58,28 @@ void
PathListToHistogramGenerator< TPath, TFunction > PathListToHistogramGenerator< TPath, TFunction >
::Compute() ::Compute()
{ {
//TODO
m_HistogramGenerator->Update(); PathPointer vertexList;
ListSamplePointer ListSample = ListSampleType::New();
int nbElementPathList = m_PathList->size();
ListSampleVectorType ResultFunction;
typename TFunction::Pointer function = TFunction::New();
for(int noPathList = 0 ; noPathList < nbElementPathList; noPathList++ )
{
vertexList = (*m_PathList)[noPathList];
function->SetInputPath( vertexList );
ResultFunction[0] = static_cast<MeasurementType>( function->Evaluate() );
ListSample->PushBack(ResultFunction);
}
m_HistogramGenerator->SetListSample( ListSample ) ;
m_HistogramGenerator->Update();
} }
......
...@@ -219,7 +219,7 @@ ADD_TEST(coTuPathListToHistogramGeneratorNew ${COMMON_TESTS} ...@@ -219,7 +219,7 @@ ADD_TEST(coTuPathListToHistogramGeneratorNew ${COMMON_TESTS}
otbPathListToHistogramGeneratorNew) otbPathListToHistogramGeneratorNew)
ADD_TEST(coTuPathListToHistogramGenerator ${COMMON_TESTS} ADD_TEST(coTuPathListToHistogramGenerator ${COMMON_TESTS}
otbPathListToHistogramGenerator) otbPathListToHistogramGenerator 100 2)
# ------- Fichiers sources CXX ----------------------------------- # ------- Fichiers sources CXX -----------------------------------
SET(BasicCommon_SRCS SET(BasicCommon_SRCS
......
...@@ -32,6 +32,8 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] ) ...@@ -32,6 +32,8 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] )
{ {
try try
{ {
unsigned int NbOfBins((unsigned int)::atoi(argv[1]));
unsigned int NbOfPointsPerHistogram((unsigned int)::atoi(argv[2]));
const unsigned int Dimension = 2; const unsigned int Dimension = 2;
typedef itk::PolyLineParametricPath< Dimension > PathType; typedef itk::PolyLineParametricPath< Dimension > PathType;
typedef PathType::Pointer PathPointer; typedef PathType::Pointer PathPointer;
...@@ -42,10 +44,10 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] ) ...@@ -42,10 +44,10 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] )
typedef otb::PathListToHistogramGenerator< PathType,FunctionType > HistogramGeneratorType; typedef otb::PathListToHistogramGenerator< PathType,FunctionType > HistogramGeneratorType;
PathType::ContinuousIndexType cindex; PathType::ContinuousIndexType cindex;
int NbAngle = 100; int NbAngle = NbOfPointsPerHistogram*NbOfBins;
/* build segments list */ /* build segments list */
PathListType* PathList; PathListType* PathList = new PathListType;
PathList->clear(); PathList->clear();
for(int i = 0 ; i <NbAngle ; i++) for(int i = 0 ; i <NbAngle ; i++)
...@@ -64,12 +66,11 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] ) ...@@ -64,12 +66,11 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] )
PathList->push_back(pathElt); PathList->push_back(pathElt);
} }
HistogramGeneratorType::Pointer histogramGenerator = HistogramGeneratorType::New(); HistogramGeneratorType::Pointer histogramGenerator = HistogramGeneratorType::New();
typedef HistogramGeneratorType::SizeType HistogramSizeType; typedef HistogramGeneratorType::SizeType HistogramSizeType;
HistogramSizeType hsize; HistogramSizeType hsize;
hsize[0] = 127; // number of bins for the Red channel hsize[0] = NbOfBins; // number of bins for the Red channel
histogramGenerator->SetInput( PathList ); histogramGenerator->SetInput( PathList );
histogramGenerator->SetNumberOfBins( hsize ); histogramGenerator->SetNumberOfBins( hsize );
...@@ -86,7 +87,12 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] ) ...@@ -86,7 +87,12 @@ int otbPathListToHistogramGenerator( int argc, char* argv[] )
for( unsigned int bin=0; bin < histogramSize; bin++ ) for( unsigned int bin=0; bin < histogramSize; bin++ )
{ {
std::cout << "bin = " << bin << " frequency = "; if(histogram->GetFrequency( bin, 0 ) !=NbOfPointsPerHistogram)
{
std::cout << "Error in histogram value !" << std::endl;
return EXIT_FAILURE;
}
std::cout << "bin = " << bin << " frequency = ";
std::cout << histogram->GetFrequency( bin, 0 ) << std::endl; std::cout << histogram->GetFrequency( bin, 0 ) << std::endl;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment