Commit 56b644be authored by Stéphane Albert's avatar Stéphane Albert

ENH: Histogram streamed calculation; AbstractModel::BuildModel() and...

ENH: Histogram streamed calculation; AbstractModel::BuildModel() and derived-classes; ::ToImageBase() and ::ToImage(); otb::DynamicCast<>(); AbstractModel::newChildModel<>() and ::parentChildModel(); VectorImageModel::m_Image smart-pointer.
parent 9783e02b
......@@ -34,6 +34,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdHistogramSequence.h"
namespace mvd
{
......@@ -59,10 +60,15 @@ AbstractImageModel
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
void
AbstractImageModel
::virtual_BuildModel()
{
/* HistogramSequence* histogramModel = */ newChildModel< HistogramSequence >();
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
} // end namespace 'mvd'
......@@ -87,7 +87,16 @@ public:
virtual ~AbstractImageModel();
/** */
inline void GenerateCachedData();
inline ImageRegionType GetLargestRegion() const;
/** */
inline CountType GetNbComponents() const;
/** */
virtual ImageBaseType::ConstPointer ToImageBase() const;
/** */
virtual ImageBaseType::Pointer ToImageBase();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
......@@ -105,7 +114,16 @@ protected:
AbstractImageModel( QObject* parent =NULL );
/** */
virtual void virtual_GenerateCachedData() =0;
virtual ImageBaseType::ConstPointer virtual_ToImageBase() const =0;
/** */
virtual ImageBaseType::Pointer virtual_ToImageBase() =0;
//
// AbstractModel overrides.
/** */
virtual void virtual_BuildModel();
//
// Protected attributes.
......@@ -139,11 +157,38 @@ namespace mvd
/*****************************************************************************/
inline
void
ImageRegionType
AbstractImageModel
::GetLargestRegion() const
{
return ToImageBase()->GetLargestPossibleRegion();
}
/*****************************************************************************/
inline
CountType
AbstractImageModel
::GetNbComponents() const
{
return ToImageBase()->GetNumberOfComponentsPerPixel();
}
/*****************************************************************************/
inline
ImageBaseType::ConstPointer
AbstractImageModel
::ToImageBase() const
{
return virtual_ToImageBase();
}
/*****************************************************************************/
inline
ImageBaseType::Pointer
AbstractImageModel
::GenerateCachedData()
::ToImageBase()
{
virtual_GenerateCachedData();
return virtual_ToImageBase();
}
} // end namespace 'mvd'
......
......@@ -19,6 +19,10 @@
#include "mvdAbstractModel.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......@@ -45,6 +49,10 @@ namespace mvd
Context comment for translator.
*/
/*****************************************************************************/
/* CLASS IMPLEMENTATION SECTION */
/*******************************************************************************/
AbstractModel
::AbstractModel( QObject* parent ) :
......
......@@ -20,13 +20,15 @@
#ifndef __mvdAbstractModel_h
#define __mvdAbstractModel_h
#include "ConfigureMonteverdi2.h"
//
// Configuration include.
//// Included at first position before any other ones.
#include "ConfigureMonteverdi2.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......@@ -34,6 +36,7 @@
//
// System includes (sorted by alphabetic order)
#include <cassert>
//
// ITK includes (sorted by alphabetic order)
......@@ -44,7 +47,9 @@
//
// Monteverdi includes (sorted by alphabetic order)
//#include "mvdTypes.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
......@@ -57,14 +62,23 @@ namespace mvd
//
// Internal classes pre-declaration.
/*****************************************************************************/
/* CLASS DEFINITION SECTION */
/** \class AbstractModel
*
*/
class Monteverdi2_EXPORT AbstractModel :
public QObject
{
/*-[ QOBJECT SECTION ]-----------------------------------------------------*/
Q_OBJECT;
/*-[ PUBLIC SECTION ]------------------------------------------------------*/
//
// Public methods.
public:
......@@ -72,34 +86,108 @@ public:
/** Destructor */
virtual ~AbstractModel();
/** */
template< typename T >
T* newChildModel();
/** */
inline void parentChildModel( AbstractModel* );
/** */
inline void BuildModel();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
// SIGNALS.
// Signals.
signals:
/*-[ PROTECTED SECTION ]---------------------------------------------------*/
//
// Protected methods.
protected:
/** Constructor */
AbstractModel( QObject* parent =NULL );
/** */
// TODO: Provide default empty virtual method body and clean-up
// derived-classes.
virtual void virtual_BuildModel() =0;
//
// Protected attributes.
protected:
/*-[ PRIVATE SECTION ]-----------------------------------------------------*/
//
// Private methods.
private:
//
// Private attributes.
private:
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
//
// SLOTS.
// Slots.
private slots:
};
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
/*****************************************************************************/
template< typename T >
T*
AbstractModel
::newChildModel()
{
T* model = new T( this );
try
{
parentChildModel( model );
}
catch( std::exception& exc )
{
delete model;
model = NULL;
throw;
}
return model;
}
/*****************************************************************************/
inline
void
AbstractModel
::parentChildModel( AbstractModel* model )
{
assert( model!=NULL );
model->BuildModel();
model->setParent( this );
}
/*****************************************************************************/
inline
void
AbstractModel
::BuildModel()
{
virtual_BuildModel();
}
} // end namespace 'mvd'
#endif // __mvdAbstractModel_h
......@@ -80,7 +80,7 @@ DatasetModel
// 2.2. Generate cached data.
// TODO: generate image-model cached data (quicklook,
// histogram-list etc.)
vectorImageModel->GenerateCachedData();
vectorImageModel->BuildModel();
}
catch( std::exception& exc )
{
......@@ -96,6 +96,13 @@ DatasetModel
vectorImageModel->setParent( this );
}
/*******************************************************************************/
void
DatasetModel
::virtual_BuildModel()
{
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -113,6 +113,12 @@ signals:
// Protected methods.
protected:
//
// AbstractModel overrides.
/** */
virtual void virtual_BuildModel();
//
// Protected attributes.
protected:
......
......@@ -37,6 +37,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdVectorImageModel.h"
namespace mvd
{
......@@ -66,6 +67,23 @@ HistogramSequence
{
}
/*******************************************************************************/
void
HistogramSequence
::virtual_BuildModel()
{
// template_BuildModel_I< VectorImageModel::SourceImageType >();
template_BuildModel_M< VectorImageModel >();
// template_BuildModel< otb::Image< FixedArray< double, 4 >, 2 > >();
// template_BuildModel< otb::Image< itk::FixedArray< float, 4 >, 2 > >();
/*
template_BuildModel< otb::VectorImage< float, 2 > >();
template_BuildModel< otb::Image< float, 2 > >();
*/
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -46,6 +46,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "mvdTypes.h"
/*****************************************************************************/
......@@ -101,6 +102,12 @@ signals:
// Protected methods.
protected:
//
// AbstractModel overrides.
/** */
virtual void virtual_BuildModel();
//
// Protected attributes.
protected:
......@@ -111,7 +118,16 @@ protected:
// Private types.
private:
/** */
typedef itk::Statistics::Histogram< Monteverdi2_FLOATING_TYPE, 1 > Histogram;
typedef
// itk::NumericTraits< T >::FloatType and
// itk::NumericTraits< T >::RealType do not depend on template
// parameter T. They are always typedef, respectively, as float
// and double.
itk::NumericTraits< DefaultImageType::InternalPixelType >::RealType
MeasurementType;
/** */
typedef itk::Statistics::Histogram< MeasurementType, 1 > Histogram;
/** */
typedef otb::ObjectList< Histogram > HistogramList;
......@@ -119,8 +135,11 @@ private:
//
// Private methods.
private:
template< typename TImage >
void template_BuildModel_I();
template< typename TImageModel >
void template_BuildModel_M();
//
// Private attributes.
private:
......@@ -134,9 +153,144 @@ private:
private slots:
};
} // end namespace 'mvd'
/*****************************************************************************/
/* INLINE SECTION */
//
// ITK includes (sorted by alphabetic order)
//
// OTB includes (sorted by alphabetic order)
#include "otbStreamingHistogramVectorImageFilter.h"
#include "otbStreamingMinMaxVectorImageFilter.h"
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractImageModel.h"
namespace mvd
{
/*******************************************************************************/
template< typename TImage >
inline
void
HistogramSequence
::template_BuildModel_I()
{
qDebug() << "Generating histogram (I)...";
AbstractImageModel* imageModel =
qobject_cast< AbstractImageModel* >( parent() );
assert( imageModel!=NULL );
//
// 1st pass: process min/MAX for each band.
// Connect min/MAX pipe-section.
typedef
otb::StreamingMinMaxVectorImageFilter< TImage >
MinMaxFilter;
typename MinMaxFilter::Pointer filterMinMax( MinMaxFilter::New() );
filterMinMax->SetInput(
otb::DynamicCast< TImage >( imageModel->ToImageBase() )
);
filterMinMax->Update();
// Extract min/MAX intensities for each bands.
typename MinMaxFilter::PixelType lSrcMin( filterMinMax->GetMinimum() );
typename MinMaxFilter::PixelType lSrcMax( filterMinMax->GetMaximum() );
//
// 2nd pass: compute histogram.
typedef
otb::StreamingHistogramVectorImageFilter< TImage >
HistogramFilter;
typename HistogramFilter::Pointer histogramFilter( HistogramFilter::New() );
histogramFilter->SetInput(
otb::DynamicCast< TImage >( imageModel->ToImageBase() )
);
histogramFilter->GetFilter()->SetHistogramMin( lSrcMin );
histogramFilter->GetFilter()->SetHistogramMax( lSrcMax );
histogramFilter->GetFilter()->SetSubSamplingRate( 1 );
histogramFilter->Update();
//
// Reference result.
m_Histograms = histogramFilter->GetHistogramList();
qDebug() << "Histogram (I) generated.";
}
/*******************************************************************************/
template< typename TImageModel >
inline
void
HistogramSequence
::template_BuildModel_M()
{
qDebug() << "Generate histogram (M)...";
TImageModel* imageModel =
qobject_cast< TImageModel* >( parent() );
assert( imageModel!=NULL );
//
// 1st pass: process min/MAX for each band.
// Connect min/MAX pipe-section.
typedef
otb::StreamingMinMaxVectorImageFilter<
typename TImageModel::SourceImageType >
MinMaxFilter;
typename MinMaxFilter::Pointer filterMinMax( MinMaxFilter::New() );
filterMinMax->SetInput( imageModel->ToImage() );
filterMinMax->Update();
// Extract min/MAX intensities for each bands.
typename MinMaxFilter::PixelType lSrcMin( filterMinMax->GetMinimum() );
typename MinMaxFilter::PixelType lSrcMax( filterMinMax->GetMaximum() );
//
// 2nd pass: compute histogram.
typedef
otb::StreamingHistogramVectorImageFilter<
typename TImageModel::SourceImageType >
HistogramFilter;
typename HistogramFilter::Pointer histogramFilter( HistogramFilter::New() );
histogramFilter->SetInput( imageModel->ToImage() );
histogramFilter->GetFilter()->SetHistogramMin( lSrcMin );
histogramFilter->GetFilter()->SetHistogramMax( lSrcMax );
histogramFilter->GetFilter()->SetSubSamplingRate( 1 );
histogramFilter->Update();
//
// Reference result.
m_Histograms = histogramFilter->GetHistogramList();
qDebug() << "Histogram (M) generated.";
}
} // end namespace 'mvd'
#endif // __mvdHistogramSequence_h
......@@ -121,9 +121,13 @@ private:
private slots:
};
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
namespace mvd
{
} // end namespace 'mvd'
#endif // __mvdMyClass_h
......@@ -44,6 +44,23 @@
#include <otbImageFileReader.h>
#include <otbVectorImage.h>
// TODO: Contribute to OTB!
namespace otb
{
template< typename T2, typename T1 >
inline
itk::SmartPointer< T2 >
DynamicCast( const itk::SmartPointer< T1 >& p1 )
{
return
typename itk::SmartPointer< T2 >(
dynamic_cast< typename itk::SmartPointer< T2 >::ObjectType* >(
p1.GetPointer()
)
);
}
} // end of namespace otb.
//
// Monteverdi includes (sorted by alphabetic order)
......@@ -52,6 +69,68 @@
namespace
{
}
/*******************************************************************************/
/* PROTOTYPE */
/*******************************************************************************/
namespace mvd
{
template< typename TValueType, unsigned int VLength >
class FixedArray :
public itk::FixedArray< TValueType, VLength >
{
public:
/** Standard Self typedef */
typedef mvd::FixedArray< TValueType, VLength > Self;
typedef itk::FixedArray< TValueType, VLength > Superclass;
typedef itk::SmartPointer< Self > Pointer;
typedef itk::SmartPointer< const Self > ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro( Self );
/** Runtime information support. */
itkTypeMacro( mvd::FixedArray, itk::FixedArray );
public:
FixedArray();
void SetSize( unsigned int sz, bool destroyExistingData=true );
void Fill( const Self& );
void Fill( const TValueType& );
};
}
/*******************************************************************************/
namespace itk
{
//
// Instantiate the macros to declare the NumericTraits for the
// mvd::FixedArray types.
//
#ifdef ITK_USE_NUMERIC_TRAITS_PARTIAL_SPECIALIZATION
itkNumericTraitsGenericArrayScalarsDimensionsMacro( mvd::FixedArray );
#else // ITK_USE_NUMERIC_TRAITS_PARTIAL_SPECIALIZATION
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, char );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned char );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, signed char );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, short );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned short );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, int );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned int );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, long );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned long );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, float );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, double );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, long double );
#ifdef ITK_TYPE_USE_LONG_LONG
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, long long );
itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned long long );
#endif // ITK_TYPE_USE_LONG_LONG
#endif // ITK_USE_NUMERIC_TRAITS_PARTIAL_SPECIALIZATION
}