#include #include #include #include #include #include #include /* #include #include #include #include #include #include #include #include #include */ // ------------------------------------------------------------------------- cpBaseQtApplication::ActorPropertiesQDialog:: ActorPropertiesQDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ), m_MainWidget( NULL ) { 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 ); } // ------------------------------------------------------------------------- cpBaseQtApplication::ActorPropertiesQDialog:: ~ActorPropertiesQDialog( ) { } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorPropertiesQDialog:: addActor( vtkProp* obj ) { if( this->m_MainWidget == NULL ) { std::stringstream title; title << "Parameters for an object of class"; auto mesh = dynamic_cast< vtkActor* >( obj ); auto axes = dynamic_cast< vtkAxesActor* >( obj ); auto image = dynamic_cast< vtkImageActor* >( obj ); if( mesh != NULL ) { title << "\"Mesh\""; this->m_MainWidget = new cpBaseQtApplication::ActorPolyDataProperties( this ); } else if( axes != NULL ) { title << "\"Axes\""; this->m_MainWidget = new cpBaseQtApplication::ActorAxesProperties( this ); } else if( image != NULL ) { title << "\"Image\""; this->m_MainWidget = new cpBaseQtApplication::ActorImageProperties( this ); } /* TODO else if( axes != NULL ) */ if( this->m_MainWidget != NULL ) { this->m_Title->setText( title.str( ).c_str( ) ); this->m_ToolsLayout->addWidget( this->m_MainWidget ); 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 ); } // fi } // fi if( this->m_MainWidget != NULL ) return( this->m_MainWidget->addActor( obj ) ); else return( false ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorPropertiesQDialog:: addRenderWindow( vtkRenderWindow* win ) { if( this->m_MainWidget != NULL && win != NULL ) return( this->m_MainWidget->addRenderWindow( win ) ); else return( false ); } // ------------------------------------------------------------------------- int cpBaseQtApplication::ActorPropertiesQDialog:: exec( ) { int ret = this->QDialog::exec( ); /* TODO if( ret == 1 ) this->updateParameters( ); else this->updateView( ); */ return( ret ); } // ------------------------------------------------------------------------- /* TODO void cpBaseQtApplication::ActorPropertiesQDialog:: _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 ); this->m_WidgetsUpdated = true; } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _updateWidgets( ) { if( this->m_WidgetsUpdated || this->m_Actors.size( ) == 0 ) return; bool s = this->_configureForAxes( ); if( !s ) s = this->_configureForImage( ); if( !s ) s = this->_configureForMesh( ); this->_addButtons( ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorPropertiesQDialog:: _configureForAxes( ) { if( this->m_Actors.size( ) == 0 ) return( false ); auto actor = dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) return( false ); // Set dialog title std::stringstream title; title << "Parameters for an object of class \"Axes\""; this->m_Title->setText( title.str( ).c_str( ) ); return( true ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorPropertiesQDialog:: _configureForImage( ) { if( this->m_Actors.size( ) == 0 ) return( false ); auto actor = dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) return( false ); auto image = actor->GetInput( ); if( image == NULL ) return( false ); // Get properties auto prop = actor->GetProperty( ); 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 ) * prop->GetOpacity( ); // Set dialog title std::stringstream title; title << "Parameters for an object of class \"Image\""; this->m_Title->setText( title.str( ).c_str( ) ); // Create widgets 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 ); return( true ); } // ------------------------------------------------------------------------- bool cpBaseQtApplication::ActorPropertiesQDialog:: _configureForMesh( ) { if( this->m_Actors.size( ) == 0 ) return( false ); auto actor = dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) return( false ); auto prop = actor->GetProperty( ); // Set dialog title std::stringstream title; title << "Parameters for an object of class \"Mesh\""; this->m_Title->setText( title.str( ).c_str( ) ); // Input boxes QSpinBox* ps_box = new QSpinBox( this ); ps_box->setObjectName( "ps_box" ); ps_box->setMinimum( 1 ); ps_box->setMaximum( 100 ); ps_box->setValue( prop->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( prop->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; prop->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 )( prop->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 ); return( true ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _setWindow( double w ) { if( this->m_Actors.size( ) == 0 ) return; auto aIt = this->m_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); if( actor != NULL ) { actor->GetProperty( )->SetColorWindow( w ); actor->Modified( ); } // fi } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _setLevel( double l ) { if( this->m_Actors.size( ) == 0 ) return; auto aIt = this->m_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); if( actor != NULL ) { actor->GetProperty( )->SetColorLevel( l ); actor->Modified( ); } // fi } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _render( ) { for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i ) ( *i )->Render( ); } // ------------------------------------------------------------------------- template< class _TActor > bool cpBaseQtApplication::ActorPropertiesQDialog:: _addActor( vtkProp* obj ) { auto new_obj = dynamic_cast< _TActor* >( obj ); auto pre_obj = dynamic_cast< _TActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( new_obj != NULL && pre_obj != NULL ) { this->m_Actors.insert( obj ); this->m_WidgetsUpdated = false; return( true ); } else return( false ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _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 cpBaseQtApplication::ActorPropertiesQDialog:: _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 cpBaseQtApplication::ActorPropertiesQDialog:: _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 cpBaseQtApplication::ActorPropertiesQDialog:: _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 cpBaseQtApplication::ActorPropertiesQDialog:: _sldOpacity( int v ) { if( this->m_Actors.size( ) == 0 ) 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_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); auto ma = dynamic_cast< vtkActor* >( aIt->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 cpBaseQtApplication::ActorPropertiesQDialog:: _boxPointSize( int v ) { if( this->m_Actors.size( ) == 0 ) return; auto aIt = this->m_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) ); if( ma != NULL ) { ma->GetProperty( )->SetPointSize( v ); ma->Modified( ); } // fi } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _boxLineWidth( int v ) { if( this->m_Actors.size( ) == 0 ) return; auto aIt = this->m_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) ); if( ma != NULL ) { ma->GetProperty( )->SetLineWidth( v ); ma->Modified( ); } // fi } // rof this->_render( ); } // ------------------------------------------------------------------------- void cpBaseQtApplication::ActorPropertiesQDialog:: _scalarVisibility( int v ) { if( this->m_Actors.size( ) == 0 ) 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_Actors.begin( ); for( ; aIt != this->m_Actors.end( ); ++aIt ) { auto ma = dynamic_cast< vtkActor* >( aIt->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 cpBaseQtApplication::ActorPropertiesQDialog:: _color( ) { if( this->m_Actors.size( ) == 0 ) 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 } */ // eof - $RCSfile$