]> Creatis software - cpPlugins.git/blob - appli/examples/example_ReadWriteImage.cxx
4d5987b715a1298d9ec5c8cfbcd969577ef6804c
[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 < 7 )
11   {
12     std::cerr
13       << "Usage: " << argv[ 0 ]
14       << " plugins_file"
15       << " input_image output_image"
16       << " dimensions pixel_type is_color" << std::endl;
17     return( 1 );
18
19   } // fi
20   std::string plugins_file = argv[ 1 ];
21   std::string input_image_file = argv[ 2 ];
22   std::string output_image_file = argv[ 3 ];
23   std::string dimensions = argv[ 4 ];
24   std::string pixel_type = argv[ 5 ];
25   bool is_color = ( std::atoi( argv[ 6 ] ) == 1 );
26
27   // Create interface
28   typedef cpPlugins::Interface::Interface TInterface;
29   typedef TInterface::TClasses            TClasses;
30
31   TInterface plugins;
32   plugins.Load( plugins_file );
33
34   // Create objects
35   typedef cpPlugins::Interface::ProcessObject TProcessObject;
36   typedef TProcessObject::TParameters         TParameters;
37   cpPlugins::Interface::ProcessObject* reader;
38   cpPlugins::Interface::ProcessObject* writer;
39
40   reader =
41     dynamic_cast< TProcessObject* >(
42       plugins.CreateObject( "cpPlugins::Plugins::ImageReader" )
43       );
44   if( reader == NULL )
45   {
46     std::cerr << "No suitable reader found in plugins." << std::endl;
47     return( 1 );
48
49   } // fi
50   writer =
51     dynamic_cast< TProcessObject* >(
52       plugins.CreateObject( "cpPlugins::Plugins::ImageWriter" )
53       );
54   if( writer == NULL )
55   {
56     delete reader;
57     std::cerr << "No suitable writer found in plugins." << std::endl;
58     return( 1 );
59
60   } // fi
61
62   // Configure reader
63   TParameters reader_params = reader->GetDefaultParameters( );
64   reader_params[ "FileName" ].second = input_image_file;
65   reader_params[ "PixelType" ].second = pixel_type;
66   reader_params[ "ImageDimension" ].second = dimensions;
67   reader_params[ "IsColorImage" ].second = ( is_color )? "1": "0";
68   reader->SetParameters( reader_params );
69
70   // Free memory
71   delete writer;
72   delete reader;
73
74   return( 0 );
75 }
76
77 // eof - $RCSfile$