]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Extensions/Visualization/MPRActors.cxx
First modifications to make this work on MS-Windows
[cpPlugins.git] / lib / cpPlugins / Extensions / Visualization / MPRActors.cxx
index 1843fb17cbb0882b4831455db8c5392f109f4fca..9808111ad8a380b9ac88ae96f8fa82ed8114add3 100644 (file)
@@ -1,6 +1,7 @@
 #include <cpPlugins/Extensions/Visualization/MPRActors.h>
 
 #include <vtkImageData.h>
+#include <vtkLookupTable.h>
 #include <vtkOutlineSource.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkProperty.h>
@@ -40,10 +41,10 @@ SetInputData( vtkImageData* image )
 
   for( int i = 0; i < 3; ++i )
   {
-    Slices[ i ]->SetInputConnection(
+    this->Slices[ i ]->SetInputConnection(
       this->ImageToWindowLevel->GetOutputPort( ), i
       );
-    Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
+    this->Slices[ i ]->UpdateText( this->GetWindow( ), this->GetLevel( ) );
 
   } // rof
 
@@ -139,6 +140,25 @@ SetInputData( vtkImageData* image )
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSegmentationData( vtkImageData* segmentation )
 {
+  double range[ 2 ];
+  this->Segmentation = segmentation;
+  this->Segmentation->GetScalarRange( range );
+
+  vtkSmartPointer< vtkLookupTable > lut =
+    vtkSmartPointer< vtkLookupTable >::New( );
+  lut->SetNumberOfTableValues( 2 );
+  lut->SetTableRange( range );
+  lut->SetTableValue( 0, 0, 0, 0, 0 );
+  lut->SetTableValue( 1, 1, 0, 0, 0.4 );
+
+  this->SegmentationToColors->SetInputData( this->Segmentation );
+  this->SegmentationToColors->SetLookupTable( lut );
+  this->SegmentationToColors->Update( );
+
+  for( int i = 0; i < 3; ++i )
+    this->Slices[ i ]->SetSegmentationConnection(
+      this->SegmentationToColors->GetOutputPort( )
+      );
 }
 
 // -------------------------------------------------------------------------
@@ -281,36 +301,66 @@ ResetWindowLevel( )
 vtkPlane* cpPlugins::Extensions::Visualization::MPRActors::
 GetSlicePlane( const int& axis ) const
 {
+  return( NULL );
 }
 
 // -------------------------------------------------------------------------
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSliceNumberMinValue( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumberMinValue( ) );
 }
 
 // -------------------------------------------------------------------------
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSliceNumberMaxValue( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumberMaxValue( ) );
 }
 
 // -------------------------------------------------------------------------
 int cpPlugins::Extensions::Visualization::MPRActors::
 GetSlice( const int& axis ) const
 {
+  return( this->Slices[ axis ]->GetSliceNumber( ) );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const int& slice )
 {
+  // Get image data extent
+  if( this->Image == NULL )
+    return;
+  int ext[ 6 ];
+  this->Image->GetExtent( ext );
+
+  // Check if the slice is valid
+  int real = slice;
+  if( slice < ext[ axis << 1 ] )
+    real = ext[ axis << 1 ];
+  if( ext[ ( axis << 1 ) + 1 ] < slice )
+    real = ext[ ( axis << 1 ) + 1 ];
+
+  // Change slice
+  this->Slices[ axis ]->SetSliceNumber( real );
+  this->Modified( );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Extensions::Visualization::MPRActors::
 SetSlice( const int& axis, const double& slice )
 {
+  if( this->Image == NULL )
+    return;
+  
+  double x[ 3 ] = { double( 0 ) };
+  double pcoords[ 3 ];
+  int ijk[ 3 ];
+
+  x[ axis ] = slice;
+  this->Image->ComputeStructuredCoordinates( x, ijk, pcoords );
+  this->SetSlice( axis, ijk[ axis ] );
 }
 
 // -------------------------------------------------------------------------