]> Creatis software - cpPlugins.git/blobdiff - appli/examples/example_ReadWriteImage.cxx
...
[cpPlugins.git] / appli / examples / example_ReadWriteImage.cxx
index 0098973bd520c79049c6a60112d1327664adce30..07591b2cf81e1298a18b6ae62c5383aa80570605 100644 (file)
@@ -2,11 +2,12 @@
 #include <iostream>
 #include <string>
 
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
 
-#include <cpPlugins/Interface/Image.h>
+// -------------------------------------------------------------------------
+typedef cpPlugins::Interface::Plugins TPlugins;
 
+// -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
   if( argc < 4 )
@@ -19,61 +20,32 @@ int main( int argc, char* argv[] )
 
   } // fi
 
-  // Create interface
-  typedef cpPlugins::Interface::Interface TInterface;
-  typedef TInterface::TClasses            TClasses;
-  TInterface plugins;
-  if( !plugins.Load( argv[ 1 ] ) )
+  // Load plugins
+  cpPlugins::Interface::Plugins plugins;
+  if( !plugins.LoadPlugins( argv[ 1 ] ) )
   {
     std::cerr << "Failed to load plugins." << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create objects
-  typedef cpPlugins::Interface::ProcessObject TProcessObject;
-  typedef cpPlugins::Interface::Parameters    TParameters;
-  cpPlugins::Interface::ProcessObject::Pointer reader, writer;
-  reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" );
-  if( reader.IsNull( ) )
-  {
-    std::cerr << "No suitable reader found in plugins." << std::endl;
-    return( 1 );
-
-  } // fi
-  writer = plugins.CreateProcessObject( "cpPlugins::ImageWriter" );
-  if( writer.IsNull( ) )
-  {
-    std::cerr << "No suitable writer found in plugins." << 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 - 1; ++i )
-    reader_params.AddValueToStringList( "FileNames", argv[ i ] );
-  reader->SetParameters( reader_params );
-
-  // Configure writer
-  TParameters writer_params = writer->GetDefaultParameters( );
-  writer_params.SetValueAsString( "FileName", argv[ argc - 1 ] );
-  writer->SetParameters( writer_params );
-
-  // Connect pipeline
-  writer->SetInput( 0, reader->GetOutput( 0 ) );
-
-  // Execute pipeline
-  std::string err = writer->Update( );
-  if( err != "" )
+    fnames.push_back( argv[ i ] );
+  
+  // Read image
+  try
   {
-    std::cerr << "ERROR: " << err << std::endl;
+    std::string name = plugins.ReadImage( fnames, "" );
+    plugins.WriteDataObject( argv[ argc - 1 ], name );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << err.what( ) << std::endl;
     return( 1 );
 
-  } // fi
-
-  dynamic_cast< cpPlugins::Interface::Image* >( reader->GetOutput( 0 ) )->GetVTKImageData( )->Print( std::cout );
-
+  } // yrt
   return( 0 );
 }