1 #include <cpBaseQtApplication/ActorPropertiesQDialog.h>
3 #include <cpBaseQtApplication/ActorAxesProperties.h>
4 #include <cpBaseQtApplication/ActorImageProperties.h>
5 #include <cpBaseQtApplication/ActorPolyDataProperties.h>
8 #include <vtkAxesActor.h>
9 #include <vtkImageActor.h>
11 #include <vtkImageData.h>
12 #include <vtkImageProperty.h>
13 #include <vtkMapper.h>
14 #include <vtkProperty.h>
17 #include <QColorDialog>
18 #include <QDoubleSpinBox>
19 #include <QPushButton>
23 // -------------------------------------------------------------------------
24 cpBaseQtApplication::ActorPropertiesQDialog::
25 ActorPropertiesQDialog( QWidget* parent, Qt::WindowFlags f )
26 : QDialog( parent, f ),
29 this->m_Title = new QLabel( this );
30 this->m_Title->setText( "Visualization properties" );
31 this->m_MainLayout = new QGridLayout( this );
32 this->m_ToolsLayout = new QVBoxLayout( );
33 this->m_ToolsLayout->addWidget( this->m_Title );
34 this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 );
37 // -------------------------------------------------------------------------
38 cpBaseQtApplication::ActorPropertiesQDialog::
39 ~ActorPropertiesQDialog( )
43 // -------------------------------------------------------------------------
44 bool cpBaseQtApplication::ActorPropertiesQDialog::
45 addActor( vtkProp* obj )
47 if( this->m_MainWidget == NULL )
49 std::stringstream title;
50 title << "Parameters for an object of class";
51 auto mesh = dynamic_cast< vtkActor* >( obj );
52 auto axes = dynamic_cast< vtkAxesActor* >( obj );
53 auto image = dynamic_cast< vtkImageActor* >( obj );
57 this->m_MainWidget = new cpBaseQtApplication::ActorPolyDataProperties( this );
59 else if( axes != NULL )
62 this->m_MainWidget = new cpBaseQtApplication::ActorAxesProperties( this );
64 else if( image != NULL )
67 this->m_MainWidget = new cpBaseQtApplication::ActorImageProperties( this );
70 else if( axes != NULL )
73 if( this->m_MainWidget != NULL )
75 this->m_Title->setText( title.str( ).c_str( ) );
76 this->m_ToolsLayout->addWidget( this->m_MainWidget );
77 this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
79 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
82 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
84 this->m_ToolsLayout->addWidget( this->m_Buttons );
90 if( this->m_MainWidget != NULL )
91 return( this->m_MainWidget->addActor( obj ) );
96 // -------------------------------------------------------------------------
97 bool cpBaseQtApplication::ActorPropertiesQDialog::
98 addRenderWindow( vtkRenderWindow* win )
100 if( this->m_MainWidget != NULL && win != NULL )
101 return( this->m_MainWidget->addRenderWindow( win ) );
106 // -------------------------------------------------------------------------
107 int cpBaseQtApplication::ActorPropertiesQDialog::
110 int ret = this->QDialog::exec( );
113 this->updateParameters( );
120 // -------------------------------------------------------------------------
122 void cpBaseQtApplication::ActorPropertiesQDialog::
126 this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok );
128 this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) )
131 this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) )
133 this->m_ToolsLayout->addWidget( this->m_Buttons );
134 this->m_WidgetsUpdated = true;
137 // -------------------------------------------------------------------------
138 void cpBaseQtApplication::ActorPropertiesQDialog::
141 if( this->m_WidgetsUpdated || this->m_Actors.size( ) == 0 )
143 bool s = this->_configureForAxes( );
144 if( !s ) s = this->_configureForImage( );
145 if( !s ) s = this->_configureForMesh( );
146 this->_addButtons( );
149 // -------------------------------------------------------------------------
150 bool cpBaseQtApplication::ActorPropertiesQDialog::
153 if( this->m_Actors.size( ) == 0 )
156 dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) );
161 std::stringstream title;
162 title << "Parameters for an object of class \"Axes\"";
163 this->m_Title->setText( title.str( ).c_str( ) );
168 // -------------------------------------------------------------------------
169 bool cpBaseQtApplication::ActorPropertiesQDialog::
170 _configureForImage( )
172 if( this->m_Actors.size( ) == 0 )
175 dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
178 auto image = actor->GetInput( );
183 auto prop = actor->GetProperty( );
185 image->GetScalarRange( r );
186 double w = actor->GetProperty( )->GetColorWindow( );
187 double l = actor->GetProperty( )->GetColorLevel( );
188 double sw = double( 1000 ) * w / ( r[ 1 ] - r[ 0 ] );
189 double sl = double( 1000 ) * ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] );
190 double op = double( 10 ) * prop->GetOpacity( );
193 std::stringstream title;
194 title << "Parameters for an object of class \"Image\"";
195 this->m_Title->setText( title.str( ).c_str( ) );
198 QDoubleSpinBox* win_box = new QDoubleSpinBox( this );
199 win_box->setObjectName( "win_box" );
200 win_box->setDecimals( 3 );
201 win_box->setMinimum( 0 );
202 win_box->setMaximum( r[ 1 ] - r[ 0 ] );
203 win_box->setValue( w );
205 win_box, SIGNAL( valueChanged( double ) ),
206 this, SLOT( _boxWindow( double ) )
209 QSlider* win_sld = new QSlider( Qt::Horizontal, this );
210 win_sld->setObjectName( "win_sld" );
211 win_sld->setRange( 0, 1000 );
212 win_sld->setValue( ( unsigned int )( sw ) );
214 win_sld, SIGNAL( valueChanged( int ) ),
215 this, SLOT( _sldWindow( int ) )
218 QHBoxLayout* win_layout = new QHBoxLayout( );
219 QLabel* win_label = new QLabel( this );
220 win_label->setText( QString( "Window: " ) );
221 win_layout->addWidget( win_label );
222 win_layout->addWidget( win_box );
223 win_layout->addWidget( win_sld );
224 this->m_ToolsLayout->addLayout( win_layout );
226 QDoubleSpinBox* lev_box = new QDoubleSpinBox( this );
227 lev_box->setObjectName( "lev_box" );
228 lev_box->setDecimals( 3 );
229 lev_box->setMinimum( r[ 0 ] );
230 lev_box->setMaximum( r[ 1 ] );
231 lev_box->setValue( l );
233 lev_box, SIGNAL( valueChanged( double ) ),
234 this, SLOT( _boxLevel( double ) )
237 QSlider* lev_sld = new QSlider( Qt::Horizontal, this );
238 lev_sld->setObjectName( "lev_sld" );
239 lev_sld->setRange( 0, 1000 );
240 lev_sld->setValue( ( unsigned int )( sl ) );
242 lev_sld, SIGNAL( valueChanged( int ) ),
243 this, SLOT( _sldLevel( int ) )
246 QHBoxLayout* lev_layout = new QHBoxLayout( );
247 QLabel* lev_label = new QLabel( this );
248 lev_label->setText( QString( "Level: " ) );
249 lev_layout->addWidget( lev_label );
250 lev_layout->addWidget( lev_box );
251 lev_layout->addWidget( lev_sld );
252 this->m_ToolsLayout->addLayout( lev_layout );
254 // Configure generic objects
255 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
256 op_sld->setObjectName( "op_sld" );
257 op_sld->setRange( 0, 10 );
258 op_sld->setValue( ( unsigned int )( op ) );
260 op_sld, SIGNAL( valueChanged( int ) ),
261 this, SLOT( _sldOpacity( int ) )
264 QHBoxLayout* op_layout = new QHBoxLayout( );
265 QLabel* op_label = new QLabel( this );
266 op_label->setText( QString( "Opacity: " ) );
267 op_layout->addWidget( op_label );
268 op_layout->addWidget( op_sld );
269 this->m_ToolsLayout->addLayout( op_layout );
274 // -------------------------------------------------------------------------
275 bool cpBaseQtApplication::ActorPropertiesQDialog::
278 if( this->m_Actors.size( ) == 0 )
281 dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
284 auto prop = actor->GetProperty( );
287 std::stringstream title;
288 title << "Parameters for an object of class \"Mesh\"";
289 this->m_Title->setText( title.str( ).c_str( ) );
292 QSpinBox* ps_box = new QSpinBox( this );
293 ps_box->setObjectName( "ps_box" );
294 ps_box->setMinimum( 1 );
295 ps_box->setMaximum( 100 );
296 ps_box->setValue( prop->GetPointSize( ) );
298 ps_box, SIGNAL( valueChanged( int ) ),
299 this, SLOT( _boxPointSize( int ) )
302 QHBoxLayout* ps_layout = new QHBoxLayout( );
303 QLabel* ps_label = new QLabel( this );
304 ps_label->setText( QString( "Point size: " ) );
305 ps_layout->addWidget( ps_label );
306 ps_layout->addWidget( ps_box );
307 this->m_ToolsLayout->addLayout( ps_layout );
309 QSpinBox* lw_box = new QSpinBox( this );
310 lw_box->setObjectName( "lw_box" );
311 lw_box->setMinimum( 1 );
312 lw_box->setMaximum( 100 );
313 lw_box->setValue( prop->GetLineWidth( ) );
315 lw_box, SIGNAL( valueChanged( int ) ),
316 this, SLOT( _boxLineWidth( int ) )
319 QHBoxLayout* lw_layout = new QHBoxLayout( );
320 QLabel* lw_label = new QLabel( this );
321 lw_label->setText( QString( "Line width: " ) );
322 lw_layout->addWidget( lw_label );
323 lw_layout->addWidget( lw_box );
324 this->m_ToolsLayout->addLayout( lw_layout );
326 QCheckBox* sv_box = new QCheckBox( this );
327 sv_box->setObjectName( "sv_box" );
328 sv_box->setText( "Scalar visibility: " );
329 sv_box->setChecked( ( actor->GetMapper( )->GetScalarVisibility( ) == 1 ) );
331 sv_box, SIGNAL( stateChanged( int ) ),
332 this, SLOT( _scalarVisibility( int ) )
335 QHBoxLayout* sv_layout = new QHBoxLayout( );
336 sv_layout->addWidget( sv_box );
337 this->m_ToolsLayout->addLayout( sv_layout );
340 prop->GetColor( cr, cg, cb );
345 QPushButton* color_button = new QPushButton( "Color", this );
346 color_button->setObjectName( "color_button" );
347 QPalette color_palette = color_button->palette( );
348 color_palette.setColor( QPalette::Button, QColor( cr, cg, cb ) );
349 color_button->setAutoFillBackground( true );
350 color_button->setPalette( color_palette );
351 color_button->update( );
352 color_button->connect(
353 color_button, SIGNAL( clicked( ) ),
354 this, SLOT( _color( ) )
357 QHBoxLayout* color_layout = new QHBoxLayout( );
358 color_layout->addWidget( color_button );
359 this->m_ToolsLayout->addLayout( color_layout );
361 // Configure generic objects
362 QSlider* op_sld = new QSlider( Qt::Horizontal, this );
363 op_sld->setObjectName( "op_sld" );
364 op_sld->setRange( 0, 10 );
366 ( unsigned int )( prop->GetOpacity( ) * double( 10 ) )
369 op_sld, SIGNAL( valueChanged( int ) ),
370 this, SLOT( _sldOpacity( int ) )
373 QHBoxLayout* op_layout = new QHBoxLayout( );
374 QLabel* op_label = new QLabel( this );
375 op_label->setText( QString( "Opacity: " ) );
376 op_layout->addWidget( op_label );
377 op_layout->addWidget( op_sld );
378 this->m_ToolsLayout->addLayout( op_layout );
383 // -------------------------------------------------------------------------
384 void cpBaseQtApplication::ActorPropertiesQDialog::
385 _setWindow( double w )
387 if( this->m_Actors.size( ) == 0 )
389 auto aIt = this->m_Actors.begin( );
390 for( ; aIt != this->m_Actors.end( ); ++aIt )
392 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
395 actor->GetProperty( )->SetColorWindow( w );
404 // -------------------------------------------------------------------------
405 void cpBaseQtApplication::ActorPropertiesQDialog::
406 _setLevel( double l )
408 if( this->m_Actors.size( ) == 0 )
410 auto aIt = this->m_Actors.begin( );
411 for( ; aIt != this->m_Actors.end( ); ++aIt )
413 auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
416 actor->GetProperty( )->SetColorLevel( l );
425 // -------------------------------------------------------------------------
426 void cpBaseQtApplication::ActorPropertiesQDialog::
429 for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i )
433 // -------------------------------------------------------------------------
434 template< class _TActor >
435 bool cpBaseQtApplication::ActorPropertiesQDialog::
436 _addActor( vtkProp* obj )
438 auto new_obj = dynamic_cast< _TActor* >( obj );
440 dynamic_cast< _TActor* >( this->m_Actors.begin( )->GetPointer( ) );
441 if( new_obj != NULL && pre_obj != NULL )
443 this->m_Actors.insert( obj );
444 this->m_WidgetsUpdated = false;
451 // -------------------------------------------------------------------------
452 void cpBaseQtApplication::ActorPropertiesQDialog::
453 _boxWindow( double v )
455 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
456 auto* sld = this->findChild< QSlider* >( "win_sld" );
457 if( box == NULL || sld == NULL )
460 double min = double( sld->minimum( ) );
461 double max = double( sld->maximum( ) );
462 double vmin = box->minimum( );
463 double vmax = box->maximum( );
464 double s = ( v - vmin ) / ( vmax - vmin );
465 s = ( ( max - min ) * s ) + min;
467 bool o = sld->blockSignals( true );
468 sld->setValue( ( unsigned int )( s ) );
469 sld->blockSignals( o );
470 this->_setWindow( v );
473 // -------------------------------------------------------------------------
474 void cpBaseQtApplication::ActorPropertiesQDialog::
477 auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
478 auto* sld = this->findChild< QSlider* >( "win_sld" );
479 if( box == NULL || sld == NULL )
482 double min = double( sld->minimum( ) );
483 double max = double( sld->maximum( ) );
484 double vmin = box->minimum( );
485 double vmax = box->maximum( );
486 double s = ( double( v ) - min ) / ( max - min );
487 s = ( ( vmax - vmin ) * s ) + vmin;
489 bool o = box->blockSignals( true );
491 box->blockSignals( o );
492 this->_setWindow( s );
495 // -------------------------------------------------------------------------
496 void cpBaseQtApplication::ActorPropertiesQDialog::
497 _boxLevel( double v )
499 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
500 auto* sld = this->findChild< QSlider* >( "lev_sld" );
501 if( box == NULL || sld == NULL )
504 double min = double( sld->minimum( ) );
505 double max = double( sld->maximum( ) );
506 double vmin = box->minimum( );
507 double vmax = box->maximum( );
508 double s = ( v - vmin ) / ( vmax - vmin );
509 s = ( ( max - min ) * s ) + min;
511 bool o = sld->blockSignals( true );
512 sld->setValue( ( unsigned int )( s ) );
513 sld->blockSignals( o );
514 this->_setLevel( v );
517 // -------------------------------------------------------------------------
518 void cpBaseQtApplication::ActorPropertiesQDialog::
521 auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
522 auto* sld = this->findChild< QSlider* >( "lev_sld" );
523 if( box == NULL || sld == NULL )
526 double min = double( sld->minimum( ) );
527 double max = double( sld->maximum( ) );
528 double vmin = box->minimum( );
529 double vmax = box->maximum( );
530 double s = ( double( v ) - min ) / ( max - min );
531 s = ( ( vmax - vmin ) * s ) + vmin;
533 bool o = box->blockSignals( true );
535 box->blockSignals( o );
536 this->_setLevel( s );
539 // -------------------------------------------------------------------------
540 void cpBaseQtApplication::ActorPropertiesQDialog::
543 if( this->m_Actors.size( ) == 0 )
545 auto* sld = this->findChild< QSlider* >( "op_sld" );
549 double min = double( sld->minimum( ) );
550 double max = double( sld->maximum( ) );
551 double s = ( double( v ) - min ) / ( max - min );
553 auto aIt = this->m_Actors.begin( );
554 for( ; aIt != this->m_Actors.end( ); ++aIt )
556 auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
557 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
560 ia->GetProperty( )->SetOpacity( s );
563 else if( ma != NULL )
565 ma->GetProperty( )->SetOpacity( s );
574 // -------------------------------------------------------------------------
575 void cpBaseQtApplication::ActorPropertiesQDialog::
576 _boxPointSize( int v )
578 if( this->m_Actors.size( ) == 0 )
580 auto aIt = this->m_Actors.begin( );
581 for( ; aIt != this->m_Actors.end( ); ++aIt )
583 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
586 ma->GetProperty( )->SetPointSize( v );
595 // -------------------------------------------------------------------------
596 void cpBaseQtApplication::ActorPropertiesQDialog::
597 _boxLineWidth( int v )
599 if( this->m_Actors.size( ) == 0 )
601 auto aIt = this->m_Actors.begin( );
602 for( ; aIt != this->m_Actors.end( ); ++aIt )
604 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
607 ma->GetProperty( )->SetLineWidth( v );
616 // -------------------------------------------------------------------------
617 void cpBaseQtApplication::ActorPropertiesQDialog::
618 _scalarVisibility( int v )
620 if( this->m_Actors.size( ) == 0 )
622 auto* btn = this->findChild< QPushButton* >( "color_button" );
623 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
624 if( btn == NULL || chk == NULL )
626 QPalette pal = btn->palette( );
627 QColor color = pal.color( QPalette::Button );
629 rgb[ 0 ] = double( color.red( ) ) / double( 255 );
630 rgb[ 1 ] = double( color.green( ) ) / double( 255 );
631 rgb[ 2 ] = double( color.blue( ) ) / double( 255 );
633 auto aIt = this->m_Actors.begin( );
634 for( ; aIt != this->m_Actors.end( ); ++aIt )
636 auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
639 if( !( chk->isChecked( ) ) )
641 ma->GetMapper( )->ScalarVisibilityOff( );
642 ma->GetProperty( )->SetColor( rgb );
645 ma->GetMapper( )->ScalarVisibilityOn( );
654 // -------------------------------------------------------------------------
655 void cpBaseQtApplication::ActorPropertiesQDialog::
658 if( this->m_Actors.size( ) == 0 )
660 auto* btn = this->findChild< QPushButton* >( "color_button" );
661 auto* chk = this->findChild< QCheckBox* >( "sv_box" );
662 if( btn == NULL || chk == NULL )
665 QPalette pal = btn->palette( );
667 QColorDialog::getColor(
668 pal.color( QPalette::Button ),
671 QColorDialog::DontUseNativeDialog
673 if( color.isValid( ) )
675 pal.setColor( QPalette::Button, color );
676 btn->setAutoFillBackground( true );
677 btn->setPalette( pal );
679 this->_scalarVisibility( 0 );