]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/ImageWidget.cxx
...
[cpPlugins.git] / lib / cpExtensions / QT / ImageWidget.cxx
index 09788440c1bc6fd38931c32f166401932c0ccea1..e55b69bc3c70817f3dd384b87ccb7d622d7fe4d4 100644 (file)
@@ -2,71 +2,91 @@
 
 #ifdef cpExtensions_QT4
 
-#include <cpExtensions/Visualization/ImageViewerActors.h>
+#include <cpExtensions/Interaction/ImageSliceStyle.h>
 #include <cpExtensions/Visualization/LUTImageActor.h>
+#include <cpExtensions/Visualization/MeshActor.h>
+#include <cpExtensions/Visualization/OutlineSource.h>
 #include <cpExtensions/Visualization/WindowLevelImageActor.h>
-#include <cpExtensions/Interaction/ImageSliceStyle.h>
+
+#include <vtkActor.h>
 #include <vtkCamera.h>
 #include <vtkImageData.h>
 #include <vtkImageProperty.h>
+#include <vtkProperty.h>
 #include <vtkRenderer.h>
 
 // -------------------------------------------------------------------------
 cpExtensions::QT::ImageWidget::
 ImageWidget( QWidget* parent, Qt::WindowFlags f )
   : Superclass( parent, f ),
-    m_ImageName( "" )
+    m_ImageName( "" ),
+    m_OutlineActor( NULL )
 {
-  this->m_ImageSliceStyle =
-    vtkSmartPointer< cpExtensions::Interaction::ImageSliceStyle >::New( );
-  this->m_ImageSliceStyle->SetCurrentRenderer( this->m_Renderer );
-  this->SetStyle( this->m_ImageSliceStyle );
+  this->m_Style = vtkSmartPointer< TStyle >::New( );
+  this->m_Style->SetCurrentRenderer( this->m_Renderer );
+  this->SetStyle( this->m_Style );
 }
 
 // -------------------------------------------------------------------------
 cpExtensions::QT::ImageWidget::
 ~ImageWidget( )
 {
+  this->Clear( );
+  if( this->m_OutlineActor != NULL )
+    delete this->m_OutlineActor;
+  for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
+    delete *a;
+  this->m_Actors.clear( );
 }
 
 // -------------------------------------------------------------------------
-vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( )
-{
-  return( this->m_ImageSliceStyle );
-}
-
-// -------------------------------------------------------------------------
-const vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( ) const
+void cpExtensions::QT::ImageWidget::
+Clear( )
 {
-  return( this->m_ImageSliceStyle );
+  this->RemoveViewProps( );
+  this->m_ImageName = "";
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
-SetImage( vtkImageData* image, int orientation, const std::string& name )
+SetImage( vtkImageData* image, const std::string& name, int orientation )
 {
+  if( name == "" )
+    return;
   if( this->m_ImageName != "" )
-  {
-    // TODO: Clear visualization
-
-  } // fi
+    this->Clear( );
   this->m_ImageName = name;
 
-  this->GetActiveCamera( )->ParallelProjectionOn( );
+  this->m_WLActor = vtkSmartPointer< TWLActor >::New( );
+  this->m_WLActor->SetImage( image );
+  this->m_WLActor->SetOrientation( orientation );
+
+  this->m_LUTActor = vtkSmartPointer< TLUTActor >::New( );
+  this->m_LUTActor->SetOrientation( orientation );
 
-  this->m_ImageViewerActors =
-    vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors >::New( );
-  this->m_ImageViewerActors->SetImage( image, orientation );
+  this->m_Outline = vtkSmartPointer< TOutline >::New( );
+  this->m_Outline->SetBounds( image->GetBounds( ) );
+  this->m_Outline->Update( );
 
-  this->m_ImageSliceStyle->SetActors( this->m_ImageViewerActors );
+  if( this->m_OutlineActor != NULL )
+    delete this->m_OutlineActor;
+  this->m_OutlineActor = new TActor( );
+  this->m_OutlineActor->SetMesh( this->m_Outline->GetOutput( ) );
 
-  this->AddViewProp(
-    this->m_ImageViewerActors->GetWindowLevelImageActor( ),
-    this->m_ImageName
-    );
-  this->AddAuxViewProps( this->m_ImageViewerActors, this->m_ImageName );
+  double cr = double( 0 );
+  double cg = double( 0 );
+  double cb = double( 0 );
+  switch( this->m_WLActor->GetOrientation( ) )
+  {
+  case 0:  cr = double( 1 ); break;
+  case 1:  cg = double( 1 ); break;
+  case 2:  cb = double( 1 ); break;
+  default: cr = double( 1 ); break;
+  } // hctiws
+  this->m_OutlineActor->GetActor( )->GetProperty( )->SetColor( cr, cg, cb );
+
+  this->AddViewProp( this->m_WLActor, this->m_ImageName );
+  this->AddAuxViewProp( this->m_OutlineActor->GetActor( ), this->m_ImageName );
   this->ResetCamera( );
 }
 
@@ -75,59 +95,32 @@ void cpExtensions::QT::ImageWidget::
 Add( vtkDataSet* data, const std::string& name )
 {
   auto image = dynamic_cast< vtkImageData* >( data );
-
-  if( image == NULL )
+  auto pdata = dynamic_cast< vtkPolyData* >( data );
+  if( image != NULL )
   {
-    /* TODO
-       if( this->m_ImageName == "" )
-       this->SetImage( data, name );
-       {
-       } // fi
-    */
-    return;
-
-  } // fi
-
-  if( this->m_ImageName == "" )
-    return;
-
-  if( this->m_ImageViewerActors.GetPointer( ) != NULL )
+    this->m_LUTActor->AddImage( image );
+    this->m_LUTActor->GetProperty( )->SetOpacity( 0.5 );
+    this->AddViewProp( this->m_LUTActor, "__LUT_IMAGE__" );
+    this->Render( );
+  }
+  else if( pdata != NULL )
   {
-    if( this->m_ImageViewerActors->AddLUTImage( image ) > 0 )
-    {
-      this->AddViewProp(
-        this->m_ImageViewerActors->GetLUTImageActor( ),
-        name
-        );
-      this->Render( );
-
-    } // fi
+    TActor* actor = new TActor( );
+    actor->SetMesh( pdata );
+    this->m_Actors.push_back( actor );
+    this->AddViewProp( actor->GetActor( ), name );
+    this->Render( );
 
   } // fi
 }
 
