X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=07591b2cf81e1298a18b6ae62c5383aa80570605;hb=7e29f3aec097ba1bff1894fed6eb1094276c5b72;hp=fa644d055832eac3eadd42602d7d021b0049c396;hpb=dd3c26560f279be2902518eff109bdd887cd63d3;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index fa644d0..07591b2 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -2,77 +2,50 @@ #include #include -#include -#include +#include +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Plugins TPlugins; + +// ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 7 ) + if( argc < 4 ) { std::cerr << "Usage: " << argv[ 0 ] << " plugins_file" - << " input_image output_image" - << " dimensions pixel_type is_color" << std::endl; + << " input_image output_image" << std::endl; return( 1 ); } // fi - std::string plugins_file = argv[ 1 ]; - std::string input_image_file = argv[ 2 ]; - std::string output_image_file = argv[ 3 ]; - unsigned int dimensions = std::atoi( argv[ 4 ] ); - std::string pixel_type = argv[ 5 ]; - bool is_color = ( std::atoi( argv[ 6 ] ) == 1 ); - - // Create interface - typedef cpPlugins::Interface::Interface TInterface; - typedef TInterface::TClasses TClasses; - - TInterface plugins; - plugins.Load( plugins_file ); - - // Create objects - typedef cpPlugins::Interface::ProcessObject TProcessObject; - typedef cpPlugins::Interface::Parameters TParameters; - cpPlugins::Interface::ProcessObject::Pointer reader; - cpPlugins::Interface::ProcessObject::Pointer writer; - reader = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageReader" ); - if( reader.IsNull( ) ) + // Load plugins + cpPlugins::Interface::Plugins plugins; + if( !plugins.LoadPlugins( argv[ 1 ] ) ) { - std::cerr << "No suitable reader found in plugins." << std::endl; + std::cerr << "Failed to load plugins." << std::endl; return( 1 ); } // fi - writer = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageWriter" ); - if( writer.IsNull( ) ) + + // Associate filenames + std::vector< std::string > fnames; + for( int i = 2; i < argc - 1; ++i ) + 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 << "No suitable writer found in plugins." << std::endl; + std::cerr << err.what( ) << std::endl; return( 1 ); - } // fi - - // Configure reader - TParameters reader_params = reader->GetDefaultParameters( ); - reader_params.AddValueToStringList( "FileNames", input_image_file ); - reader_params.SetValueAsString( "PixelType", pixel_type ); - reader_params.SetValueAsUint( "ImageDimension", dimensions ); - reader_params.SetValueAsUint( "IsColorImage", ( is_color? 1: 0 ) ); - reader->SetParameters( reader_params ); - - // Configure reader - TParameters writer_params = writer->GetDefaultParameters( ); - writer_params.SetValueAsString( "FileName", output_image_file ); - writer->SetParameters( writer_params ); - - // Connect pipeline - writer->SetInput( 0, reader->GetOutput( 0 ) ); - - std::string msg = writer->Update( ); - - if( msg != "" ) - std::cerr << "ERROR: " << msg << std::endl; - + } // yrt return( 0 ); }