]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.cxx
sphere widget done, finally
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.cxx
index ee4947e834d4394463a547de1e958d4752e66f58..b444328be321e2946c54807f4a59345da8f312fd 100644 (file)
@@ -1,11 +1,13 @@
 #include <cpExtensions/Visualization/ImageSliceActors.h>
 
+#include <cstring>
 #include <sstream>
 
 #include <vtkAlgorithmOutput.h>
 #include <vtkCamera.h>
 #include <vtkCellArray.h>
 #include <vtkImageData.h>
+#include <vtkImageProperty.h>
 #include <vtkPoints.h>
 #include <vtkProperty.h>
 #include <vtkRenderer.h>
 #include <vtkRenderWindowInteractor.h>
 #include <vtkTextProperty.h>
 
+// -------------------------------------------------------------------------
+double cpExtensions::Visualization::ImageSliceActors::
+m_PlaneColors[ 3 ][ 3 ] =
+{
+  { 1, 0, 0 },
+  { 0, 1, 0 },
+  { 0, 0, 1 }
+};
+
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::ImageSliceActors*
 cpExtensions::Visualization::ImageSliceActors::
@@ -22,166 +33,107 @@ New( )
   return( new Self( ) );
 }
 
-// -------------------------------------------------------------------------
-cpExtensions::Visualization::
-ImageBlender* cpExtensions::Visualization::ImageSliceActors::
-GetBlender( )
-{
-  return( this->m_ImageBlender );
-}
-
-// -------------------------------------------------------------------------
-const cpExtensions::Visualization::
-ImageBlender* cpExtensions::Visualization::ImageSliceActors::
-GetBlender( ) const
-{
-  return( this->m_ImageBlender );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageSliceActors::
-SetBlender( ImageBlender* blender )
-{
-  this->m_ImageBlender = blender;
-
-  // Create mapper and actors
-  this->m_ImageMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
-  this->m_ImageMapper->SetInputConnection(
-    this->m_ImageBlender->GetOutputPort( )
-    );
-  this->m_ImageMapper->SetOrientation( 0 );
-  this->m_ImageMapper->Update( );
-
-  // Create actor
-  this->m_ImageActor = vtkSmartPointer< vtkImageActor >::New( );
-  this->m_ImageActor->SetMapper( this->m_ImageMapper );
-  this->m_ImageActor->SetInterpolate( this->m_Interpolate );
-  this->m_ImageActor->Modified( );
-
-  if( this->m_Style.GetPointer( ) != NULL )
-    this->m_Style->AssociateImageActor( this->m_ImageActor );
-  this->AddItem( this->m_ImageActor );
-
-  this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
-  this->ResetCursor( );
-  this->Modified( );
-}
-
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetAxis( int axis )
 {
   this->m_ImageMapper->SetOrientation( axis );
+  this->m_BlenderMapper->SetOrientation( axis );
   this->m_ImageMapper->Update( );
+  this->m_BlenderMapper->Update( );
   this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
   this->m_ImageActor->Modified( );
+  this->m_BlenderActor->Modified( );
   this->Modified( );
   this->ResetCamera( );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-AddInputConnection( vtkAlgorithmOutput* aout )
+SetInputConnection( vtkAlgorithmOutput* aout )
 {
   // Get input vtkImageData
   if( aout == NULL )
     return;
 
-  if( this->m_ImageBlender.GetPointer( ) == NULL )
-  {
-    // Try to infere if input comes from a color mapping filter
-    vtkAlgorithm* producer = aout->GetProducer( );
-    vtkSmartPointer< ImageBlender > blender =
-      dynamic_cast< ImageBlender* >( producer );
-    if( blender.GetPointer( ) == NULL )
-    {
-      // Ok, create a new blender with default window level
-      vtkImageData* data = dynamic_cast< vtkImageData* >(
-        producer->GetOutputDataObject( aout->GetIndex( ) )
-        );
-      double r[ 2 ];
-      data->GetScalarRange( r );
-
-      blender = vtkSmartPointer< ImageBlender >::New( );
-      blender->AddInputConnection( aout );
-      blender->SetWindow( r[ 1 ] - r[ 0 ] );
-      blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
-
-    } // fi
-    this->SetBlender( blender );
-  }
-  else
-    this->m_ImageBlender->AddInputConnection( aout );
+  // Create mapper and actors
+  this->m_ImageMapper->SetInputConnection( aout );
+  this->_ConfigureInputImage( );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
-AddInputData( vtkImageData* data )
+SetInputImage( vtkImageData* data )
 {
   // Get input vtkImageData
   if( data == NULL )
     return;
 
-  if( this->m_ImageBlender.GetPointer( ) == NULL )
-  {
-    // Create a new blender with default window level
-    double r[ 2 ];
-    data->GetScalarRange( r );
+  // Create mapper and actors
+  this->m_ImageMapper->SetInputData( data );
+  this->_ConfigureInputImage( );
+}
 
-    vtkSmartPointer< ImageBlender > blender =
-      vtkSmartPointer< ImageBlender >::New( );
-    blender->AddInputData( data );
-    blender->SetWindow( r[ 1 ] - r[ 0 ] );
-    blender->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
-    this->SetBlender( blender );
-  }
-  else
-    this->m_ImageBlender->AddInputData( data );
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::ImageSliceActors::
+AddBinaryConnection(
+  vtkAlgorithmOutput* aout,
+  const double& r, const double& g, const double& b
+  )
+{
+  if( aout == NULL )
+    return( -1 );
+  this->m_Blender->AddInputConnection( aout );
+  this->_ConfigureBinaryImage( r, g, b );
+  return( this->m_Blender->GetNumberOfInputPorts( ) - 1 );
+}
+
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::ImageSliceActors::
+AddBinaryImage(
+  vtkImageData* data,
+  const double& r, const double& g, const double& b
+  )
+{
+  if( data == NULL )
+    return( -1 );
+  this->m_Blender->AddInputData( data );
+  this->_ConfigureBinaryImage( r, g, b );
+  return( this->m_Blender->GetNumberOfInputPorts( ) - 1 );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 Clear( )
 {
-  // Reset values
-  this->m_VisibleExtent[ 0 ] =
-    this->m_VisibleExtent[ 2 ] =
-    this->m_VisibleExtent[ 4 ] = -1;
-  this->m_VisibleExtent[ 1 ] =
-    this->m_VisibleExtent[ 3 ] =
-    this->m_VisibleExtent[ 5 ] = 0;
-  this->m_VisibleBounds[ 0 ] =
-    this->m_VisibleBounds[ 2 ] =
-    this->m_VisibleBounds[ 4 ] = double( 0 );
-  this->m_VisibleBounds[ 1 ] =
-    this->m_VisibleBounds[ 3 ] =
-    this->m_VisibleBounds[ 5 ] = double( 0 );
-
   // Unbind from container
   this->RemoveAllItems( );
 
-  // Delete all images
-  this->m_ImageActor   = NULL;
-  this->m_ImageMapper  = NULL;
-  this->m_ImageBlender = NULL;
-
-  // Reconfigure unique objects
-  this->m_Cursor               = vtkSmartPointer< vtkPolyData >::New( );
-  this->m_CursorMapper         = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->m_CursorActor          = vtkSmartPointer< vtkActor >::New( );
-  this->m_HorizontalLine       = vtkSmartPointer< vtkPolyData >::New( );
-  this->m_HorizontalLineMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->m_HorizontalLineActor  = vtkSmartPointer< vtkActor >::New( );
-  this->m_VerticalLine         = vtkSmartPointer< vtkPolyData >::New( );
-  this->m_VerticalLineMapper   = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->m_VerticalLineActor    = vtkSmartPointer< vtkActor >::New( );
-  this->m_Plane                = vtkSmartPointer< vtkPolyData >::New( );
-  this->m_PlaneMapper          = vtkSmartPointer< vtkPolyDataMapper >::New( );
-  this->m_TextActor            = vtkSmartPointer< vtkTextActor >::New( );
-  this->m_PlaneActor           = vtkSmartPointer< vtkActor >::New( );
-  this->m_TextBuffer[ 0 ] = '\0';
+  // Filters and mappers
+  this->m_ImageMapper   = vtkSmartPointer< vtkImageSliceMapper >::New( );
+  this->m_ImageActor    = vtkSmartPointer< vtkImageActor >::New( );
+  this->m_Blender       = vtkSmartPointer< TBlender >::New( );
+  this->m_BlenderMapper = vtkSmartPointer< vtkImageSliceMapper >::New( );
+  this->m_BlenderLUT    = vtkSmartPointer< vtkLookupTable >::New( );
+  this->m_BlenderActor  = vtkSmartPointer< vtkImageActor >::New( );
+
+  this->m_ImageActor->SetMapper( this->m_ImageMapper );
+  this->m_BlenderMapper->
+    SetInputConnection( this->m_Blender->GetOutputPort( ) );
+
+  this->m_BlenderLUT->SetNumberOfTableValues( 1 );
+  this->m_BlenderLUT->SetTableRange( 0, 1 );
+  this->m_BlenderLUT->SetTableValue( 0, 0, 0, 0, 0 );
+  this->m_BlenderLUT->Build( );
 
-  // Unique objects configuration
+  this->m_BlenderActor->SetMapper( this->m_BlenderMapper );
+  this->m_BlenderActor->GetProperty( )->SetLookupTable( this->m_BlenderLUT );
+  this->m_BlenderActor->GetProperty( )->UseLookupTableScalarRangeOn( );
+
+  // Remove associated objects
+  this->m_AssociatedSlices.clear( );
+
+  // White cursor
   vtkSmartPointer< vtkPoints > cursor_points =
     vtkSmartPointer< vtkPoints >::New( );
   vtkSmartPointer< vtkCellArray > cursor_lines =
@@ -190,26 +142,28 @@ Clear( )
   cursor_points->InsertNextPoint( 0, 0, 0 );
   cursor_points->InsertNextPoint( 0, 0, 0 );
   cursor_points->InsertNextPoint( 0, 0, 0 );
-  cursor_points->InsertNextPoint( 0, 0, 0 );
-  cursor_points->InsertNextPoint( 0, 0, 0 );
-  cursor_points->InsertNextPoint( 0, 0, 0 );
-  cursor_points->InsertNextPoint( 0, 0, 0 );
   cursor_lines->InsertNextCell( 2 );
   cursor_lines->InsertCellPoint( 0 );
   cursor_lines->InsertCellPoint( 1 );
   cursor_lines->InsertNextCell( 2 );
   cursor_lines->InsertCellPoint( 2 );
   cursor_lines->InsertCellPoint( 3 );
-  cursor_lines->InsertNextCell( 2 );
-  cursor_lines->InsertCellPoint( 4 );
-  cursor_lines->InsertCellPoint( 5 );
-  cursor_lines->InsertNextCell( 2 );
-  cursor_lines->InsertCellPoint( 6 );
-  cursor_lines->InsertCellPoint( 7 );
+
+  this->m_Cursor = vtkSmartPointer< vtkPolyData >::New( );
+  this->m_CursorMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->m_CursorActor = vtkSmartPointer< vtkActor >::New( );
+
   this->m_Cursor->SetPoints( cursor_points );
   this->m_Cursor->SetLines( cursor_lines );
   this->m_CursorMapper->SetInputData( this->m_Cursor );
   this->m_CursorActor->SetMapper( this->m_CursorMapper );
+  this->m_CursorActor->GetProperty( )->SetColor( 1, 1, 0 );
+  this->m_CursorActor->GetProperty( )->SetLineWidth( 2 );
+
+  // Plane intersections
+  this->m_Axis1       = vtkSmartPointer< vtkPolyData >::New( );
+  this->m_Axis1Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->m_Axis1Actor  = vtkSmartPointer< vtkActor >::New( );
 
   vtkSmartPointer< vtkPoints > h_points =
     vtkSmartPointer< vtkPoints >::New( );
@@ -220,10 +174,14 @@ Clear( )
   h_lines->InsertNextCell( 2 );
   h_lines->InsertCellPoint( 0 );
   h_lines->InsertCellPoint( 1 );
-  this->m_HorizontalLine->SetPoints( h_points );
-  this->m_HorizontalLine->SetLines( h_lines );
-  this->m_HorizontalLineMapper->SetInputData( this->m_HorizontalLine );
-  this->m_HorizontalLineActor->SetMapper( this->m_HorizontalLineMapper );
+  this->m_Axis1->SetPoints( h_points );
+  this->m_Axis1->SetLines( h_lines );
+  this->m_Axis1Mapper->SetInputData( this->m_Axis1 );
+  this->m_Axis1Actor->SetMapper( this->m_Axis1Mapper );
+
+  this->m_Axis2       = vtkSmartPointer< vtkPolyData >::New( );
+  this->m_Axis2Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->m_Axis2Actor  = vtkSmartPointer< vtkActor >::New( );
 
   vtkSmartPointer< vtkPoints > v_points =
     vtkSmartPointer< vtkPoints >::New( );
@@ -234,16 +192,20 @@ Clear( )
   v_lines->InsertNextCell( 2 );
   v_lines->InsertCellPoint( 0 );
   v_lines->InsertCellPoint( 1 );
-  this->m_VerticalLine->SetPoints( v_points );
-  this->m_VerticalLine->SetLines( v_lines );
-  this->m_VerticalLineMapper->SetInputData( this->m_VerticalLine );
-  this->m_VerticalLineActor->SetMapper( this->m_VerticalLineMapper );
+  this->m_Axis2->SetPoints( v_points );
+  this->m_Axis2->SetLines( v_lines );
+  this->m_Axis2Mapper->SetInputData( this->m_Axis2 );
+  this->m_Axis2Actor->SetMapper( this->m_Axis2Mapper );
+
+  // Plane
+  this->m_Plane       = vtkSmartPointer< vtkPolyData >::New( );
+  this->m_PlaneMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+  this->m_PlaneActor  = vtkSmartPointer< vtkActor >::New( );
 
   vtkSmartPointer< vtkPoints > plane_points =
     vtkSmartPointer< vtkPoints >::New( );
   vtkSmartPointer< vtkCellArray > plane_lines =
     vtkSmartPointer< vtkCellArray >::New( );
-
   plane_points->InsertNextPoint( 0, 0, 0 );
   plane_points->InsertNextPoint( 0, 1, 0 );
   plane_points->InsertNextPoint( 1, 1, 0 );
@@ -260,9 +222,12 @@ Clear( )
   this->m_PlaneMapper->SetInputData( this->m_Plane );
   this->m_PlaneActor->SetMapper( this->m_PlaneMapper );
 
+  // Text actor
+  this->m_TextActor = vtkSmartPointer< vtkTextActor >::New( );
+  this->m_TextBuffer[ 0 ] = '\0';
   this->m_TextActor->SetTextScaleModeToNone( );
   vtkTextProperty* textprop = this->m_TextActor->GetTextProperty( );
-  textprop->SetColor( 1, 1, 1 );
+  textprop->SetColor( 1, 1, 0 );
   textprop->SetFontFamilyToCourier( );
   textprop->SetFontSize( 18 );
   textprop->BoldOff( );
@@ -273,13 +238,6 @@ Clear( )
   vtkCoordinate* coord = this->m_TextActor->GetPositionCoordinate( );
   coord->SetCoordinateSystemToNormalizedViewport( );
   coord->SetValue( 0.01, 0.01 );
-
-  // Update actor collection
-  this->AddItem( this->m_CursorActor );
-  this->AddItem( this->m_HorizontalLineActor );
-  this->AddItem( this->m_VerticalLineActor );
-  this->AddItem( this->m_TextActor );
-  this->AddItem( this->m_PlaneActor );
 }
 
 // -------------------------------------------------------------------------
@@ -306,26 +264,20 @@ GetStyle( ) const
 
 // -------------------------------------------------------------------------
 vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id )
+GetInputImage( )
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return(
-      dynamic_cast< vtkImageData* >( this->m_ImageBlender->GetInput( id ) )
-      );
+  if( this->m_ImageMapper.GetPointer( ) != NULL )
+    return( this->m_ImageMapper->GetInput( ) );
   else
     return( NULL );
 }
 
 // -------------------------------------------------------------------------
 const vtkImageData* cpExtensions::Visualization::ImageSliceActors::
-GetInputImage( unsigned int id ) const
+GetInputImage( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return(
-      dynamic_cast< const vtkImageData* >(
-        this->m_ImageBlender->GetInput( )
-        )
-      );
+  if( this->m_ImageMapper.GetPointer( ) != NULL )
+    return( this->m_ImageMapper->GetInput( ) );
   else
     return( NULL );
 }
@@ -347,15 +299,15 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
     rwi->SetInteractorStyle( this->m_Style );
 
   // Update actors
-  vtkProp* prop;
-  this->InitTraversal( );
-  while( prop = this->GetNextProp( ) )
-    renderer->AddViewProp( prop );
-  renderer->Modified( );
-  if( !force_style )
+  renderer->AddViewProp( this->m_ImageActor );
+  renderer->AddViewProp( this->m_BlenderActor );
+  if( force_style )
   {
-    renderer->RemoveViewProp( this->m_CursorActor );
-    renderer->RemoveViewProp( this->m_TextActor );
+    renderer->AddViewProp( this->m_CursorActor );
+    renderer->AddViewProp( this->m_PlaneActor );
+    renderer->AddViewProp( this->m_TextActor );
+    renderer->AddViewProp( this->m_Axis1Actor );
+    renderer->AddViewProp( this->m_Axis2Actor );
 
   } // fi
 
@@ -395,19 +347,26 @@ PopActorsFrom( vtkRenderWindow* window )
 {
   vtkRenderWindowInteractor* rwi = window->GetInteractor( );
   vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
-
   if( renderer != NULL )
   {
-    // Update actors
-    vtkProp* prop;
-    this->InitTraversal( );
-    while( prop = this->GetNextProp( ) )
-      renderer->RemoveViewProp( prop );
-    renderer->Modified( );
+    renderer->RemoveViewProp( this->m_ImageActor );
+    renderer->RemoveViewProp( this->m_BlenderActor );
+    renderer->RemoveViewProp( this->m_CursorActor );
+    renderer->RemoveViewProp( this->m_PlaneActor );
+    renderer->RemoveViewProp( this->m_TextActor );
+    renderer->RemoveViewProp( this->m_Axis1Actor );
+    renderer->RemoveViewProp( this->m_Axis2Actor );
+    if( rwi != NULL )
+      rwi->Render( );
 
   } // fi
-  if( rwi != NULL )
-    rwi->Render( );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageSliceActors::
+GetNumberOfImages( ) const
+{
+  return( this->m_Blender->GetNumberOfInputPorts( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -424,6 +383,20 @@ GetImageActor( ) const
   return( this->m_ImageActor );
 }
 
+// -------------------------------------------------------------------------
+vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetBinaryActor( )
+{
+  return( this->m_BlenderActor );
+}
+
+// -------------------------------------------------------------------------
+const vtkImageActor* cpExtensions::Visualization::ImageSliceActors::
+GetBinaryActor( ) const
+{
+  return( this->m_BlenderActor );
+}
+
 // -------------------------------------------------------------------------
 vtkTextActor* cpExtensions::Visualization::ImageSliceActors::
 GetTextActor( )
@@ -479,6 +452,7 @@ SetInterpolate( bool v )
   if( this->m_Interpolate != v )
   {
     this->m_ImageActor->SetInterpolate( v );
+    this->m_BlenderActor->SetInterpolate( v );
     this->m_Interpolate = v;
     this->Modified( );
 
@@ -515,7 +489,7 @@ GetDisplayBounds( double bounds[ 6 ] ) const
 {
   if( this->m_ImageActor.GetPointer( ) == NULL )
   {
-    bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 );
+    bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double(  0 );
     bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 );
   }
   else
@@ -528,8 +502,6 @@ ResetCursor( )
 {
   if( this->m_ImageMapper.GetPointer( ) != NULL )
   {
-    double bounds[ 6 ];
-    this->m_ImageMapper->GetInput( )->GetBounds( bounds );
     double pos[] =
       {
         this->m_VisibleBounds[ 0 ],
@@ -545,10 +517,6 @@ ResetCursor( )
     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( );
@@ -573,79 +541,137 @@ SetCursor( double pos[ 3 ] )
 
   // Update cross
   double* bounds = this->m_VisibleBounds;
-  double
-    p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ],
-    p4[ 3 ], p5[ 3 ], p6[ 3 ], p7[ 3 ];
+  double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ];
 
-  p0[ a2 ] = p1[ a2 ] = p4[ a2 ] = p5[ a2 ] = pos[ a2 ];
-  p2[ a1 ] = p3[ a1 ] = p6[ a1 ] = p7[ a1 ] = pos[ a1 ];
+  p0[ a2 ] = p1[ a2 ] = pos[ a2 ];
+  p2[ a1 ] = p3[ a1 ] = pos[ a1 ];
   p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ];
-  p4[ a0 ] = p5[ a0 ] = p6[ a0 ] = p7[ a0 ] = bounds[ ma0 + 1 ];
-  p0[ a1 ] = p4[ a1 ] = bounds[ ma1 ];
-  p1[ a1 ] = p5[ a1 ] = bounds[ ma1 + 1 ];
-  p2[ a2 ] = p6[ a2 ] = bounds[ ma2 ];
-  p3[ a2 ] = p7[ a2 ] = bounds[ ma2 + 1 ];
+  p0[ a1 ] = bounds[ ma1 ];
+  p1[ a1 ] = bounds[ ma1 + 1 ];
+  p2[ a2 ] = bounds[ ma2 ];
+  p3[ a2 ] = bounds[ ma2 + 1 ];
 
   vtkPoints* points = this->m_Cursor->GetPoints( );
   points->SetPoint( 0, p0 );
   points->SetPoint( 1, p1 );
   points->SetPoint( 2, p2 );
   points->SetPoint( 3, p3 );
-  points->SetPoint( 4, p4 );
-  points->SetPoint( 5, p5 );
-  points->SetPoint( 6, p6 );
-  points->SetPoint( 7, p7 );
   this->m_Cursor->Modified( );
   this->m_CursorMapper->Modified( );
   this->m_CursorActor->Modified( );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+ResetAxesCursor( )
+{
+  if( this->m_ImageMapper.GetPointer( ) != NULL )
+  {
+    double pos[] =
+      {
+        this->m_VisibleBounds[ 0 ],
+        this->m_VisibleBounds[ 2 ],
+        this->m_VisibleBounds[ 4 ]
+      };
+    this->SetAxesCursor( pos );
+  }
+  else
+  {
+    vtkPoints* points = this->m_Axis1->GetPoints( );
+    points->SetPoint( 0, 0, 0, 0 );
+    points->SetPoint( 1, 0, 0, 0 );
+    this->m_Axis1->Modified( );
+    this->m_Axis1Mapper->Modified( );
+    this->m_Axis1Actor->Modified( );
+
+    points = this->m_Axis2->GetPoints( );
+    points->SetPoint( 0, 0, 0, 0 );
+    points->SetPoint( 1, 0, 0, 0 );
+    this->m_Axis2->Modified( );
+    this->m_Axis2Mapper->Modified( );
+    this->m_Axis2Actor->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetAxesCursor( double pos[ 3 ] )
+{
+  if( this->m_ImageMapper.GetPointer( ) == NULL )
+    return;
+
+  // Get ordered axes
+  int a0 = this->GetAxis( );
+  int a1 = ( a0 + 1 ) % 3;
+  int a2 = ( a0 + 2 ) % 3;
+  int ma0 = a0 << 1;
+  int ma1 = a1 << 1;
+  int ma2 = a2 << 1;
+
+  // Update cross
+  double* bounds = this->m_VisibleBounds;
+  double p0[ 3 ], p1[ 3 ], p2[ 3 ], p3[ 3 ];
+
+  p0[ a2 ] = p1[ a2 ] = pos[ a2 ];
+  p2[ a1 ] = p3[ a1 ] = pos[ a1 ];
+  p0[ a0 ] = p1[ a0 ] = p2[ a0 ] = p3[ a0 ] = bounds[ ma0 ];
+  p0[ a1 ] = bounds[ ma1 ];
+  p1[ a1 ] = bounds[ ma1 + 1 ];
+  p2[ a2 ] = bounds[ ma2 ];
+  p3[ a2 ] = bounds[ ma2 + 1 ];
+
+  vtkPoints* points1 = this->m_Axis1->GetPoints( );
+  points1->SetPoint( 0, p2 );
+  points1->SetPoint( 1, p3 );
+
+  vtkPoints* points2 = this->m_Axis2->GetPoints( );
+  points2->SetPoint( 0, p0 );
+  points2->SetPoint( 1, p1 );
+
+  this->m_Axis1->Modified( );
+  this->m_Axis1Mapper->Modified( );
+  this->m_Axis1Actor->Modified( );
+
+  this->m_Axis2->Modified( );
+  this->m_Axis2Mapper->Modified( );
+  this->m_Axis2Actor->Modified( );
+}
+
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::ImageSliceActors::
 GetMinWindow( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetMinWindow( ) );
-  else
-    return( double( 0 ) );
+  return( this->m_WLRange[ 0 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::ImageSliceActors::
 GetMaxWindow( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetMaxWindow( ) );
-  else
-    return( double( 0 ) );
+  return( this->m_WLRange[ 1 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::ImageSliceActors::
 GetMinLevel( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetMinLevel( ) );
-  else
-    return( double( 0 ) );
+  return( this->m_WLRange[ 2 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::ImageSliceActors::
 GetMaxLevel( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetMaxLevel( ) );
-  else
-    return( double( 0 ) );
+  return( this->m_WLRange[ 3 ] );
 }
 
 // -------------------------------------------------------------------------
 double cpExtensions::Visualization::ImageSliceActors::
 GetWindow( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetWindow( ) );
+  if( this->m_ImageActor.GetPointer( ) != NULL )
+    return( this->m_ImageActor->GetProperty( )->GetColorWindow( ) );
   else
     return( double( 0 ) );
 }
@@ -654,8 +680,8 @@ GetWindow( ) const
 double cpExtensions::Visualization::ImageSliceActors::
 GetLevel( ) const
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-    return( this->m_ImageBlender->GetLevel( ) );
+  if( this->m_ImageActor.GetPointer( ) != NULL )
+    return( this->m_ImageActor->GetProperty( )->GetColorLevel( ) );
   else
     return( double( 0 ) );
 }
@@ -664,45 +690,47 @@ GetLevel( ) const
 void cpExtensions::Visualization::ImageSliceActors::
 SetWindow( double w )
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-  {
-    this->m_ImageBlender->SetWindow( w );
-    this->Modified( );
-
-  } // fi
+  if( this->m_ImageActor.GetPointer( ) == NULL )
+    return;
+  double v = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w;
+  v        = ( v > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: v;
+  this->m_ImageActor->GetProperty( )->SetColorWindow( v );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetLevel( double l )
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-  {
-    this->m_ImageBlender->SetLevel( l );
-    this->Modified( );
-
-  } // fi
+  if( this->m_ImageActor.GetPointer( ) == NULL )
+    return;
+  double v = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l;
+  v        = ( v > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: v;
+  this->m_ImageActor->GetProperty( )->SetColorLevel( v );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetWindowLevel( double w, double l )
 {
-  if( this->m_ImageBlender.GetPointer( ) != NULL )
-  {
-    this->m_ImageBlender->SetWindowLevel( w, l );
-    this->UpdateText( w, l );
-    this->Modified( );
-
-  } // fi
+  if( this->m_ImageActor.GetPointer( ) == NULL )
+    return;
+  double a = ( w < this->m_WLRange[ 0 ] )? this->m_WLRange[ 0 ]: w;
+  a        = ( a > this->m_WLRange[ 1 ] )? this->m_WLRange[ 1 ]: a;
+  double b = ( l < this->m_WLRange[ 2 ] )? this->m_WLRange[ 2 ]: l;
+  b        = ( b > this->m_WLRange[ 3 ] )? this->m_WLRange[ 3 ]: b;
+  this->m_ImageActor->GetProperty( )->SetColorWindow( a );
+  this->m_ImageActor->GetProperty( )->SetColorLevel( b );
+  this->UpdateText( a, b );
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 ResetWindowLevel( )
 {
-  std::cerr << "ACA Resetear" << std::endl;
-  std::exit( 1 );
+  this->SetWindowLevel(
+    this->m_WLRange[ 1 ] * double( 0.5 ),
+    ( this->m_WLRange[ 3 ] + this->m_WLRange[ 2 ] ) * double( 0.5 )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -757,9 +785,11 @@ SetSliceNumber( const int& slice )
 
   // Update mappers and display bounds
   this->m_ImageMapper->SetSliceNumber( slice );
+  this->m_BlenderMapper->SetSliceNumber( slice );
   this->m_ImageMapper->Modified( );
+  this->m_BlenderMapper->Modified( );
   this->m_ImageActor->Modified( );
-  this->m_ImageMapper->Update( );
+  this->m_BlenderActor->Modified( );
 
   // Update display extent (this isn't done automatically)
   this->m_ImageMapper->GetInput( )->GetExtent( this->m_VisibleExtent );
@@ -806,22 +836,34 @@ SetSliceNumber( const int& slice )
   {
     plane_points->SetPoint( 1, bnds[ 1 ], bnds[ 2 ], bnds[ 5 ] );
     plane_points->SetPoint( 3, bnds[ 0 ], bnds[ 3 ], bnds[ 4 ] );
-    if( axis == 0 )
-      this->m_PlaneActor->GetProperty( )->SetColor( 1, 0, 0 );
-    else
-      this->m_PlaneActor->GetProperty( )->SetColor( 0, 0, 1 );
   }
   else if( axis == 1 ) // ZX, y-normal
   {
     plane_points->SetPoint( 1, bnds[ 0 ], bnds[ 2 ], bnds[ 5 ] );
     plane_points->SetPoint( 3, bnds[ 1 ], bnds[ 3 ], bnds[ 4 ] );
-    this->m_PlaneActor->GetProperty( )->SetColor( 0, 1, 0 );
 
   } // fi
+
+  // Set plane colors
+  this->m_PlaneActor->GetProperty( )->
+    SetColor( this->m_PlaneColors[ axis ] );
+  this->m_Axis1Actor->GetProperty( )->
+    SetColor( this->m_PlaneColors[ ( axis + 1 ) % 3 ] );
+  this->m_Axis2Actor->GetProperty( )->
+    SetColor( this->m_PlaneColors[ ( axis + 2 ) % 3 ] );
+
   this->m_Plane->Modified( );
   this->m_PlaneMapper->Modified( );
   this->m_PlaneActor->Modified( );
 
+  this->m_Axis1->Modified( );
+  this->m_Axis1Mapper->Modified( );
+  this->m_Axis1Actor->Modified( );
+
+  this->m_Axis2->Modified( );
+  this->m_Axis2Mapper->Modified( );
+  this->m_Axis2Actor->Modified( );
+
   // Update text
   this->UpdateText( );
 
@@ -864,7 +906,7 @@ SetSliceNumber( const int& slice )
 void cpExtensions::Visualization::ImageSliceActors::
 SetSlice( double* pos )
 {
-  vtkImageData* image = this->GetInputImage( );
+  vtkImageData* image = this->GetInputImage( );
   if( image == NULL )
     return;
 
@@ -911,7 +953,7 @@ UpdateText( double pos[ 3 ] )
     else if( axId == 2 ) axis = 'Z';
     int slice = this->GetSliceNumber( );
 
-    vtkImageData* image = this->GetInputImage( );
+    vtkImageData* image = this->GetInputImage( );
     int ijk[ 3 ];
     double pcoords[ 3 ];
     image->ComputeStructuredCoordinates( pos, ijk, pcoords );
@@ -1036,6 +1078,72 @@ _ConfigureStyle( )
   this->m_Style->AddLeaveCommand( Self::_LeaveCommand, this );
 }
 
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_ConfigureInputImage( )
+{
+  this->m_ImageMapper->SetOrientation( 0 );
+  this->m_ImageMapper->Update( );
+
+  // Create actor
+  this->m_ImageActor->SetInterpolate( this->m_Interpolate );
+  this->m_ImageActor->Modified( );
+
+  if( this->m_Style.GetPointer( ) != NULL )
+    this->m_Style->AssociateImageActor( this->m_ImageActor );
+  this->AddItem( this->m_ImageActor );
+
+  this->SetSliceNumber( this->GetSliceNumberMinValue( ) );
+  this->ResetCursor( );
+  this->Modified( );
+
+  // Reset cursors
+  this->ResetCursor( );
+  this->ResetAxesCursor( );
+
+  // Update window/level ranges
+  vtkImageData* data = this->GetInputImage( );
+  if( data != NULL )
+  {
+    double r[ 2 ];
+    data->GetScalarRange( r );
+    this->m_WLRange[ 0 ] = double( 0 );
+    this->m_WLRange[ 1 ] = r[ 1 ] - r[ 0 ];
+    this->m_WLRange[ 2 ] = r[ 0 ];
+    this->m_WLRange[ 3 ] = r[ 1 ];
+    this->ResetWindowLevel( );
+
+    // Configure blender
+    this->m_BlenderBase = vtkSmartPointer< vtkImageData >::New( );
+    this->m_BlenderBase->ShallowCopy( data );
+    this->m_BlenderBase->AllocateScalars( VTK_UNSIGNED_CHAR, 1 );
+    std::memset(
+      this->m_BlenderBase->GetScalarPointer( ), 0,
+      this->m_BlenderBase->GetActualMemorySize( )
+      );
+    this->m_Blender->AddInputData( this->m_BlenderBase );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_ConfigureBinaryImage( const double& r, const double& g, const double& b )
+{
+  unsigned int nValues = this->m_BlenderLUT->GetNumberOfTableValues( );
+  this->m_BlenderLUT->SetNumberOfTableValues( nValues + 1 );
+  this->m_BlenderLUT->SetTableRange( 0, nValues );
+  this->m_BlenderLUT->SetTableValue( nValues, r, g, b, 0.5 );
+  this->m_BlenderLUT->Build( );
+
+  this->m_BlenderLUT->Modified( );
+  this->m_Blender->Modified( );
+  this->m_Blender->Update( );
+
+  this->m_BlenderMapper->Modified( );
+  this->m_BlenderActor->Modified( );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 _MouseMoveCommand(
@@ -1058,6 +1166,9 @@ _MouseMoveCommand(
   {
     if( !alt && ctr && !sft )
     {
+      // Show axes in current renderer
+      actors->SetAxesCursor( pos );
+
       // Interactively move slices
       auto i = actors->m_SlicesCommands.begin( );
       for( ; i != actors->m_SlicesCommands.end( ); ++i )
@@ -1093,7 +1204,7 @@ _MouseMoveCommand(
       auto i = actors->m_WindowLevelCommands.begin( );
       for( ; i != actors->m_WindowLevelCommands.end( ); ++i )
         i->first( dx, dy, i->second );
-      
+
     } // fi
 
   } // fi
@@ -1145,7 +1256,7 @@ _MouseWheelCommand(
 
     } // rof
     actors->Render( 1e-3 );
-    
+
     // Associate objects
     auto i = actors->m_RenderCommands.begin( );
     for( ; i != actors->m_RenderCommands.end( ); ++i )