-// -------------------------------------------------------------------------
-int cpExtensions::QT::ImageWidget::
-GetOrientation( ) const
-{
-  return( this->m_ImageViewerActors->GetOrientation( ) );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetSliceNumber( int slice )
-{
-  this->m_ImageViewerActors->SetSliceNumber( slice );
-  this->Render( );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
 ResetCamera( )
 {
-  if( this->m_ImageViewerActors.GetPointer( ) != NULL )
+  if( this->m_WLActor.GetPointer( ) != NULL )
   {
-    auto image = this->m_ImageViewerActors->GetImage( );
+    auto image = this->m_WLActor->GetImage( );
     if( image != NULL )
     {
       double bounds[ 6 ];
@@ -139,7 +132,7 @@ ResetCamera( )
       center[ 1 ] = ( bounds[ 3 ] + bounds[ 2 ] ) / double( 2 );
       center[ 2 ] = ( bounds[ 5 ] + bounds[ 4 ] ) / double( 2 );
 
-      int ori = this->m_ImageViewerActors->GetOrientation( );
+      int ori = this->m_WLActor->GetOrientation( );
       double pos[ 3 ] = { double( 0 ) };
       pos[ ori ] = double( 1 );
       pos[ 0 ] += center[ 0 ];
@@ -163,16 +156,17 @@ ResetCamera( )
       }
       else if( ori == 2 )
       {
-        if     ( this->m_Quadrant == 0 ) up[ 1 ] = double( 1 );
-        else if( this->m_Quadrant == 1 ) up[ 1 ] = double( 1 );
-        else if( this->m_Quadrant == 2 ) up[ 1 ] = double( 1 );
-        else if( this->m_Quadrant == 3 ) up[ 1 ] = double( 1 );
+        if     ( this->m_Quadrant == 0 ) up[ 1 ] = double( -1 );
+        else if( this->m_Quadrant == 1 ) up[ 1 ] = double( -1 );
+        else if( this->m_Quadrant == 2 ) up[ 1 ] = double( -1 );
+        else if( this->m_Quadrant == 3 ) up[ 1 ] = double( -1 );
         pos[ 2 ] *= double( -1 );
 
       } // fi
 
       // Reconfigure camera and return
       auto camera = this->m_Renderer->GetActiveCamera( );
+      camera->ParallelProjectionOn( );
       camera->SetFocalPoint( center );
       camera->SetPosition( pos );
       camera->SetViewUp( up );
@@ -186,120 +180,49 @@ ResetCamera( )
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-GetScalarRange( double r[ 2 ] ) const
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-    actor->GetRange( r );
-  else
-    r[ 0 ] = r[ 1 ] = double( 0 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-GetWindowLevel( double wl[ 2 ] ) const
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    wl[ 0 ] = actor->GetWindow( );
-    wl[ 1 ] = actor->GetLevel( );
-  }
-  else
-    wl[ 0 ] = wl[ 1 ] = double( 0 );
-}
-
-// -------------------------------------------------------------------------
-double cpExtensions::QT::ImageWidget::
-GetImageOpacity( ) const
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-    return( actor->GetProperty( )->GetOpacity( ) );
-  else
-    return( double( 0 ) );
-}
-
-// -------------------------------------------------------------------------
-unsigned char cpExtensions::QT::ImageWidget::
-GetImageInterpolation( ) const
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    int int_type = actor->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 );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetScalarRange( double r[ 2 ] )
+cpExtensions::QT::ImageWidget::
+TWLActor* cpExtensions::QT::ImageWidget::
+GetImageActor( )
 {
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    actor->ConfigureWindowLevel( r[ 0 ], r[ 1 ] );
-    this->Render( );
-
-  } // fi
+  return( this->m_WLActor );
 }
 
 // -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetWindowLevel( double wl[ 2 ] )
+const cpExtensions::QT::ImageWidget::
+TWLActor* cpExtensions::QT::ImageWidget::
+GetImageActor( ) const
 {
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    actor->SetWindowLevel( wl[ 0 ], wl[ 1 ] );
-    this->Render( );
-
-  } // fi
+  return( this->m_WLActor );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
-SetImageOpacity( double o )
+SetColor( const std::string& name, double r, double g, double b )
 {
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
+  auto props = this->GetViewProps( name );
+  for( auto p = props.begin( ); p != props.end( ); ++p )
   {
-    actor->GetProperty( )->SetOpacity( o );
-    this->Render( );
+    auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+    if( actor != NULL )
+      actor->GetProperty( )->SetColor( r, g, b );
 
-  } // fi
+  } // rof
+  this->Render( );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
-SetImageInterpolation( unsigned char i )
+SetLineWidth( const std::string& name, double w )
 {
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
+  auto props = this->GetViewProps( name );
+  for( auto p = props.begin( ); p != props.end( ); ++p )
   {
-    int int_type = 0;
-    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
-    actor->GetProperty( )->SetInterpolationType( int_type );
-    this->Render( );
+    auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+    if( actor != NULL )
+      actor->GetProperty( )->SetLineWidth( w );
 
-  } // fi
+  } // rof
+  this->Render( );
 }
 
 #endif // cpExtensions_QT4