]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/ActorPropertiesQtDialog.cxx
Visual properties dialog finished.
[cpPlugins.git] / lib / cpPlugins / ActorPropertiesQtDialog.cxx
similarity index 73%
rename from lib/cpPlugins/DataObjectVisualizationQtDialog.cxx
rename to lib/cpPlugins/ActorPropertiesQtDialog.cxx
index 7494eed3116ce07575d14644c2dde45b1f3d980a..eaed06a66ec736a44aea536a8bf09f9f208200dd 100644 (file)
@@ -1,14 +1,15 @@
-#include <cpPlugins/DataObjectVisualizationQtDialog.h>
+#include <cpPlugins/ActorPropertiesQtDialog.h>
 
+#ifdef cpPlugins_QT4
+
+#include <vtkActor.h>
+#include <vtkAxesActor.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 <QSlider>
 
 // -------------------------------------------------------------------------
-cpPlugins::DataObjectVisualizationQtDialog::
-DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f )
+cpPlugins::ActorPropertiesQtDialog::
+ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f )
   : QDialog( parent, f ),
-    m_DataObject( NULL ),
     m_WidgetsUpdated( false )
 {
   this->m_Title = new QLabel( this );
@@ -31,34 +31,52 @@ DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f )
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::DataObjectVisualizationQtDialog::
-~DataObjectVisualizationQtDialog( )
+cpPlugins::ActorPropertiesQtDialog::
+~ActorPropertiesQtDialog( )
 {
+  this->m_Actors.clear( );
+  this->m_Windows.clear( );
   delete this->m_Title;
   delete this->m_ToolsLayout;
   delete this->m_MainLayout;
 }
 
 // -------------------------------------------------------------------------
