Commit 9632acfd authored by Stéphane Albert's avatar Stéphane Albert

ENH: Fixed unecessary virtual instead of inline methods; Added...

ENH: Fixed unecessary virtual instead of inline methods; Added otb::ToFixedArray() and otb::ToVariableLangthArray() rebinders (mvdAlgorithm); Fixed ColorDynamicsWidget default layout; Fixed HistogramModel access to Min/Max pixels.
parent 49ecb941
......@@ -93,10 +93,10 @@ public:
inline CountType GetNbComponents() const;
/** */
virtual ImageBaseType::ConstPointer ToImageBase() const;
inline ImageBaseType::ConstPointer ToImageBase() const;
/** */
virtual ImageBaseType::Pointer ToImageBase();
inline ImageBaseType::Pointer ToImageBase();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
......
......@@ -18,6 +18,10 @@
=========================================================================*/
#include "mvdAlgorithm.h"
/*****************************************************************************/
/* INCLUDE SECTION */
//
// Qt includes (sorted by alphabetic order)
//// Must be included before system/custom includes.
......
......@@ -24,6 +24,10 @@
//// 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 +38,9 @@
//
// ITK includes (sorted by alphabetic order)
#include "itkFixedArray.h"
#include "itkExceptionObject.h"
#include "itkVariableLengthVector.h"
//
// OTB includes (sorted by alphabetic order)
......@@ -42,6 +49,10 @@
// Monteverdi includes (sorted by alphabetic order)
#include "mvdTypes.h"
/*****************************************************************************/
/* PRE-DECLARATION SECTION */
//
// External classes pre-declaration.
namespace
......@@ -52,10 +63,81 @@ namespace mvd
{
//
// Internal classes pre-declaration.
} // end of namespace 'mvd'.
//
// Functions declaration.
/*****************************************************************************/
/* FUNCTIONS DECLARATION. */
namespace otb
{
/**
* Convert an itk::VariableLengthVector< T2 > into a
* itk::FixedArray< T1, N >.
*
* Elements of type T1 are (safely) statically casted into T2.
*
* An itk::RangeError exception instance is thrown if lengths/sizes of
* both the containers are not equal.
*
* N.B.: Caller must ensure to that size N of itk::FixedArray< T1, N >
* to match the variable size of the itk::VariableLengthVector< T1 >.
*/
template< typename T2, unsigned int N, typename T1 >
inline
itk::FixedArray< T2, N >
ToFixedArray( const itk::VariableLengthVector< T1 >& v );
/**
* Convert an itk::VariableLengthVector< T2 > into a
* itk::FixedArray< T1, N >.
*
* Elements of type T1 are (safely) statically casted into T2.
*
* An itk::RangeError exception instance is thrown if lengths/sizes of
* both the containers are not equal.
*
* N.B.: Caller must ensure to that size N of itk::FixedArray< T1, N >
* to match the variable size of the itk::VariableLengthVector< T1 >.
*/
template< typename T2, unsigned int N, typename T1 >
inline
itk::FixedArray< T2, N >&
ToFixedArray( itk::FixedArray< T2, N >& a,
const itk::VariableLengthVector< T1 >& v );
/**
* Convert an itk::FixedArray< T2, N > into a
* itk::VariableLengthVector< T1 >.
*
* Elements of type T1 are (safely) statically casted into T2.
*
* An itk::RangeError exception instance is thrown if lengths/sizes of
* both the containers are not equal.
*/
template< typename T2, typename T1, unsigned int N >
inline
itk::VariableLengthVector< T2 >
ToVariableLengthVector( const itk::FixedArray< T1, N >& a );
/**
* Convert an itk::FixedArray< T2, N > into a
* itk::VariableLengthVector< T1 >.
*
* Elements of type T1 are (safely) statically casted into T2.
*
* An itk::RangeError exception instance is thrown if lengths/sizes of
* both the containers are not equal.
*/
template< typename T2, typename T1, unsigned int N >
inline
itk::VariableLengthVector< T2 >&
ToVariableLengthVector( itk::FixedArray< T1, N >& a,
const itk::VariableLengthVector< T1 >& v );
} // end namespace 'otb'
namespace mvd
{
/**
* Convert a StringVector object to a QStringList object.
*
......@@ -63,7 +145,8 @@ namespace mvd
* QStringList is shallow-copied.
*/
inline
QStringList ToQStringList( const StringVector& sv );
QStringList
ToQStringList( const StringVector& sv );
/**
* Append the content of a StringVector object to the content of a
......@@ -73,13 +156,95 @@ QStringList ToQStringList( const StringVector& sv );
* QStringList is shallow-copied.
*/
inline
QStringList AppendToQStringList( QStringList& qsl,
const StringVector& sv );
QStringList&
AppendToQStringList( QStringList& qsl,
const StringVector& sv );
//
// Inlined-functions implementations.
//
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
namespace otb
{
/*******************************************************************************/
template< typename T2, unsigned int N, typename T1 >
inline
itk::FixedArray< T2, N >
ToFixedArray( const itk::VariableLengthVector< T1 >& v )
{
assert( v.Size()==N );
throw itk::RangeError( __FILE__, __LINE__ );
itk::FixedArray< T2, N > a;
for( unsigned int i=0; i<N; ++i )
a[ i ] = static_cast< T2 >( v[ i ] );
return a;
}
/*******************************************************************************/
template< typename T2, unsigned int N, typename T1 >
inline
itk::FixedArray< T2, N >&
ToFixedArray( itk::FixedArray< T2, N >& a,
const itk::VariableLengthVector< T1 >& v )
{
assert( v.Size()==N && v.Size()==a.Size() );
throw itk::RangeError( __FILE__, __LINE__ );
for( unsigned int i=0; i<N; ++i )
a[ i ] = static_cast< T2>( v[ i ] );
return a;
}
/*******************************************************************************/
template< typename T2, typename T1, unsigned int N >
inline
itk::VariableLengthVector< T2 >
ToVariableLengthVector( const itk::FixedArray< T1, N >& a )
{
assert( a.Size()==N );
throw itk::RangeError( __FILE__, __LINE__ );
itk::VariableLengthVector< T2 > v;
v.Reserve( N );
for( unsigned int i=0; i<N; ++i )
v[ i ] = static_cast< T2 >( a[ i ] );
return v;
}
/*******************************************************************************/
template< typename T2, typename T1, unsigned int N >
inline
itk::VariableLengthVector< T2 >&
ToVariableLengthVector( itk::VariableLengthVector< T2 >& v,
const itk::FixedArray< T1, N >& a )
{
assert( a.Size()==N );
throw itk::RangeError( __FILE__, __LINE__ );
v.Reserve( N );
for( unsigned int i=0; i<N; ++i )
v[ i ] = static_cast< T2 >( a[ i ] );
return v;
}
} // end namespace 'otb'.
namespace mvd
{
/*******************************************************************************/
inline
QStringList
......@@ -91,7 +256,7 @@ ToQStringList( const StringVector& sv )
/*******************************************************************************/
inline
QStringList
QStringList&
AppendToQStringList( QStringList& qsl, const StringVector& sv )
{
for( StringVector::const_iterator it( sv.begin() );
......
......@@ -103,6 +103,12 @@
</item>
<item row="1" column="0">
<widget class="QLabel" name="intensityLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Intensity:</string>
</property>
......@@ -113,6 +119,12 @@
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="lowIntensitySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>true</bool>
</property>
......@@ -129,6 +141,12 @@
</item>
<item row="1" column="2">
<widget class="QDoubleSpinBox" name="highIntensitySpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>true</bool>
</property>
......@@ -149,7 +167,7 @@
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -162,7 +180,7 @@
<item row="2" column="0">
<widget class="QLabel" name="quantileLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......@@ -180,6 +198,12 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>true</bool>
</property>
......@@ -196,6 +220,12 @@
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frame">
<bool>true</bool>
</property>
......@@ -213,7 +243,7 @@
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>326</width>
<height>347</height>
<height>333</height>
</rect>
</property>
<property name="windowTitle">
......
......@@ -57,7 +57,9 @@ namespace mvd
HistogramModel
::HistogramModel( QObject* parent ) :
AbstractModel( parent ),
m_Histograms()
m_Histograms(),
m_MinPixel(),
m_MaxPixel()
{
}
......
......@@ -46,6 +46,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdAbstractModel.h"
#include "mvdAlgorithm.h"
#include "mvdTypes.h"
......@@ -83,14 +84,6 @@ class Monteverdi2_EXPORT HistogramModel :
//
// Public types.
public:
/** */
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;
//
// Public methods.
......@@ -106,10 +99,10 @@ public:
inline double GetQuantile( unsigned int band, double p ) const;
/** */
inline MeasurementType GetMinIntensity( unsigned int band ) const;
inline DefaultImageType::PixelType GetMinPixel() const;
/** */
inline MeasurementType GetMaxIntensity( unsigned int band ) const;
inline DefaultImageType::PixelType GetMaxPixel() const;
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
......@@ -138,6 +131,21 @@ protected:
//
// Private types.
private:
/** */
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.
//
// So, itk::NumericTraits< DefaultImageType::InternalPixelType
// >::RealType is equivalent to itk::NumericTraits< float
// >::RealType which is always an alias of double.
//
// This typedef is used for compatibility with
// itk::Histogram<>::MeasurementType.
itk::NumericTraits< DefaultImageType::InternalPixelType >::RealType
MeasurementType;
/** */
typedef itk::Statistics::Histogram< MeasurementType, 1 > Histogram;
......@@ -159,9 +167,9 @@ private:
/** */
HistogramList::Pointer m_Histograms;
/** */
Histogram::MeasurementVectorType m_MinIntensities;
DefaultImageType::PixelType m_MinPixel;
/** */
Histogram::MeasurementVectorType m_MaxIntensities;
DefaultImageType::PixelType m_MaxPixel;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
......@@ -193,24 +201,20 @@ namespace mvd
/*******************************************************************************/
inline
HistogramModel::MeasurementType
DefaultImageType::PixelType
HistogramModel
::GetMinIntensity( unsigned int band ) const
::GetMinPixel() const
{
assert( band<m_MinIntensities.Size() );
return m_MinIntensities[ band ];
return m_MinPixel;
}
/*******************************************************************************/
inline
HistogramModel::MeasurementType
DefaultImageType::PixelType
HistogramModel
::GetMaxIntensity( unsigned int band ) const
::GetMaxPixel() const
{
assert( band<m_MaxIntensities.Size() );
return m_MaxIntensities[ band ];
return m_MaxPixel;
}
/*******************************************************************************/
......@@ -270,14 +274,14 @@ HistogramModel
/*
// Extract min/MAX intensities for each band.
typename MinMaxFilter::PixelType lSrcMin( filterMinMax->GetMinimum() );
typename MinMaxFilter::PixelType lSrcMax( filterMinMax->GetMaximum()
);
// itk::VariableLengthVector< FLOAT_TYPE >
typename MinMaxFilter::PixelType lSrcMin( f );
typename MinMaxFilter::PixelType lSrcMax( filterMinMax->GetMaximum() );
*/
// Extract-convert-remember min/MAX intensities for each band.
m_MinIntensities = filterMinMax->GetMinimum();
m_MaxIntensities = filterMinMax->GetMaximum();
m_MinPixel = filterMinMax->GetMinimum();
m_MaxPixel = filterMinMax->GetMaximum();
qDebug() << tr( "%1: Pass #1 - done (%2 ms)." )
.arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
......@@ -303,8 +307,8 @@ HistogramModel
);
// Setup histogram filter.
histogramFilter->GetFilter()->SetHistogramMin( m_MinIntensities );
histogramFilter->GetFilter()->SetHistogramMax( m_MaxIntensities );
histogramFilter->GetFilter()->SetHistogramMin( m_MinPixel );
histogramFilter->GetFilter()->SetHistogramMax( m_MaxPixel );
histogramFilter->GetFilter()->SetSubSamplingRate( 1 );
// Go.
......@@ -364,9 +368,15 @@ HistogramModel
filterMinMax->Update();
/*
// Extract min/MAX intensities for each bands.
typename MinMaxFilter::PixelType lSrcMin( filterMinMax->GetMinimum() );
typename MinMaxFilter::PixelType lSrcMax( filterMinMax->GetMaximum() );
*/
// Extract-convert-remember min/MAX intensities for each band.
m_MinPixel = filterMinMax->GetMinimum();
m_MaxPixel = filterMinMax->GetMaximum();
qDebug() << tr( "%1: Pass #1 - done (%2 ms)." )
.arg( QDateTime::currentDateTime().toString( Qt::ISODate ) )
......@@ -391,8 +401,8 @@ HistogramModel
histogramFilter->SetInput( imageModel->ToImage() );
// Setup histogram filter.
histogramFilter->GetFilter()->SetHistogramMin( lSrcMin );
histogramFilter->GetFilter()->SetHistogramMax( lSrcMax );
histogramFilter->GetFilter()->SetHistogramMin( m_MinPixel );
histogramFilter->GetFilter()->SetHistogramMax( m_MaxPixel );
histogramFilter->GetFilter()->SetSubSamplingRate( 1 );
// Go.
......
......@@ -101,6 +101,7 @@ public:
};
}
/*******************************************************************************/
/*
namespace itk
{
//
......@@ -128,6 +129,7 @@ itkNumericTraitsGenericArrayDimensionsMacro( mvd::FixedArray, unsigned long long
#endif // ITK_TYPE_USE_LONG_LONG
#endif // ITK_USE_NUMERIC_TRAITS_PARTIAL_SPECIALIZATION
}
*/
/*******************************************************************************/
/* PROTOTYPE */
/*******************************************************************************/
......
......@@ -421,6 +421,7 @@ VectorImageModel::SourceImageType::ConstPointer
VectorImageModel
::ToImage() const
{
// TODO: Fix unsafe weak-pointer dereferencing.
return m_Image.GetPointer();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment