X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=07591b2cf81e1298a18b6ae62c5383aa80570605;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=8c562a96dcb0ea9aebcc94faea5b9c11a6d6c9c8;hpb=9015cf98c60cf4ab304a639990004ee783a8bec0;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index 8c562a9..07591b2 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -2,9 +2,12 @@ #include #include -#include -#include +#include +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Plugins TPlugins; + +// ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { if( argc < 4 ) @@ -17,58 +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::string name = plugins.ReadImage( fnames, "" ); + plugins.WriteDataObject( argv[ argc - 1 ], name ); + } + catch( std::exception& err ) { - std::cerr << "ERROR: " << err << std::endl; + std::cerr << err.what( ) << std::endl; return( 1 ); - } // fi + } // yrt return( 0 ); }