X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=07591b2cf81e1298a18b6ae62c5383aa80570605;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=b051277e30cad06e532e62495f19a39c56153899;hpb=c3c3da5217b6eb255db9c0424f22d4e01250901e;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index b051277..07591b2 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -2,16 +2,10 @@ #include #include -#include -#include -#include +#include // ------------------------------------------------------------------------- -typedef cpPlugins::Interface::Interface TInterface; -typedef cpPlugins::Interface::ProcessObject TProcessObject; -typedef cpPlugins::Interface::DataObject TDataObject; -typedef cpPlugins::Interface::Parameters TParameters; -typedef TInterface::TClasses TClasses; +typedef cpPlugins::Interface::Plugins TPlugins; // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) @@ -26,53 +20,32 @@ int main( int argc, char* argv[] ) } // fi - // Create interface - 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 - TProcessObject::Pointer reader, writer; - reader = plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" ); - writer = plugins.CreateProcessObject( "cpPlugins::IO::ImageWriter" ); - if( reader.IsNull( ) || writer.IsNull( ) ) - { - std::cerr - << "No suitable reader found in plugins." << std::endl - << "Reader: " << reader.GetPointer( ) << std::endl - << "Writer: " << writer.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 - 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< TDataObject >( 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 - + } // yrt return( 0 ); }