Commit 0eb09a45 authored by Martin Bauer's avatar Martin Bauer

Generalized GUI display adaptor to show fields of arbitrary f-size

parent f6275747
Pipeline #13656 passed with stages
in 643 minutes and 29 seconds
......@@ -56,7 +56,6 @@ namespace gui {
typedef typename field_t::value_type T;
static const uint_t F_SIZE = field_t::F_SIZE;
static_assert( F_SIZE ==1, "Only Scalar fields can be displayed" );
void drawScalarFieldNumeric( CellView * cell, const typename field_t::const_iterator & it );
void drawScalarFieldColormap( CellView * cell, const typename field_t::const_iterator & it, T min, T max );
......@@ -65,7 +64,7 @@ namespace gui {
using FieldDisplayAdaptor<field_t>::field_;
using FieldDisplayAdaptor<field_t>::sliceInterval_;
using FieldDisplayAdaptor<field_t>::blockDataId_;
cell_idx_t f;
DisplayPropertiesItem * displayProperties_;
};
......
......@@ -37,6 +37,7 @@ namespace gui {
template< typename field_t>
ScalarFieldDisplayAdaptor<field_t>::ScalarFieldDisplayAdaptor( ConstBlockDataID scalarFieldID )
: FieldDisplayAdaptor<field_t>( scalarFieldID ),
f(0),
displayProperties_ ( NULL )
{
}
......@@ -67,7 +68,17 @@ void ScalarFieldDisplayAdaptor<field_t>::addConfigurationItem( QTreeWidgetItem *
if ( ! displayProperties_ )
{
QStringList options;
options << "Numeric" << "Color Map";
if( field_t::F_SIZE == 1) {
options << "Numeric" << "Color Map";
}
else
{
for( uint_t i=0; i < field_t::F_SIZE; ++i ) {
options << QString("%1 Numeric").arg(i);
options << QString("%1 Color Map").arg(i);
}
}
displayProperties_ = new DisplayPropertiesItem( options, parentItem );
displayProperties_->enableGradientSelect();
......@@ -87,10 +98,11 @@ void ScalarFieldDisplayAdaptor<field_t>::draw( QVector<QVector<CellView*> > & gr
return;
// displayType is option index in the QStringList passed to the constructor of displayProperties
int displayType = displayProperties_->getComboBoxSelection();
int comboSelection = displayProperties_->getComboBoxSelection();
int displayType = comboSelection % 2;
f = comboSelection / 2;
assert ( displayType >=0 && displayType <2 );
T min = std::numeric_limits<T>::max();
T max = std::numeric_limits<T>::min();
if ( displayType == 1 )
......@@ -117,26 +129,28 @@ void ScalarFieldDisplayAdaptor<field_t>::draw( QVector<QVector<CellView*> > & gr
}
template< typename field_t>
void ScalarFieldDisplayAdaptor<field_t>::drawScalarFieldNumeric( CellView * cell, const typename field_t::const_iterator & it )
void ScalarFieldDisplayAdaptor<field_t>::drawScalarFieldNumeric( CellView * cell,
const typename field_t::const_iterator & it)
{
if( boost::is_same<T,float>::value || boost::is_same<T,double>::value )
cell->setText( QString("%1").arg( real_c(*it), 0,'g',6) );
else if ( *it < std::numeric_limits<T>::max() )
cell->setText( QString("%1").arg(*it) );
cell->setText(QString("%1").arg(real_c(it.getF(f)), 0, 'g', 6));
else if ( it.getF(f) < std::numeric_limits<T>::max() )
cell->setText( QString("%1").arg(it.getF(f)) );
else
cell->setText("");
}
template< typename field_t>
void ScalarFieldDisplayAdaptor<field_t>::drawScalarFieldColormap( CellView * cell, const typename field_t::const_iterator & it,
T min, T max )
void ScalarFieldDisplayAdaptor<field_t>::drawScalarFieldColormap( CellView * cell,
const typename field_t::const_iterator & it,
T min, T max )
{
real_t normVal = 0;
if ( fabs( real_c(max) - real_c(min) ) > 1e-7 )
normVal = real_c( *it - min ) / real_c(max-min);
normVal = real_c(it.getF(f) - min) / real_c(max - min);
if ( *it < std::numeric_limits<T>::max() )
if ( it.getF(f) < std::numeric_limits<T>::max() )
cell->setBrush( displayProperties_->getColorFromColormap( normVal ) );
else
cell->setBrush( QBrush(Qt::red) );
......
......@@ -136,6 +136,14 @@ DisplayAdaptor * GUI::findDisplayAdaptorForBlockID ( ConstBlockDataID bdId ) con
if ( block.isDataOfType< GhostLayerField<real_t,3> > ( bdId) ) return new ScalarField3DisplayAdaptor<GhostLayerField<real_t,3> > ( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,2> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 2> >( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,3> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 3> >( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,4> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 4> >( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,5> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 5> >( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,6> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 6> >( bdId );
if ( block.isDataOfType< GhostLayerField<real_t,7> >( bdId) ) return new ScalarFieldDisplayAdaptor<GhostLayerField<real_t, 7> >( bdId );
// Fields
if ( block.isDataOfType< Field<uint8_t ,1> >( bdId) ) return new ScalarFieldDisplayAdaptor<Field<uint8_t ,1> >( bdId );
if ( block.isDataOfType< Field<uint16_t,1> >( bdId) ) return new ScalarFieldDisplayAdaptor<Field<uint16_t,1> >( bdId );
......
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