]> Creatis software - cpPlugins.git/blob - appli/PipelineEditor/PipelineEditor.cxx
Cast image filter added. ROI filter modified.
[cpPlugins.git] / appli / PipelineEditor / PipelineEditor.cxx
1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
3
4 #include <cpPlugins/Utility.h>
5 #include <cpExtensions/QT/SimpleMPRWidget.h>
6 #include <cpExtensions/QT/ImageWidget.h>
7 #include <cpExtensions/QT/ActorsWidgetInterface.h>
8 #include <vtkImageData.h>
9 #include <vtkPolyData.h>
10
11 // -------------------------------------------------------------------------
12 PipelineEditor::
13 PipelineEditor( int argc, char* argv[], QWidget* parent )
14   : Superclass( argc, argv, parent ),
15     m_UI( new Ui::PipelineEditor )
16 {
17   // Basic configuration
18   this->m_BaseWindowTitle = "PipelineEditor - ";
19   this->m_UI->setupUi( this );
20   this->setCanvas( this->m_UI->Canvas );
21   this->setNavigator( this->m_UI->Navigator );
22   this->m_UI->Navigator->Update( );
23
24   // Connect slots <-> signals
25   cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
26   cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
27   cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
28   cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
29   cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
30   cpBaseQtApplication_ConnectAction( actionActorsProperties, _actorsProperties );
31   this->m_UI->Canvas->connectOutputPortSlot(
32     this, SLOT( _slotView( const std::string&, bool ) )
33     );
34   this->connect(
35     this->m_UI->actionPrintExecutionInformation, SIGNAL( triggered( bool ) ),
36     this, SLOT( _slotPrintExecutionInformation( bool ) )
37     );
38
39   // Load command-line given workspace (if any)
40   if( argc > 1 )
41     this->_loadWorkspace( argv[ 1 ] );
42 }
43
44 // -------------------------------------------------------------------------
45 PipelineEditor::
46 ~PipelineEditor( )
47 {
48   delete this->m_UI;
49 }
50
51 // -------------------------------------------------------------------------
52 void PipelineEditor::
53 _slotView( const std::string& name, bool show )
54 {
55   typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
56
57   // Get filter parameters
58   std::vector< std::string > tokens;
59   cpPlugins::Tokenize( tokens, name, "@" );
60   if( tokens.size( ) != 2 )
61     return;
62   auto filter_name = tokens[ 1 ];
63   auto output_name = tokens[ 0 ];
64
65   // Process data
66   if( show )
67   {
68     try
69     {
70       auto ws = this->workspace( );
71       auto filter = ws->GetFilter( filter_name );
72       cpBaseQtApplication_Execute( filter->Update( ) );
73       auto image = filter->GetOutputData< vtkImageData >( output_name );
74       auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
75       _TViewer* viewer = NULL;
76       if( image != NULL )
77       {
78         int dim = image->GetDataDimension( );
79         if( dim == 2 )
80           viewer =
81             this->_configureViewer< cpExtensions::QT::ImageWidget >(
82               this->m_UI->Viewer
83               );
84         else if( dim == 3 )
85           viewer =
86             this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
87               this->m_UI->Viewer
88               );
89       }
90       else if( mesh != NULL )
91       {
92         viewer =
93           this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
94             this->m_UI->Viewer
95             );
96
97       } // fi
98       if(
99         dynamic_cast< QWidget* >( viewer ) !=
100         dynamic_cast< QWidget* >( this->m_UI->Viewer ) &&
101         viewer != NULL
102         )
103       {
104         delete this->m_UI->Viewer;
105         this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
106         this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
107         this->setViewer( viewer );
108
109       } // fi
110       if( image != NULL )
111       {
112         this->m_Blocker.block( );
113         auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
114         auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
115         if( mpr != NULL )
116           mpr->SetImage( image, name );
117         else if( imv != NULL )
118           imv->SetImage( image, name );
119         this->m_Blocker.unblock( );
120       }
121       else if( mesh != NULL )
122       {
123         this->m_Blocker.block( );
124         auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
125         if( mpr != NULL )
126           mpr->Add( mesh, name );
127         this->m_Blocker.unblock( );
128
129       } // fi
130     }
131     catch( std::exception& err )
132     {
133       QMessageBox::critical(
134         NULL,
135         QMessageBox::tr( "Error showing data" ),
136         QMessageBox::tr( err.what( ) )
137         );
138
139     } // yrt
140
141   } // fi
142 }
143
144 // -------------------------------------------------------------------------
145 void PipelineEditor::
146 _slotPrintExecutionInformation( bool show )
147 {
148   if( this->m_Workspace.IsNotNull( ) )
149     this->m_Workspace->SetPrintExecution( show );
150 }
151
152 // -------------------------------------------------------------------------
153 #include <cpBaseQtApplication/MainHelper.h>
154 cpBaseQtApplication_Main( PipelineEditor );
155 cpBaseQtApplication_MainComplement;
156
157 // eof - $RCSfile$