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