#include <iostream>
#include <string>
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
+// -------------------------------------------------------------------------
+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 );
}