]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
More widgets added
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index 5892fe14b90ec4b9028a90efaa075e86b87a7fbb..17dc4c45035be5b973135d00e93a81f6266d6ac6 100644 (file)
@@ -29,22 +29,77 @@ New( )
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-AddSlicesCommand( TCursorCommand command, void* data )
+AddSlicesCommand( TSlicesCommand command, void* data )
 {
-  this->m_SlicesCommands.push_back(
-    std::pair< TCursorCommand, void* >( command, data )
-    );
-  this->Modified( );
+  if( command != NULL )
+  {
+    this->m_SlicesCommands[ command ] = data;
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-AddSeedCommand( TCursorCommand command, void* data )
+AddWindowLevelCommand( TWindowLevelCommand command, void* data )
 {
-  this->m_SeedCommands.push_back(
-    std::pair< TCursorCommand, void* >( command, data )
-    );
-  this->Modified( );
+  if( command != NULL )
+  {
+    this->m_WindowLevelCommands[ command ] = data;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+AddRenderCommand( TVoidCommand command, void* data )
+{
+  if( command != NULL )
+  {
+    this->m_RenderCommands[ command ] = data;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+RemoveSlicesCommand( TSlicesCommand command )
+{
+  auto i = this->m_SlicesCommands.find( command );
+  if( i != this->m_SlicesCommands.end( ) )
+  {
+    this->m_SlicesCommands.erase( i );
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+RemoveWindowLevelCommand( TWindowLevelCommand command )
+{
+  auto i = this->m_WindowLevelCommands.find( command );
+  if( i != this->m_WindowLevelCommands.end( ) )
+  {
+    this->m_WindowLevelCommands.erase( i );
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+RemoveRenderCommand( TVoidCommand command )
+{
+  auto i = this->m_RenderCommands.find( command );
+  if( i != this->m_RenderCommands.end( ) )
+  {
+    this->m_RenderCommands.erase( i );
+    this->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -126,8 +181,6 @@ Clear( )
   this->m_ImageMaps.clear( );
   this->m_SliceMappers.clear( );
   this->m_ImageActors.clear( );
-  this->m_AssociatedSlices.clear( );
-  this->m_AssociatedActors.clear( );
 
   // Reconfigure unique objects
   this->m_Cursor        = vtkSmartPointer< vtkPolyData >::New( );
@@ -211,14 +264,6 @@ Clear( )
   this->AddItem( this->m_PlaneActor );
 }
 
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AssociateSlice( Self* other )
-{
-  this->m_AssociatedSlices.push_back( other );
-  this->Modified( );
-}
-
 // -------------------------------------------------------------------------
 vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors::
 GetStyle( )
@@ -375,21 +420,6 @@ GetPlaneFunction( ) const
   return( this->m_PlaneFunction );
 }
 
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AddActor( vtkAlgorithm* algorithm, vtkActor* actor )
-{
-  this->m_AssociatedActors.push_back( TAssociatedActor( algorithm, actor ) );
-  this->AddItem( actor );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-AddActor( vtkActor* actor )
-{
-  this->AddActor( NULL, actor );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetInterpolate( bool v )
@@ -808,26 +838,38 @@ SetSliceNumber( const int& slice )
   if( nImages == 0 )
     return;
 
+  // Compute plane properties
+  int axis = this->m_SliceMappers[ 0 ]->GetOrientation( );
+  vtkAlgorithm* algo = this->m_SliceMappers[ 0 ]->GetInputAlgorithm( );
+  vtkInformation* info = algo->GetOutputInformation( 0 );
+  int ext[ 6 ];
+  double ori[ 3 ], spac[ 3 ], pos[ 3 ];
+  info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext );
+  info->Get( vtkDataObject::ORIGIN( ), ori );
+  info->Get( vtkDataObject::SPACING( ), spac );
+  this->m_SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos );
+
+  // Update display extent
+  int d_ext[ 6 ] =
+    {
+      ext[ 0 ], ext[ 1 ],
+      ext[ 2 ], ext[ 3 ],
+      ext[ 4 ], ext[ 5 ]
+    };
+  d_ext[ axis << 1 ] = slice;
+  d_ext[ ( axis << 1 ) + 1 ] = slice;
+
   // Change visualization extent
   for( unsigned int i = 0; i < nImages; ++i )
   {
     this->m_SliceMappers[ i ]->SetSliceNumber( slice );
+    this->m_ImageActors[ i ]->SetDisplayExtent( d_ext );
     this->m_SliceMappers[ i ]->Modified( );
     this->m_ImageActors[ i ]->Modified( );
     this->m_SliceMappers[ i ]->Update( );
 
   } // rof
 
-  // Compute plane
-  vtkAlgorithm* algo = this->m_SliceMappers[ 0 ]->GetInputAlgorithm( );
-  vtkInformation* info = algo->GetOutputInformation( 0 );
-  int ext[ 6 ];
-  double ori[ 3 ], spac[ 3 ], pos[ 3 ];
-  info->Get( vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT( ), ext );
-  info->Get( vtkDataObject::ORIGIN( ), ori );
-  info->Get( vtkDataObject::SPACING( ), spac );
-  this->m_SliceMappers[ 0 ]->GetSlicePlane( )->GetOrigin( pos );
-
   // Prevent obscuring voxels by offsetting the plane geometry
   double xbnds[ ] =
     {
@@ -871,7 +913,6 @@ SetSliceNumber( const int& slice )
   this->m_PlaneFunction->SetOrigin( pos );
 
   // Configure visualization and implicit plane orientation
-  int axis = this->m_SliceMappers[ 0 ]->GetOrientation( );
   this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
   this->m_PlaneActor->GetProperty( )->SetLineWidth( 2 );
   vtkPoints* plane_points = this->m_Plane->GetPoints( );
@@ -908,37 +949,8 @@ SetSliceNumber( const int& slice )
   this->m_PlaneMapper->Modified( );
   this->m_PlaneActor->Modified( );
 
-  // Prepare other actors to 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
-
-     if( this->OtherActors[ i ].second.GetPointer( ) != NULL )
-     {
-     this->OtherActors[ i ].second->GetMapper( )->Modified( );
-     this->OtherActors[ i ].second->Modified( );
-
-     } // fi
-
-     } // rof
-
-     if( this->m_UpdateCommand != NULL )
-     this->m_UpdateCommand( this->m_UpdateData );
-  */
-
   // Update text
   this->UpdateText( );
-
-  // Associated slices
-  for( unsigned int i = 0; i < this->m_AssociatedSlices.size( ); ++i )
-    if( this->m_AssociatedSlices[ i ]->GetAxis( ) == this->GetAxis( ) )
-      this->m_AssociatedSlices[ i ]->SetSliceNumber( slice );
 }
 
 // -------------------------------------------------------------------------
@@ -1068,6 +1080,36 @@ UpdateText( const double& w, const double& l )
   this->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+Render( )
+{
+  vtkInteractorStyle* style = this->GetStyle( );
+  if( style == NULL )
+    return;
+  vtkRenderWindowInteractor* rwi = style->GetInteractor( );
+  if( rwi != NULL )
+    rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+ResetCamera( )
+{
+  vtkInteractorStyle* style = this->GetStyle( );
+  if( style == NULL )
+    return;
+  vtkRenderWindowInteractor* rwi = style->GetInteractor( );
+  if( rwi == NULL )
+    return;
+  vtkRenderWindow* rw = rwi->GetRenderWindow( );
+  if( rw == NULL )
+    return;
+  vtkRenderer* renderer = rw->GetRenderers( )->GetFirstRenderer( );
+  if( renderer != NULL )
+    renderer->ResetCamera( );
+}
+
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::ImageSliceActors::
 ImageSliceActors( )
@@ -1089,12 +1131,9 @@ void cpExtensions::Visualization::ImageSliceActors::
 _ConfigureStyle( )
 {
   // Connect this view with a controller
-  this->m_Style = vtkSmartPointer< ImageInteractorStyle >::New( );
+  this->m_Style = vtkSmartPointer< TStyle >::New( );
   this->m_Style->AddMouseMoveCommand( Self::_MouseMoveCommand, this );
   this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this );
-  this->m_Style->AddMouseDoubleClickCommand(
-    Self::_MouseDoubleClickCommand, this
-    );
   this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this );
   this->m_Style->AddKeyCommand( Self::_KeyCommand, this );
 }
@@ -1174,8 +1213,7 @@ _ConfigureNewInput( int axis )
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 _MouseMoveCommand(
-  void* data,
-  const ImageInteractorStyle::ButtonID& btn, double* pos,
+  void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
   bool alt, bool ctr, bool sft
   )
 {
@@ -1183,32 +1221,33 @@ _MouseMoveCommand(
   if( actors == NULL )
     return;
 
-  if( btn == ImageInteractorStyle::ButtonID_None )
+  if( btn == TStyle::ButtonID_None )
   {
+    // Just show the pixel information
     actors->SetCursor( pos );
     actors->UpdateText( pos );
-    actors->GetStyle( )->GetInteractor( )->Render( );
-  }
-  else if( btn == ImageInteractorStyle::ButtonID_Left )
-  {
-    unsigned int nC = actors->m_SlicesCommands.size( );
-    if( !alt && ctr && !sft && nC > 0 )
-    {
-      for( unsigned int i = 0; i < nC; ++i )
-        actors->m_SlicesCommands[ i ].first(
-          pos, actors->GetAxis( ), actors->m_SlicesCommands[ i ].second
-          );
-      actors->GetStyle( )->GetInteractor( )->Render( );
-
-    } // fi
+    actors->Render( );
   }
-  else if( btn == ImageInteractorStyle::ButtonID_Middle )
+  else if( btn == TStyle::ButtonID_Left )
   {
+    /* TODO
+       unsigned int nC = actors->m_SlicesCommands.size( );
+       if( !alt && ctr && !sft && nC > 0 )
+       {
+       for( unsigned int i = 0; i < nC; ++i )
+       actors->m_SlicesCommands[ i ].first(
+       pos, actors->GetAxis( ), actors->m_SlicesCommands[ i ].second
+       );
+       actors->Render( );
+
+       } // fi
+    */
   }
-  else if( btn == ImageInteractorStyle::ButtonID_Right )
+  else if( btn == TStyle::ButtonID_Right )
   {
     if( !alt && !ctr && sft )
     {
+      // Change image window level
       double bounds[ 6 ];
       actors->m_SliceMappers[ 0 ]->GetBounds( bounds );
 
@@ -1222,12 +1261,16 @@ _MouseMoveCommand(
 
       dx *= actors->m_StartWindowLevel[ 0 ];
       dy *= actors->m_StartWindowLevel[ 1 ];
-      actors->SetWindowLevel(
-        actors->m_StartWindowLevel[ 0 ] + dx,
-        actors->m_StartWindowLevel[ 1 ] + dy
-        );
-      actors->GetStyle( )->GetInteractor( )->Render( );
-
+      dx += actors->m_StartWindowLevel[ 0 ];
+      dy += actors->m_StartWindowLevel[ 1 ];
+      actors->SetWindowLevel( dx, dy );
+      actors->Render( );
+
+      // Associate objects
+      auto i = actors->m_WindowLevelCommands.begin( );
+      for( ; i != actors->m_WindowLevelCommands.end( ); ++i )
+        i->first( dx, dy, i->second );
+      
     } // fi
 
   } // fi
@@ -1236,8 +1279,7 @@ _MouseMoveCommand(
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 _MouseClickCommand(
-  void* data,
-  const ImageInteractorStyle::ButtonID& btn, double* pos,
+  void* data, const TStyle::ButtonID& btn, int* idx, double* pos,
   bool alt, bool ctr, bool sft
   )
 {
@@ -1254,9 +1296,8 @@ _MouseClickCommand(
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-_MouseDoubleClickCommand(
-  void* data,
-  const ImageInteractorStyle::ButtonID& btn, double* pos,
+_MouseWheelCommand(
+  void* data, const int& dir,
   bool alt, bool ctr, bool sft
   )
 {
@@ -1264,55 +1305,59 @@ _MouseDoubleClickCommand(
   if( actors == NULL )
     return;
 
-  if( btn == ImageInteractorStyle::ButtonID_Left )
+  if( !alt && !ctr )
   {
-    unsigned int nC = actors->m_SeedCommands.size( );
-    if( !alt && ctr && !sft && nC > 0 )
-    {
-      for( unsigned int i = 0; i < nC; ++i )
-        actors->m_SeedCommands[ i ].first(
-          pos, actors->GetAxis( ), actors->m_SeedCommands[ i ].second
-          );
-      actors->GetStyle( )->GetInteractor( )->Render( );
+    int slice = actors->GetSliceNumber( ) + ( dir * ( ( sft )? 10: 1 ) );
+    if( slice < actors->GetSliceNumberMinValue( ) )
+      slice = actors->GetSliceNumberMinValue( );
+    if( slice > actors->GetSliceNumberMaxValue( ) )
+      slice = actors->GetSliceNumberMaxValue( );
+    actors->SetSliceNumber( slice );
+    actors->Render( );
+
+    // Associate objects
+    auto i = actors->m_RenderCommands.begin( );
+    for( ; i != actors->m_RenderCommands.end( ); ++i )
+      i->first( i->second );
 
-    } // fi
-  }
-  else if( btn == ImageInteractorStyle::ButtonID_Middle )
-  {
-  }
-  else if( btn == ImageInteractorStyle::ButtonID_Right )
-  {
   } // fi
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-_MouseWheelCommand(
-  void* data,
-  const int& dir, bool alt, bool ctr, bool sft
-  )
+_KeyCommand( void* data, const char& key )
 {
   ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
   if( actors == NULL )
     return;
 
-  if( !alt && !ctr && !sft )
+  switch( key )
   {
-    actors->SetSliceNumber( actors->GetSliceNumber( ) + dir );
-    actors->GetStyle( )->GetInteractor( )->Render( );
-  }
-  else if( !alt && !ctr && sft )
+  case 'r': case 'R':
   {
-    actors->SetSliceNumber( actors->GetSliceNumber( ) + ( dir * 10 ) );
-    actors->GetStyle( )->GetInteractor( )->Render( );
+    actors->ResetCamera( );
+    actors->Render( );
 
-  } // fi
-}
+    // Associate objects
+    auto i = actors->m_RenderCommands.begin( );
+    for( ; i != actors->m_RenderCommands.end( ); ++i )
+      i->first( i->second );
+  }
+  break;
+  case 'w': case 'W':
+  {
+    actors->ResetWindowLevel( );
+    actors->Render( );
 
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-_KeyCommand( void* data, const char& key )
-{
+    // Associate objects
+    auto i = actors->m_RenderCommands.begin( );
+    for( ; i != actors->m_RenderCommands.end( ); ++i )
+      i->first( i->second );
+  }
+  break;
+  default:
+    break;
+  } // hctiws
 }
 
 // eof - $RCSfile$