]> Creatis software - cpPlugins.git/blob - appli/examples/example_ReadWriteImage.cxx
8c562a96dcb0ea9aebcc94faea5b9c11a6d6c9c8
[cpPlugins.git] / appli / examples / example_ReadWriteImage.cxx
1 #include <cstdlib>
2 #include <iostream>
3 #include <string>
4
5 #include <cpPlugins/Interface/Interface.h>
6 #include <cpPlugins/Interface/ProcessObject.h>
7
8 int main( int argc, char* argv[] )
9 {
10   if( argc < 4 )
11   {
12     std::cerr
13       << "Usage: " << argv[ 0 ]
14       << " plugins_file"
15       << " input_image output_image" << std::endl;
16     return( 1 );
17
18   } // fi
19
20   // Create interface
21   typedef cpPlugins::Interface::Interface TInterface;
22   typedef TInterface::TClasses            TClasses;
23   TInterface plugins;
24   if( !plugins.Load( argv[ 1 ] ) )
25   {
26     std::cerr << "Failed to load plugins." << std::endl;
27     return( 1 );
28
29   } // fi
30
31   // Create objects
32   typedef cpPlugins::Interface::ProcessObject TProcessObject;
33   typedef cpPlugins::Interface::Parameters    TParameters;
34   cpPlugins::Interface::ProcessObject::Pointer reader, writer;
35   reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" );
36   if( reader.IsNull( ) )
37   {
38     std::cerr << "No suitable reader found in plugins." << std::endl;
39     return( 1 );
40
41   } // fi
42   writer = plugins.CreateProcessObject( "cpPlugins::ImageWriter" );
43   if( writer.IsNull( ) )
44   {
45     std::cerr << "No suitable writer found in plugins." << std::endl;
46     return( 1 );
47
48   } // fi
49
50   // Configure reader
51   TParameters reader_params = reader->GetDefaultParameters( );
52   for( int i = 2; i < argc - 1; ++i )
53     reader_params.AddValueToStringList( "FileNames", argv[ i ] );
54   reader->SetParameters( reader_params );
55
56   // Configure writer
57   TParameters writer_params = writer->GetDefaultParameters( );
58   writer_params.SetValueAsString( "FileName", argv[ argc - 1 ] );
59   writer->SetParameters( writer_params );
60
61   // Connect pipeline
62   writer->SetInput( 0, reader->GetOutput( 0 ) );
63
64   // Execute pipeline
65   std::string err = writer->Update( );
66   if( err != "" )
67   {
68     std::cerr << "ERROR: " << err << std::endl;
69     return( 1 );
70
71   } // fi
72   return( 0 );
73 }
74
75 // eof - $RCSfile$