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 )
96 this->_configureViewer< cpExtensions::QT::SimpleMPRWidget >(
102 dynamic_cast< QWidget* >( viewer ) !=
103 dynamic_cast< QWidget* >( this->m_UI->Viewer )
106 delete this->m_UI->Viewer;
107 this->m_UI->Viewer = dynamic_cast< QWidget* >( viewer );
108 this->m_UI->MainSplitter->insertWidget( 0, this->m_UI->Viewer );
109 this->setViewer( viewer );
114 this->m_Blocker.block( );
115 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
116 auto imv = dynamic_cast< cpExtensions::QT::ImageWidget* >( viewer );
118 mpr->SetImage( image, name );
119 else if( imv != NULL )
120 imv->SetImage( image, name );
121 this->m_Blocker.unblock( );
123 else if( mesh != NULL )
125 this->m_Blocker.block( );
126 auto mpr = dynamic_cast< cpExtensions::QT::SimpleMPRWidget* >( viewer );
128 mpr->Add( mesh, name );
129 this->m_Blocker.unblock( );
133 catch( std::exception& err )
135 QMessageBox::critical(
137 QMessageBox::tr( "Error showing data" ),
138 QMessageBox::tr( err.what( ) )
146 // -------------------------------------------------------------------------
147 #include <cpBaseQtApplication/MainHelper.h>
148 cpBaseQtApplication_Main( PipelineEditor );
149 cpBaseQtApplication_MainComplement;