]> Creatis software - cpPlugins.git/blobdiff - appli/examples/example_View2DImage.cxx
...
[cpPlugins.git] / appli / examples / example_View2DImage.cxx
index c18ca50afb3b98e83fe87cdf0bc038b3b9124772..be654b2217e23599f24766f5e7638361ba68739b 100644 (file)
@@ -1,25 +1,20 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+#include <vector>
 
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindowInteractor.h>
 
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
 #include <cpPlugins/Interface/Image.h>
 
 #include <cpExtensions/Visualization/ImageSliceActors.h>
 
 // -------------------------------------------------------------------------
-typedef cpPlugins::Interface::Interface     TInterface;
-typedef cpPlugins::Interface::ProcessObject TProcessObject;
-typedef cpPlugins::Interface::DataObject    TDataObject;
-typedef cpPlugins::Interface::Image         TImage;
-typedef cpPlugins::Interface::Parameters    TParameters;
-typedef TInterface::TClasses                TClasses;
-
+typedef cpPlugins::Interface::Plugins                 TPlugins;
+typedef cpPlugins::Interface::Image                   TImage;
 typedef cpExtensions::Visualization::ImageSliceActors TSliceActors;
 
 // -------------------------------------------------------------------------
@@ -35,43 +30,33 @@ int main( int argc, char* argv[] )
 
   } // fi
 
-  // Create interface
-  TInterface plugins;
-  if( !plugins.Load( argv[ 1 ] ) )
+  // Load plugins
+  cpPlugins::Interface::Plugins plugins;
+  if( !plugins.LoadPluginsPath( argv[ 1 ] ) )
   {
     std::cerr << "Failed to load plugins." << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create objects
-  TProcessObject::Pointer reader;
-  reader = plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" );
-  if( reader.IsNull( ) )
-  {
-    std::cerr
-      << "No suitable reader found in plugins." << std::endl
-      << "Reader: " << reader.GetPointer( ) << std::endl
-      << std::endl;
-    return( 1 );
-
-  } // fi
-
-  // Configure reader
-  TParameters reader_params = reader->GetDefaultParameters( );
+  // Associate filenames
+  std::vector< std::string > fnames;
   for( int i = 2; i < argc; ++i )
-    reader_params.AddValueToStringList( "FileNames", argv[ i ] );
-  reader->SetParameters( reader_params );
-
-  // Execute pipeline
-  std::string err = reader->Update( );
-  if( err != "" )
+    fnames.push_back( argv[ i ] );
+  
+  // Read image
+  std::string name = "";
+  try
+  {
+    name = plugins.ReadImage( fnames, "" );
+  }
+  catch( std::exception& err )
   {
-    std::cerr << "ERROR: " << err << std::endl;
+    std::cerr << err.what( ) << std::endl;
     return( 1 );
 
-  } // fi
-  TImage* image = reader->GetOutput< TImage >( 0 );
+  } // yrt
+  TImage* image = plugins.GetData< TImage >( name );
 
   // Configure visualization objects
   vtkSmartPointer< vtkRenderer > renderer =
@@ -91,12 +76,24 @@ int main( int argc, char* argv[] )
   // Create slice actors
   vtkSmartPointer< TSliceActors > image_actors =
     vtkSmartPointer< TSliceActors >::New( );
-  image_actors->AddInputData(
-    image->GetVTK< vtkImageData >( ), 2,
-    TSliceActors::LUTType_WindowLevel
-    );
+  image_actors->SetInputImage( image->GetVTK< vtkImageData >( ) );
+  image_actors->SetAxis( 2 );
   image_actors->PushActorsInto( window );
 
+  // Activate seed widget
+  if( argc == 4 )
+  {
+    TSliceActors::TStyle* style =
+      dynamic_cast< TSliceActors::TStyle* >( image_actors->GetStyle( ) );
+    if( style != NULL )
+    {
+      if( std::string( argv[ 3 ] ) == std::string( "seed" ) )
+        style->SeedWidgetOn( );
+
+    } // fi
+
+  } // fi
+
   // Begin interaction
   renderer->ResetCamera( );
   window->Render( );