]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/MPRActors.cxx
Windows updated.
[cpPlugins.git] / lib / cpExtensions / Visualization / MPRActors.cxx
index 90fdb7d83c7f68842d4d356191b61bdeedbe03c0..bc758c4c42a10a3a5e9e88b33d917f4377ed1578 100644 (file)
@@ -1,8 +1,11 @@
 #include <cpExtensions/Visualization/MPRActors.h>
 
+#include <cmath>
+
 #include <vtkAlgorithmOutput.h>
 #include <vtkImageData.h>
 #include <vtkInformation.h>
+#include <vtkLookupTable.h>
 #include <vtkOutlineSource.h>
 #include <vtkProperty.h>
 #include <vtkRenderer.h>
@@ -40,6 +43,7 @@ AddInputConnection( vtkAlgorithmOutput* aout )
     this->ImageMaps[ 0 ]->SetInputConnection( aout );
     this->SetLookupTableToWindowLevel( 0 );
     this->_Update( 0 );
+    this->ResetWindowLevel( 0 );
     return( 0 );
   }
   else
@@ -64,7 +68,9 @@ AddInputConnection( vtkAlgorithmOutput* aout )
         vtkSmartPointer< vtkImageMapToColors >::New( )
         );
       this->ImageMaps[ N ]->SetInputConnection( aout );
-      this->SetLookupTableToWindowLevel( N );
+      this->SetLookupTableToColor(
+        N, double( 1 ), double( 0 ), double( 0 )
+        );
       this->_Update( N );
       return( N );
     }
@@ -87,6 +93,7 @@ AddInputData( vtkImageData* image )
     this->ImageMaps[ 0 ]->SetInputData( image );
     this->SetLookupTableToWindowLevel( 0 );
     this->_Update( 0 );
+    this->ResetWindowLevel( 0 );
     return( 0 );
   }
   else
@@ -107,7 +114,9 @@ AddInputData( vtkImageData* image )
         vtkSmartPointer< vtkImageMapToColors >::New( )
         );
       this->ImageMaps[ N ]->SetInputData( image );
-      this->SetLookupTableToWindowLevel( N );
+      this->SetLookupTableToColor(
+        N, double( 1 ), double( 0 ), double( 0 )
+        );
       this->_Update( N );
       return( N );
     }
@@ -196,6 +205,15 @@ PopDataFrom(
     w->RemoveActor( this->ImageOutlineActor );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+LinkInteractors( )
+{
+  this->_Update( 0 );
+  this->_Update( 1 );
+  this->_Update( 2 );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
 SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
@@ -345,6 +363,27 @@ SetLevel( unsigned int i, const double& l )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+SetWindowLevel( unsigned int i, const double& w, const double& l )
+{
+  vtkWindowLevelLookupTable* lut =
+    dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
+  if( lut != NULL )
+  {
+    lut->SetWindow( w );
+    lut->SetLevel( l );
+    lut->Build( );
+    this->ImageMaps[ i ]->Modified( );
+
+    for( unsigned int j = 0; j < 3; ++j )
+      this->Slices[ 0 ][ j ]->UpdateText( w, l );
+
+    this->Modified( );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::MPRActors::
 ResetWindowLevel( unsigned int i )
@@ -357,6 +396,8 @@ ResetWindowLevel( unsigned int i )
     double r[ 2 ];
     image->GetScalarRange( r );
     lut->SetTableRange( r );
+    lut->SetWindow( r[ 1 ] - r[ 0 ] );
+    lut->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
     lut->Build( );
     this->ImageMaps[ i ]->Modified( );
     this->Modified( );
@@ -364,6 +405,66 @@ ResetWindowLevel( unsigned int i )
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+SetLookupTableToColor(
+  unsigned int i, const double& r, const double& g, const double& b
+  )
+{
+  static const double _0 = double( 0 );
+  static const double _1 = double( 1 );
+  static const double _2 = double( 2 );
+  static const double _4 = double( 4 );
+  static const double _6 = double( 6 );
+  static const double _OPACITY = double( 0.6 );
+
+  // Check if the input has been configured
+  vtkImageData* image = this->_Image( i );
+  if( image == NULL )
+    return;
+
+  double range[ 2 ];
+  image->GetScalarRange( range );
+
+  // Get HSV from display color
+  double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax;
+  double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin;
+  double d = cmax - cmin;
+
+  double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0;
+  double value = cmax;
+  double hue = _0;
+  if( d > _0 )
+  {
+    if( r == cmax )
+      hue = std::fmod( ( g - b ) / d, _6 );
+    else if( g == cmax )
+      hue = ( ( b - r ) / d ) + _2;
+    else if( b == cmax )
+      hue = ( ( r - g ) / d ) + _4;
+    hue *= _1 / _6;
+    
+  } // fi
+
+  // Define new lookup table
+  vtkSmartPointer< vtkLookupTable > lut =
+    vtkSmartPointer< vtkLookupTable >::New( );
+  lut->SetScaleToLinear( );
+  /*
+    lut->SetAboveRangeColor( _0, _0, _0, _0 );
+    lut->SetBelowRangeColor( _0, _0, _0, _0 );
+  */
+  lut->SetNanColor( _0, _0, _0, _0 );
+  lut->SetTableRange( range[ 0 ], range[ 1 ] );
+  lut->SetAlphaRange( _0, _OPACITY );
+  lut->SetHueRange( _0, hue );
+  lut->SetSaturationRange( _0, saturation );
+  lut->SetValueRange( _0, value );
+  lut->Build( );
+
+  this->SetLookupTable( i, lut );
+}
+
 // -------------------------------------------------------------------------
 int cpExtensions::Visualization::MPRActors::
 GetSliceNumberMinValue( const int& axis ) const
@@ -464,7 +565,9 @@ _Image( unsigned int i ) const
     vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( );
     vtkInformation* info = algo->GetOutputInformation( 0 );
     return(
-      vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
+      vtkImageData::SafeDownCast(
+        info->Get( vtkDataObject::DATA_OBJECT( ) )
+        )
       );
   }
   else
@@ -490,6 +593,16 @@ _Update( unsigned int i )
         );
       this->Slices[ j ][ k ]->UpdateText( );
 
+      // Add all of slice's props
+      this->Slices[ j ][ k ]->InitTraversal( );
+      vtkProp* prop = this->Slices[ j ][ k ]->GetNextProp( );
+      while( prop != NULL )
+      {
+        this->AddItem( prop );
+        prop = this->Slices[ j ][ k ]->GetNextProp( );
+
+      } // elihw
+
     } // rof
 
   } // rof