]> Creatis software - cpPlugins.git/blob - appli/examples/plugins/example_plugins_ReadImage.cxx
Code cleaning
[cpPlugins.git] / appli / examples / plugins / example_plugins_ReadImage.cxx
1 #include <iostream>
2 #include <cpPlugins/Interface.h>
3
4 int main( int argc, char* argv[] )
5 {
6   // Manage inputs
7   if( argc < 2 )
8   {
9     std::cerr << "Usage: " << argv[ 0 ] << " image_file(s)" << std::endl;
10     return( 1 );
11
12   } // fi
13
14   // Create interface and load library
15   cpPlugins::Interface interface;
16   try
17   {
18     interface.LoadEnvironment( );
19     interface.GuessPlugins( );
20   }
21   catch( std::exception& err )
22   {
23     std::cerr << "Error caught: " << err.what( ) << std::endl;
24     return( 1 );
25
26   } // yrt
27
28   // Create reader
29   auto reader = interface.CreateProcessObject( "IO", "ImageReader" );
30   if( reader.IsNull( ) )
31   {
32     std::cerr
33       << "Error caugh: Could not create a valid image reader."
34       << std::endl;
35     return( 1 );
36
37   } // fi
38
39   // Configure reader
40   auto parameters = reader->GetParameters( );
41   for( int i = 1; i < argc; ++i )
42     parameters->AddToOpenFileNameList( "FileNames",  argv[ i ] );
43
44   // Execute reader
45   try
46   {
47     reader->PrintExecutionOn( );
48     reader->Update( );
49   }
50   catch( std::exception& err )
51   {
52     std::cerr << "Error caugth: " << err.what( ) << std::endl;
53     return( 1 );
54
55   } // yrt
56
57   // Show simple information
58   reader->GetOutputData( "Output" )->Print( std::cout );
59
60   // Finish
61   return( 0 );
62 }
63
64 // eof - $RCSfile$