1 #include <cpPlugins/ActorPropertiesQtDialog.h>
5 #include <cpPlugins/ActorAxesProperties.h>
6 #include <cpPlugins/ActorImageProperties.h>
7 #include <cpPlugins/ActorPolyDataProperties.h>
10 #include <vtkAxesActor.h>
11 #include <vtkImageActor.h>
13 #include <vtkImageData.h>
14 #include <vtkImageProperty.h>
15 #include <vtkMapper.h>
16 #include <vtkProperty.h>
19 #include <QColorDialog>
20 #include <QDoubleSpinBox>
21 #include <QPushButton>
25 // -------------------------------------------------------------------------
26 cpPlugins::ActorPropertiesQtDialog::
27 ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f )
28 : QDialog( parent, f ),
31 this->m_Title = new QLabel( this );
32 this->m_Title->setText( "Visualization properties" );
33 this->m_MainLayout = new QGridLayout( this );
34 this->m_ToolsLayout = new QVBoxLayout( );
35 this->m_ToolsLayout->addWidget( this->m_Title );
36 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
39 // -------------------------------------------------------------------------
40 cpPlugins::ActorPropertiesQtDialog::
41 ~ActorPropertiesQtDialog( )
45 // -------------------------------------------------------------------------
46 bool cpPlugins::ActorPropertiesQtDialog::
47 addActor( vtkProp* obj )
49 if( this->m_MainWidget == NULL )
51 std::stringstream title;
52 title << "Parameters for an object of class";
53 auto mesh = dynamic_cast< vtkActor* >( obj );
54 auto axes = dynamic_cast< vtkAxesActor* >( obj );
55 auto image = dynamic_cast< vtkImageActor* >( obj );
59 this->m_MainWidget = new cpPlugins::ActorPolyDataProperties( this );
61 else if( axes != NULL )
64 this->m_MainWidget = new cpPlugins::ActorAxesProperties( this );
66 else if( image != NULL )
69 this->m_MainWidget = new cpPlugins::ActorImageProperties( this );
72 else if( axes != NULL )
75 if( this->m_MainWidget != NULL )
77 this->m_Title->setText( title.str( ).c_str( ) );
78 this->m_ToolsLayout->addWidget( this->m_MainWidget );
79 this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
81 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
84 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
86 this->m_ToolsLayout->addWidget( this->m_Buttons );
92 if( this->m_MainWidget != NULL )
93 return( this->m_MainWidget->addActor( obj ) );
98 // -------------------------------------------------------------------------
99 bool cpPlugins::ActorPropertiesQtDialog::
100 addRenderWindow( vtkRenderWindow* win )
102 if( this->m_MainWidget != NULL && win != NULL )
103 return( this->m_MainWidget->addRenderWindow( win ) );
108 // -------------------------------------------------------------------------
109 int cpPlugins::ActorPropertiesQtDialog::
112 int ret = this->QDialog::exec( );
115 this->updateParameters( );
122 // -------------------------------------------------------------------------
124 void cpPlugins::ActorPropertiesQtDialog::
128 this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
130 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
133 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
135 this->m_ToolsLayout->addWidget( this->m_Buttons );
136 this->m_WidgetsUpdated = true;
139 // -------------------------------------------------------------------------
140 void cpPlugins::ActorPropertiesQtDialog::
143 if( this->m_WidgetsUpdated || this->m_Actors.size( ) == 0 )
145 bool s = this->_configureForAxes( );
146 if( !s ) s = this->_configureForImage( );
147 if( !s ) s = this->_configureForMesh( );
148 this->_addButtons( );
151 // -------------------------------------------------------------------------
152 bool cpPlugins::ActorPropertiesQtDialog::
155 if( this->m_Actors.size( ) == 0 )
158 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
163 std::stringstream title;
164 title << "Parameters for an object of class \"Axes\"";
165 this->m_Title->setText( title.str( ).c_str( ) );
170 // -------------------------------------------------------------------------
171 bool cpPlugins::ActorPropertiesQtDialog::
172 _configureForImage( )
174 if( this->m_Actors.size( ) == 0 )
177 dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
180 auto image = actor->GetInput( );
185 auto prop = actor->GetProperty( );
187 image->GetScalarRange( r );
188 double w = actor->GetProperty( )->GetColorWindow( );
189 double l = actor->GetProperty( )->GetColorLevel( );
190 double sw = double( 1000 ) * w / ( r[ 1 ] - r[ 0 ] );
191 double sl = double( 1000 ) * ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
192 double op = double( 10 ) * prop->GetOpacity( );
195 std::stringstream title;
196 title << "Parameters for an object of class \"Image\"";
197 this->m_Title->setText( title.str( ).c_str( ) );
200 QDoubleSpinBox* win_box = new QDoubleSpinBox( this );
201 win_box->setObjectName( "win_box" );
202 win_box->setDecimals( 3 );
203 win_box->setMinimum( 0 );
204 win_box->setMaximum( r[ 1 ] - r[ 0 ] );
205 win_box->setValue( w );
207 win_box, SIGNAL( valueChanged( double ) ),
208 this, SLOT( _boxWindow( double ) )
211 QSlider* win_sld = new QSlider( Qt::Horizontal, this );
212 win_sld->setObjectName( "win_sld" );
213 win_sld->setRange( 0, 1000 );
214 win_sld->setValue( ( unsigned int )( sw ) );
216 win_sld, SIGNAL( valueChanged( int ) ),
217 this, SLOT( _sldWindow( int ) )
220 QHBoxLayout* win_layout = new QHBoxLayout( );
221 QLabel* win_label = new QLabel( this );
222 win_label->setText( QString( "Window: " ) );
223 win_layout->addWidget( win_label );
224 win_layout->addWidget( win_box );
225 win_layout->addWidget( win_sld );
226 this->m_ToolsLayout->addLayout( win_layout );
228 QDoubleSpinBox* lev_box = new QDoubleSpinBox( this );
229 lev_box->setObjectName( "lev_box" );
230 lev_box->setDecimals( 3 );
231 lev_box->setMinimum( r[ 0 ] );
232 lev_box->setMaximum( r[ 1 ] );
233 lev_box->setValue( l );
235 lev_box, SIGNAL( valueChanged( double ) ),
236 this, SLOT( _boxLevel( double ) )
239 QSlider* lev_sld = new QSlider( Qt::Horizontal, this );
240 lev_sld->setObjectName( "lev_sld" );
241 lev_sld->setRange( 0, 1000 );
242 lev_sld->setValue( ( unsigned int )( sl ) );
244 lev_sld, SIGNAL( valueChanged( int ) ),
245 this, SLOT( _sldLevel( int ) )
248 QHBoxLayout* lev_layout = new QHBoxLayout( );
249 QLabel* lev_label = new QLabel( this );
250 lev_label->setText( QString( "Level: " ) );
251 lev_layout->addWidget( lev_label );
252 lev_layout->addWidget( lev_box );
253 lev_layout->addWidget( lev_sld );
254 this->m_ToolsLayout->addLayout( lev_layout );
256 // Configure generic objects
257 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
258 op_sld->setObjectName( "op_sld" );
259 op_sld->setRange( 0, 10 );
260 op_sld->setValue( ( unsigned int )( op ) );
262 op_sld, SIGNAL( valueChanged( int ) ),
263 this, SLOT( _sldOpacity( int ) )
266 QHBoxLayout* op_layout = new QHBoxLayout( );
267 QLabel* op_label = new QLabel( this );
268 op_label->setText( QString( "Opacity: " ) );
269 op_layout->addWidget( op_label );
270 op_layout->addWidget( op_sld );
271 this->m_ToolsLayout->addLayout( op_layout );
276 // -------------------------------------------------------------------------
277 bool cpPlugins::ActorPropertiesQtDialog::
280 if( this->m_Actors.size( ) == 0 )
283 dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
286 auto prop = actor->GetProperty( );
289 std::stringstream title;
290 title << "Parameters for an object of class \"Mesh\"";
291 this->m_Title->setText( title.str( ).c_str( ) );
294 QSpinBox* ps_box = new QSpinBox( this );
295 ps_box->setObjectName( "ps_box" );
296 ps_box->setMinimum( 1 );
297 ps_box->setMaximum( 100 );
298 ps_box->setValue( prop->GetPointSize( ) );
300 ps_box, SIGNAL( valueChanged( int ) ),
301 this, SLOT( _boxPointSize( int ) )
304 QHBoxLayout* ps_layout = new QHBoxLayout( );
305 QLabel* ps_label = new QLabel( this );
306 ps_label->setText( QString( "Point size: " ) );
307 ps_layout->addWidget( ps_label );
308 ps_layout->addWidget( ps_box );
309 this->m_ToolsLayout->addLayout( ps_layout );
311 QSpinBox* lw_box = new QSpinBox( this );
312 lw_box->setObjectName( "lw_box" );
313 lw_box->setMinimum( 1 );
314 lw_box->setMaximum( 100 );
315 lw_box->setValue( prop->GetLineWidth( ) );
317 lw_box, SIGNAL( valueChanged( int ) ),
318 this, SLOT( _boxLineWidth( int ) )
321 QHBoxLayout* lw_layout = new QHBoxLayout( );
322 QLabel* lw_label = new QLabel( this );
323 lw_label->setText( QString( "Line width: " ) );
324 lw_layout->addWidget( lw_label );
325 lw_layout->addWidget( lw_box );
326 this->m_ToolsLayout->addLayout( lw_layout );
328 QCheckBox* sv_box = new QCheckBox( this );
329 sv_box->setObjectName( "sv_box" );
330 sv_box->setText( "Scalar visibility: " );
331 sv_box->setChecked( ( actor->GetMapper( )->GetScalarVisibility( ) == 1 ) );
333 sv_box, SIGNAL( stateChanged( int ) ),
334 this, SLOT( _scalarVisibility( int ) )
337 QHBoxLayout* sv_layout = new QHBoxLayout( );
338 sv_layout->addWidget( sv_box );
339 this->m_ToolsLayout->addLayout( sv_layout );
342 prop->GetColor( cr, cg, cb );
347 QPushButton* color_button = new QPushButton( "Color", this );
348 color_button->setObjectName( "color_button" );
349 QPalette color_palette = color_button->palette( );
350 color_palette.setColor( QPalette::Button, QColor( cr, cg, cb ) );
351 color_button->setAutoFillBackground( true );
352 color_button->setPalette( color_palette );
353 color_button->update( );
354 color_button->connect(
355 color_button, SIGNAL( clicked( ) ),
356 this, SLOT( _color( ) )
359 QHBoxLayout* color_layout = new QHBoxLayout( );
360 color_layout->addWidget( color_button );
361 this->m_ToolsLayout->addLayout( color_layout );
363 // Configure generic objects
364 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
365 op_sld->setObjectName( "op_sld" );
366 op_sld->setRange( 0, 10 );
368 ( unsigned int )( prop->GetOpacity( ) * double( 10 ) )
371 op_sld, SIGNAL( valueChanged( int ) ),
372 this, SLOT( _sldOpacity( int ) )
375 QHBoxLayout* op_layout = new QHBoxLayout( );
376 QLabel* op_label = new QLabel( this );
377 op_label->setText( QString( "Opacity: " ) );
378 op_layout->addWidget( op_label );
379 op_layout->addWidget( op_sld );
380 this->m_ToolsLayout->addLayout( op_layout );
385 // -------------------------------------------------------------------------
386 void cpPlugins::ActorPropertiesQtDialog::
387 _setWindow( double w )
389 if( this->m_Actors.size( ) == 0 )
391 auto aIt = this->m_Actors.begin( );
392 for( ; aIt != this->m_Actors.end( ); ++aIt )
394 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
397 actor->GetProperty( )->SetColorWindow( w );
406 // -------------------------------------------------------------------------
407 void cpPlugins::ActorPropertiesQtDialog::
408 _setLevel( double l )
410 if( this->m_Actors.size( ) == 0 )
412 auto aIt = this->m_Actors.begin( );
413 for( ; aIt != this->m_Actors.end( ); ++aIt )
415 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
418 actor->GetProperty( )->SetColorLevel( l );
427 // -------------------------------------------------------------------------
428 void cpPlugins::ActorPropertiesQtDialog::
431 for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i )
435 // -------------------------------------------------------------------------
436 template< class _TActor >
437 bool cpPlugins::ActorPropertiesQtDialog::
438 _addActor( vtkProp* obj )
440 auto new_obj = dynamic_cast< _TActor* >( obj );
442 dynamic_cast< _TActor* >( this->m_Actors.begin( )->GetPointer( ) );
443 if( new_obj != NULL && pre_obj != NULL )
445 this->m_Actors.insert( obj );
446 this->m_WidgetsUpdated = false;
453 // -------------------------------------------------------------------------
454 void cpPlugins::ActorPropertiesQtDialog::
455 _boxWindow( double v )
457 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
458 auto* sld = this->findChild< QSlider* >( "win_sld" );
459 if( box == NULL || sld == NULL )
462 double min = double( sld->minimum( ) );
463 double max = double( sld->maximum( ) );
464 double vmin = box->minimum( );
465 double vmax = box->maximum( );
466 double s = ( v - vmin ) / ( vmax - vmin );
467 s = ( ( max - min ) * s ) + min;
469 bool o = sld->blockSignals( true );
470 sld->setValue( ( unsigned int )( s ) );
471 sld->blockSignals( o );
472 this->_setWindow( v );
475 // -------------------------------------------------------------------------
476 void cpPlugins::ActorPropertiesQtDialog::
479 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
480 auto* sld = this->findChild< QSlider* >( "win_sld" );
481 if( box == NULL || sld == NULL )
484 double min = double( sld->minimum( ) );
485 double max = double( sld->maximum( ) );
486 double vmin = box->minimum( );
487 double vmax = box->maximum( );
488 double s = ( double( v ) - min ) / ( max - min );
489 s = ( ( vmax - vmin ) * s ) + vmin;
491 bool o = box->blockSignals( true );
493 box->blockSignals( o );
494 this->_setWindow( s );
497 // -------------------------------------------------------------------------
498 void cpPlugins::ActorPropertiesQtDialog::
499 _boxLevel( double v )
501 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
502 auto* sld = this->findChild< QSlider* >( "lev_sld" );
503 if( box == NULL || sld == NULL )
506 double min = double( sld->minimum( ) );
507 double max = double( sld->maximum( ) );
508 double vmin = box->minimum( );
509 double vmax = box->maximum( );
510 double s = ( v - vmin ) / ( vmax - vmin );
511 s = ( ( max - min ) * s ) + min;
513 bool o = sld->blockSignals( true );
514 sld->setValue( ( unsigned int )( s ) );
515 sld->blockSignals( o );
516 this->_setLevel( v );
519 // -------------------------------------------------------------------------
520 void cpPlugins::ActorPropertiesQtDialog::
523 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
524 auto* sld = this->findChild< QSlider* >( "lev_sld" );
525 if( box == NULL || sld == NULL )
528 double min = double( sld->minimum( ) );
529 double max = double( sld->maximum( ) );
530 double vmin = box->minimum( );
531 double vmax = box->maximum( );
532 double s = ( double( v ) - min ) / ( max - min );
533 s = ( ( vmax - vmin ) * s ) + vmin;
535 bool o = box->blockSignals( true );
537 box->blockSignals( o );
538 this->_setLevel( s );
541 // -------------------------------------------------------------------------
542 void cpPlugins::ActorPropertiesQtDialog::
545 if( this->m_Actors.size( ) == 0 )
547 auto* sld = this->findChild< QSlider* >( "op_sld" );
551 double min = double( sld->minimum( ) );
552 double max = double( sld->maximum( ) );
553 double s = ( double( v ) - min ) / ( max - min );
555 auto aIt = this->m_Actors.begin( );
556 for( ; aIt != this->m_Actors.end( ); ++aIt )
558 auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
559 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
562 ia->GetProperty( )->SetOpacity( s );
565 else if( ma != NULL )
567 ma->GetProperty( )->SetOpacity( s );
576 // -------------------------------------------------------------------------
577 void cpPlugins::ActorPropertiesQtDialog::
578 _boxPointSize( int v )
580 if( this->m_Actors.size( ) == 0 )
582 auto aIt = this->m_Actors.begin( );
583 for( ; aIt != this->m_Actors.end( ); ++aIt )
585 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
588 ma->GetProperty( )->SetPointSize( v );
597 // -------------------------------------------------------------------------
598 void cpPlugins::ActorPropertiesQtDialog::
599 _boxLineWidth( int v )
601 if( this->m_Actors.size( ) == 0 )
603 auto aIt = this->m_Actors.begin( );
604 for( ; aIt != this->m_Actors.end( ); ++aIt )
606 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
609 ma->GetProperty( )->SetLineWidth( v );
618 // -------------------------------------------------------------------------
619 void cpPlugins::ActorPropertiesQtDialog::
620 _scalarVisibility( int v )
622 if( this->m_Actors.size( ) == 0 )
624 auto* btn = this->findChild< QPushButton* >( "color_button" );
625 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
626 if( btn == NULL || chk == NULL )
628 QPalette pal = btn->palette( );
629 QColor color = pal.color( QPalette::Button );
631 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
632 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
633 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
635 auto aIt = this->m_Actors.begin( );
636 for( ; aIt != this->m_Actors.end( ); ++aIt )
638 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
641 if( !( chk->isChecked( ) ) )
643 ma->GetMapper( )->ScalarVisibilityOff( );
644 ma->GetProperty( )->SetColor( rgb );
647 ma->GetMapper( )->ScalarVisibilityOn( );
656 // -------------------------------------------------------------------------
657 void cpPlugins::ActorPropertiesQtDialog::
660 if( this->m_Actors.size( ) == 0 )
662 auto* btn = this->findChild< QPushButton* >( "color_button" );
663 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
664 if( btn == NULL || chk == NULL )
667 QPalette pal = btn->palette( );
669 QColorDialog::getColor(
670 pal.color( QPalette::Button ),
673 QColorDialog::DontUseNativeDialog
675 if( color.isValid( ) )
677 pal.setColor( QPalette::Button, color );
678 btn->setAutoFillBackground( true );
679 btn->setPalette( pal );
681 this->_scalarVisibility( 0 );
687 #endif // cpPlugins_QT4