]> Creatis software - cpPlugins.git/blob - appli/examples/plugins/ImageTracer.cxx
...
[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 #endif // cpExtensions_QT4
18
19 //----------------------------------------------------------------------------
20 int main( int argc, char* argv[] )
21 {
22 #ifdef cpExtensions_QT4
23
24   // Manage inputs
25   if( argc < 2 )
26   {
27     std::cerr << "Usage: " << argv[ 0 ] << " image_file(s)" << std::endl;
28     return( 1 );
29
30   } // fi
31
32   // Create interface
33   cpPlugins::Interface::Plugins::Pointer interface =
34     cpPlugins::Interface::Plugins::New( );
35   try
36   {
37     interface->LoadEnvironments( );
38     interface->GuessPlugins( );
39   }
40   catch( std::exception& err )
41   {
42     std::cerr << "Error caught: " << err.what( ) << std::endl;
43     return( 1 );
44
45   } // yrt
46
47   // Create workspace
48   typedef cpPlugins::Interface::Workspace _TWorkspace;
49   _TWorkspace::Pointer ws = _TWorkspace::New( );
50   ws->PrintExecutionOn( );
51   ws->Load( argv[ 1 ] );
52
53   // Configure filters
54   /* TODO
55      auto reader = ws->CreateFilter( "IO", "ImageReader", "reader" );
56      auto widget = ws->CreateFilter( "Widgets", "SplineWidget", "spline" );
57      ws->Connect( "reader", "spline", "Output", "Input" );
58      auto params = reader->GetParameters( );
59      for( int i = 1; i < argc; ++i )
60      params->AddToOpenFileNameList( "FileNames",  argv[ i ] );
61   */
62   auto reader = ws->GetFilter( "reader" );
63   auto spline = ws->GetFilter( "spline" );
64   auto seeds = ws->GetFilter( "seeds" );
65   auto axis = ws->GetFilter( "axis" );
66   auto writer = ws->GetFilter( "writer" );
67   auto raster = ws->GetFilter( "raster" );
68
69   // Execute reader
70   try
71   {
72     reader->Update( );
73   }
74   catch( std::exception& err )
75   {
76     std::cerr << "Error caugth: " << err.what( ) << std::endl;
77     return( 1 );
78
79   } // yrt
80
81   // Qt initialization
82   QApplication app( argc, argv );
83   QMainWindow wnd;
84   wnd.setGeometry( 0, 0, 1024, 768 );
85   cpExtensions::QT::ImageWidget view( &wnd );
86   view.SetImage(
87     reader->GetOutputData< vtkImageData >( "Output" ), 2, "image"
88     );
89   spline->AddInteractor( view.GetInteractor( ) );
90   seeds->AddInteractor( view.GetInteractor( ) );
91   spline->Update( );
92   seeds->Update( );
93
94   // Start application and show data
95   wnd.setCentralWidget( &view );
96   wnd.show( );
97   app.exec( );
98   spline->Modified( );
99   spline->Update( );
100   raster->Update( );
101   writer->Update( );
102
103   wnd.show( );
104   app.exec( );
105   
106   seeds->Modified( );
107   seeds->Update( );
108   axis->Update( );
109   // view.Add( axis->GetOutputData< vtkPolyData >( "Output" ) );
110   wnd.show( );
111   return( app.exec( ) );
112
113   // TODO: widget->GetOutputData< vtkPolyData >( "Output" )->Print( std::cout );
114
115   /*
116     auto raster = ws->CreateFilter( "MeshToImageFilters", "RasterMeshFilter", "raster" );
117     ws->Connect( "spline", "raster", "Output", "Input" );
118     ws->Connect( "reader", "raster", "Output", "Template" );
119     raster->Update( );
120   */
121   
122 #else // cpExtensions_QT4
123   return( 0 );
124 #endif // cpExtensions_QT4
125 }
126
127 // eof - $RCSfile$