]> Creatis software - cpPlugins.git/commitdiff
OpenGL binary images visualization finished.
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Nov 2015 22:52:07 +0000 (17:52 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Fri, 13 Nov 2015 22:52:07 +0000 (17:52 -0500)
appli/examples/example_ViewImageThreshold.cxx
lib/cpExtensions/Visualization/ImageBlender.cxx
lib/cpExtensions/Visualization/ImageBlender.h
lib/cpExtensions/Visualization/ImageSliceActors.cxx
lib/cpExtensions/Visualization/ImageSliceActors.h
lib/cpExtensions/Visualization/MPRActors.cxx

index 9c7ffea408aeb41ae549083d122ce3194eb58bb9..3d3bc077bfac580a2d86ed21f21a2d9da3d36340 100644 (file)
@@ -1,5 +1,6 @@
 #include <cstdlib>
 #include <iostream>
+#include <sstream>
 #include <string>
 #include <vector>
 
@@ -20,18 +21,25 @@ typedef cpExtensions::Visualization::ImageSliceActors TSliceActors;
 // -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
-  if( argc < 5 )
+  if( argc < 9 )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " plugins_file input_image lower upper"
+      << " plugins_file input_image"
+      << " lower1 upper1 lower2 upper2 lower3 upper3"
       << std::endl;
     return( 1 );
 
   } // fi
   std::string plugins_file = argv[ 1 ];
-  double lower = std::atof( argv[ argc - 2 ] );
-  double upper = std::atof( argv[ argc - 1 ] );
+  std::string input_image_file = argv[ 2 ];
+  double lower[ 3 ], upper[ 3 ];
+  lower[ 0 ] = std::atof( argv[ 3 ] );
+  upper[ 0 ] = std::atof( argv[ 4 ] );
+  lower[ 1 ] = std::atof( argv[ 5 ] );
+  upper[ 1 ] = std::atof( argv[ 6 ] );
+  lower[ 2 ] = std::atof( argv[ 7 ] );
+  upper[ 2 ] = std::atof( argv[ 8 ] );
 
   // Load plugins
   cpPlugins::Interface::Plugins plugins;
@@ -42,16 +50,11 @@ int main( int argc, char* argv[] )
 
   } // fi
 
-  // Associate filenames
-  std::vector< std::string > fnames;
-  for( int i = 2; i < argc - 2; ++i )
-    fnames.push_back( argv[ i ] );
-  
   // Read image
   std::string image_name = "";
   try
   {
-    image_name = plugins.ReadImage( fnames, "" );
+    image_name = plugins.ReadImage( input_image_file, "" );
   }
   catch( std::exception& err )
   {
@@ -60,57 +63,76 @@ int main( int argc, char* argv[] )
 
   } // yrt
 
-  // Apply a two-level threshold
+  // Apply three a two-level threshold
+  std::vector< std::string > thresholds_names;
   std::string filter_name =
     "cpPlugins::BasicFilters::BinaryThresholdImageFilter";
-
-  if( !( plugins.ActivateFilter( filter_name ) ) )
+  for( int i = 0; i < 3; ++i )
   {
-    std::cerr << "No filter found" << std::endl;
-    return( 1 );
+    if( !( plugins.ActivateFilter( filter_name ) ) )
+    {
+      std::cerr << "No filter found" << std::endl;
+      return( 1 );
 
-  } // fi
+    } // fi
 
