+#include <cpPlugins/ActorImageProperties.h>
+
+#ifdef cpPlugins_QT4
+
+#include <cpPlugins/ui_ActorImageProperties.h>
+
+#include <vtkImageActor.h>
+#include <vtkImageData.h>
+#include <vtkImageMapper3D.h>
+#include <vtkImageProperty.h>
+
+// -------------------------------------------------------------------------
+cpPlugins::ActorImageProperties::
+ActorImageProperties( QWidget* parent )
+ : cpPlugins::ActorProperties( parent ),
+ m_UI( new Ui::ActorImageProperties )
+{
+ this->m_UI->setupUi( this );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::ActorImageProperties::
+~ActorImageProperties( )
+{
+ delete this->m_UI;
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::ActorImageProperties::
+addActor( vtkProp* obj )
+{
+ auto actor = dynamic_cast< vtkImageActor* >( obj );
+ if( actor != NULL )
+ {
+ this->m_Actors.insert( obj );
+ if( this->m_Actors.size( ) == 1 )
+ this->_updateWidgets( );
+ return( true );
+ }
+ else
+ return( false );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_updateWidgets( )
+{
+ auto actor =
+ dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
+ if( actor == NULL )
+ return;
+
+ // Get properties
+ auto prop = actor->GetProperty( );
+ auto mapper = actor->GetMapper( );
+ auto image = mapper->GetInput( );
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ double win = prop->GetColorWindow( );
+ double lev = prop->GetColorLevel( );
+ double op = prop->GetOpacity( );
+ int interp = prop->GetInterpolationType( );
+
+ this->m_UI->ValueWindow->setMinimum( 0 );
+ this->m_UI->ValueWindow->setMaximum( r[ 1 ] - r[ 0 ] );
+ this->m_UI->ValueLevel->setMinimum( r[ 0 ] );
+ this->m_UI->ValueLevel->setMaximum( r[ 1 ] );
+ this->m_UI->ValueWindow->setValue( win );
+ this->m_UI->ValueLevel->setValue( lev );
+
+ double w = win / ( r[ 1 ] - r[ 0 ] );
+ double l = ( lev - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
+
+ op *= double( this->m_UI->Opacity->maximum( ) );
+ this->m_UI->Opacity->setValue( int( op ) );
+
+ w *= double( this->m_UI->Window->maximum( ) );
+ this->m_UI->Window->setValue( int( w ) );
+
+ l *= double( this->m_UI->Level->maximum( ) );
+ this->m_UI->Level->setValue( int( l ) );
+
+ if( interp == VTK_CUBIC_INTERPOLATION )
+ this->m_UI->Interpolation->setCurrentIndex( 0 );
+ else if( interp == VTK_LINEAR_INTERPOLATION )
+ this->m_UI->Interpolation->setCurrentIndex( 1 );
+ else if( interp == VTK_NEAREST_INTERPOLATION )
+ this->m_UI->Interpolation->setCurrentIndex( 2 );
+
+ // Connect stuff
+ this->connect(
+ this->m_UI->Opacity, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _Opacity( int ) )
+ );
+ this->connect(
+ this->m_UI->Window, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _Window( int ) )
+ );
+ this->connect(
+ this->m_UI->Level, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _Level( int ) )
+ );
+ this->connect(
+ this->m_UI->ValueWindow, SIGNAL( valueChanged( double ) ),
+ this, SLOT( _Window( double ) )
+ );
+ this->connect(
+ this->m_UI->ValueLevel, SIGNAL( valueChanged( double ) ),
+ this, SLOT( _Level( double ) )
+ );
+ this->connect(
+ this->m_UI->Interpolation, SIGNAL( currentIndexChanged( int ) ),
+ this, SLOT( _Interpolation( int ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Opacity( int v )
+{
+ double op = double( v ) / double( this->m_UI->Opacity->maximum( ) );
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetOpacity( op );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Window( int v )
+{
+ double x = this->m_UI->ValueWindow->minimum( );
+ double y = this->m_UI->ValueWindow->maximum( );
+ double z = double( v ) / double( this->m_UI->Window->maximum( ) );
+ double w = ( ( y - x ) * z ) + x;
+ bool prev = this->m_UI->ValueWindow->blockSignals( true );
+ this->m_UI->ValueWindow->setValue( w );
+ this->m_UI->ValueWindow->blockSignals( prev );
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetColorWindow( w );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Level( int v )
+{
+ double x = this->m_UI->ValueLevel->minimum( );
+ double y = this->m_UI->ValueLevel->maximum( );
+ double z = double( v ) / double( this->m_UI->Level->maximum( ) );
+ double l = ( ( y - x ) * z ) + x;
+ bool prev = this->m_UI->ValueLevel->blockSignals( true );
+ this->m_UI->ValueLevel->setValue( l );
+ this->m_UI->ValueLevel->blockSignals( prev );
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetColorLevel( l );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Window( double v )
+{
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetColorWindow( v );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+
+ double x = this->m_UI->ValueWindow->minimum( );
+ double y = this->m_UI->ValueWindow->maximum( );
+ double z = ( v - x ) / ( y - x );
+ double w = double( z ) * double( this->m_UI->Window->maximum( ) );
+ bool prev = this->m_UI->Window->blockSignals( true );
+ this->m_UI->Window->setValue( int( w ) );
+ this->m_UI->Window->blockSignals( prev );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Level( double v )
+{
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetColorLevel( v );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+
+ double x = this->m_UI->ValueLevel->minimum( );
+ double y = this->m_UI->ValueLevel->maximum( );
+ double z = ( v - x ) / ( y - x );
+ double l = double( z ) * double( this->m_UI->Level->maximum( ) );
+ bool prev = this->m_UI->Level->blockSignals( true );
+ this->m_UI->Level->setValue( int( l ) );
+ this->m_UI->Level->blockSignals( prev );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::ActorImageProperties::
+_Interpolation( int v )
+{
+ int interp = VTK_NEAREST_INTERPOLATION;
+ if ( v == 0 ) interp = VTK_CUBIC_INTERPOLATION;
+ else if( v == 1 ) interp = VTK_LINEAR_INTERPOLATION;
+ else if( v == 2 ) interp = VTK_NEAREST_INTERPOLATION;
+
+ auto aIt = this->m_Actors.begin( );
+ for( ; aIt != this->m_Actors.end( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+ ma->GetProperty( )->SetInterpolationType( interp );
+ ma->Modified( );
+
+ } // rof
+ this->_render( );
+}
+
+#endif // cpPlugins_QT4
+
+// eof - $RCSfile$