X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=07591b2cf81e1298a18b6ae62c5383aa80570605;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=0098973bd520c79049c6a60112d1327664adce30;hpb=3b51a08c6a78ed09578f198f6a13dd769d460bef;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index 0098973..07591b2 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -2,11 +2,12 @@ #include #include -#include -#include +#include -#include +// ------------------------------------------------------------------------- +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 ); }