Commit f31cf8e8 authored by Stéphane Albert's avatar Stéphane Albert
Browse files

ENH: Improved VectorImageModel::Settings interface; Optimzzed modified and...

ENH: Improved VectorImageModel::Settings interface; Optimzzed modified and applied flags of ::Settings (not setting flag when not needed).
parent 2470289f
......@@ -389,8 +389,8 @@ MainWindow::closeEvent( QCloseEvent* event )
assert( Application::ConstInstance()->GetModel()==
Application::ConstInstance()->GetModel< DatasetModel >() );
// Get model.
const DatasetModel* model =
Application::ConstInstance()->GetModel< DatasetModel >();
DatasetModel* model =
Application::Instance()->GetModel< DatasetModel >();
if( model==NULL || !model->IsModified() )
return;
......
......@@ -74,6 +74,13 @@ AbstractModel
return false;
}
/*******************************************************************************/
void
AbstractModel
::ClearModified()
{
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......
......@@ -108,6 +108,10 @@ public:
*/
virtual bool IsModified() const;
/**
*/
virtual void ClearModified();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......
......@@ -72,6 +72,7 @@ namespace mvd
namespace otb
{
/**
* Convert an itk::VariableLengthVector< T2 > into a
* itk::FixedArray< T1, N >.
......@@ -137,6 +138,8 @@ ToVariableLengthVector( itk::FixedArray< T1, N >& a,
const itk::VariableLengthVector< T1 >& v );
} // end namespace 'otb'
/*****************************************************************************/
namespace mvd
{
/**
......@@ -171,6 +174,7 @@ AppendToQStringList( QStringList& qsl,
*
* \return The Unicode converted QString.
*/
inline
QString
FromStdString( const std::string& str );
......@@ -191,6 +195,56 @@ ToStdString( const QString& str );
} // end namespace 'mvd'.
/*****************************************************************************/
namespace mvd
{
/**
* \brief Test condition on all elements in range.
*
* \param first First element of range to test.
* \param last Upper (external) boundary of range to test.
* \param pred Predicate testing element in range.
*
* \return true if predicate is true on all elements in the range
* [first, last[ or if range is empty.
*/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
AllOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred );
/**
* \brief Test if any of element in range fulfills condition.
*
* \param first First element of range to test.
* \param last Upper (external) boundary of range to test.
* \param pred Predicate testing element in range.
*
* \return true if predicated is true for, at least, one element in range
* [first, last[. If range is empty, this function returns false.
*/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
AnyOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred );
/**
* \brief Test if no element in range fulfills condition.
*
* \param first First element of range to test.
* \param last Upper (external) boundary of range to test.
* \param pred Predicate testing element in range.
*
* \return true if predicated is false for all elements in range [first, last[. If range is empty, this function returns true.
*/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
NoneOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred );
} // end namespace 'mvd'.
/*****************************************************************************/
/* INLINE SECTION */
......@@ -318,4 +372,61 @@ ToStdString( const QString& str )
} // end namespace 'mvd'
namespace mvd
{
/*******************************************************************************/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
AllOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred )
{
while( first!=last )
{
if( !pred( *first ) )
return false;
++first;
}
return true;
}
/*******************************************************************************/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
AnyOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred )
{
while( first!=last )
{
if( pred( *first ) )
return true;
++first;
}
return false;
}
/*******************************************************************************/
template< typename TInputIterator, typename TUnaryPredicate >
inline
bool
NoneOf( TInputIterator first, TInputIterator last, TUnaryPredicate pred )
{
while( first!=last )
{
if( pred( *first ) )
return false;
++first;
}
return true;
}
} // end namespace 'mvd'
#endif // __mvdAlgorithm_h
......@@ -282,11 +282,11 @@ ColorDynamicsController
colorDynamicsWidget->GetChannel( channel );
DefaultImageType::PixelType::ValueType min(
minPx[ settings.RgbChannel( channel ) ]
minPx[ settings.GetRgbChannel( channel ) ]
);
DefaultImageType::PixelType::ValueType max(
maxPx[ settings.RgbChannel( channel ) ]
maxPx[ settings.GetRgbChannel( channel ) ]
);
// Block widget's signals...
......@@ -352,11 +352,11 @@ ColorDynamicsController
colorDynamicsWidget->GetChannel( channel );
DefaultImageType::PixelType::ValueType min(
minPx[ settings.RgbChannel( channel ) ]
minPx[ settings.GetRgbChannel( channel ) ]
);
DefaultImageType::PixelType::ValueType max(
maxPx[ settings.RgbChannel( channel ) ]
maxPx[ settings.GetRgbChannel( channel ) ]
);
// Block widget's signals...
//...but force call to valueChanged() slot to force refresh.
......@@ -435,8 +435,8 @@ ColorDynamicsController
);
*/
ParametersType::ValueType low = settings.DynamicsParam( 2 * channel );
ParametersType::ValueType high = settings.DynamicsParam( 2 * channel + 1 );
ParametersType::ValueType low = settings.GetDynamicsParam( 2 * channel );
ParametersType::ValueType hi = settings.GetDynamicsParam( 2 * channel + 1 );
// Block widget's signals...
//...but force call to valueChanged() slot to force refresh.
......@@ -446,8 +446,8 @@ ColorDynamicsController
colorBandDynWgt->SetLowIntensity( low );
OnLowIntensityChanged( channel, low );
colorBandDynWgt->SetHighIntensity( high );
OnHighIntensityChanged( channel, high );
colorBandDynWgt->SetHighIntensity( hi );
OnHighIntensityChanged( channel, hi );
}
colorBandDynWgt->blockSignals( false );
}
......@@ -537,13 +537,13 @@ ColorDynamicsController
// Calculate quantile intensity.
HistogramModel::MeasurementType intensity =
imageModel->GetHistogramModel()->Quantile(
settings.RgbChannel( channel ),
settings.GetRgbChannel( channel ),
0.01 * value,
BOUND_LOWER
);
// Update quantile intensity in model.
settings.DynamicsParam( 2 * channel ) = intensity;
settings.SetDynamicsParam( 2 * channel, intensity );
// Get color-dynamics widgets.
ColorDynamicsWidget* colorDynWgt = GetWidget< ColorDynamicsWidget >();
......@@ -582,13 +582,13 @@ ColorDynamicsController
// Calculate quantile intensity.
HistogramModel::MeasurementType intensity =
imageModel->GetHistogramModel()->Quantile(
settings.RgbChannel( channel ),
settings.GetRgbChannel( channel ),
0.01 * value,
BOUND_UPPER
);
// Update quantile intensity in model.
settings.DynamicsParam( 2 * channel + 1 ) = intensity;
settings.SetDynamicsParam( 2 * channel + 1, intensity );
// Get color-dynamics widgets.
ColorDynamicsWidget* colorDynWgt = GetWidget< ColorDynamicsWidget >();
......@@ -622,7 +622,7 @@ ColorDynamicsController
assert( imageModel->GetHistogramModel()!=NULL );
// Update parameter value.
imageModel->GetSettings().DynamicsParam( 2 * channel ) = value;
imageModel->GetSettings().SetDynamicsParam( 2 * channel, value );
// Get color-dynamics widgets.
ColorDynamicsWidget* colorDynWgt = GetWidget< ColorDynamicsWidget >();
......@@ -636,7 +636,7 @@ ColorDynamicsController
// Refresh quantile display.
colorBandDynWgt->SetLowQuantile(
100.0 * imageModel->GetHistogramModel()->Percentile(
imageModel->GetSettings().RgbChannel( channel ),
imageModel->GetSettings().GetRgbChannel( channel ),
value,
BOUND_LOWER )
);
......@@ -660,7 +660,7 @@ ColorDynamicsController
assert( imageModel->GetHistogramModel()!=NULL );
// Update parameter value in model.
imageModel->GetSettings().DynamicsParam( 2 * channel + 1 ) = value;
imageModel->GetSettings().SetDynamicsParam( 2 * channel + 1, value );
// Get color-dynamics widgets.
ColorDynamicsWidget* colorDynWgt = GetWidget< ColorDynamicsWidget >();
......@@ -674,7 +674,7 @@ ColorDynamicsController
// Refresh quantile display.
colorBandDynWgt->SetHighQuantile(
100.0 * imageModel->GetHistogramModel()->Percentile(
imageModel->GetSettings().RgbChannel( channel ),
imageModel->GetSettings().GetRgbChannel( channel ),
value,
BOUND_UPPER )
);
......@@ -711,6 +711,7 @@ ColorDynamicsController
emit ModelUpdated();
}
/*******************************************************************************/
void
ColorDynamicsController
::OnApplyAllClicked( RgbaChannel channel, double low, double high )
......@@ -730,7 +731,7 @@ ColorDynamicsController
HistogramModel::MeasurementType lintensity =
imageModel->GetHistogramModel()->Quantile(
settings.RgbChannel( i ),
settings.GetRgbChannel( i ),
0.01 * low,
BOUND_LOWER
);
......@@ -738,14 +739,14 @@ ColorDynamicsController
// Calculate quantile intensity.
HistogramModel::MeasurementType uintensity =
imageModel->GetHistogramModel()->Quantile(
settings.RgbChannel( i ),
settings.GetRgbChannel( i ),
0.01 * high,
BOUND_UPPER
);
// Update quantile intensity in model.
settings.DynamicsParam( 2 * i ) = lintensity;
settings.DynamicsParam( 2 * i + 1 ) = uintensity;
settings.SetDynamicsParam( 2 * i, lintensity );
settings.SetDynamicsParam( 2 * i + 1, uintensity );
// Get color-dynamics widgets.
ColorDynamicsWidget* colorDynWgt = GetWidget< ColorDynamicsWidget >();
......
......@@ -171,7 +171,7 @@ ColorSetupController
RgbaChannel channel = static_cast< RgbaChannel >( i );
VectorImageModel::Settings::ChannelVector::value_type band =
imageModel->GetSettings().RgbChannel( i );
imageModel->GetSettings().GetRgbChannel( i );
// Set current-index of channel.
colorSetupWidget->SetCurrentIndex( channel, band );
......@@ -197,7 +197,7 @@ ColorSetupController
assert( imageModel!=NULL );
// Update channel index.
imageModel->GetSettings().RgbChannel( channel ) = index;
imageModel->GetSettings().SetRgbChannel( channel, index );
// Signal band-index of RGB channel has changed to other
// controllers.
......
......@@ -251,11 +251,6 @@ DatasetDescriptor
)
);
}
// Dynamics
// TODO: Manage XML structure errors.
// TODO: Set dynamics text here.
// if everything went ok
return true;
}
......
......@@ -320,9 +320,26 @@ DatasetModel
/*******************************************************************************/
void
DatasetModel
::Save() const
::ClearModified()
{
AbstractImageModelList aimList( GetImageModels() );
for( AbstractImageModelList::iterator it( aimList.begin() );
it!=aimList.end();
++it )
{
( *it )->ClearModified();
}
}
/*******************************************************************************/
void
DatasetModel
::Save()
{
WriteDescriptor();
ClearModified();
}
/*******************************************************************************/
......
......@@ -157,13 +157,15 @@ public:
/**
*/
void Save() const;
void Save();
//
// AbstractModel overrides.
virtual bool IsModified() const;
virtual void ClearModified();
/*-[ SIGNALS SECTION ]-----------------------------------------------------*/
//
......
......@@ -78,7 +78,6 @@ VectorImageModel
m_RegionsToLoadVector(),
m_Filename()
{
QObject::connect(
this,
SIGNAL( ViewportRegionChanged(double, double) ),
......@@ -286,15 +285,19 @@ VectorImageModel
for( CountType i=0; i<RGBA_CHANNEL_ALPHA; ++i )
{
Settings::ChannelVector::value_type band =
GetSettings().RgbChannel( static_cast< RgbaChannel >( i ) );
GetSettings().GetRgbChannel( static_cast< RgbaChannel >( i ) );
ParametersType::ValueType index = 2 * i;
GetSettings().DynamicsParam( index ) =
histogramModel->Quantile( band , 0.02, BOUND_LOWER );
GetSettings().SetDynamicsParam(
index,
histogramModel->Quantile( band , 0.02, BOUND_LOWER )
);
GetSettings().DynamicsParam( index + 1) =
histogramModel->Quantile( band , 0.02, BOUND_UPPER );
GetSettings().SetDynamicsParam(
index,
histogramModel->Quantile( band , 0.02, BOUND_UPPER )
);
}
}
......@@ -745,6 +748,20 @@ VectorImageModel
return GetSettings().IsModified();
}
/*******************************************************************************/
void
VectorImageModel
::ClearModified()
{
GetSettings().ClearModified();
// TODO: Remove temporary hack (Quicklook modified flag).
QuicklookModel* quicklookModel = GetQuicklookModel();
// If image-model is not quicklook-model.
if( quicklookModel!=NULL )
quicklookModel->ClearModified();
}
/*******************************************************************************/
/* SLOTS */
/*******************************************************************************/
......@@ -766,7 +783,7 @@ VectorImageModel
renderingFunc->SetChannelList( rgb );
renderingFunc->SetParameters( GetSettings().GetDynamicsParams() );
// TODO: Remove temporary hack (rendering settings).
// TODO: Remove temporary hack (Quicklook rendering settings).
QuicklookModel* quicklookModel = GetQuicklookModel();
// If image-model is not quicklook-model.
if( quicklookModel!=NULL )
......
......@@ -109,131 +109,87 @@ public:
/**
* \brief Constructor.
*/
Settings() :
m_RgbChannels(),
m_DynamicsParams( 6 ),
m_IsModified( false ),
m_IsApplied( false )
{
}
Settings();
/**
* \brief Copy constructor.
*
* \param
*
* Copy settings POD content without modified nor applied flag.
*/
Settings( const Settings& other );
/**
* \brief Destructor.
*/
~Settings()
{
}
~Settings() ;
/**
*/
inline
bool
IsApplied() const
{
return m_IsApplied;
}
inline bool IsApplied() const;
/**
*/
inline
bool
IsModified() const
{
return m_IsModified;
}
inline bool IsModified() const;
/** */
inline
void
SetModified()
{
m_IsModified = true;
m_IsApplied = false;
}
inline void SetModified();
/** */
inline void SetApplied()
{
m_IsApplied = true;
}
inline void ClearModified();
/** */
inline
void
SetRgbChannels( const ChannelVector& rgb )
{
m_RgbChannels = rgb;
inline void SetApplied();
SetModified();
}
/** */
inline void SetRgbChannels( const ChannelVector& rgb );
/** */
inline
const ChannelVector&
GetRgbChannels() const
{
return m_RgbChannels;
}
inline const ChannelVector& GetRgbChannels() const;
/**
*/
inline
ChannelVector::value_type&
RgbChannel( ChannelVector::size_type i )
{
SetModified();
return m_RgbChannels[ i ];
}
#if 0
inline ChannelVector::value_type& RgbChannel( ChannelVector::size_type i );
#endif
/**
*/
inline
const ChannelVector::value_type&
RgbChannel( ChannelVector::size_type i ) const
{
return m_RgbChannels[ i ];
}
void SetRgbChannel( ChannelVector::size_type i,
const ChannelVector::value_type& channel );
/**
*/
inline
void
SetDynamicsParams( const ParametersType& params )
{
m_DynamicsParams = params;
const ChannelVector::value_type&
GetRgbChannel( ChannelVector::size_type i ) const;
SetModified();
}
/**
*/
inline void SetDynamicsParams( const ParametersType& params );
/**
*/
inline
const ParametersType&
GetDynamicsParams() const
{
return m_DynamicsParams;
}
inline const ParametersType& GetDynamicsParams() const;
/**
*/
inline
const ParametersType::ValueType&
DynamicsParam( CountType i ) const
{
return m_DynamicsParams[ i ];
}
const ParametersType::ValueType& GetDynamicsParam( CountType i ) const;
/**
*/
inline
ParametersType::ValueType&
DynamicsParam( CountType i )
{
SetModified();