-  // Connect inputs
-  TPlugins::TStringContainer input_names;
-  plugins.GetActiveFilterInputsNames( input_names );
-  for( auto iIt = input_names.begin( ); iIt != input_names.end( ); ++iIt )
-    plugins.ConnectInputInActiveFilter( image_name, *iIt );
-
-  // Configure
-  TPlugins::TParameters* filter_params = plugins.GetActiveFilterParameters( );
-  filter_params->SetReal( "LowerThresholdValue", lower );
-  filter_params->SetReal( "UpperThresholdValue", upper );
-  filter_params->SetUint( "InsideValue", 1 );
-  filter_params->SetUint( "OutsideValue", 0 );
-
-  // Execute
-  TPlugins::TStringContainer output_names;
-  try
-  {
-    if( !( plugins.UpdateActiveFilter( output_names, image_name ) ) )
+    // Connect inputs
+    TPlugins::TStringContainer input_names;
+    plugins.GetActiveFilterInputsNames( input_names );
+    for( auto iIt = input_names.begin( ); iIt != input_names.end( ); ++iIt )
+      plugins.ConnectInputInActiveFilter( image_name, *iIt );
+
+    // Configure
+    TPlugins::TParameters* filter_params = plugins.GetActiveFilterParameters( );
+    filter_params->SetReal( "LowerThresholdValue", lower[ i ] );
+    filter_params->SetReal( "UpperThresholdValue", upper[ i ] );
+    filter_params->SetUint( "InsideValue", i + 10 );
+    filter_params->SetUint( "OutsideValue", 0 );
+
+    // Configure outputs
+    TPlugins::TStringContainer output_names;
+    plugins.GetActiveFilterOutputsNames( output_names );
+
+    std::stringstream obj_name_str;
+    obj_name_str << "output_" << i;
+    plugins.SetOutputNameInActiveFilter(
+      obj_name_str.str( ),
+      *( output_names.begin( ) )
+      );
+
+    // Execute
+    output_names.clear( );
+    try
     {
-      std::cerr << "Error executing filter." << std::endl;
+      if( !( plugins.UpdateActiveFilter( output_names, image_name ) ) )
+      {
+        std::cerr << "Error executing filter." << std::endl;
+        return( 1 );
+
+      } // fi
+    }
+    catch( std::exception& err )
+    {
+      std::cerr << err.what( ) << std::endl;
       return( 1 );
 
-    } // fi
-  }
-  catch( std::exception& err )
-  {
-    std::cerr << err.what( ) << std::endl;
-    return( 1 );
+    } // yrt
+    thresholds_names.push_back( *( output_names.begin( ) ) );
 
-  } // yrt
-  std::string threshold_name = *( output_names.begin( ) );
+    plugins.DeactivateFilter( );
+
+  } // rof
   
   // Get both images
   TImage* image = plugins.GetData< TImage >( image_name );
-  TImage* threshold = plugins.GetData< TImage >( threshold_name );
+  TImage* thr0 = plugins.GetData< TImage >( thresholds_names[ 0 ] );
+  TImage* thr1 = plugins.GetData< TImage >( thresholds_names[ 1 ] );
+  TImage* thr2 = plugins.GetData< TImage >( thresholds_names[ 2 ] );
 
   // Configure visualization objects
   vtkSmartPointer< vtkRenderer > renderer =
     vtkSmartPointer< vtkRenderer >::New( );
-  renderer->SetBackground( 0.1, 0.3, 0.5 );
+  renderer->SetBackground( 0.3, 0.3, 0.3 );
 
   vtkSmartPointer< vtkRenderWindow > window =
     vtkSmartPointer< vtkRenderWindow >::New( );
@@ -126,7 +148,9 @@ int main( int argc, char* argv[] )
   vtkSmartPointer< TSliceActors > image_actors =
     vtkSmartPointer< TSliceActors >::New( );
   image_actors->SetInputImage( image->GetVTK< vtkImageData >( ) );
-  image_actors->AddBinaryImage( threshold->GetVTK< vtkImageData >( ), 1, 0, 1 );
+  image_actors->AddBinaryImage( thr0->GetVTK< vtkImageData >( ), 1, 0, 0 );
+  image_actors->AddBinaryImage( thr1->GetVTK< vtkImageData >( ), 0, 1, 0 );
+  image_actors->AddBinaryImage( thr2->GetVTK< vtkImageData >( ), 0, 0, 1 );
   image_actors->SetAxis( 2 );
   image_actors->PushActorsInto( window );
 
