]> Creatis software - cpPlugins.git/blobdiff - appli/examples/example_View2DImage.cxx
...
[cpPlugins.git] / appli / examples / example_View2DImage.cxx
index 2778e8844a785901a6c1f374eb6b63a30d81468d..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;
 
 // -------------------------------------------------------------------------
@@ -29,53 +24,39 @@ int main( int argc, char* argv[] )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " plugins_file input_image [widget]"
+      << " plugins_file input_image"
       << std::endl;
     return( 1 );
 
   } // 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.CreateObject( "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->GetParameters( );
-  if( argc > 4 )
+  // Associate filenames
+  std::vector< std::string > fnames;
+  for( int i = 2; i < argc; ++i )
+    fnames.push_back( argv[ i ] );
+  
+  // Read image
+  std::string name = "";
+  try
   {
-    for( int i = 2; i < argc; ++i )
-      reader_params->AddToStringList( "FileNames", argv[ i ] );
+    name = plugins.ReadImage( fnames, "" );
   }
-  else
-    reader_params->AddToStringList( "FileNames", argv[ 2 ] );
-
-  // Execute pipeline
-  std::string err = reader->Update( );
-  if( err != "" )
+  catch( std::exception& err )
   {
-    std::cerr << "ERROR: " << err << std::endl;
+    std::cerr << err.what( ) << std::endl;
     return( 1 );
 
-  } // fi
-  TImage* image = reader->GetOutput< TImage >( "Output" );
+  } // yrt
+  TImage* image = plugins.GetData< TImage >( name );
 
   // Configure visualization objects
   vtkSmartPointer< vtkRenderer > renderer =
@@ -95,7 +76,7 @@ int main( int argc, char* argv[] )
   // Create slice actors
   vtkSmartPointer< TSliceActors > image_actors =
     vtkSmartPointer< TSliceActors >::New( );
-  image_actors->AddInputData( image->GetVTK< vtkImageData >( ) );
+  image_actors->SetInputImage( image->GetVTK< vtkImageData >( ) );
   image_actors->SetAxis( 2 );
   image_actors->PushActorsInto( window );
 
@@ -114,7 +95,7 @@ int main( int argc, char* argv[] )
   } // fi
 
   // Begin interaction
-  image_actors->ResetCamera( );
+  renderer->ResetCamera( );
   window->Render( );
   interactor->Start( );