]> Creatis software - cpPlugins.git/blob - appli/examples/plugins/ShowImage.cxx
a339de20881b70ced457cb10078bb0ac72e2e729
[cpPlugins.git] / appli / examples / plugins / ShowImage.cxx
1 #include <cpExtensions/Config.h>
2
3 #ifdef cpExtensions_QT4
4
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpPlugins/Interface/Workspace.h>
7
8 #include <QApplication>
9 #include <QWidget>
10 #include <QMainWindow>
11 #include <QHBoxLayout>
12
13 #include <vtkImageData.h>
14
15 #endif // cpExtensions_QT4
16
17 //----------------------------------------------------------------------------
18 int main( int argc, char* argv[] )
19 {
20 #ifdef cpExtensions_QT4
21
22   // Manage inputs
23   if( argc < 2 )
24   {
25     std::cerr << "Usage: " << argv[ 0 ] << " image_file(s)" << std::endl;
26     return( 1 );
27
28   } // fi
29
30   // Create interface
31   cpPlugins::Interface::Plugins::Pointer interface =
32     cpPlugins::Interface::Plugins::New( );
33   try
34   {
35     interface->LoadEnvironments( );
36     interface->GuessPlugins( );
37   }
38   catch( std::exception& err )
39   {
40     std::cerr << "Error caught: " << err.what( ) << std::endl;
41     return( 1 );
42
43   } // yrt
44
45   // Create workspace
46   typedef cpPlugins::Interface::Workspace _TWorkspace;
47   _TWorkspace::Pointer ws = _TWorkspace::New( );
48   ws->PrintExecutionOn( );
49
50   // Configure reader
51   auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" );
52   auto params = reader->GetParameters( );
53   for( int i = 1; i < argc; ++i )
54     params->AddToOpenFileNameList( "FileNames",  argv[ i ] );
55
56   // Execute reader
57   try
58   {
59     reader->Update( );
60   }
61   catch( std::exception& err )
62   {
63     std::cerr << "Error caugth: " << err.what( ) << std::endl;
64     return( 1 );
65
66   } // yrt
67
68   // Configure viewer
69   auto image = reader->GetOutputData< vtkImageData >( "Output" );
70   switch( image->GetDataDimension( ) )
71   {
72   case 2:
73   {
74     return( 0 );
75   }
76   break;
77   case 3:
78   {
79     // Qt initialization
80     QApplication app( argc, argv );
81     QMainWindow wnd;
82     wnd.setGeometry( 0, 0, 1024, 768 );
83
84     // Create main widget
85     cpExtensions::QT::SimpleMPRWidget view( &wnd );
86     view.SetImage( image, "image" );
87
88     // Start application and show data
89     wnd.setCentralWidget( &view );
90     wnd.show( );
91
92     return( app.exec( ) );
93   }
94   break;
95   default:
96   {
97     std::cerr << "Unmanaged dimension." << std::endl;
98     return( 1 );
99   }
100   break;
101     
102   } // hctiws
103 #else // cpExtensions_QT4
104   return( 0 );
105 #endif // cpExtensions_QT4
106 }
107
108 // eof - $RCSfile$