index ee4f61642ab9e7c12a330cdfefde657b81528de3..ee808e5aa51a87f84c6b03a52f770452f8989a00 100644 (file)
@@ -49,13 +49,52 @@ RequestInformation(
   return( 1 );
 }
 
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::ImageBlender::
+RequestData(
+  vtkInformation* request,
+  vtkInformationVector** inputVector,
+  vtkInformationVector* outputVector
+  )
+{
+  this->m_Ranges.clear( );
+  for( int i = 0; i < this->GetNumberOfInputPorts( ); ++i )
+  {
+    vtkInformationVector* portInfo = inputVector[ i ];
+    for( int j = 0; j < portInfo->GetNumberOfInformationObjects( ); ++j )
+    {
+      vtkInformation* info = portInfo->GetInformationObject( j );
+      vtkImageData* image = vtkImageData::SafeDownCast(
+        info->Get( vtkDataObject::DATA_OBJECT( ) )
+        );
+      if( image != NULL )
+      {
+        double r[ 2 ];
+        image->GetScalarRange( r );
+        this->m_Ranges.push_back( r[ 0 ] );
+        this->m_Ranges.push_back( r[ 1 ] );
+      }
+      else
+      {
+        this->m_Ranges.push_back( double( 0 ) );
+        this->m_Ranges.push_back( double( 0 ) );
+
+      } // fi
+
+    } // rof
+
+  } // rof
+  this->Superclass::RequestData( request, inputVector, outputVector );
+}
+
 // -------------------------------------------------------------------------
 // Description:
 // This templated function executes the filter for any type of data.
 template< class T >
 void cpExtensions_Visualization_ImageBlender_Execute(
   cpExtensions::Visualization::ImageBlender* self,
-  vtkImageData** inDatas, int numInputs, vtkImageData* outData,
+  vtkImageData** inDatas, int numInputs,
+  const std::vector< double >& ranges, vtkImageData* outData,
   int outExt[ 6 ], int id, T* really_not_used
   )
 {
@@ -92,11 +131,17 @@ void cpExtensions_Visualization_ImageBlender_Execute(
     // Pixel operation
     while( outSI != outSIEnd )
     {
-#error TENER EN CUENTA EL ORDEN DE LAS IMAGENES PARA PONER COLORES
-
-      double vmax = double( *inSI[ 0 ] );
+      // Input 0 is ignored: it is just used to guarantee sizes all over
+      // the result
+      double vmax = double( 0 );
       for( int k = 1; k < numInputs; ++k )
-        vmax = ( vmax < double( *inSI[ k ] ) )? double( *inSI[ k ] ): vmax;
+      {
+        double v =
+          ( ( double( k ) * double( *inSI[ k ] ) ) - ranges[ k << 1 ] ) /
+          ( ranges[ ( k << 1 ) + 1 ] - ranges[ k << 1 ] );
+        vmax = ( vmax < v )? v: vmax;
+
+      } // rof
       *outSI = static_cast< T >( vmax );
       outSI++;
       for( int l = 0; l < numInputs; ++l )
@@ -160,7 +205,7 @@ ThreadedRequestData(
   {
     vtkTemplateMacro(
       cpExtensions_Visualization_ImageBlender_Execute(
-        this, inData[ 0 ], numInputs,
+        this, inData[ 0 ], numInputs, this->m_Ranges,
         outData[ 0 ], outExt, id, static_cast< VTK_TT* >( 0 )
         )
       );
index c49c62e8a142e424ff81d11614261f38eb94af9d..deca4aff087025e458f62854865826744f554e23 100644 (file)
@@ -33,6 +33,11 @@ namespace cpExtensions
         vtkInformationVector** inputVector,
         vtkInformationVector* outputVector
         );
+      int RequestData(
+        vtkInformation* request,
+        vtkInformationVector** inputVector,
+        vtkInformationVector* outputVector
+        );
       void ThreadedRequestData(
         vtkInformation* request,
         vtkInformationVector** inputVector,
@@ -46,6 +51,9 @@ namespace cpExtensions
       // Purposely not implemented.
       ImageBlender( const Self& other );
       void operator=( const Self& other );
+
+    protected:
+      std::vector< double > m_Ranges;
     };
 
   } // ecapseman
index c1f85232105c4dc0bb9c64901adfaa86e75f9d48..b444328be321e2946c54807f4a59345da8f312fd 100644 (file)
 #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::
@@ -72,6 +81,11 @@ AddBinaryConnection(
   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 );
 }
 
 // -------------------------------------------------------------------------
@@ -83,20 +97,9 @@ AddBinaryImage(
 {
   if( data == NULL )
     return( -1 );
-
   this->m_Blender->AddInputData( data );
-
-  unsigned int nValues = this->m_BlenderLUT->GetNumberOfTableValues( );
-  this->m_BlenderLUT->SetNumberOfTableValues( nValues + 1 );
-  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( );
+  this->_ConfigureBinaryImage( r, g, b );
+  return( this->m_Blender->GetNumberOfInputPorts( ) - 1 );
 }
 
 // -------------------------------------------------------------------------
@@ -119,6 +122,7 @@ Clear( )
     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( );
 
@@ -130,7 +134,6 @@ Clear( )
   this->m_AssociatedSlices.clear( );
 
   // White cursor
-  /*
   vtkSmartPointer< vtkPoints > cursor_points =
     vtkSmartPointer< vtkPoints >::New( );
   vtkSmartPointer< vtkCellArray > cursor_lines =
@@ -139,22 +142,12 @@ 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( );
@@ -164,96 +157,13 @@ Clear( )
   this->m_Cursor->SetLines( cursor_lines );
   this->m_CursorMapper->SetInputData( this->m_Cursor );
   this->m_CursorActor->SetMapper( this->m_CursorMapper );
-  */
-
-  /*
-    vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
-    vtkSmartPointer< vtkActor >          m_CursorActor;
-
-    vtkSmartPointer< vtkPolyData >       m_HorizontalLine;
-    vtkSmartPointer< vtkPolyDataMapper > m_HorizontalLineMapper;
-    vtkSmartPointer< vtkActor >          m_HorizontalLineActor;
-
-    vtkSmartPointer< vtkPolyData >       m_VerticalLine;
-    vtkSmartPointer< vtkPolyDataMapper > m_VerticalLineMapper;
-    vtkSmartPointer< vtkActor >          m_VerticalLineActor;
-
-    vtkSmartPointer< vtkPolyData >       m_Plane;
-    vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
-    vtkSmartPointer< vtkActor >          m_PlaneActor;
+  this->m_CursorActor->GetProperty( )->SetColor( 1, 1, 0 );
+  this->m_CursorActor->GetProperty( )->SetLineWidth( 2 );
 
-    char                                 m_TextBuffer[ 1024 ];
-    vtkSmartPointer< vtkTextActor >      m_TextActor;
-  */
-
-
-
-
-
-  /*
-  // 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 );
-
-  // Delete all images
-  this->m_ImageActor  = NULL;
-  this->m_ImageMapper = 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';
-
-  // Unique objects configuration
-  vtkSmartPointer< vtkPoints > cursor_points =
-    vtkSmartPointer< vtkPoints >::New( );
-  vtkSmartPointer< vtkCellArray > cursor_lines =
-    vtkSmartPointer< vtkCellArray >::New( );
-  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_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->SetPoints( cursor_points );
-  this->m_Cursor->SetLines( cursor_lines );
-  this->m_CursorMapper->SetInputData( this->m_Cursor );
-  this->m_CursorActor->SetMapper( this->m_CursorMapper );
+  // 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( );
@@ -264,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( );
@@ -278,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 );
@@ -304,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( );
@@ -317,14 +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 );
-  */
 }
 
 // -------------------------------------------------------------------------
@@ -390,13 +303,11 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
   renderer->AddViewProp( this->m_BlenderActor );
   if( force_style )
   {
-    /* TODO
-       renderer->AddViewProp( this->m_CursorActor );
-       renderer->AddViewProp( this->m_HorizontalLineActor );
-       renderer->AddViewProp( this->m_VerticalLineActor );
-       renderer->AddViewProp( this->m_PlaneActor );
-       renderer->AddViewProp( 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
 
@@ -434,23 +345,28 @@ PushActorsInto( vtkRenderWindow* window, bool force_style )
 void cpExtensions::Visualization::ImageSliceActors::
 PopActorsFrom( vtkRenderWindow* window )
 {
-  /* TODO
-     vtkRenderWindowInteractor* rwi = window->GetInteractor( );
-     vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
+  vtkRenderWindowInteractor* rwi = window->GetInteractor( );
+  vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( );
+  if( renderer != NULL )
+  {
+    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( );
 
-     if( renderer != NULL )
-     {
-     // Update actors
-     vtkProp* prop;
-     this->InitTraversal( );
-     while( prop = this->GetNextProp( ) )
-     renderer->RemoveViewProp( prop );
-     renderer->Modified( );
-
-     } // fi
-     if( rwi != NULL )
-     rwi->Render( );
-  */
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageSliceActors::
+GetNumberOfImages( ) const
+{
+  return( this->m_Blender->GetNumberOfInputPorts( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -573,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
@@ -584,11 +500,8 @@ GetDisplayBounds( double bounds[ 6 ] ) const
 void cpExtensions::Visualization::ImageSliceActors::
 ResetCursor( )
 {
-  /* TODO
   if( this->m_ImageMapper.GetPointer( ) != NULL )
   {
-    double bounds[ 6 ];
-    this->m_ImageMapper->GetInput( )->GetBounds( bounds );
     double pos[] =
       {
         this->m_VisibleBounds[ 0 ],
@@ -604,23 +517,17 @@ 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( );
 
   } // fi
-  */
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 SetCursor( double pos[ 3 ] )
 {
-  /*
   if( this->m_ImageMapper.GetPointer( ) == NULL )
     return;
 
@@ -634,32 +541,101 @@ 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( );
 }
 
 // -------------------------------------------------------------------------
@@ -744,6 +720,7 @@ SetWindowLevel( double w, double 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 );
 }
 
 // -------------------------------------------------------------------------
@@ -850,7 +827,6 @@ SetSliceNumber( const int& slice )
   double* bnds = this->m_VisibleBounds;
 
   // Configure visualization and implicit plane orientation
-  /*
   this->m_PlaneActor->GetProperty( )->SetRepresentationToWireframe( );
   this->m_PlaneActor->GetProperty( )->SetLineWidth( 3 );
   vtkPoints* plane_points = this->m_Plane->GetPoints( );
@@ -860,25 +836,36 @@ 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( );
-  */
 
   // Update lines from associated slices
   /* TODO
@@ -933,7 +920,6 @@ SetSlice( double* pos )
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( )
 {
-  /* TODO
   if( this->m_ImageMapper.GetPointer( ) != NULL )
   {
     char axis;
@@ -952,14 +938,12 @@ UpdateText( )
   this->m_TextActor->SetInput( this->m_TextBuffer );
   this->m_TextActor->Modified( );
   this->Modified( );
-  */
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( double pos[ 3 ] )
 {
-  /* TODO
   if( this->m_ImageMapper.GetPointer( ) != NULL )
   {
     char axis;
@@ -1010,14 +994,12 @@ UpdateText( double pos[ 3 ] )
   this->m_TextActor->SetInput( this->m_TextBuffer );
   this->m_TextActor->Modified( );
   this->Modified( );
-*/
 }
 
 // -------------------------------------------------------------------------
 void cpExtensions::Visualization::ImageSliceActors::
 UpdateText( const double& w, const double& l )
 {
-  /* TODO
   if( this->m_ImageMapper.GetPointer( ) != NULL )
   {
     char axis;
@@ -1036,7 +1018,6 @@ UpdateText( const double& w, const double& l )
   this->m_TextActor->SetInput( this->m_TextBuffer );
   this->m_TextActor->Modified( );
   this->Modified( );
-*/
 }
 
 // -------------------------------------------------------------------------
@@ -1116,6 +1097,10 @@ _ConfigureInputImage( )
   this->ResetCursor( );
   this->Modified( );
 
+  // Reset cursors
+  this->ResetCursor( );
+  this->ResetAxesCursor( );
+
   // Update window/level ranges
   vtkImageData* data = this->GetInputImage( );
   if( data != NULL )
@@ -1141,6 +1126,24 @@ _ConfigureInputImage( )
   } // 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(
@@ -1163,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 )
@@ -1305,7 +1311,7 @@ _EnterCommand( void* data )
     return;
 
   actors->ResetCursor( );
-  // TODO: actors->m_CursorActor->VisibilityOn( );
+  actors->m_CursorActor->VisibilityOn( );
   actors->Render( 1e-3 );
 }
 
@@ -1318,7 +1324,7 @@ _LeaveCommand( void* data )
     return;
 
   actors->ResetCursor( );
-  // TODO: actors->m_CursorActor->VisibilityOff( );
+  actors->m_CursorActor->VisibilityOff( );
   actors->Render( 1e-3 );
 }
 
index 378c7a388c8796ff2d0db9267fcf95eb012dd69a..c8d739f9a8185925b322965e4a34962aa1bcd59a 100644 (file)
@@ -111,6 +111,9 @@ namespace cpExtensions
       void ResetCursor( );
       void SetCursor( double pos[ 3 ] );
 
+      void ResetAxesCursor( );
+      void SetAxesCursor( double pos[ 3 ] );
+
       double GetMinWindow( ) const;
       double GetMaxWindow( ) const;
       double GetMinLevel( ) const;
@@ -141,6 +144,9 @@ namespace cpExtensions
 
       void _ConfigureStyle( );
       void _ConfigureInputImage( );
+      void _ConfigureBinaryImage(
+        const double& r, const double& g, const double& b
+        );
 
       // Events
       static void _MouseMoveCommand(
@@ -172,6 +178,8 @@ namespace cpExtensions
       Self& operator=( const Self& );
 
     protected:
+      static double m_PlaneColors[ 3 ][ 3 ];
+
       vtkSmartPointer< TStyle > m_Style;
       vtkRenderWindow* m_Window;
 
@@ -200,13 +208,13 @@ namespace cpExtensions
       vtkSmartPointer< vtkPolyDataMapper > m_CursorMapper;
       vtkSmartPointer< vtkActor >          m_CursorActor;
 
-      vtkSmartPointer< vtkPolyData >       m_HorizontalLine;
-      vtkSmartPointer< vtkPolyDataMapper > m_HorizontalLineMapper;
-      vtkSmartPointer< vtkActor >          m_HorizontalLineActor;
+      vtkSmartPointer< vtkPolyData >       m_Axis1;
+      vtkSmartPointer< vtkPolyDataMapper > m_Axis1Mapper;
+      vtkSmartPointer< vtkActor >          m_Axis1Actor;
 
-      vtkSmartPointer< vtkPolyData >       m_VerticalLine;
-      vtkSmartPointer< vtkPolyDataMapper > m_VerticalLineMapper;
-      vtkSmartPointer< vtkActor >          m_VerticalLineActor;
+      vtkSmartPointer< vtkPolyData >       m_Axis2;
+      vtkSmartPointer< vtkPolyDataMapper > m_Axis2Mapper;
+      vtkSmartPointer< vtkActor >          m_Axis2Actor;
 
       vtkSmartPointer< vtkPolyData >       m_Plane;
       vtkSmartPointer< vtkPolyDataMapper > m_PlaneMapper;
index 53b77e1fc8c1ebcfa2b62346a146ec0d9dda4f48..b04194484b71dcbaf4b3d2eb670cf308b480f82a 100644 (file)
@@ -67,13 +67,7 @@ AddInputData( vtkImageData* new_image )
 unsigned int cpExtensions::Visualization::MPRActors::
 GetNumberOfImages( ) const
 {
-  /* TODO
-     ImageBlender* blender = this->Slices[ 0 ][ 0 ]->GetBlender( );
-     if( blender != NULL )
-     return( blender->GetNumberOfImages( ) );
-     else
-  */
-  return( 0 );
+  return( this->Slices[ 0 ][ 0 ]->GetNumberOfImages( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -90,35 +84,8 @@ PushActorsInto(
   this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false );
   this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false );
 
-  vtkRenderer* xren =
-    ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL;
-  vtkRenderer* yren =
-    ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL;
-  vtkRenderer* zren =
-    ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL;
   vtkRenderer* wren =
     ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL;
-
-  /* TODO
-     if( xren != NULL )
-     {
-     xren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
-     xren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
-
-     } // fi
-     if( yren != NULL )
-     {
-     yren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
-     yren->AddActor( this->Slices[ 0 ][ 2 ]->GetPlaneActor( ) );
-
-     } // fi
-     if( zren != NULL )
-     {
-     zren->AddActor( this->Slices[ 0 ][ 0 ]->GetPlaneActor( ) );
-     zren->AddActor( this->Slices[ 0 ][ 1 ]->GetPlaneActor( ) );
-
-     } // fi
-  */
   if( wren != NULL )
     wren->AddActor( this->ImageOutlineActor );
 }