X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2Fexamples%2Fexample_ReadWriteImage.cxx;h=b051277e30cad06e532e62495f19a39c56153899;hb=3633aade338a13bc83642e99e6d61b6499e4b3af;hp=e07761c07a0a8d93b21d2ddf6be5a913bfae2037;hpb=cf8ebcdb1e31f332e74569b2be5dfb5f5100df07;p=cpPlugins.git diff --git a/appli/examples/example_ReadWriteImage.cxx b/appli/examples/example_ReadWriteImage.cxx index e07761c..b051277 100644 --- a/appli/examples/example_ReadWriteImage.cxx +++ b/appli/examples/example_ReadWriteImage.cxx @@ -4,85 +4,74 @@ #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; + +// ------------------------------------------------------------------------- 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 ) + if( !plugins.Load( 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 ) + + // Create objects + TProcessObject::Pointer reader, writer; + reader = plugins.CreateProcessObject( "cpPlugins::IO::ImageReader" ); + writer = plugins.CreateProcessObject( "cpPlugins::IO::ImageWriter" ); + if( reader.IsNull( ) || writer.IsNull( ) ) { - delete reader; - std::cerr << "No suitable writer found in plugins." << std::endl; + 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( ); - 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"; + for( int i = 2; i < argc - 1; ++i ) + reader_params.AddValueToStringList( "FileNames", argv[ i ] ); reader->SetParameters( reader_params ); - // Configure reader + // Configure writer TParameters writer_params = writer->GetDefaultParameters( ); - writer_params[ "FileName" ].second = output_image_file; + writer_params.SetValueAsString( "FileName", argv[ argc - 1 ] ); writer->SetParameters( writer_params ); // Connect pipeline - writer->SetInput( 0, reader->GetOutput( 0 ) ); - - std::string msg = writer->Update( ); + writer->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); - if( msg != "" ) - std::cerr << "ERROR: " << msg << std::endl; + // Execute pipeline + std::string err = writer->Update( ); + if( err != "" ) + { + std::cerr << "ERROR: " << err << std::endl; + return( 1 ); - // Free memory - delete writer; - delete reader; + } // fi return( 0 ); }