]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
Widget integration (step 5/6): generic widget controller finished and tested on linux...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index 469f270f6b7df5886232ed7601f339c857579110..5722c583d608b0159ebe9537e61ca5fcbcb84909 100644 (file)
@@ -1,5 +1,7 @@
 #include <cpExtensions/Visualization/ImageSliceActors.h>
 
+#include <sstream>
+
 #include <vtkAlgorithmOutput.h>
 #include <vtkCellArray.h>
 #include <vtkImageData.h>
@@ -7,6 +9,7 @@
 #include <vtkPlane.h>
 #include <vtkPoints.h>
 #include <vtkProperty.h>
+#include <vtkRenderer.h>
 #include <vtkStreamingDemandDrivenPipeline.h>
 #include <vtkTextProperty.h>
 
@@ -50,7 +53,7 @@ Clear( )
   // Delete all images
   this->SliceMappers.clear( );
   this->ImageActors.clear( );
-  this->OtherActors.clear( );
+  this->AssociatedActors.clear( );
 
   // Reconfigure unique objects
   this->PlaneFunction = vtkSmartPointer< vtkPlane >::New( );
@@ -97,6 +100,44 @@ Clear( )
   coord->SetValue( 0.01, 0.01 );
 }
 
+// -------------------------------------------------------------------------
+vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
+GetStyle( )
+{
+  return( this->Style.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+const vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
+GetStyle( ) const
+{
+  return( this->Style.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+PushActorsInto( vtkRenderer* renderer )
+{
+  unsigned int N = this->GetNumberOfImageActors( );
+  for( unsigned int n = 0; n < N; ++n )
+    renderer->AddActor( this->GetImageActor( n ) );
+  renderer->AddActor( this->GetTextActor( ) );
+  renderer->AddActor( this->GetPlaneActor( ) );
+  renderer->Modified( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+PopActorsFrom( vtkRenderer* renderer )
+{
+  unsigned int N = this->GetNumberOfImageActors( );
+  for( unsigned int n = 0; n < N; ++n )
+    renderer->RemoveActor( this->GetImageActor( n ) );
+  renderer->RemoveActor( this->GetTextActor( ) );
+  renderer->RemoveActor( this->GetPlaneActor( ) );
+  renderer->Modified( );
+}
+
 // -------------------------------------------------------------------------
 unsigned int cpExtensions::Visualization::ImageSliceActors::
 GetNumberOfImageActors( ) const
@@ -170,7 +211,7 @@ GetPlaneFunction( ) const
 void cpExtensions::Visualization::ImageSliceActors::
 AddActor( vtkAlgorithm* algorithm, vtkActor* actor )
 {
-  this->OtherActors.push_back( TActorPair( algorithm, actor ) );
+  this->AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) );
   this->AddItem( actor );
 }
 
@@ -381,26 +422,28 @@ SetSliceNumber( const int& slice )
   this->PlaneActor->Modified( );
 
   // Prepare other actors to update
-  for( unsigned int i = 0; i < this->OtherActors.size( ); ++i )
-  {
-    if( this->OtherActors[ i ].first.GetPointer( ) != NULL )
-    {
-      this->OtherActors[ i ].first->Modified( );
-      this->OtherActors[ i ].first->Update( );
+  /* TODO
+     for( unsigned int i = 0; i < this->OtherActors.size( ); ++i )
+     {
+     if( this->OtherActors[ i ].first.GetPointer( ) != NULL )
+     {
+     this->OtherActors[ i ].first->Modified( );
+     this->OtherActors[ i ].first->Update( );
 
-    } // fi
+     } // fi
 
-    if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
-    {
-      this->OtherActors[ i ].second->GetMapper( )->Modified( );
-      this->OtherActors[ i ].second->Modified( );
+     if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
+     {
+     this->OtherActors[ i ].second->GetMapper( )->Modified( );
+     this->OtherActors[ i ].second->Modified( );
 
-    } // fi
+     } // fi
 
-  } // rof
+     } // rof
 
-  if( this->m_UpdateCommand != NULL )
-    this->m_UpdateCommand( this->m_UpdateData );
+     if( this->m_UpdateCommand != NULL )
+     this->m_UpdateCommand( this->m_UpdateData );
+  */
 
   // Update text
   this->UpdateText( );
@@ -430,6 +473,57 @@ UpdateText( )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+UpdateText( double pos[ 3 ] )
+{
+  if( this->SliceMappers.size( ) > 0 )
+  {
+    char axis;
+    int axId = this->SliceMappers[ 0 ]->GetOrientation( );
+    if     ( axId == 0 ) axis = 'X';
+    else if( axId == 1 ) axis = 'Y';
+    else if( axId == 2 ) axis = 'Z';
+
+    vtkImageData* image = this->SliceMappers[ 0 ]->GetInput( );
+
+    int ijk[ 3 ];
+    double pcoords[ 3 ];
+    image->ComputeStructuredCoordinates( pos, ijk, pcoords );
+    {
+      int nScl = image->GetNumberOfScalarComponents( );
+      std::stringstream str;
+      str
+        << "[" << ijk[ 0 ]
+        << "," << ijk[ 1 ]
+        << "," << ijk[ 2 ] << "]=(";
+      str <<
+        image->GetScalarComponentAsFloat(
+          ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], 0
+          );
+      for( int n = 1; n < nScl; ++n )
+        str
+          << " "
+          << image->GetScalarComponentAsFloat(
+            ijk[ 0 ], ijk[ 1 ], ijk[ 2 ], n
+            );
+      str << ")";
+      std::sprintf(
+        this->TextBuffer, "Axis: %c (%d) | Pixel %s",
+        axis,
+        this->SliceMappers[ 0 ]->GetSliceNumber( ),
+        str.str( ).c_str( )
+        );
+
+    } // fi
+  }
+  else
+    this->TextBuffer[ 0 ] = '\0';
+  this->TextActor->SetInput( this->TextBuffer );
+  this->TextActor->Modified( );
+  this->Modified( );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( const double& w, const double& l )
@@ -458,10 +552,17 @@ UpdateText( const double& w, const double& l )
 cpExtensions::Visualization::ImageSliceActors::
 ImageSliceActors( )
   : Superclass( ),
-    Interpolate( false ),
-    m_UpdateCommand( NULL ),
-    m_UpdateData( NULL )
+    Interpolate( false )
 {
+  // Connect this view with a controller
+  this->Style = vtkSmartPointer< ImageInteractorStyle >::New( );
+  this->Style->AssociateView( this );
+  this->Style->SetMouseMoveCommand( Self::_MouseMoveCommand );
+  this->Style->SetMouseClickCommand( Self::_MouseClickCommand );
+  this->Style->SetMouseDoubleClickCommand( Self::_MouseDoubleClickCommand );
+  this->Style->SetMouseWheelCommand( Self::_MouseWheelCommand );
+  this->Style->SetKeyCommand( Self::_KeyCommand );
+
   this->Clear( );
 }
 
@@ -497,6 +598,7 @@ _ConfigureNewInput( int axis )
   {
     this->AddItem( this->TextActor );
     this->AddItem( this->PlaneActor );
+    this->Style->AssociateImageActor( actor );
 
   } // fi
   this->AddItem( actor );
@@ -506,4 +608,69 @@ _ConfigureNewInput( int axis )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseMoveCommand(
+  void* data,
+  const ImageInteractorStyle::ButtonID& btn, double* pos,
+  bool alt, bool ctr, bool sft
+  )
+{
+  ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+  if( actors == NULL )
+    return;
+
+  if( btn == ImageInteractorStyle::ButtonID_None )
+  {
+    actors->UpdateText( pos );
+  }
+  else if( btn == ImageInteractorStyle::ButtonID_Left )
+  {
+  }
+  else if( btn == ImageInteractorStyle::ButtonID_Middle )
+  {
+  }
+  else if( btn == ImageInteractorStyle::ButtonID_Right )
+  {
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseClickCommand(
+  void* data,
+  const ImageInteractorStyle::ButtonID& btn, double* pos,
+  bool alt, bool ctr, bool sft
+  )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseDoubleClickCommand(
+  void* data,
+  const ImageInteractorStyle::ButtonID& btn, double* pos,
+  bool alt, bool ctr, bool sft
+  )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_MouseWheelCommand(
+  void* data,
+  const int& dir, bool alt, bool ctr, bool sft
+  )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_KeyCommand(
+  void* data,
+  const char& key
+  )
+{
+}
+
 // eof - $RCSfile$