1 #include <cpPlugins/ActorPropertiesQtDialog.h>
6 #include <vtkAxesActor.h>
7 #include <vtkImageActor.h>
8 #include <vtkImageData.h>
9 #include <vtkImageProperty.h>
10 #include <vtkMapper.h>
11 #include <vtkProperty.h>
14 #include <QColorDialog>
15 #include <QDoubleSpinBox>
16 #include <QPushButton>
19 // -------------------------------------------------------------------------
20 cpPlugins::ActorPropertiesQtDialog::
21 ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f )
22 : QDialog( parent, f ),
23 m_WidgetsUpdated( false )
25 this->m_Title = new QLabel( this );
26 this->m_Title->setText( "Visualization properties" );
27 this->m_MainLayout = new QGridLayout( this );
28 this->m_ToolsLayout = new QVBoxLayout( );
29 this->m_ToolsLayout->addWidget( this->m_Title );
30 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
33 // -------------------------------------------------------------------------
34 cpPlugins::ActorPropertiesQtDialog::
35 ~ActorPropertiesQtDialog( )
37 this->m_Actors.clear( );
38 this->m_Windows.clear( );
40 delete this->m_ToolsLayout;
41 delete this->m_MainLayout;
44 // -------------------------------------------------------------------------
45 bool cpPlugins::ActorPropertiesQtDialog::
46 addActor( vtkProp* obj )
51 if( this->m_Actors.size( ) > 0 )
53 bool s = this->_addActor< vtkAxesActor >( obj );
54 if( !s ) s = this->_addActor< vtkImageActor >( obj );
55 if( !s ) s = this->_addActor< vtkActor >( obj );
60 this->m_Actors.insert( obj );
61 this->m_WidgetsUpdated = false;
67 // -------------------------------------------------------------------------
68 bool cpPlugins::ActorPropertiesQtDialog::
69 addRenderWindow( vtkRenderWindow* win )
73 this->m_Windows.insert( win );
74 this->m_WidgetsUpdated = false;
78 // -------------------------------------------------------------------------
79 int cpPlugins::ActorPropertiesQtDialog::
82 this->_updateWidgets( );
83 int ret = this->QDialog::exec( );
86 this->updateParameters( );
93 // -------------------------------------------------------------------------
94 void cpPlugins::ActorPropertiesQtDialog::
98 this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
100 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
103 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
105 this->m_ToolsLayout->addWidget( this->m_Buttons );
106 this->m_WidgetsUpdated = true;
109 // -------------------------------------------------------------------------
110 void cpPlugins::ActorPropertiesQtDialog::
113 if( this->m_WidgetsUpdated || this->m_Actors.size( ) == 0 )
115 bool s = this->_configureForAxes( );
116 if( !s ) s = this->_configureForImage( );
117 if( !s ) s = this->_configureForMesh( );
118 this->_addButtons( );
121 // -------------------------------------------------------------------------
122 bool cpPlugins::ActorPropertiesQtDialog::
125 if( this->m_Actors.size( ) == 0 )
128 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
133 std::stringstream title;
134 title << "Parameters for an object of class \"Axes\"";
135 this->m_Title->setText( title.str( ).c_str( ) );
139 178 axes SetShaftTypeToCylinder
140 179 axes SetXAxisLabelText "x"
141 180 axes SetYAxisLabelText "y"
142 181 axes SetZAxisLabelText "z"
143 182 axes SetTotalLength 1.5 1.5 1.5
144 183 vtkTextProperty tprop
147 186 tprop SetFontFamilyToTimes
148 187 [ axes GetXAxisCaptionActor2D ] SetCaptionTextProperty tprop
149 188 vtkTextProperty tprop2
150 189 tprop2 ShallowCopy tprop
151 190 [ axes GetYAxisCaptionActor2D ] SetCaptionTextProperty tprop2
152 191 vtkTextProperty tprop3
153 192 tprop3 ShallowCopy tprop
154 193 [ axes GetZAxisCaptionActor2D ] SetCaptionTextProperty tprop3
160 // -------------------------------------------------------------------------
161 bool cpPlugins::ActorPropertiesQtDialog::
162 _configureForImage( )
164 if( this->m_Actors.size( ) == 0 )
167 dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
170 auto image = actor->GetInput( );
175 auto prop = actor->GetProperty( );
177 image->GetScalarRange( r );
178 double w = actor->GetProperty( )->GetColorWindow( );
179 double l = actor->GetProperty( )->GetColorLevel( );
180 double sw = double( 1000 ) * w / ( r[ 1 ] - r[ 0 ] );
181 double sl = double( 1000 ) * ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
182 double op = double( 10 ) * prop->GetOpacity( );
185 std::stringstream title;
186 title << "Parameters for an object of class \"Image\"";
187 this->m_Title->setText( title.str( ).c_str( ) );
190 QDoubleSpinBox* win_box = new QDoubleSpinBox( this );
191 win_box->setObjectName( "win_box" );
192 win_box->setDecimals( 3 );
193 win_box->setMinimum( 0 );
194 win_box->setMaximum( r[ 1 ] - r[ 0 ] );
195 win_box->setValue( w );
197 win_box, SIGNAL( valueChanged( double ) ),
198 this, SLOT( _boxWindow( double ) )
201 QSlider* win_sld = new QSlider( Qt::Horizontal, this );
202 win_sld->setObjectName( "win_sld" );
203 win_sld->setRange( 0, 1000 );
204 win_sld->setValue( ( unsigned int )( sw ) );
206 win_sld, SIGNAL( valueChanged( int ) ),
207 this, SLOT( _sldWindow( int ) )
210 QHBoxLayout* win_layout = new QHBoxLayout( );
211 QLabel* win_label = new QLabel( this );
212 win_label->setText( QString( "Window: " ) );
213 win_layout->addWidget( win_label );
214 win_layout->addWidget( win_box );
215 win_layout->addWidget( win_sld );
216 this->m_ToolsLayout->addLayout( win_layout );
218 QDoubleSpinBox* lev_box = new QDoubleSpinBox( this );
219 lev_box->setObjectName( "lev_box" );
220 lev_box->setDecimals( 3 );
221 lev_box->setMinimum( r[ 0 ] );
222 lev_box->setMaximum( r[ 1 ] );
223 lev_box->setValue( l );
225 lev_box, SIGNAL( valueChanged( double ) ),
226 this, SLOT( _boxLevel( double ) )
229 QSlider* lev_sld = new QSlider( Qt::Horizontal, this );
230 lev_sld->setObjectName( "lev_sld" );
231 lev_sld->setRange( 0, 1000 );
232 lev_sld->setValue( ( unsigned int )( sl ) );
234 lev_sld, SIGNAL( valueChanged( int ) ),
235 this, SLOT( _sldLevel( int ) )
238 QHBoxLayout* lev_layout = new QHBoxLayout( );
239 QLabel* lev_label = new QLabel( this );
240 lev_label->setText( QString( "Level: " ) );
241 lev_layout->addWidget( lev_label );
242 lev_layout->addWidget( lev_box );
243 lev_layout->addWidget( lev_sld );
244 this->m_ToolsLayout->addLayout( lev_layout );
246 // Configure generic objects
247 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
248 op_sld->setObjectName( "op_sld" );
249 op_sld->setRange( 0, 10 );
250 op_sld->setValue( ( unsigned int )( op ) );
252 op_sld, SIGNAL( valueChanged( int ) ),
253 this, SLOT( _sldOpacity( int ) )
256 QHBoxLayout* op_layout = new QHBoxLayout( );
257 QLabel* op_label = new QLabel( this );
258 op_label->setText( QString( "Opacity: " ) );
259 op_layout->addWidget( op_label );
260 op_layout->addWidget( op_sld );
261 this->m_ToolsLayout->addLayout( op_layout );
266 // -------------------------------------------------------------------------
267 bool cpPlugins::ActorPropertiesQtDialog::
270 if( this->m_Actors.size( ) == 0 )
273 dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
276 auto prop = actor->GetProperty( );
279 std::stringstream title;
280 title << "Parameters for an object of class \"Mesh\"";
281 this->m_Title->setText( title.str( ).c_str( ) );
284 QSpinBox* ps_box = new QSpinBox( this );
285 ps_box->setObjectName( "ps_box" );
286 ps_box->setMinimum( 1 );
287 ps_box->setMaximum( 100 );
288 ps_box->setValue( prop->GetPointSize( ) );
290 ps_box, SIGNAL( valueChanged( int ) ),
291 this, SLOT( _boxPointSize( int ) )
294 QHBoxLayout* ps_layout = new QHBoxLayout( );
295 QLabel* ps_label = new QLabel( this );
296 ps_label->setText( QString( "Point size: " ) );
297 ps_layout->addWidget( ps_label );
298 ps_layout->addWidget( ps_box );
299 this->m_ToolsLayout->addLayout( ps_layout );
301 QSpinBox* lw_box = new QSpinBox( this );
302 lw_box->setObjectName( "lw_box" );
303 lw_box->setMinimum( 1 );
304 lw_box->setMaximum( 100 );
305 lw_box->setValue( prop->GetLineWidth( ) );
307 lw_box, SIGNAL( valueChanged( int ) ),
308 this, SLOT( _boxLineWidth( int ) )
311 QHBoxLayout* lw_layout = new QHBoxLayout( );
312 QLabel* lw_label = new QLabel( this );
313 lw_label->setText( QString( "Line width: " ) );
314 lw_layout->addWidget( lw_label );
315 lw_layout->addWidget( lw_box );
316 this->m_ToolsLayout->addLayout( lw_layout );
318 QCheckBox* sv_box = new QCheckBox( this );
319 sv_box->setObjectName( "sv_box" );
320 sv_box->setText( "Scalar visibility: " );
321 sv_box->setChecked( ( actor->GetMapper( )->GetScalarVisibility( ) == 1 ) );
323 sv_box, SIGNAL( stateChanged( int ) ),
324 this, SLOT( _scalarVisibility( int ) )
327 QHBoxLayout* sv_layout = new QHBoxLayout( );
328 sv_layout->addWidget( sv_box );
329 this->m_ToolsLayout->addLayout( sv_layout );
332 prop->GetColor( cr, cg, cb );
337 QPushButton* color_button = new QPushButton( "Color", this );
338 color_button->setObjectName( "color_button" );
339 QPalette color_palette = color_button->palette( );
340 color_palette.setColor( QPalette::Button, QColor( cr, cg, cb ) );
341 color_button->setAutoFillBackground( true );
342 color_button->setPalette( color_palette );
343 color_button->update( );
344 color_button->connect(
345 color_button, SIGNAL( clicked( ) ),
346 this, SLOT( _color( ) )
349 QHBoxLayout* color_layout = new QHBoxLayout( );
350 color_layout->addWidget( color_button );
351 this->m_ToolsLayout->addLayout( color_layout );
353 // Configure generic objects
354 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
355 op_sld->setObjectName( "op_sld" );
356 op_sld->setRange( 0, 10 );
358 ( unsigned int )( prop->GetOpacity( ) * double( 10 ) )
361 op_sld, SIGNAL( valueChanged( int ) ),
362 this, SLOT( _sldOpacity( int ) )
365 QHBoxLayout* op_layout = new QHBoxLayout( );
366 QLabel* op_label = new QLabel( this );
367 op_label->setText( QString( "Opacity: " ) );
368 op_layout->addWidget( op_label );
369 op_layout->addWidget( op_sld );
370 this->m_ToolsLayout->addLayout( op_layout );
375 // -------------------------------------------------------------------------
376 void cpPlugins::ActorPropertiesQtDialog::
377 _setWindow( double w )
379 if( this->m_Actors.size( ) == 0 )
381 auto aIt = this->m_Actors.begin( );
382 for( ; aIt != this->m_Actors.end( ); ++aIt )
384 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
387 actor->GetProperty( )->SetColorWindow( w );
396 // -------------------------------------------------------------------------
397 void cpPlugins::ActorPropertiesQtDialog::
398 _setLevel( double l )
400 if( this->m_Actors.size( ) == 0 )
402 auto aIt = this->m_Actors.begin( );
403 for( ; aIt != this->m_Actors.end( ); ++aIt )
405 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
408 actor->GetProperty( )->SetColorLevel( l );
417 // -------------------------------------------------------------------------
418 void cpPlugins::ActorPropertiesQtDialog::
421 for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i )
425 // -------------------------------------------------------------------------
426 template< class _TActor >
427 bool cpPlugins::ActorPropertiesQtDialog::
428 _addActor( vtkProp* obj )
430 auto new_obj = dynamic_cast< _TActor* >( obj );
432 dynamic_cast< _TActor* >( this->m_Actors.begin( )->GetPointer( ) );
433 if( new_obj != NULL && pre_obj != NULL )
435 this->m_Actors.insert( obj );
436 this->m_WidgetsUpdated = false;
443 // -------------------------------------------------------------------------
444 void cpPlugins::ActorPropertiesQtDialog::
445 _boxWindow( double v )
447 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
448 auto* sld = this->findChild< QSlider* >( "win_sld" );
449 if( box == NULL || sld == NULL )
452 double min = double( sld->minimum( ) );
453 double max = double( sld->maximum( ) );
454 double vmin = box->minimum( );
455 double vmax = box->maximum( );
456 double s = ( v - vmin ) / ( vmax - vmin );
457 s = ( ( max - min ) * s ) + min;
459 bool o = sld->blockSignals( true );
460 sld->setValue( ( unsigned int )( s ) );
461 sld->blockSignals( o );
462 this->_setWindow( v );
465 // -------------------------------------------------------------------------
466 void cpPlugins::ActorPropertiesQtDialog::
469 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
470 auto* sld = this->findChild< QSlider* >( "win_sld" );
471 if( box == NULL || sld == NULL )
474 double min = double( sld->minimum( ) );
475 double max = double( sld->maximum( ) );
476 double vmin = box->minimum( );
477 double vmax = box->maximum( );
478 double s = ( double( v ) - min ) / ( max - min );
479 s = ( ( vmax - vmin ) * s ) + vmin;
481 bool o = box->blockSignals( true );
483 box->blockSignals( o );
484 this->_setWindow( s );
487 // -------------------------------------------------------------------------
488 void cpPlugins::ActorPropertiesQtDialog::
489 _boxLevel( double v )
491 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
492 auto* sld = this->findChild< QSlider* >( "lev_sld" );
493 if( box == NULL || sld == NULL )
496 double min = double( sld->minimum( ) );
497 double max = double( sld->maximum( ) );
498 double vmin = box->minimum( );
499 double vmax = box->maximum( );
500 double s = ( v - vmin ) / ( vmax - vmin );
501 s = ( ( max - min ) * s ) + min;
503 bool o = sld->blockSignals( true );
504 sld->setValue( ( unsigned int )( s ) );
505 sld->blockSignals( o );
506 this->_setLevel( v );
509 // -------------------------------------------------------------------------
510 void cpPlugins::ActorPropertiesQtDialog::
513 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
514 auto* sld = this->findChild< QSlider* >( "lev_sld" );
515 if( box == NULL || sld == NULL )
518 double min = double( sld->minimum( ) );
519 double max = double( sld->maximum( ) );
520 double vmin = box->minimum( );
521 double vmax = box->maximum( );
522 double s = ( double( v ) - min ) / ( max - min );
523 s = ( ( vmax - vmin ) * s ) + vmin;
525 bool o = box->blockSignals( true );
527 box->blockSignals( o );
528 this->_setLevel( s );
531 // -------------------------------------------------------------------------
532 void cpPlugins::ActorPropertiesQtDialog::
535 if( this->m_Actors.size( ) == 0 )
537 auto* sld = this->findChild< QSlider* >( "op_sld" );
541 double min = double( sld->minimum( ) );
542 double max = double( sld->maximum( ) );
543 double s = ( double( v ) - min ) / ( max - min );
545 auto aIt = this->m_Actors.begin( );
546 for( ; aIt != this->m_Actors.end( ); ++aIt )
548 auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
549 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
552 ia->GetProperty( )->SetOpacity( s );
555 else if( ma != NULL )
557 ma->GetProperty( )->SetOpacity( s );
566 // -------------------------------------------------------------------------
567 void cpPlugins::ActorPropertiesQtDialog::
568 _boxPointSize( int v )
570 if( this->m_Actors.size( ) == 0 )
572 auto aIt = this->m_Actors.begin( );
573 for( ; aIt != this->m_Actors.end( ); ++aIt )
575 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
578 ma->GetProperty( )->SetPointSize( v );
587 // -------------------------------------------------------------------------
588 void cpPlugins::ActorPropertiesQtDialog::
589 _boxLineWidth( int v )
591 if( this->m_Actors.size( ) == 0 )
593 auto aIt = this->m_Actors.begin( );
594 for( ; aIt != this->m_Actors.end( ); ++aIt )
596 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
599 ma->GetProperty( )->SetLineWidth( v );
608 // -------------------------------------------------------------------------
609 void cpPlugins::ActorPropertiesQtDialog::
610 _scalarVisibility( int v )
612 if( this->m_Actors.size( ) == 0 )
614 auto* btn = this->findChild< QPushButton* >( "color_button" );
615 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
616 if( btn == NULL || chk == NULL )
618 QPalette pal = btn->palette( );
619 QColor color = pal.color( QPalette::Button );
621 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
622 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
623 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
625 auto aIt = this->m_Actors.begin( );
626 for( ; aIt != this->m_Actors.end( ); ++aIt )
628 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
631 if( !( chk->isChecked( ) ) )
633 ma->GetMapper( )->ScalarVisibilityOff( );
634 ma->GetProperty( )->SetColor( rgb );
637 ma->GetMapper( )->ScalarVisibilityOn( );
646 // -------------------------------------------------------------------------
647 void cpPlugins::ActorPropertiesQtDialog::
650 if( this->m_Actors.size( ) == 0 )
652 auto* btn = this->findChild< QPushButton* >( "color_button" );
653 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
654 if( btn == NULL || chk == NULL )
657 QPalette pal = btn->palette( );
659 QColorDialog::getColor(
660 pal.color( QPalette::Button ),
663 QColorDialog::DontUseNativeDialog
665 if( color.isValid( ) )
667 pal.setColor( QPalette::Button, color );
668 btn->setAutoFillBackground( true );
669 btn->setPalette( pal );
671 this->_scalarVisibility( 0 );
676 #endif // cpPlugins_QT4