]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/ImageWidget.cxx
...
[cpPlugins.git] / lib / cpExtensions / QT / ImageWidget.cxx
index 60ca9a0ed1760f00dc7cb7f371d38e89dfe2d0a4..bac5f17ffbde3a14fcddd08095cc4ff544f70448 100644 (file)
@@ -1,24 +1,17 @@
 #include <cpExtensions/QT/ImageWidget.h>
-
-#ifdef cpExtensions_QT4
-
 #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 <vtkActor.h>
 #include <vtkCamera.h>
 #include <vtkImageData.h>
+#include <vtkImageProperty.h>
 #include <vtkProperty.h>
 #include <vtkRenderer.h>
 
-/* TODO
-   #include <cpExtensions/Visualization/ImageViewerActors.h>
-   #include <cpExtensions/Visualization/LUTImageActor.h>
-   #include <vtkImageData.h>
-   #include <vtkImageProperty.h>
-*/
-
 // -------------------------------------------------------------------------
 cpExtensions::QT::ImageWidget::
 ImageWidget( QWidget* parent, Qt::WindowFlags f )
@@ -35,8 +28,12 @@ ImageWidget( QWidget* parent, Qt::WindowFlags f )
 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( );
 }
 
 // -------------------------------------------------------------------------
@@ -49,7 +46,7 @@ Clear( )
 
 // -------------------------------------------------------------------------
 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;
@@ -61,6 +58,9 @@ SetImage( vtkImageData* image, int orientation, const std::string& name )
   this->m_WLActor->SetImage( image );
   this->m_WLActor->SetOrientation( orientation );
 
+  this->m_LUTActor = vtkSmartPointer< TLUTActor >::New( );
+  this->m_LUTActor->SetOrientation( orientation );
+
   this->m_Outline = vtkSmartPointer< TOutline >::New( );
   this->m_Outline->SetBounds( image->GetBounds( ) );
   this->m_Outline->Update( );
@@ -87,6 +87,30 @@ SetImage( vtkImageData* image, int orientation, const std::string& name )
   this->ResetCamera( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::QT::ImageWidget::
+Add( vtkDataSet* data, const std::string& name )
+{
+  auto image = dynamic_cast< vtkImageData* >( data );
+  auto pdata = dynamic_cast< vtkPolyData* >( data );
+  if( image != 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 )
+  {
+    TActor* actor = new TActor( );
+    actor->SetMesh( pdata );
+    this->m_Actors.push_back( actor );
+    this->AddViewProp( actor->GetActor( ), name );
+    this->Render( );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
 ResetCamera( )
@@ -129,10 +153,10 @@ 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
@@ -168,230 +192,34 @@ GetImageActor( ) const
   return( this->m_WLActor );
 }
 
-
-/* TODO
-// -------------------------------------------------------------------------
-vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( )
-{
-  return( this->m_ImageSliceStyle );
-}
-
-// -------------------------------------------------------------------------
-const vtkInteractorStyle* cpExtensions::QT::ImageWidget::
-GetInteractorStyle( ) const
-{
-  return( this->m_ImageSliceStyle );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
-SetImage( vtkImageData* image, int orientation, const std::string& name )
+SetColor( const std::string& name, double r, double g, double b )
 {
-  if( this->m_ImageName != "" )
+  auto props = this->GetViewProps( name );
+  for( auto p = props.begin( ); p != props.end( ); ++p )
   {
-    // TODO: Clear visualization
-
-  } // fi
-  this->m_ImageName = name;
-
-  this->GetActiveCamera( )->ParallelProjectionOn( );
-
-  this->m_ImageViewerActors =
-    vtkSmartPointer< cpExtensions::Visualization::ImageViewerActors >::New( );
-  this->m_ImageViewerActors->SetImage( image, orientation );
-
-  this->m_ImageSliceStyle->SetActors( this->m_ImageViewerActors );
+    auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+    if( actor != NULL )
+      actor->GetProperty( )->SetColor( r, g, b );
 
-  this->AddViewProp(
-    this->m_ImageViewerActors->GetWindowLevelImageActor( ),
-    this->m_ImageName
-    );
-  this->AddAuxViewProps( this->m_ImageViewerActors, this->m_ImageName );
-  this->ResetCamera( );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-Add( vtkDataSet* data, const std::string& name )
-{
-  auto image = dynamic_cast< vtkImageData* >( data );
-
-  if( image == NULL )
-  {
-       if( this->m_ImageName == "" )
-       this->SetImage( data, name );
-       {
-       } // fi
-    return;
-
-  } // fi
-
-  if( this->m_ImageName == "" )
-    return;
-
-  if( this->m_ImageViewerActors.GetPointer( ) != NULL )
-  {
-    if( this->m_ImageViewerActors->AddLUTImage( image ) > 0 )
-    {
-      this->AddViewProp(
-        this->m_ImageViewerActors->GetLUTImageActor( ),
-        name
-        );
-      this->Render( );
-
-    } // fi
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-int cpExtensions::QT::ImageWidget::
-GetOrientation( ) const
-{
-  return( this->m_ImageViewerActors->GetOrientation( ) );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetSliceNumber( int slice )
-{
-  this->m_ImageViewerActors->SetSliceNumber( slice );
+  } // rof
   this->Render( );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::QT::ImageWidget::
-GetScalarRange( double r[ 2 ] ) const
+SetLineWidth( const std::string& name, double w )
 {
-  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 ] )
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    actor->ConfigureWindowLevel( r[ 0 ], r[ 1 ] );
-    this->Render( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetWindowLevel( double wl[ 2 ] )
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
+  auto props = this->GetViewProps( name );
+  for( auto p = props.begin( ); p != props.end( ); ++p )
   {
-    actor->SetWindowLevel( wl[ 0 ], wl[ 1 ] );
-    this->Render( );
+    auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+    if( actor != NULL )
+      actor->GetProperty( )->SetLineWidth( w );
 
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetImageOpacity( double o )
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    actor->GetProperty( )->SetOpacity( o );
-    this->Render( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::ImageWidget::
-SetImageInterpolation( unsigned char i )
-{
-  auto actor = this->m_ImageViewerActors->GetWindowLevelImageActor( );
-  if( actor != NULL )
-  {
-    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( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-vtkProp* cpExtensions::QT::ImageWidget::
-GetImageActor( )
-{
-  return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) );
-}
-
-// -------------------------------------------------------------------------
-const vtkProp* cpExtensions::QT::ImageWidget::
-GetImageActor( ) const
-{
-  return( this->m_ImageViewerActors->GetWindowLevelImageActor( ) );
+  } // rof
+  this->Render( );
 }
-*/
-
-#endif // cpExtensions_QT4
 
 // eof - $RCSfile$