]> Creatis software - cpPlugins.git/blob - appli/examples/example_ReadWriteImage.cxx
07591b2cf81e1298a18b6ae62c5383aa80570605
[cpPlugins.git] / appli / examples / example_ReadWriteImage.cxx
1 #include <cstdlib>
2 #include <iostream>
3 #include <string>
4
5 #include <cpPlugins/Interface/Plugins.h>
6
7 // -------------------------------------------------------------------------
8 typedef cpPlugins::Interface::Plugins TPlugins;
9
10 // -------------------------------------------------------------------------
11 int main( int argc, char* argv[] )
12 {
13   if( argc < 4 )
14   {
15     std::cerr
16       << "Usage: " << argv[ 0 ]
17       << " plugins_file"
18       << " input_image output_image" << std::endl;
19     return( 1 );
20
21   } // fi
22
23   // Load plugins
24   cpPlugins::Interface::Plugins plugins;
25   if( !plugins.LoadPlugins( argv[ 1 ] ) )
26   {
27     std::cerr << "Failed to load plugins." << std::endl;
28     return( 1 );
29
30   } // fi
31
32   // Associate filenames
33   std::vector< std::string > fnames;
34   for( int i = 2; i < argc - 1; ++i )
35     fnames.push_back( argv[ i ] );
36   
37   // Read image
38   try
39   {
40     std::string name = plugins.ReadImage( fnames, "" );
41     plugins.WriteDataObject( argv[ argc - 1 ], name );
42   }
43   catch( std::exception& err )
44   {
45     std::cerr << err.what( ) << std::endl;
46     return( 1 );
47
48   } // yrt
49   return( 0 );
50 }
51
52 // eof - $RCSfile$