--- /dev/null
+#include <cpPlugins/DataObjectVisualizationQtDialog.h>
+
+#include <vtkImageActor.h>
+#include <vtkImageData.h>
+#include <vtkImageProperty.h>
+#include <vtkMapper.h>
+#include <vtkPolyData.h>
+#include <vtkProperty.h>
+
+#ifdef cpPlugins_QT4
+
+#include <QCheckBox>
+#include <QColorDialog>
+#include <QDoubleSpinBox>
+#include <QPushButton>
+#include <QSlider>
+
+// -------------------------------------------------------------------------
+cpPlugins::DataObjectVisualizationQtDialog::
+DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f )
+ : QDialog( parent, f ),
+ m_DataObject( NULL ),
+ m_WidgetsUpdated( false )
+{
+ this->m_Title = new QLabel( this );
+ this->m_Title->setText( "Visualization properties" );
+ this->m_MainLayout = new QGridLayout( this );
+ this->m_ToolsLayout = new QVBoxLayout( );
+ this->m_ToolsLayout->addWidget( this->m_Title );
+ this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::DataObjectVisualizationQtDialog::
+~DataObjectVisualizationQtDialog( )
+{
+ delete this->m_Title;
+ delete this->m_ToolsLayout;
+ delete this->m_MainLayout;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::DataObject* cpPlugins::DataObjectVisualizationQtDialog::
+getDataObject( ) const
+{
+ return( this->m_DataObject );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::DataObjectVisualizationQtDialog::
+setDataObject( DataObject* obj )
+{
+ if( this->m_DataObject != NULL || obj == NULL )
+ return( false );
+ this->m_DataObject = obj;
+ this->m_WidgetsUpdated = false;
+ return( true );
+}
+
+// -------------------------------------------------------------------------
+int cpPlugins::DataObjectVisualizationQtDialog::
+exec( )
+{
+ this->_updateWidgets( );
+ int ret = this->QDialog::exec( );
+ /* TODO
+ if( ret == 1 )
+ this->updateParameters( );
+ else
+ this->updateView( );
+ */
+ return( ret );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_addButtons( )
+{
+ // Add buttons
+ this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
+ this->connect(
+ this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
+ );
+ this->connect(
+ this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
+ );
+ this->m_ToolsLayout->addWidget( this->m_Buttons );
+ // TODO: this->updateView( );
+ this->m_WidgetsUpdated = true;
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_updateWidgets( )
+{
+ if( this->m_WidgetsUpdated || this->m_DataObject == NULL )
+ return;
+
+ // Set dialog title
+ std::stringstream title;
+ title
+ << "Parameters for an object of class \""
+ << this->m_DataObject->GetClassName( )
+ << "\"";
+ this->m_Title->setText( title.str( ).c_str( ) );
+
+ // Configure particular objects
+ this->_configureForImage( );
+ this->_configureForMesh( );
+
+ // Update values
+ this->_addButtons( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_configureForImage( )
+{
+ auto image = this->m_DataObject->GetVTK< vtkImageData >( );
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ if( image == NULL || aIt == this->m_DataObject->EndVTKActors( ) )
+ return;
+ auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+ if( actor == NULL )
+ return;
+
+ double r[ 2 ];
+ image->GetScalarRange( r );
+ double w = actor->GetProperty( )->GetColorWindow( );
+ double l = actor->GetProperty( )->GetColorLevel( );
+ double sw = double( 1000 ) * w / ( r[ 1 ] - r[ 0 ] );
+ double sl = double( 1000 ) * ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
+ double op = double( 10 ) * actor->GetProperty( )->GetOpacity( );
+
+ QDoubleSpinBox* win_box = new QDoubleSpinBox( this );
+ win_box->setObjectName( "win_box" );
+ win_box->setDecimals( 3 );
+ win_box->setMinimum( 0 );
+ win_box->setMaximum( r[ 1 ] - r[ 0 ] );
+ win_box->setValue( w );
+ win_box->connect(
+ win_box, SIGNAL( valueChanged( double ) ),
+ this, SLOT( _boxWindow( double ) )
+ );
+
+ QSlider* win_sld = new QSlider( Qt::Horizontal, this );
+ win_sld->setObjectName( "win_sld" );
+ win_sld->setRange( 0, 1000 );
+ win_sld->setValue( ( unsigned int )( sw ) );
+ win_sld->connect(
+ win_sld, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _sldWindow( int ) )
+ );
+
+ QHBoxLayout* win_layout = new QHBoxLayout( );
+ QLabel* win_label = new QLabel( this );
+ win_label->setText( QString( "Window: " ) );
+ win_layout->addWidget( win_label );
+ win_layout->addWidget( win_box );
+ win_layout->addWidget( win_sld );
+ this->m_ToolsLayout->addLayout( win_layout );
+
+ QDoubleSpinBox* lev_box = new QDoubleSpinBox( this );
+ lev_box->setObjectName( "lev_box" );
+ lev_box->setDecimals( 3 );
+ lev_box->setMinimum( r[ 0 ] );
+ lev_box->setMaximum( r[ 1 ] );
+ lev_box->setValue( l );
+ lev_box->connect(
+ lev_box, SIGNAL( valueChanged( double ) ),
+ this, SLOT( _boxLevel( double ) )
+ );
+
+ QSlider* lev_sld = new QSlider( Qt::Horizontal, this );
+ lev_sld->setObjectName( "lev_sld" );
+ lev_sld->setRange( 0, 1000 );
+ lev_sld->setValue( ( unsigned int )( sl ) );
+ lev_sld->connect(
+ lev_sld, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _sldLevel( int ) )
+ );
+
+ QHBoxLayout* lev_layout = new QHBoxLayout( );
+ QLabel* lev_label = new QLabel( this );
+ lev_label->setText( QString( "Level: " ) );
+ lev_layout->addWidget( lev_label );
+ lev_layout->addWidget( lev_box );
+ lev_layout->addWidget( lev_sld );
+ this->m_ToolsLayout->addLayout( lev_layout );
+
+ // Configure generic objects
+ QSlider* op_sld = new QSlider( Qt::Horizontal, this );
+ op_sld->setObjectName( "op_sld" );
+ op_sld->setRange( 0, 10 );
+ op_sld->setValue( ( unsigned int )( op ) );
+ op_sld->connect(
+ op_sld, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _sldOpacity( int ) )
+ );
+
+ QHBoxLayout* op_layout = new QHBoxLayout( );
+ QLabel* op_label = new QLabel( this );
+ op_label->setText( QString( "Opacity: " ) );
+ op_layout->addWidget( op_label );
+ op_layout->addWidget( op_sld );
+ this->m_ToolsLayout->addLayout( op_layout );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_configureForMesh( )
+{
+ auto mesh = this->m_DataObject->GetVTK< vtkPolyData >( );
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ if( mesh == NULL || aIt == this->m_DataObject->EndVTKActors( ) )
+ return;
+ auto actor = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) );
+ if( actor == NULL )
+ return;
+
+ QSpinBox* ps_box = new QSpinBox( this );
+ ps_box->setObjectName( "ps_box" );
+ ps_box->setMinimum( 1 );
+ ps_box->setMaximum( 100 );
+ ps_box->setValue( actor->GetProperty( )->GetPointSize( ) );
+ ps_box->connect(
+ ps_box, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _boxPointSize( int ) )
+ );
+
+ QHBoxLayout* ps_layout = new QHBoxLayout( );
+ QLabel* ps_label = new QLabel( this );
+ ps_label->setText( QString( "Point size: " ) );
+ ps_layout->addWidget( ps_label );
+ ps_layout->addWidget( ps_box );
+ this->m_ToolsLayout->addLayout( ps_layout );
+
+ QSpinBox* lw_box = new QSpinBox( this );
+ lw_box->setObjectName( "lw_box" );
+ lw_box->setMinimum( 1 );
+ lw_box->setMaximum( 100 );
+ lw_box->setValue( actor->GetProperty( )->GetLineWidth( ) );
+ lw_box->connect(
+ lw_box, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _boxLineWidth( int ) )
+ );
+
+ QHBoxLayout* lw_layout = new QHBoxLayout( );
+ QLabel* lw_label = new QLabel( this );
+ lw_label->setText( QString( "Line width: " ) );
+ lw_layout->addWidget( lw_label );
+ lw_layout->addWidget( lw_box );
+ this->m_ToolsLayout->addLayout( lw_layout );
+
+ QCheckBox* sv_box = new QCheckBox( this );
+ sv_box->setObjectName( "sv_box" );
+ sv_box->setText( "Scalar visibility: " );
+ sv_box->setChecked( ( actor->GetMapper( )->GetScalarVisibility( ) == 1 ) );
+ sv_box->connect(
+ sv_box, SIGNAL( stateChanged( int ) ),
+ this, SLOT( _scalarVisibility( int ) )
+ );
+
+ QHBoxLayout* sv_layout = new QHBoxLayout( );
+ sv_layout->addWidget( sv_box );
+ this->m_ToolsLayout->addLayout( sv_layout );
+
+ double cr, cg, cb;
+ actor->GetProperty( )->GetColor( cr, cg, cb );
+ cr *= double( 255 );
+ cg *= double( 255 );
+ cb *= double( 255 );
+
+ QPushButton* color_button = new QPushButton( "Color", this );
+ color_button->setObjectName( "color_button" );
+ QPalette color_palette = color_button->palette( );
+ color_palette.setColor( QPalette::Button, QColor( cr, cg, cb ) );
+ color_button->setAutoFillBackground( true );
+ color_button->setPalette( color_palette );
+ color_button->update( );
+ color_button->connect(
+ color_button, SIGNAL( clicked( ) ),
+ this, SLOT( _color( ) )
+ );
+
+ QHBoxLayout* color_layout = new QHBoxLayout( );
+ color_layout->addWidget( color_button );
+ this->m_ToolsLayout->addLayout( color_layout );
+
+ // Configure generic objects
+ QSlider* op_sld = new QSlider( Qt::Horizontal, this );
+ op_sld->setObjectName( "op_sld" );
+ op_sld->setRange( 0, 10 );
+ op_sld->setValue(
+ ( unsigned int )( actor->GetProperty( )->GetOpacity( ) * double( 10 ) )
+ );
+ op_sld->connect(
+ op_sld, SIGNAL( valueChanged( int ) ),
+ this, SLOT( _sldOpacity( int ) )
+ );
+
+ QHBoxLayout* op_layout = new QHBoxLayout( );
+ QLabel* op_label = new QLabel( this );
+ op_label->setText( QString( "Opacity: " ) );
+ op_layout->addWidget( op_label );
+ op_layout->addWidget( op_sld );
+ this->m_ToolsLayout->addLayout( op_layout );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_setWindow( double w )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+ {
+ auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+ if( actor != NULL )
+ {
+ actor->GetProperty( )->SetColorWindow( w );
+ actor->Modified( );
+
+ } // fi
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_setLevel( double l )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+ {
+ auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+ if( actor != NULL )
+ {
+ actor->GetProperty( )->SetColorLevel( l );
+ actor->Modified( );
+
+ } // fi
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_render( )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ this->m_DataObject->RenderVTKActors( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_boxWindow( double v )
+{
+ auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
+ auto* sld = this->findChild< QSlider* >( "win_sld" );
+ if( box == NULL || sld == NULL )
+ return;
+
+ double min = double( sld->minimum( ) );
+ double max = double( sld->maximum( ) );
+ double vmin = box->minimum( );
+ double vmax = box->maximum( );
+ double s = ( v - vmin ) / ( vmax - vmin );
+ s = ( ( max - min ) * s ) + min;
+
+ bool o = sld->blockSignals( true );
+ sld->setValue( ( unsigned int )( s ) );
+ sld->blockSignals( o );
+ this->_setWindow( v );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_sldWindow( int v )
+{
+ auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
+ auto* sld = this->findChild< QSlider* >( "win_sld" );
+ if( box == NULL || sld == NULL )
+ return;
+
+ double min = double( sld->minimum( ) );
+ double max = double( sld->maximum( ) );
+ double vmin = box->minimum( );
+ double vmax = box->maximum( );
+ double s = ( double( v ) - min ) / ( max - min );
+ s = ( ( vmax - vmin ) * s ) + vmin;
+
+ bool o = box->blockSignals( true );
+ box->setValue( s );
+ box->blockSignals( o );
+ this->_setWindow( s );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_boxLevel( double v )
+{
+ auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
+ auto* sld = this->findChild< QSlider* >( "lev_sld" );
+ if( box == NULL || sld == NULL )
+ return;
+
+ double min = double( sld->minimum( ) );
+ double max = double( sld->maximum( ) );
+ double vmin = box->minimum( );
+ double vmax = box->maximum( );
+ double s = ( v - vmin ) / ( vmax - vmin );
+ s = ( ( max - min ) * s ) + min;
+
+ bool o = sld->blockSignals( true );
+ sld->setValue( ( unsigned int )( s ) );
+ sld->blockSignals( o );
+ this->_setLevel( v );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_sldLevel( int v )
+{
+ auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
+ auto* sld = this->findChild< QSlider* >( "lev_sld" );
+ if( box == NULL || sld == NULL )
+ return;
+
+ double min = double( sld->minimum( ) );
+ double max = double( sld->maximum( ) );
+ double vmin = box->minimum( );
+ double vmax = box->maximum( );
+ double s = ( double( v ) - min ) / ( max - min );
+ s = ( ( vmax - vmin ) * s ) + vmin;
+
+ bool o = box->blockSignals( true );
+ box->setValue( s );
+ box->blockSignals( o );
+ this->_setLevel( s );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_sldOpacity( int v )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ auto* sld = this->findChild< QSlider* >( "op_sld" );
+ if( sld == NULL )
+ return;
+
+ double min = double( sld->minimum( ) );
+ double max = double( sld->maximum( ) );
+ double s = ( double( v ) - min ) / ( max - min );
+
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+ {
+ auto ia = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+ auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) );
+ if( ia != NULL )
+ {
+ ia->GetProperty( )->SetOpacity( s );
+ ia->Modified( );
+ }
+ else if( ma != NULL )
+ {
+ ma->GetProperty( )->SetOpacity( s );
+ ma->Modified( );
+
+ } // fi
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_boxPointSize( int v )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_boxLineWidth( int v )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_scalarVisibility( int v )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ auto* btn = this->findChild< QPushButton* >( "color_button" );
+ auto* chk = this->findChild< QCheckBox* >( "sv_box" );
+ if( btn == NULL || chk == NULL )
+ return;
+ QPalette pal = btn->palette( );
+ QColor color = pal.color( QPalette::Button );
+ double rgb[ 3 ];
+ rgb[ 0 ] = double( color.red( ) ) / double( 255 );
+ rgb[ 1 ] = double( color.green( ) ) / double( 255 );
+ rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
+
+ auto aIt = this->m_DataObject->BeginVTKActors( );
+ for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+ {
+ auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) );
+ if( ma != NULL )
+ {
+ if( !( chk->isChecked( ) ) )
+ {
+ ma->GetMapper( )->ScalarVisibilityOff( );
+ ma->GetProperty( )->SetColor( rgb );
+ }
+ else
+ ma->GetMapper( )->ScalarVisibilityOn( );
+ ma->Modified( );
+
+ } // fi
+
+ } // rof
+ this->_render( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::DataObjectVisualizationQtDialog::
+_color( )
+{
+ if( this->m_DataObject == NULL )
+ return;
+ auto* btn = this->findChild< QPushButton* >( "color_button" );
+ auto* chk = this->findChild< QCheckBox* >( "sv_box" );
+ if( btn == NULL || chk == NULL )
+ return;
+
+ QPalette pal = btn->palette( );
+ QColor color =
+ QColorDialog::getColor(
+ pal.color( QPalette::Button ),
+ this,
+ "Select Color",
+ QColorDialog::DontUseNativeDialog
+ );
+ if( color.isValid( ) )
+ {
+ pal.setColor( QPalette::Button, color );
+ btn->setAutoFillBackground( true );
+ btn->setPalette( pal );
+ btn->update( );
+ this->_scalarVisibility( 0 );
+
+ } // fi
+}
+
+#endif // cpPlugins_QT4
+
+// eof - $RCSfile$