]> Creatis software - cpPlugins.git/blob - appli/examples/example_ReadImageSeriesWriteImage.cxx
cab163c43a0f1d05844919e940e77caf9279aded
[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* reader;
42   cpPlugins::Interface::ProcessObject* writer;
43
44   reader =
45     dynamic_cast< TProcessObject* >(
46       plugins.CreateObject( "cpPlugins::Plugins::ImageSeriesReader" )
47       );
48   if( reader == NULL )
49   {
50     std::cerr << "No suitable reader found in plugins." << std::endl;
51     return( 1 );
52
53   } // fi
54   writer =
55     dynamic_cast< TProcessObject* >(
56       plugins.CreateObject( "cpPlugins::Plugins::ImageWriter" )
57       );
58   if( writer == NULL )
59   {
60     delete reader;
61     std::cerr << "No suitable writer found in plugins." << std::endl;
62     return( 1 );
63
64   } // fi
65
66   // Configure reader
67   TParameters reader_params = reader->GetDefaultParameters( );
68   reader_params[ "FileNames" ].second = input_image_files.str( );
69   reader_params[ "PixelType" ].second = pixel_type;
70   reader_params[ "ImageDimension" ].second = dimensions;
71   reader_params[ "IsColorImage" ].second = ( is_color )? "1": "0";
72   reader->SetParameters( reader_params );
73
74   // Configure reader
75   TParameters writer_params = writer->GetDefaultParameters( );
76   writer_params[ "FileName" ].second = output_image_file;
77   writer->SetParameters( writer_params );
78
79   // Connect pipeline
80   writer->SetInput( 0, reader->GetOutput( 0 ) );
81
82   std::string msg = writer->Update( );
83
84   if( msg != "" )
85     std::cerr << "ERROR: " << msg << std::endl;
86
87   // Free memory
88   delete writer;
89   delete reader;
90
91   return( 0 );
92 }
93
94 // eof - $RCSfile$