]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/RendererWidget.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / lib / cpExtensions / QT / RendererWidget.cxx
index 251ecea5cb82ebe6cc4e84e03e80f4dfe8b019ed..b9d9838e352c3a8525d3acee93d9a425c5d125b6 100644 (file)
@@ -4,15 +4,20 @@
 
 #include <vtkAxesActor.h>
 #include <vtkCamera.h>
+#include <vtkImageProperty.h>
 #include <vtkInteractorStyle.h>
 #include <vtkOrientationMarkerWidget.h>
+#include <vtkProperty.h>
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
 
 // -------------------------------------------------------------------------
 cpExtensions::QT::RendererWidget::
 RendererWidget( QWidget* parent, Qt::WindowFlags f )
-  : Superclass( parent, f )
+  : Superclass( parent, f ),
+    Superclass2( )
 {
   this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
   this->GetRenderWindow( )->AddRenderer( this->m_Renderer );
@@ -341,6 +346,650 @@ Render( )
   this->GetRenderWindow( )->Render( );
 }
 
+// -------------------------------------------------------------------------
+std::set< vtkRenderWindowInteractor* > cpExtensions::QT::RendererWidget::
+GetInteractors( ) const
+{
+  Self* self = const_cast< Self* >( this );
+  std::set< vtkRenderWindowInteractor* > ret;
+  ret.insert( self->GetRenderWindow( )->GetInteractor( ) );
+  return( ret );
+}
+
+// -------------------------------------------------------------------------
+std::set< std::string > cpExtensions::QT::RendererWidget::
+GetActorsNames( ) const
+{
+  std::set< std::string > names;
+  for(
+    auto p = this->m_ViewProps.begin( );
+    p != this->m_ViewProps.end( );
+    ++p
+    )
+    names.insert( p->first );
+  return( names );
+}
+
+// -------------------------------------------------------------------------
+bool cpExtensions::QT::RendererWidget::
+IsWindowLevelImageActor( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto a = it->second.begin( );
+    if( a != it->second.end( ) )
+      return( dynamic_cast< TWLActor* >( a->GetPointer( ) ) != NULL );
+    else
+      return( false );
+  }
+  else
+    return( false );
+}
+
+// -------------------------------------------------------------------------
+bool cpExtensions::QT::RendererWidget::
+IsLUTImageActor( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto a = it->second.begin( );
+    if( a != it->second.end( ) )
+      return( dynamic_cast< TLUTActor* >( a->GetPointer( ) ) != NULL );
+    else
+      return( false );
+  }
+  else
+    return( false );
+}
+
+// -------------------------------------------------------------------------
+bool cpExtensions::QT::RendererWidget::
+Is3DActor( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto a = it->second.begin( );
+    if( a != it->second.end( ) )
+      return( dynamic_cast< vtkActor* >( a->GetPointer( ) ) != NULL );
+    else
+      return( false );
+  }
+  else
+    return( false );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+GetScalarRange( const std::string& name, double r[ 2 ] ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    TWLActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      a->GetRange( r );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+GetWindowLevel( const std::string& name, double wl[ 2 ] ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    TWLActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      a->GetWindowLevel( wl );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::QT::RendererWidget::
+GetWindow( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    TWLActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetWindow( ) );
+    else
+      return( 0 );
+  }
+  else
+    return( 0 );
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::QT::RendererWidget::
+GetLevel( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    TWLActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetLevel( ) );
+    else
+      return( 0 );
+  }
+  else
+    return( 0 );
+}
+
+// -------------------------------------------------------------------------
+char cpExtensions::QT::RendererWidget::
+GetImageInterpolation( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    TWLActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+    {
+      int int_type = a->GetProperty( )->GetInterpolationType( );
+      char ret = 0;
+      switch( int_type )
+      {
+      case VTK_NEAREST_INTERPOLATION: ret = 'N'; break;
+      case VTK_LINEAR_INTERPOLATION: ret = 'L'; break;
+      case VTK_CUBIC_INTERPOLATION: ret = 'C'; break;
+      default: ret = 0; break;
+      } // hctiws
+      return( ret );
+    }
+    else
+      return( 0 );
+  }
+  else
+    return( 0 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+GetColor( const std::string& name, double& r, double& g, double& b ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    vtkActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetProperty( )->GetColor( r, g, b ) );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::QT::RendererWidget::
+GetOpacity( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    vtkActor* a = NULL;
+    vtkImageSlice* s = NULL;
+    while( a == NULL && s == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      s = dynamic_cast< vtkImageSlice* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetProperty( )->GetOpacity( ) );
+    else if( s != NULL )
+      return( s->GetProperty( )->GetOpacity( ) );
+    else
+      return( 0 );
+  }
+  return( 0 );
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::QT::RendererWidget::
+GetPointSize( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    vtkActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetProperty( )->GetPointSize( ) );
+    else
+      return( 0 );
+  }
+  return( 0 );
+}
+
+// -------------------------------------------------------------------------
+double cpExtensions::QT::RendererWidget::
+GetLineWidth( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    vtkActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetProperty( )->GetLineWidth( ) );
+    else
+      return( 0 );
+  }
+  return( 0 );
+}
+
+// -------------------------------------------------------------------------
+int cpExtensions::QT::RendererWidget::
+GetRepresentation( const std::string& name ) const
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    auto p = it->second.begin( );
+    vtkActor* a = NULL;
+    while( a == NULL && p != it->second.end( ) )
+    {
+      a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      p++;
+
+    } // elihw
+    if( a != NULL )
+      return( a->GetProperty( )->GetRepresentation( ) );
+    else
+      return( -1 );
+  }
+  return( -1 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetScalarRange( const std::string& name, double r[ 2 ] )
+{
+  this->SetScalarRange( name, r[ 0 ], r[ 1 ] );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetScalarRange( const std::string& name, double min, double max )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->SetRange( min, max );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetWindowLevel( const std::string& name, double wl[ 2 ] )
+{
+  this->SetWindowLevel( name, wl[ 0 ], wl[ 1 ] );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetWindowLevel( const std::string& name, double w, double l )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->SetWindowLevel( w, l );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetWindow( const std::string& name, double w )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->SetWindow( w );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetLevel( const std::string& name, double l )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->SetLevel( l );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetImageInterpolation( const std::string& name, char i )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      TWLActor* a = dynamic_cast< TWLActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        int int_type = VTK_NEAREST_INTERPOLATION;
+        switch( i )
+        {
+        case 'L': int_type = VTK_LINEAR_INTERPOLATION; break;
+        case 'C': int_type = VTK_CUBIC_INTERPOLATION; break;
+        default:  int_type = VTK_NEAREST_INTERPOLATION; break;
+        } // hctiws
+        a->GetProperty( )->SetInterpolationType( int_type );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetColor( const std::string& name, double r, double g, double b )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetColor( r, g, b );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetOpacity( const std::string& name, double o )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      vtkImageSlice* s = dynamic_cast< vtkImageSlice* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetOpacity( o );
+      }
+      else if( s != NULL )
+      {
+        render = true;
+        s->GetProperty( )->SetOpacity( o );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetPointSize( const std::string& name, double s )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetPointSize( s );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetLineWidth( const std::string& name, double w )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetLineWidth( w );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetRepresentationToPoints( const std::string& name )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetRepresentationToPoints( );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetRepresentationToSurface( const std::string& name )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetRepresentationToSurface( );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::RendererWidget::
+SetRepresentationToWireframe( const std::string& name )
+{
+  auto it = this->m_ViewProps.find( name );
+  if( it != this->m_ViewProps.end( ) )
+  {
+    bool render = false;
+    for( auto p = it->second.begin( ); p != it->second.end( ); ++p )
+    {
+      vtkActor* a = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+      if( a != NULL )
+      {
+        render = true;
+        a->GetProperty( )->SetRepresentationToWireframe( );
+
+      } // fi
+
+    } // rof
+    if( render )
+      this->Render( );
+
+  } // fi
+}
+
 #endif // cpExtensions_QT4
 
 // eof - $RCSfile$