#include #ifdef cpExtensions_QT4 #include #include // ------------------------------------------------------------------------- cpExtensions::QT::WindowLevelImageConfiguration:: WindowLevelImageConfiguration( QWidget* parent, Qt::WindowFlags f ) : Superclass( parent, f ), m_UI( new Ui::WindowLevelImageConfiguration ), m_Data( NULL ), m_Name( "" ) { this->m_UI->setupUi( this ); } // ------------------------------------------------------------------------- cpExtensions::QT::WindowLevelImageConfiguration:: ~WindowLevelImageConfiguration( ) { delete this->m_UI; } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: setData( ActorsWidgetInterface* data, const std::string& name ) { if( this->m_Data != data ) { this->m_Data = data; this->m_Name = name; // Get data double range[ 2 ], win_lev[ 2 ]; this->m_Data->GetScalarRange( this->m_Name, range ); this->m_Data->GetWindowLevel( this->m_Name, win_lev ); // Intensity range this->m_UI->MinimumBox->setMinimum( -1000000 ); this->m_UI->MinimumBox->setMaximum( 1000000 ); this->m_UI->MaximumBox->setMinimum( -1000000 ); this->m_UI->MaximumBox->setMaximum( 1000000 ); this->m_UI->MinimumBox->setValue( range[ 0 ] ); this->m_UI->MaximumBox->setValue( range[ 1 ] ); // Window/level double off = range[ 1 ] - range[ 0 ]; this->m_UI->WindowBox->setMinimum( 0 ); this->m_UI->WindowBox->setMaximum( off ); this->m_UI->LevelBox->setMinimum( range[ 0 ] ); this->m_UI->LevelBox->setMaximum( range[ 1 ] ); this->m_UI->WindowBox->setValue( win_lev[ 0 ] ); this->m_UI->LevelBox->setValue( win_lev[ 1 ] ); double w = win_lev[ 0 ] / off; w *= double( this->m_UI->WindowSlider->maximum( ) ) - double( this->m_UI->WindowSlider->minimum( ) ); w += double( this->m_UI->WindowSlider->minimum( ) ); this->m_UI->WindowSlider->setValue( w ); double l = ( win_lev[ 1 ] - range[ 0 ] ) / off; l *= double( this->m_UI->LevelSlider->maximum( ) ) - double( this->m_UI->LevelSlider->minimum( ) ); l += double( this->m_UI->LevelSlider->minimum( ) ); this->m_UI->LevelSlider->setValue( l ); // Opacity double o = this->m_Data->GetOpacity( this->m_Name ); o *= double( this->m_UI->OpacitySlider->maximum( ) ) - double( this->m_UI->OpacitySlider->minimum( ) ); o += double( this->m_UI->OpacitySlider->minimum( ) ); this->m_UI->OpacitySlider->setValue( o ); // Interpolation mode switch( this->m_Data->GetImageInterpolation( this->m_Name ) ) { case 'L': this->m_UI->InterpolatorBox->setCurrentIndex( 1 ); break; case 'C': this->m_UI->InterpolatorBox->setCurrentIndex( 2 ); break; default : this->m_UI->InterpolatorBox->setCurrentIndex( 0 ); break; } // hctiws // Slots <-> signals this->connect( this->m_UI->MaximumBox, SIGNAL( valueChanged( int ) ), this, SLOT( _maximumValue( int ) ) ); this->connect( this->m_UI->MinimumBox, SIGNAL( valueChanged( int ) ), this, SLOT( _minimumValue( int ) ) ); this->connect( this->m_UI->LevelBox, SIGNAL( valueChanged( int ) ), this, SLOT( _levelValue( int ) ) ); this->connect( this->m_UI->LevelSlider, SIGNAL( valueChanged( int ) ), this, SLOT( _levelValue( int ) ) ); this->connect( this->m_UI->WindowBox, SIGNAL( valueChanged( int ) ), this, SLOT( _windowValue( int ) ) ); this->connect( this->m_UI->WindowSlider, SIGNAL( valueChanged( int ) ), this, SLOT( _windowValue( int ) ) ); this->connect( this->m_UI->OpacitySlider, SIGNAL( valueChanged( int ) ), this, SLOT( _opacityValue( int ) ) ); this->connect( this->m_UI->InterpolatorBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( _interpolatorValue( int ) ) ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _maximumValue( int v ) { double range[ 2 ]; range[ 0 ] = double( this->m_UI->MinimumBox->value( ) ); range[ 1 ] = double( v ); this->m_Data->SetScalarRange( this->m_Name, range ); } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _minimumValue( int v ) { double range[ 2 ]; range[ 0 ] = double( v ); range[ 1 ] = double( this->m_UI->MaximumBox->value( ) ); this->m_Data->SetScalarRange( this->m_Name, range ); } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _levelValue( int v ) { double r[ 2 ]; double l, s; this->m_Data->GetScalarRange( this->m_Name, r ); if( this->sender( ) == this->m_UI->LevelSlider ) { s = double( v ) / double( this->m_UI->LevelSlider->maximum( ) ); l = ( ( r[ 1 ] - r[ 0 ] ) * s ) + r[ 0 ]; } else { l = double( v ); s = ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] ); } // fi s *= this->m_UI->LevelSlider->maximum( ); bool b = this->m_UI->LevelSlider->blockSignals( true ); this->m_UI->LevelSlider->setValue( s ); this->m_UI->LevelSlider->blockSignals( b ); b = this->m_UI->LevelBox->blockSignals( true ); this->m_UI->LevelBox->setValue( l ); this->m_UI->LevelBox->blockSignals( b ); this->m_Data->SetLevel( this->m_Name, l ); } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _windowValue( int v ) { double r[ 2 ]; double w, s; this->m_Data->GetScalarRange( this->m_Name, r ); if( this->sender( ) == this->m_UI->WindowSlider ) { s = double( v ) / double( this->m_UI->WindowSlider->maximum( ) ); w = ( ( r[ 1 ] - r[ 0 ] ) * s ) + r[ 0 ]; } else { w = double( v ); s = ( w - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] ); } // fi s *= this->m_UI->WindowSlider->maximum( ); bool b = this->m_UI->WindowSlider->blockSignals( true ); this->m_UI->WindowSlider->setValue( s ); this->m_UI->WindowSlider->blockSignals( b ); b = this->m_UI->WindowBox->blockSignals( true ); this->m_UI->WindowBox->setValue( w ); this->m_UI->WindowBox->blockSignals( b ); this->m_Data->SetWindow( this->m_Name, w ); } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _opacityValue( int v ) { if( this->m_Data != NULL ) { double o = double( v ); o -= double( this->m_UI->OpacitySlider->minimum( ) ); o /= double( this->m_UI->OpacitySlider->maximum( ) ) - double( this->m_UI->OpacitySlider->minimum( ) ); this->m_Data->SetOpacity( this->m_Name, o ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::WindowLevelImageConfiguration:: _interpolatorValue( int v ) { switch( v ) { case 1 : this->m_Data->SetImageInterpolation( this->m_Name, 'L' ); break; case 2 : this->m_Data->SetImageInterpolation( this->m_Name, 'C' ); break; default : this->m_Data->SetImageInterpolation( this->m_Name, 'N' ); break; } // hctiws } #endif // cpExtensions_QT4 // eof - $RCSfile$