]> Creatis software - cpPlugins.git/blob - appli/examples/example_ReadImageSeriesWriteImage.cxx
Garbage collector added
[cpPlugins.git] / appli / examples / example_ReadImageSeriesWriteImage.cxx
1 #include <cstdlib>
2 #include <iostream>
3 #include <sstream>
4 #include <string>
5
6 #include <cpPlugins/Interface/Interface.h>
7 #include <cpPlugins/Interface/ProcessObject.h>
8
9 int main( int argc, char* argv[] )
10 {
11   if( argc < 7 )
12   {
13     std::cerr
14       << "Usage: " << argv[ 0 ]
15       << " plugins_file"
16       << " output_image"
17       << " dimensions pixel_type is_color input_image_files" << std::endl;
18     return( 1 );
19
20   } // fi
21   std::string plugins_file = argv[ 1 ];
22   std::string output_image_file = argv[ 2 ];
23   std::string dimensions = argv[ 3 ];
24   std::string pixel_type = argv[ 4 ];
25   bool is_color = ( std::atoi( argv[ 5 ] ) == 1 );
26
27   std::stringstream input_image_files;
28   for( int i = 6; i < argc; ++i )
29     input_image_files << argv[ i ] << ";";
30   
31   // Create interface
32   typedef cpPlugins::Interface::Interface TInterface;
33   typedef TInterface::TClasses            TClasses;
34
35   TInterface plugins;
36   plugins.Load( plugins_file );
37
38   // Create objects
39   typedef cpPlugins::Interface::ProcessObject TProcessObject;
40   typedef TProcessObject::TParameters         TParameters;
41   cpPlugins::Interface::ProcessObject::Pointer reader;
42   cpPlugins::Interface::ProcessObject::Pointer writer;
43
44   reader =
45     plugins.CreateProcessObject( "cpPlugins::Plugins::ImageSeriesReader" );
46   if( reader.IsNull( ) )
47   {
48     std::cerr << "No suitable reader found in plugins." << std::endl;
49     return( 1 );
50
51   } // fi
52   writer = plugins.CreateProcessObject( "cpPlugins::Plugins::ImageWriter" );
53   if( writer.IsNull( ) )
54   {
55     std::cerr << "No suitable writer found in plugins." << std::endl;
56     return( 1 );
57
58   } // fi
59
60   // Configure reader
61   TParameters reader_params = reader->GetDefaultParameters( );
62   reader_params[ "FileNames" ].second = input_image_files.str( );
63   reader_params[ "PixelType" ].second = pixel_type;
64   reader_params[ "ImageDimension" ].second = dimensions;
65   reader_params[ "IsColorImage" ].second = ( is_color )? "1": "0";
66   reader->SetParameters( reader_params );
67
68   // Configure reader
69   TParameters writer_params = writer->GetDefaultParameters( );
70   writer_params[ "FileName" ].second = output_image_file;
71   writer->SetParameters( writer_params );
72
73   // Connect pipeline
74   writer->SetInput( 0, reader->GetOutput( 0 ) );
75
76   std::string msg = writer->Update( );
77
78   if( msg != "" )
79     std::cerr << "ERROR: " << msg << std::endl;
80
81   return( 0 );
82 }
83
84 // eof - $RCSfile$