1 #include <PipelineEditor.h>
2 #include <ui_PipelineEditor.h>
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>
11 // -------------------------------------------------------------------------
13 PipelineEditor( int argc, char* argv[], QWidget* parent )
14 : Superclass( argc, argv, parent ),
15 m_UI( new Ui::PipelineEditor )
17 // Basic configuration
18 this->m_SingleWorkspace = true;
19 this->m_BaseWindowTitle = "PipelineEditor - ";
20 this->m_UI->setupUi( this );
21 this->setCanvas( this->m_UI->Canvas );
22 this->setNavigator( this->m_UI->Navigator );
23 this->m_UI->Navigator->Update( );
25 // Connect slots <-> signals
26 cpBaseQtApplication_ConnectAction( actionLoadDirectory, _loadPluginsFromPath );
27 cpBaseQtApplication_ConnectAction( actionLoadLibrary, _loadPlugins );
28 cpBaseQtApplication_ConnectAction( actionOpenWorkspace, _loadWorkspace );
29 cpBaseQtApplication_ConnectAction( actionSaveWorkspace, _saveWorkspace );
30 cpBaseQtApplication_ConnectAction( actionSaveWorkspaceAs, _saveWorkspace );
31 cpBaseQtApplication_ConnectAction( actionActorsProperties, _actorsProperties );
32 this->m_UI->Canvas->connectOutputPortSlot(
33 this, SLOT( _slotView( const std::string&, bool ) )
36 // Load command-line given workspace (if any)
37 this->m_ActiveWS = "empty";
40 this->_loadWorkspace( argv[ 1 ] );
41 this->m_ActiveWS = argv[ 1 ];
44 this->_addWorkspace( this->m_ActiveWS );
47 // -------------------------------------------------------------------------
54 // -------------------------------------------------------------------------
56 _slotView( const std::string& name, bool show )
58 typedef cpExtensions::QT::ActorsWidgetInterface _TViewer;
60 // Get filter parameters
61 std::vector< std::string > tokens;
62 cpPlugins::Tokenize( tokens, name, "@" );
63 if( tokens.size( ) != 2 )
65 auto filter_name = tokens[ 1 ];
66 auto output_name = tokens[ 0 ];
73 auto ws = this->workspace( this->m_ActiveWS );
74 auto filter = ws->GetFilter( filter_name );
75 cpBaseQtApplication_Execute( filter->Update( ) );
76 auto image = filter->GetOutputData< vtkImageData >( output_name );
77 auto mesh = filter->GetOutputData< vtkPolyData >( output_name );
78 _TViewer* viewer = NULL;
81 int dim = image->GetDataDimension( );
84 this->_configureViewer< cpExtensions::QT::ImageWidget >(
89 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
93 else if( mesh != NULL )
99 dynamic_cast< QWidget* >( viewer ) !=
100 dynamic_cast< QWidget* >( this->m_UI->Viewer )
103 delete this->m_UI->Viewer;
104 this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
105 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
106 this->setViewer( viewer );
111 this->m_Blocker.block( );
112 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
113 auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
115 mpr->SetImage( image, name );
116 else if( imv != NULL )
117 imv->SetImage( image, name );
118 this->m_Blocker.unblock( );
120 else if( mesh != NULL )
122 this->m_Blocker.block( );
123 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
125 mpr->Add( mesh, name );
126 this->m_Blocker.unblock( );
130 catch( std::exception& err )
132 QMessageBox::critical(
134 QMessageBox::tr( "Error showing data" ),
135 QMessageBox::tr( err.what( ) )
143 // -------------------------------------------------------------------------
144 #include <cpBaseQtApplication/MainHelper.h>
145 cpBaseQtApplication_Main( PipelineEditor );
146 cpBaseQtApplication_MainComplement;