]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
Merge ssh://git.creatis.insa-lyon.fr/cpPlugins
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index 8287399d509c2debd9eb057895870274b483b7a9..104812144453fcefac9f8eb6705d95df1fb00826 100644 (file)
@@ -133,7 +133,20 @@ AddInputConnection( vtkAlgorithmOutput* aout, int axis )
   }
   else
     this->m_ImageMaps.push_back( new_map );
-  
+
+  // Update window level values
+  if( new_map != NULL )
+  {
+    double range[ 2 ];
+    dynamic_cast< vtkImageData* >( new_map->GetInput( ) )->
+      GetScalarRange( range );
+    this->m_MinWindow = double( 0 );
+    this->m_MaxWindow = range[ 1 ] - range[ 0 ];
+    this->m_MinLevel = range[ 0 ];
+    this->m_MaxLevel = range[ 1 ];
+
+  } // fi
+
   // Create mapper and actors
   vtkSmartPointer< vtkImageSliceMapper > mapper =
     vtkSmartPointer< vtkImageSliceMapper >::New( );
@@ -149,6 +162,18 @@ AddInputConnection( vtkAlgorithmOutput* aout, int axis )
 void cpExtensions::Visualization::ImageSliceActors::
 AddInputData( vtkImageData* data, int axis )
 {
+  // Update window level values
+  if( this->m_ImageMaps.size( ) == 0 )
+  {
+    double range[ 2 ];
+    data->GetScalarRange( range );
+    this->m_MinWindow = double( 0 );
+    this->m_MaxWindow = range[ 1 ] - range[ 0 ];
+    this->m_MinLevel = range[ 0 ];
+    this->m_MaxLevel = range[ 1 ];
+
+  } // fi
+
   // Configure LUT, if possible (NULL is returned if not)
   this->_ConfigureNewLUT( data );
   vtkImageMapToColors* new_map = *( this->m_ImageMaps.rbegin( ) );
@@ -174,6 +199,12 @@ AddInputData( vtkImageData* data, int axis )
 void cpExtensions::Visualization::ImageSliceActors::
 Clear( )
 {
+  // Reset values
+  this->m_MinWindow = double( 0 );
+  this->m_MaxWindow = double( 0 );
+  this->m_MinLevel = double( 0 );
+  this->m_MaxLevel = double( 0 );
+
   // Unbind from container
   this->RemoveAllItems( );
 
@@ -347,17 +378,17 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
     if( axis == 0 )
     {
       camera->SetPosition( double( 1 ), double( 0 ), double( 0 ) );
-      camera->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
+      camera->SetViewUp  ( double( 0 ), double( 0 ), double( 1 ) );
     }
     else if( axis == 1 )
     {
-      camera->SetPosition( double( 0 ), double( 1 ), double(  0 ) );
-      camera->SetViewUp  ( double( 0 ), double( 0 ), double( -1 ) );
+      camera->SetPosition( double( 0 ), double( 1 ), double( 0 ) );
+      camera->SetViewUp  ( double( 0 ), double( 0 ), double( 1 ) );
     }
     else // if( axis == 2 )
     {
-      camera->SetPosition( double( 0 ), double( 0 ), double( 1 ) );
-      camera->SetViewUp  ( double( 0 ), double( 1 ), double( 0 ) );
+      camera->SetPosition( double( 0 ), double(  0 ), double( -1 ) );
+      camera->SetViewUp  ( double( 0 ), double( -1 ), double(  0 ) );
 
     } // fi
 
@@ -511,18 +542,29 @@ GetDisplayBounds( double bounds[ 6 ] ) const
 void cpExtensions::Visualization::ImageSliceActors::
 ResetCursor( )
 {
-  vtkPoints* points = this->m_Cursor->GetPoints( );
-  points->SetPoint( 0, 0, 0, 0 );
-  points->SetPoint( 1, 0, 0, 0 );
-  points->SetPoint( 2, 0, 0, 0 );
-  points->SetPoint( 3, 0, 0, 0 );
-  points->SetPoint( 4, 0, 0, 0 );
-  points->SetPoint( 5, 0, 0, 0 );
-  points->SetPoint( 6, 0, 0, 0 );
-  points->SetPoint( 7, 0, 0, 0 );
-  this->m_Cursor->Modified( );
-  this->m_CursorMapper->Modified( );
-  this->m_CursorActor->Modified( );
+  if( this->m_SliceMappers.size( ) > 0 )
+  {
+    double bounds[ 6 ];
+    this->m_SliceMappers[ 0 ]->GetInput( )->GetBounds( bounds );
+    double pos[] = { bounds[ 0 ], bounds[ 2 ], bounds[ 4 ] };
+    this->SetCursor( pos );
+  }
+  else
+  {
+    vtkPoints* points = this->m_Cursor->GetPoints( );
+    points->SetPoint( 0, 0, 0, 0 );
+    points->SetPoint( 1, 0, 0, 0 );
+    points->SetPoint( 2, 0, 0, 0 );
+    points->SetPoint( 3, 0, 0, 0 );
+    points->SetPoint( 4, 0, 0, 0 );
+    points->SetPoint( 5, 0, 0, 0 );
+    points->SetPoint( 6, 0, 0, 0 );
+    points->SetPoint( 7, 0, 0, 0 );
+    this->m_Cursor->Modified( );
+    this->m_CursorMapper->Modified( );
+    this->m_CursorActor->Modified( );
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
@@ -671,12 +713,11 @@ SetWindow( double w )
   if( lut == NULL )
     return;
 
-  /* TODO: Min and Max values are assigned 0!!!
-     if( w < this->MinWindow )
-     w = this->MinWindow;
-     if( w > this->MaxWindow )
-     w = this->MaxWindow;
-  */
+  if( w < this->m_MinWindow )
+    w = this->m_MinWindow;
+  if( w > this->m_MaxWindow )
+    w = this->m_MaxWindow;
+
   lut->SetWindow( w );
   lut->Build( );
   this->m_ImageMaps[ 0 ]->Modified( );
@@ -698,12 +739,11 @@ SetLevel( double l )
   if( lut == NULL )
     return;
 
-  /* TODO: Min and Max values are assigned 0!!!
-     if( l < this->MinLevel )
-     l = this->MinLevel;
-     if( l > this->MaxLevel )
-     l = this->MaxLevel;
-  */
+  if( l < this->m_MinLevel )
+    l = this->m_MinLevel;
+  if( l > this->m_MaxLevel )
+    l = this->m_MaxLevel;
+
   lut->SetLevel( l );
   lut->Build( );
   this->m_ImageMaps[ 0 ]->Modified( );
@@ -725,16 +765,15 @@ SetWindowLevel( double w, double l )
   if( lut == NULL )
     return;
 
-  /* TODO: Min and Max values are assigned 0!!!
-     if( w < this->MinWindow )
-     w = this->MinWindow;
-     if( w > this->MaxWindow )
-     w = this->MaxWindow;
-     if( l < this->MinLevel )
-     l = this->MinLevel;
-     if( l > this->MaxLevel )
-     l = this->MaxLevel;
-  */
+  if( w < this->m_MinWindow )
+    w = this->m_MinWindow;
+  if( w > this->m_MaxWindow )
+    w = this->m_MaxWindow;
+  if( l < this->m_MinLevel )
+    l = this->m_MinLevel;
+  if( l > this->m_MaxLevel )
+    l = this->m_MaxLevel;
+
   lut->SetWindow( w );
   lut->SetLevel( l );
   lut->Build( );
@@ -1109,6 +1148,8 @@ _ConfigureStyle( )
   this->m_Style->AddMouseClickCommand( Self::_MouseClickCommand, this );
   this->m_Style->AddMouseWheelCommand( Self::_MouseWheelCommand, this );
   this->m_Style->AddKeyCommand( Self::_KeyCommand, this );
+  this->m_Style->AddEnterCommand( Self::_EnterCommand, this );
+  this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this );
 }
 
 // -------------------------------------------------------------------------
@@ -1140,11 +1181,6 @@ _ConfigureNewLUT( vtkImageData* data )
     lut->SetLevel( ( range[ 1 ] + range[ 0 ] ) / double( 2 ) );
     lut->Build( );
     this->m_ImageMaps[ 0 ]->SetLookupTable( lut );
-
-    this->m_MinWindow = double( 0 );
-    this->m_MaxWindow = range[ 1 ] - range[ 0 ];
-    this->m_MinLevel = range[ 0 ];
-    this->m_MaxLevel = range[ 1 ];
   }
   else
     this->SetLookupTableAsColor( nImgs, 1, 0, 0 );
@@ -1180,6 +1216,7 @@ _ConfigureNewInput( int axis )
     this->SetSliceNumber( this->GetSliceNumber( ) );
   else
     this->SetSliceNumber( this->GetSliceNumberMaxValue( ) );
+  this->ResetCursor( );
   this->Modified( );
 }
 
@@ -1203,18 +1240,15 @@ _MouseMoveCommand(
   }
   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
-    */
+    if( !alt && ctr && !sft )
+    {
+      // Interactively move slices
+      auto i = actors->m_SlicesCommands.begin( );
+      for( ; i != actors->m_SlicesCommands.end( ); ++i )
+        i->first( pos, actors->GetAxis( ), i->second );
+      actors->Render( );
+
+    } // fi
   }
   else if( btn == TStyle::ButtonID_Right )
   {
@@ -1341,4 +1375,30 @@ _KeyCommand( void* data, const char& key )
   } // hctiws
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_EnterCommand( void* data )
+{
+  ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+  if( actors == NULL )
+    return;
+
+  actors->ResetCursor( );
+  actors->m_CursorActor->VisibilityOn( );
+  actors->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_LeaveCommand( void* data )
+{
+  ImageSliceActors* actors = reinterpret_cast< ImageSliceActors* >( data );
+  if( actors == NULL )
+    return;
+
+  actors->ResetCursor( );
+  actors->m_CursorActor->VisibilityOff( );
+  actors->Render( );
+}
+
 // eof - $RCSfile$