X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=07591b2cf81e1298a18b6ae62c5383aa80570605;hb=b6c7e73ebcce23619daced67f85d9e1364b33f30;hp=e07761c07a0a8d93b21d2ddf6be5a913bfae2037;hpb=cf8ebcdb1e31f332e74569b2be5dfb5f5100df07;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index e07761c..07591b2 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -2,88 +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 ]; - std::string dimensions = 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 TProcessObject::TParameters TParameters; - cpPlugins::Interface::ProcessObject* reader; - cpPlugins::Interface::ProcessObject* writer; - reader = - dynamic_cast< TProcessObject* >( - plugins.CreateObject( "cpPlugins::Plugins::ImageReader" ) - ); - if( reader == NULL ) + // 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 = - dynamic_cast< TProcessObject* >( - plugins.CreateObject( "cpPlugins::Plugins::ImageWriter" ) - ); - if( writer == NULL ) + + // 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 ) { - delete reader; - 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[ "FileName" ].second = input_image_file; - reader_params[ "PixelType" ].second = pixel_type; - reader_params[ "ImageDimension" ].second = dimensions; - reader_params[ "IsColorImage" ].second = ( is_color )? "1": "0"; - reader->SetParameters( reader_params ); - - // Configure reader - TParameters writer_params = writer->GetDefaultParameters( ); - writer_params[ "FileName" ].second = 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; - - // Free memory - delete writer; - delete reader; - + } // yrt return( 0 ); }