-cpPlugins::DataObject* cpPlugins::DataObjectVisualizationQtDialog::
-getDataObject( ) const
+bool cpPlugins::ActorPropertiesQtDialog::
+addActor( vtkProp* obj )
 {
-  return( this->m_DataObject );
+  if( obj == NULL )
+    return( false );
+
+  if( this->m_Actors.size( ) > 0 )
+  {
+    bool     s = this->_addActor< vtkAxesActor >( obj );
+    if( !s ) s = this->_addActor< vtkImageActor >( obj );
+    if( !s ) s = this->_addActor< vtkActor >( obj );
+    return( s );
+  }
+  else
+  {
+    this->m_Actors.insert( obj );
+    this->m_WidgetsUpdated = false;
+    return( true );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::DataObjectVisualizationQtDialog::
-setDataObject( DataObject* obj )
+bool cpPlugins::ActorPropertiesQtDialog::
+addRenderWindow( vtkRenderWindow* win )
 {
-  if( this->m_DataObject != NULL || obj == NULL )
+  if( win == NULL )
     return( false );
-  this->m_DataObject = obj;
+  this->m_Windows.insert( win );
   this->m_WidgetsUpdated = false;
   return( true );
 }
 
 // -------------------------------------------------------------------------
-int cpPlugins::DataObjectVisualizationQtDialog::
+int cpPlugins::ActorPropertiesQtDialog::
 exec( )
 {
   this->_updateWidgets( );
@@ -73,7 +91,7 @@ exec( )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _addButtons( )
 {
   // Add buttons
@@ -85,54 +103,70 @@ _addButtons( )
     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::
+void cpPlugins::ActorPropertiesQtDialog::
 _updateWidgets( )
 {
-  if( this->m_WidgetsUpdated || this->m_DataObject == NULL )
+  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 cpPlugins::ActorPropertiesQtDialog::
+_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 \""
-    << this->m_DataObject->GetClassName( )
-    << "\"";
+  title << "Parameters for an object of class \"Axes\"";
   this->m_Title->setText( title.str( ).c_str( ) );
 
-  // Configure particular objects
-  this->_configureForImage( );
-  this->_configureForMesh( );
-
-  // Update values
-  this->_addButtons( );
+  return( true );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+bool cpPlugins::ActorPropertiesQtDialog::
 _configureForImage( )
 {
-  /* TODO
-  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( this->m_Actors.size( ) == 0 )
+    return( false );
+  auto actor =
+    dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) );
   if( actor == NULL )
-    return;
-  
+    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 ) * actor->GetProperty( )->GetOpacity( );
+  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 );
@@ -205,27 +239,33 @@ _configureForImage( )
   op_layout->addWidget( op_label );
   op_layout->addWidget( op_sld );
   this->m_ToolsLayout->addLayout( op_layout );
-*/
+
+  return( true );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+bool cpPlugins::ActorPropertiesQtDialog::
 _configureForMesh( )
 {
-  /* TODO
-  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( this->m_Actors.size( ) == 0 )
+    return( false );
+  auto actor =
+    dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) );
   if( actor == NULL )
-    return;
+    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( actor->GetProperty( )->GetPointSize( ) );
+  ps_box->setValue( prop->GetPointSize( ) );
   ps_box->connect(
     ps_box, SIGNAL( valueChanged( int ) ),
     this, SLOT( _boxPointSize( int ) )
@@ -242,7 +282,7 @@ _configureForMesh( )
   lw_box->setObjectName( "lw_box" );
   lw_box->setMinimum( 1 );
   lw_box->setMaximum( 100 );
-  lw_box->setValue( actor->GetProperty( )->GetLineWidth( ) );
+  lw_box->setValue( prop->GetLineWidth( ) );
   lw_box->connect(
     lw_box, SIGNAL( valueChanged( int ) ),
     this, SLOT( _boxLineWidth( int ) )
@@ -269,7 +309,7 @@ _configureForMesh( )
   this->m_ToolsLayout->addLayout( sv_layout );
 
   double cr, cg, cb;
-  actor->GetProperty( )->GetColor( cr, cg, cb );
+  prop->GetColor( cr, cg, cb );
   cr *= double( 255 );
   cg *= double( 255 );
   cb *= double( 255 );
@@ -295,7 +335,7 @@ _configureForMesh( )
   op_sld->setObjectName( "op_sld" );
   op_sld->setRange( 0, 10 );
   op_sld->setValue(
-    ( unsigned int )( actor->GetProperty( )->GetOpacity( ) * double( 10 ) )
+    ( unsigned int )( prop->GetOpacity( ) * double( 10 ) )
     );
   op_sld->connect(
     op_sld, SIGNAL( valueChanged( int ) ),
@@ -308,20 +348,20 @@ _configureForMesh( )
   op_layout->addWidget( op_label );
   op_layout->addWidget( op_sld );
   this->m_ToolsLayout->addLayout( op_layout );
-*/
+
+  return( true );
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _setWindow( double w )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
+  if( this->m_Actors.size( ) == 0 )
     return;
-  auto aIt = this->m_DataObject->BeginVTKActors( );
-  for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+  auto aIt = this->m_Actors.begin( );
+  for( ; aIt != this->m_Actors.end( ); ++aIt )
   {
-    auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+    auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
     if( actor != NULL )
     {
       actor->GetProperty( )->SetColorWindow( w );
@@ -331,20 +371,18 @@ _setWindow( double w )
 
   } // rof
   this->_render( );
-*/
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _setLevel( double l )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
+  if( this->m_Actors.size( ) == 0 )
     return;
-  auto aIt = this->m_DataObject->BeginVTKActors( );
-  for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt )
+  auto aIt = this->m_Actors.begin( );
+  for( ; aIt != this->m_Actors.end( ); ++aIt )
   {
-    auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
+    auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
     if( actor != NULL )
     {
       actor->GetProperty( )->SetColorLevel( l );
@@ -354,22 +392,36 @@ _setLevel( double l )
 
   } // rof
   this->_render( );
-*/
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _render( )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
-    return;
-  this->m_DataObject->RenderVTKActors( );
-*/
+  for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i )
+    ( *i )->Render( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TActor >
+bool cpPlugins::ActorPropertiesQtDialog::
+_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 cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _boxWindow( double v )
 {
   auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
@@ -391,7 +443,7 @@ _boxWindow( double v )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _sldWindow( int v )
 {
   auto* box = this->findChild< QDoubleSpinBox* >( "win_box" );
@@ -413,7 +465,7 @@ _sldWindow( int v )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _boxLevel( double v )
 {
   auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
@@ -435,7 +487,7 @@ _boxLevel( double v )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _sldLevel( int v )
 {
   auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" );
@@ -457,11 +509,10 @@ _sldLevel( int v )
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _sldOpacity( int v )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
+  if( this->m_Actors.size( ) == 0 )
     return;
   auto* sld = this->findChild< QSlider* >( "op_sld" );
   if( sld == NULL )
@@ -471,11 +522,11 @@ _sldOpacity( int v )
   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 aIt = this->m_Actors.begin( );
+  for( ; aIt != this->m_Actors.end( ); ++aIt )
   {
-    auto ia = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) );
-    auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) );
+    auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) );
+    auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
     if( ia != NULL )
     {
       ia->GetProperty( )->SetOpacity( s );
@@ -490,27 +541,25 @@ _sldOpacity( int v )
 
   } // rof
   this->_render( );
-*/
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _boxPointSize( int v )
 {
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _boxLineWidth( int v )
 {
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _scalarVisibility( int v )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
+  if( this->m_Actors.size( ) == 0 )
     return;
   auto* btn = this->findChild< QPushButton* >( "color_button" );
   auto* chk = this->findChild< QCheckBox* >( "sv_box" );
@@ -523,10 +572,10 @@ _scalarVisibility( int v )
   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 aIt = this->m_Actors.begin( );
+  for( ; aIt != this->m_Actors.end( ); ++aIt )
   {
-    auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) );
+    auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) );
     if( ma != NULL )
     {
       if( !( chk->isChecked( ) ) )
@@ -542,15 +591,13 @@ _scalarVisibility( int v )
 
   } // rof
   this->_render( );
-*/
 }
 
 // -------------------------------------------------------------------------
-void cpPlugins::DataObjectVisualizationQtDialog::
+void cpPlugins::ActorPropertiesQtDialog::
 _color( )
 {
-  /* TODO
-  if( this->m_DataObject == NULL )
+  if( this->m_Actors.size( ) == 0 )
     return;
   auto* btn = this->findChild< QPushButton* >( "color_button" );
   auto* chk = this->findChild< QCheckBox* >( "sv_box" );
@@ -574,7 +621,6 @@ _color( )
     this->_scalarVisibility( 0 );
 
   } // fi
-*/
 }
 
 #endif // cpPlugins_QT4