1 #include <cpPlugins/Interface/Plugins.h>
3 #ifdef cpPlugins_Interface_QT4
6 #include <QApplication>
14 # define PLUGIN_PREFIX ""
15 # define PLUGIN_EXT "dll"
16 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
18 # define PLUGIN_PREFIX "lib"
19 # define PLUGIN_EXT "so"
20 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
23 #endif // cpPlugins_Interface_QT4
25 // -------------------------------------------------------------------------
26 cpPlugins::Interface::Plugins::
29 m_Application( NULL ),
31 m_LastLoadedPlugin( "" ),
32 m_ActiveFilter( NULL )
34 this->m_Interface = new TInterface( );
37 // -------------------------------------------------------------------------
38 cpPlugins::Interface::Plugins::
41 if( this->m_Interface != NULL )
42 delete this->m_Interface;
45 // -------------------------------------------------------------------------
46 QWidget* cpPlugins::Interface::Plugins::
49 return( this->m_Widget );
52 // -------------------------------------------------------------------------
53 const QWidget* cpPlugins::Interface::Plugins::
56 return( this->m_Widget );
59 // -------------------------------------------------------------------------
60 void cpPlugins::Interface::Plugins::
61 SetWidget( QWidget* widget )
63 this->m_Widget = widget;
66 // -------------------------------------------------------------------------
67 void cpPlugins::Interface::Plugins::
70 #ifdef cpPlugins_Interface_QT4
71 if( this->m_Widget != NULL )
73 QApplication::setOverrideCursor( Qt::WaitCursor );
74 this->m_Widget->setEnabled( false );
77 #endif // cpPlugins_Interface_QT4
80 // -------------------------------------------------------------------------
81 void cpPlugins::Interface::Plugins::
84 #ifdef cpPlugins_Interface_QT4
85 if( this->m_Widget != NULL )
87 QApplication::restoreOverrideCursor( );
88 this->m_Widget->setEnabled( true );
91 #endif // cpPlugins_Interface_QT4
94 // -------------------------------------------------------------------------
95 void cpPlugins::Interface::Plugins::
98 #ifdef cpPlugins_Interface_QT4
99 if( this->m_Widget != NULL )
101 QFileDialog dialog( this->m_Widget );
102 dialog.setFileMode( QFileDialog::ExistingFile );
103 dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) );
104 dialog.setNameFilter( QFileDialog::tr( PLUGIN_REGEX ) );
105 dialog.setDefaultSuffix( QFileDialog::tr( PLUGIN_EXT ) );
106 if( !( dialog.exec( ) ) )
109 std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
110 if( !( this->LoadPlugins( fname ) ) )
111 QMessageBox::critical(
113 QMessageBox::tr( "Ignoring plugin" ),
114 QMessageBox::tr( fname.c_str( ) )
118 #endif // cpPlugins_Interface_QT4
121 // -------------------------------------------------------------------------
122 BaseApplication* cpPlugins::Interface::Plugins::
125 return( this->m_Application );
128 // -------------------------------------------------------------------------
129 const BaseApplication* cpPlugins::Interface::Plugins::
130 GetApplication( ) const
132 return( this->m_Application );
135 // -------------------------------------------------------------------------
136 void cpPlugins::Interface::Plugins::
137 SetApplication( BaseApplication* a )
139 this->m_Application = a;
142 // -------------------------------------------------------------------------
143 bool cpPlugins::Interface::Plugins::
146 // TODO: what to do here?
149 // -------------------------------------------------------------------------
150 bool cpPlugins::Interface::Plugins::
151 LoadPlugins( const std::string& fname )
153 this->BlockWidget( );
155 // Is it already loaded?
157 if( this->m_LoadedPlugins.find( fname ) == this->m_LoadedPlugins.end( ) )
159 // Was it succesfully loaded?
160 ret = this->m_Interface->Load( fname );
162 // Update a simple track
165 this->m_LoadedPlugins.insert( fname );
166 this->m_LastLoadedPlugin = fname;
167 this->_UpdateLoadedPluginsInformation( );
173 this->UnblockWidget( );
177 // -------------------------------------------------------------------------
178 bool cpPlugins::Interface::Plugins::
179 LoadPluginsConfigurationFile( const std::string& fname )
181 // Load file into a char buffer
183 fname.c_str( ), std::ios::in | std::ios::binary | std::ios::ate
188 std::streampos size = in.tellg( );
189 char* buffer = new char[ size ];
190 in.seekg( 0, std::ios::beg );
191 in.read( buffer, size );
195 std::stringstream in_stream( buffer );
199 in_stream.getline( line, 4096 );
200 this->LoadPlugins( line );
208 // -------------------------------------------------------------------------
209 const cpPlugins::Interface::Plugins::
210 TStringContainer& cpPlugins::Interface::Plugins::
211 GetLoadedPlugins( ) const
213 return( this->m_LoadedPlugins );
216 // -------------------------------------------------------------------------
217 void cpPlugins::Interface::Plugins::
218 GetLoadedFilters( TStringContainer& filters ) const
221 auto pIt = this->m_LoadedFilters.begin( );
222 for( ; pIt != this->m_LoadedFilters.end( ); ++pIt )
223 for( auto fIt = pIt->second.begin( ); fIt != pIt->second.end( ); ++fIt )
224 filters.insert( *fIt );
227 // -------------------------------------------------------------------------
228 const cpPlugins::Interface::Plugins::
229 TStringContainer& cpPlugins::Interface::Plugins::
230 GetLoadedFilters( const std::string& plugin ) const
232 static const TStringContainer EMPTY;
233 auto pIt = this->m_LoadedFilters.find( plugin );
234 if( pIt != this->m_LoadedFilters.end( ) )
235 return( pIt->second );
240 // -------------------------------------------------------------------------
241 void cpPlugins::Interface::Plugins::
242 AddInteractor( vtkRenderWindowInteractor* interactor )
244 this->m_Interactors.insert( interactor );
247 // -------------------------------------------------------------------------
248 void cpPlugins::Interface::Plugins::
249 RemoveInteractor( vtkRenderWindowInteractor* interactor )
251 this->m_Interactors.erase( interactor );
254 // -------------------------------------------------------------------------
255 void cpPlugins::Interface::Plugins::
258 this->m_Interactors.clear( );
261 // -------------------------------------------------------------------------
262 #define cpPlugins_Plugins_HasMacro( F ) \
263 bool cpPlugins::Interface::Plugins:: \
266 return( this->m_IOFilters.find( #F ) != this->m_IOFilters.end( ) ); \
269 cpPlugins_Plugins_HasMacro( ImageReader );
270 cpPlugins_Plugins_HasMacro( DicomSeriesReader );
271 cpPlugins_Plugins_HasMacro( MeshReader );
272 cpPlugins_Plugins_HasMacro( ImageWriter );
273 cpPlugins_Plugins_HasMacro( MeshWriter );
275 // -------------------------------------------------------------------------
276 std::string cpPlugins::Interface::Plugins::
277 ReadImage( const std::string& fname, const std::string& parent )
279 std::vector< std::string > fnames( 1, fname );
280 return( this->ReadImage( fnames, parent ) );
283 // -------------------------------------------------------------------------
284 std::string cpPlugins::Interface::Plugins::
286 const std::vector< std::string >& fnames, const std::string& parent
290 auto fIt = this->m_IOFilters.find( "ImageReader" );
291 if( fIt == this->m_IOFilters.end( ) )
293 this->m_ActiveFilter = fIt->second;
296 TParameters* params = this->GetActiveFilterParameters( );
297 params->ClearStringList( "FileNames" );
298 for( auto nIt = fnames.begin( ); nIt != fnames.end( ); ++nIt )
299 params->AddToStringList( "FileNames", *nIt );
302 std::string err = this->UpdateActiveFilter( );
305 #error GET OBJECT NAME
313 // -------------------------------------------------------------------------
314 std::string cpPlugins::Interface::Plugins::
315 ReadImage( const std::string& parent )
319 // -------------------------------------------------------------------------
320 std::string cpPlugins::Interface::Plugins::
321 ReadDicomSeries( const std::string& parent )
325 // -------------------------------------------------------------------------
326 std::string cpPlugins::Interface::Plugins::
328 const std::string& fname, const std::string& parent
333 // -------------------------------------------------------------------------
334 std::string cpPlugins::Interface::Plugins::
335 ReadMesh( const std::string& parent )
339 // -------------------------------------------------------------------------
340 std::string cpPlugins::Interface::Plugins::
342 const std::string& fname, const std::string& name
347 // -------------------------------------------------------------------------
348 std::string cpPlugins::Interface::Plugins::
349 WriteDataObject( const std::string& name )
353 // -------------------------------------------------------------------------
354 void cpPlugins::Interface::Plugins::
359 // -------------------------------------------------------------------------
360 void cpPlugins::Interface::Plugins::
361 DeleteDataObject( const std::string& name )
365 // -------------------------------------------------------------------------
366 void cpPlugins::Interface::Plugins::
367 GetDataObjects( TStringContainer& names )
371 // -------------------------------------------------------------------------
372 std::string cpPlugins::Interface::Plugins::
373 GetParent( const std::string& name ) const
377 // -------------------------------------------------------------------------
378 void cpPlugins::Interface::Plugins::
380 TStringContainer& names, const std::string& name
385 // -------------------------------------------------------------------------
386 void cpPlugins::Interface::Plugins::
387 GetRoots( TStringContainer& names ) const
391 // -------------------------------------------------------------------------
392 bool cpPlugins::Interface::Plugins::
393 ActivateFilter( const std::string& name )
397 // -------------------------------------------------------------------------
398 void cpPlugins::Interface::Plugins::
403 // -------------------------------------------------------------------------
404 bool cpPlugins::Interface::Plugins::
405 HasActiveFilter( ) const
409 // -------------------------------------------------------------------------
410 bool cpPlugins::Interface::Plugins::
411 IsActiveFilterInteractive( ) const
415 // -------------------------------------------------------------------------
416 void cpPlugins::Interface::Plugins::
417 GetActiveFilterInputsNames( TStringContainer& names ) const
421 // -------------------------------------------------------------------------
422 void cpPlugins::Interface::Plugins::
423 GetActiveFilterOutputsNames( TStringContainer& names ) const
427 // -------------------------------------------------------------------------
428 bool cpPlugins::Interface::Plugins::
429 ConnectInputInActiveFilter(
430 const std::string& object_name, const std::string& input_name
435 // -------------------------------------------------------------------------
436 bool cpPlugins::Interface::Plugins::
437 SetOutputNameInActiveFilter(
438 const std::string& new_object_name, const std::string& output_name
443 // -------------------------------------------------------------------------
444 TParameters* cpPlugins::Interface::Plugins::
445 GetActiveFilterParameters( )
449 // -------------------------------------------------------------------------
450 const TParameters* cpPlugins::Interface::Plugins::
451 GetActiveFilterParameters( ) const
455 // -------------------------------------------------------------------------
456 TProcessObject::DialogResult cpPlugins::Interface::Plugins::
457 ConfigureActiveFilter( )
461 // -------------------------------------------------------------------------
462 std::string cpPlugins::Interface::Plugins::
463 UpdateActiveFilter( )
467 // -------------------------------------------------------------------------
468 void cpPlugins::Interface::Plugins::
469 _UpdateLoadedPluginsInformation( )
473 // -------------------------------------------------------------------------
474 bool cpPlugins::Interface::Plugins::
475 _InsertNewData( TDataObject* dobj, const std::string& parent )
483 BaseApplication* m_Application;
486 TInterface m_Interface;
487 TStringContainer m_LoadedPlugins;
488 std::string m_LastLoadedPlugin;
491 std::map< std::string, TProcessObject::Pointer > m_IOFilters;
492 TProcessObject::Pointer m_ActiveFilter;
493 std::map< std::string, std::string > m_ActiveFilterOutputs;
494 std::map< std::string, TStringContainer > m_LoadedFilters;
496 // Loaded data objects
497 typedef std::pair< std::string, TDataObject::Pointer > _TTreeNode;
498 std::map< std::string, _TTreeNode > m_DataObjects;
500 // Associated interactors
501 std::set< vtkRenderWindowInteractor* > m_Interactors;
586 #include <cpPlugins/Interface/Config.h>
591 #ifdef cpPlugins_Interface_QT4
593 #include <QApplication>
594 #include <QFileDialog>
596 #include <QMessageBox>
600 # define PLUGIN_PREFIX ""
601 # define PLUGIN_EXT "dll"
602 # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
604 # define PLUGIN_PREFIX "lib"
605 # define PLUGIN_EXT "so"
606 # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
609 #endif // cpPlugins_Interface_QT4
614 // -------------------------------------------------------------------------
615 void cpPlugins::Interface::Plugins::
616 AddInteractor( vtkRenderWindowInteractor* interactor )
618 this->m_Interactors.insert( interactor );
621 // -------------------------------------------------------------------------
622 void cpPlugins::Interface::Plugins::
623 RemoveInteractor( vtkRenderWindowInteractor* interactor )
625 this->m_Interactors.erase( interactor );
628 // -------------------------------------------------------------------------
629 void cpPlugins::Interface::Plugins::
632 this->m_Interactors.clear( );
635 // -------------------------------------------------------------------------
636 bool cpPlugins::Interface::Plugins::
637 HasImageReader( ) const
639 return( this->m_ImageReader.IsNotNull( ) );
642 // -------------------------------------------------------------------------
643 bool cpPlugins::Interface::Plugins::
644 HasDicomSeriesReader( ) const
646 return( this->m_DicomSeriesReader.IsNotNull( ) );
649 // -------------------------------------------------------------------------
650 bool cpPlugins::Interface::Plugins::
651 HasMeshReader( ) const
653 return( this->m_MeshReader.IsNotNull( ) );
656 // -------------------------------------------------------------------------
657 bool cpPlugins::Interface::Plugins::
658 HasImageWriter( ) const
660 return( this->m_ImageWriter.IsNotNull( ) );
663 // -------------------------------------------------------------------------
664 bool cpPlugins::Interface::Plugins::
665 HasMeshWriter( ) const
667 return( this->m_MeshWriter.IsNotNull( ) );
670 // -------------------------------------------------------------------------
671 std::string cpPlugins::Interface::Plugins::
672 ReadImage( const std::string& fname, const std::string& parent )
674 std::vector< std::string > fnames;
675 fnames.push_back( fname );
676 return( this->ReadImage( fnames, parent ) );
679 // -------------------------------------------------------------------------
680 std::string cpPlugins::Interface::Plugins::
682 const std::vector< std::string >& fnames, const std::string& parent
685 // Check if object exists
686 if( this->m_ImageReader.IsNull( ) )
690 TParameters* params = this->m_ImageReader->GetParameters( );
691 params->ClearStringList( "FileNames" );
692 auto i = fnames.begin( );
693 for( ; i != fnames.end( ); ++i )
694 params->AddToStringList( "FileNames", *i );
697 this->BlockWidget( );
698 std::string err = this->m_ImageReader->Update( );
699 this->UnblockWidget( );
701 // Get result, if any
704 TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
705 this->m_ImageReader->DisconnectOutputs( );
707 // Add newly added data
708 if( this->_InsertNewData( image, parent ) )
709 return( image->GetName( ) );
715 #ifdef cpPlugins_Interface_QT4
716 if( this->m_Widget != NULL )
717 QMessageBox::critical(
719 QMessageBox::tr( "Error reading image." ),
720 QMessageBox::tr( err.c_str( ) )
722 #else // cpPlugins_Interface_QT4
723 std::cerr << "Error reading image: " << err << std::endl;
724 #endif // cpPlugins_Interface_QT4
730 // -------------------------------------------------------------------------
731 std::string cpPlugins::Interface::Plugins::
732 ReadImage( const std::string& parent )
734 // Check if object exists
735 if( this->m_ImageReader.IsNull( ) )
739 TProcessObject::DialogResult dret =
740 this->m_ImageReader->ExecConfigurationDialog( this->m_Widget );
741 if( dret == TProcessObject::DialogResult_Cancel )
745 this->BlockWidget( );
746 std::string err = this->m_ImageReader->Update( );
747 this->UnblockWidget( );
749 // Get result, if any
752 TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
753 this->m_ImageReader->DisconnectOutputs( );
755 // Add newly added data
756 if( this->_InsertNewData( image, parent ) )
757 return( image->GetName( ) );
763 #ifdef cpPlugins_Interface_QT4
764 if( this->m_Widget != NULL )
765 QMessageBox::critical(
767 QMessageBox::tr( "Error reading image." ),
768 QMessageBox::tr( err.c_str( ) )
770 #else // cpPlugins_Interface_QT4
771 std::cerr << "Error reading image: " << err << std::endl;
772 #endif // cpPlugins_Interface_QT4
778 // -------------------------------------------------------------------------
779 std::string cpPlugins::Interface::Plugins::
780 ReadDicomSeries( const std::string& parent )
782 // Check if object exists
783 if( this->m_DicomSeriesReader.IsNull( ) )
787 TProcessObject::DialogResult dret =
788 this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget );
789 if( dret == TProcessObject::DialogResult_Cancel )
793 this->BlockWidget( );
794 std::string err = this->m_DicomSeriesReader->Update( );
795 this->UnblockWidget( );
797 // Get result, if any
801 this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
802 this->m_DicomSeriesReader->DisconnectOutputs( );
804 // Add newly added data
805 if( this->_InsertNewData( image, parent ) )
806 return( image->GetName( ) );
812 #ifdef cpPlugins_Interface_QT4
813 if( this->m_Widget != NULL )
814 QMessageBox::critical(
816 QMessageBox::tr( "Error reading image." ),
817 QMessageBox::tr( err.c_str( ) )
819 #else // cpPlugins_Interface_QT4
820 std::cerr << "Error reading image: " << err << std::endl;
821 #endif // cpPlugins_Interface_QT4
827 // -------------------------------------------------------------------------
828 std::string cpPlugins::Interface::Plugins::
829 ReadMesh( const std::string& fname, const std::string& parent )
831 // Check if object exists
832 if( this->m_MeshReader.IsNull( ) )
836 TParameters* params = this->m_MeshReader->GetParameters( );
837 params->SetString( "FileName", fname );
840 this->BlockWidget( );
841 std::string err = this->m_MeshReader->Update( );
842 this->UnblockWidget( );
844 // Get result, if any
847 TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
848 this->m_MeshReader->DisconnectOutputs( );
850 // Add newly added data
851 if( this->_InsertNewData( mesh, parent ) )
852 return( mesh->GetName( ) );
858 #ifdef cpPlugins_Interface_QT4
859 if( this->m_Widget != NULL )
860 QMessageBox::critical(
862 QMessageBox::tr( "Error reading mesh." ),
863 QMessageBox::tr( err.c_str( ) )
865 #else // cpPlugins_Interface_QT4
866 std::cerr << "Error reading mesh: " << err << std::endl;
867 #endif // cpPlugins_Interface_QT4
873 // -------------------------------------------------------------------------
874 std::string cpPlugins::Interface::Plugins::
875 ReadMesh( const std::string& parent )
877 // Check if object exists
878 if( this->m_MeshReader.IsNull( ) )
882 TProcessObject::DialogResult dret =
883 this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
884 if( dret == TProcessObject::DialogResult_Cancel )
888 this->BlockWidget( );
889 std::string err = this->m_MeshReader->Update( );
890 this->UnblockWidget( );
892 // Get result, if any
895 TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
896 this->m_MeshReader->DisconnectOutputs( );
898 // Add newly added data
899 if( this->_InsertNewData( mesh, parent ) )
900 return( mesh->GetName( ) );
906 #ifdef cpPlugins_Interface_QT4
907 if( this->m_Widget != NULL )
908 QMessageBox::critical(
910 QMessageBox::tr( "Error reading mesh." ),
911 QMessageBox::tr( err.c_str( ) )
913 #else // cpPlugins_Interface_QT4
914 std::cerr << "Error reading mesh: " << err << std::endl;
915 #endif // cpPlugins_Interface_QT4
921 // -------------------------------------------------------------------------
922 bool cpPlugins::Interface::Plugins::
923 WriteImage( const std::string& fname, const std::string& name )
925 // Check if objects exist
926 if( this->m_ImageWriter.IsNull( ) )
928 TImage* image = this->GetImage( name );
933 this->m_ImageWriter->GetParameters( )->SetString( "FileName", fname );
934 this->m_ImageWriter->SetInput( "Input", image );
937 this->BlockWidget( );
938 std::string err = this->m_ImageWriter->Update( );
939 this->UnblockWidget( );
941 // Get result, if any
944 #ifdef cpPlugins_Interface_QT4
945 if( this->m_Widget != NULL )
946 QMessageBox::critical(
948 QMessageBox::tr( "Error reading mesh." ),
949 QMessageBox::tr( err.c_str( ) )
951 #else // cpPlugins_Interface_QT4
952 std::cerr << "Error reading mesh: " << err << std::endl;
953 #endif // cpPlugins_Interface_QT4
960 // -------------------------------------------------------------------------
961 bool cpPlugins::Interface::Plugins::
962 WriteImage( const std::string& name )
964 // Check if objects exist
965 if( this->m_ImageWriter.IsNull( ) )
967 TImage* image = this->GetImage( name );
972 TProcessObject::DialogResult dret =
973 this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget );
974 if( dret == TProcessObject::DialogResult_Cancel )
976 this->m_ImageWriter->SetInput( "Input", image );
979 this->BlockWidget( );
980 std::string err = this->m_ImageWriter->Update( );
981 this->UnblockWidget( );
983 // Get result, if any
986 #ifdef cpPlugins_Interface_QT4
987 if( this->m_Widget != NULL )
988 QMessageBox::critical(
990 QMessageBox::tr( "Error reading mesh." ),
991 QMessageBox::tr( err.c_str( ) )
993 #else // cpPlugins_Interface_QT4
994 std::cerr << "Error reading mesh: " << err << std::endl;
995 #endif // cpPlugins_Interface_QT4
1002 // -------------------------------------------------------------------------
1003 bool cpPlugins::Interface::Plugins::
1004 WriteMesh( const std::string& fname, const std::string& name )
1006 // Check if objects exist
1007 if( this->m_MeshWriter.IsNull( ) )
1009 TMesh* mesh = this->GetMesh( name );
1014 this->m_MeshWriter->GetParameters( )->SetString( "FileName", fname );
1015 this->m_MeshWriter->SetInput( "Input", mesh );
1018 this->BlockWidget( );
1019 std::string err = this->m_MeshWriter->Update( );
1020 this->UnblockWidget( );
1022 // Get result, if any
1025 #ifdef cpPlugins_Interface_QT4
1026 if( this->m_Widget != NULL )
1027 QMessageBox::critical(
1029 QMessageBox::tr( "Error reading mesh." ),
1030 QMessageBox::tr( err.c_str( ) )
1032 #else // cpPlugins_Interface_QT4
1033 std::cerr << "Error reading mesh: " << err << std::endl;
1034 #endif // cpPlugins_Interface_QT4
1041 // -------------------------------------------------------------------------
1042 bool cpPlugins::Interface::Plugins::
1043 WriteMesh( const std::string& name )
1045 // Check if objects exist
1046 if( this->m_MeshWriter.IsNull( ) )
1048 TMesh* mesh = this->GetMesh( name );
1053 TProcessObject::DialogResult dret =
1054 this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget );
1055 if( dret == TProcessObject::DialogResult_Cancel )
1057 this->m_MeshWriter->SetInput( "Input", mesh );
1060 this->BlockWidget( );
1061 std::string err = this->m_MeshWriter->Update( );
1062 this->UnblockWidget( );
1064 // Get result, if any
1067 #ifdef cpPlugins_Interface_QT4
1068 if( this->m_Widget != NULL )
1069 QMessageBox::critical(
1071 QMessageBox::tr( "Error reading mesh." ),
1072 QMessageBox::tr( err.c_str( ) )
1074 #else // cpPlugins_Interface_QT4
1075 std::cerr << "Error reading mesh: " << err << std::endl;
1076 #endif // cpPlugins_Interface_QT4
1083 // -------------------------------------------------------------------------
1084 void cpPlugins::Interface::Plugins::
1087 this->m_Objects.clear( );
1090 // -------------------------------------------------------------------------
1091 void cpPlugins::Interface::Plugins::
1092 DeleteDataObject( const std::string& name )
1094 auto i = this->m_Objects.find( name );
1095 if( i != this->m_Objects.end( ) )
1097 this->m_Objects.erase( i );
1100 std::vector< std::string > children;
1101 for( i = this->m_Objects.begin( ); i != this->m_Objects.end( ); ++i )
1102 if( i->second.first == name )
1103 children.push_back( i->first );
1106 auto c = children.begin( );
1107 for( ; c != children.end( ); ++c )
1108 this->DeleteDataObject( *c );
1113 // -------------------------------------------------------------------------
1114 std::string cpPlugins::Interface::Plugins::
1115 GetParent( const std::string& name ) const
1117 auto i = this->m_Objects.find( name );
1118 if( i != this->m_Objects.end( ) )
1119 return( i->second.first );
1124 // -------------------------------------------------------------------------
1125 const cpPlugins::Interface::Plugins::
1126 TTree& cpPlugins::Interface::Plugins::
1127 GetDataObjects( ) const
1129 return( this->m_Objects );
1132 // -------------------------------------------------------------------------
1133 cpPlugins::Interface::Plugins::
1134 TDataObject* cpPlugins::Interface::Plugins::
1135 GetDataObject( const std::string& name )
1137 auto i = this->m_Objects.find( name );
1138 if( i != this->m_Objects.end( ) )
1139 return( dynamic_cast< TDataObject* >( i->second.second.GetPointer( ) ) );
1144 // -------------------------------------------------------------------------
1145 const cpPlugins::Interface::Plugins::
1146 TDataObject* cpPlugins::Interface::Plugins::
1147 GetDataObject( const std::string& name ) const
1149 auto i = this->m_Objects.find( name );
1150 if( i != this->m_Objects.end( ) )
1152 dynamic_cast< const TDataObject* >( i->second.second.GetPointer( ) )
1158 // -------------------------------------------------------------------------
1159 cpPlugins::Interface::Plugins::
1160 TImage* cpPlugins::Interface::Plugins::
1161 GetImage( const std::string& name )
1163 auto i = this->m_Objects.find( name );
1164 if( i != this->m_Objects.end( ) )
1165 return( dynamic_cast< TImage* >( i->second.second.GetPointer( ) ) );
1170 // -------------------------------------------------------------------------
1171 const cpPlugins::Interface::Plugins::
1172 TImage* cpPlugins::Interface::Plugins::
1173 GetImage( const std::string& name ) const
1175 auto i = this->m_Objects.find( name );
1176 if( i != this->m_Objects.end( ) )
1177 return( dynamic_cast< const TImage* >( i->second.second.GetPointer( ) ) );
1182 // -------------------------------------------------------------------------
1183 cpPlugins::Interface::Plugins::
1184 TMesh* cpPlugins::Interface::Plugins::
1185 GetMesh( const std::string& name )
1187 auto i = this->m_Objects.find( name );
1188 if( i != this->m_Objects.end( ) )
1189 return( dynamic_cast< TMesh* >( i->second.second.GetPointer( ) ) );
1194 // -------------------------------------------------------------------------
1195 const cpPlugins::Interface::Plugins::
1196 TMesh* cpPlugins::Interface::Plugins::
1197 GetMesh( const std::string& name ) const
1199 auto i = this->m_Objects.find( name );
1200 if( i != this->m_Objects.end( ) )
1201 return( dynamic_cast< const TMesh* >( i->second.second.GetPointer( ) ) );
1206 // -------------------------------------------------------------------------
1207 bool cpPlugins::Interface::Plugins::
1208 ActivateFilter( const std::string& name )
1210 this->m_ActiveFilter = this->m_Interface.CreateProcessObject( name );
1211 if( this->m_ActiveFilter.IsNotNull( ) )
1213 this->m_ActiveFilter->SetPlugins( this );
1214 this->m_ActiveFilterOutputs.clear( );
1215 auto i = this->m_Interactors.begin( );
1216 for( ; i != this->m_Interactors.end( ); ++i )
1217 this->m_ActiveFilter->AddInteractor( *i );
1224 // -------------------------------------------------------------------------
1225 void cpPlugins::Interface::Plugins::
1228 this->m_ActiveFilter = NULL;
1231 // -------------------------------------------------------------------------
1232 bool cpPlugins::Interface::Plugins::
1233 HasActiveFilter( ) const
1235 return( this->m_ActiveFilter.IsNotNull( ) );
1238 // -------------------------------------------------------------------------
1239 bool cpPlugins::Interface::Plugins::
1240 IsActiveFilterInteractive( ) const
1242 if( this->m_ActiveFilter.IsNotNull( ) )
1243 return( this->m_ActiveFilter->IsInteractive( ) );
1248 // -------------------------------------------------------------------------
1249 unsigned int cpPlugins::Interface::Plugins::
1250 GetNumberOfInputsInActiveFilter( ) const
1252 if( this->m_ActiveFilter.IsNotNull( ) )
1253 return( this->m_ActiveFilter->GetNumberOfInputs( ) );
1258 // -------------------------------------------------------------------------
1259 unsigned int cpPlugins::Interface::Plugins::
1260 GetNumberOfOutputsInActiveFilter( ) const
1262 if( this->m_ActiveFilter.IsNotNull( ) )
1263 return( this->m_ActiveFilter->GetNumberOfOutputs( ) );
1268 // -------------------------------------------------------------------------
1269 std::vector< std::string > cpPlugins::Interface::Plugins::
1270 GetActiveFilterInputsNames( ) const
1272 if( this->m_ActiveFilter.IsNotNull( ) )
1273 return( this->m_ActiveFilter->GetInputsNames( ) );
1275 return( std::vector< std::string >( ) );
1278 // -------------------------------------------------------------------------
1279 std::vector< std::string > cpPlugins::Interface::Plugins::
1280 GetActiveFilterOutputsNames( ) const
1282 if( this->m_ActiveFilter.IsNotNull( ) )
1283 return( this->m_ActiveFilter->GetOutputsNames( ) );
1285 return( std::vector< std::string >( ) );
1288 // -------------------------------------------------------------------------
1289 void cpPlugins::Interface::Plugins::
1290 ConnectInputInActiveFilter(
1291 const std::string& object_name, const std::string& input
1294 if( this->m_ActiveFilter.IsNotNull( ) )
1296 TDataObject* dobj = this->GetDataObject( object_name );
1298 this->m_ActiveFilter->SetInput( input, dobj );
1303 // -------------------------------------------------------------------------
1304 void cpPlugins::Interface::Plugins::
1305 SetOutputNameInActiveFilter(
1306 const std::string& new_name, const std::string& output
1309 this->m_ActiveFilterOutputs[ output ] = new_name;
1312 // -------------------------------------------------------------------------
1313 cpPlugins::Interface::Plugins::
1314 TParameters* cpPlugins::Interface::Plugins::
1315 GetActiveFilterParameters( )
1317 if( this->m_ActiveFilter.IsNotNull( ) )
1318 return( this->m_ActiveFilter->GetParameters( ) );
1323 // -------------------------------------------------------------------------
1324 const cpPlugins::Interface::Plugins::
1325 TParameters* cpPlugins::Interface::Plugins::
1326 GetActiveFilterParameters( ) const
1328 if( this->m_ActiveFilter.IsNotNull( ) )
1329 return( this->m_ActiveFilter->GetParameters( ) );
1334 // -------------------------------------------------------------------------
1335 cpPlugins::Interface::Plugins::
1336 TProcessObject::DialogResult cpPlugins::Interface::Plugins::
1337 ConfigureActiveFilter( )
1339 if( this->m_ActiveFilter.IsNotNull( ) )
1340 return( this->m_ActiveFilter->ExecConfigurationDialog( this->m_Widget ) );
1342 return( TProcessObject::DialogResult_Cancel );
1345 // -------------------------------------------------------------------------
1346 std::string cpPlugins::Interface::Plugins::
1347 UpdateActiveFilter( std::vector< std::string >& outputs )
1350 this->BlockWidget( );
1351 std::string err = this->m_ActiveFilter->Update( );
1352 this->UnblockWidget( );
1354 // Associate outputs
1358 std::string parent = "";
1359 if( this->GetNumberOfInputsInActiveFilter( ) > 0 )
1361 std::string input = this->m_ActiveFilter->GetInputsNames( )[ 0 ];
1363 this->m_ActiveFilter->GetInput< TDataObject >( input )->GetName( );
1367 auto i = this->m_ActiveFilterOutputs.begin( );
1368 for( ; i != this->m_ActiveFilterOutputs.end( ); ++i )
1371 this->m_ActiveFilter->GetOutput< TDataObject >( i->first );
1372 out->SetName( i->second );
1373 outputs.push_back( out->GetName( ) );
1374 this->_InsertNewData( out, parent );
1382 // -------------------------------------------------------------------------
1383 void cpPlugins::Interface::Plugins::
1384 _UpdateLoadedPluginsInformation( )
1386 typedef TInterface::TClasses _C;
1388 this->m_Filters.clear( );
1389 _C& classes = this->m_Interface.GetClasses( );
1390 for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i )
1392 TProcessObject::Pointer o =
1393 this->m_Interface.CreateProcessObject( i->first );
1394 std::string name = o->GetClassName( );
1395 std::string category = o->GetClassCategory( );
1396 if( category == "ImageReader" )
1397 this->m_ImageReader = o;
1398 else if( category == "ImageWriter" )
1399 this->m_ImageWriter = o;
1400 else if( category == "MeshReader" )
1401 this->m_MeshReader = o;
1402 else if( category == "MeshWriter" )
1403 this->m_MeshWriter = o;
1404 else if( category == "DicomSeriesReader" )
1405 this->m_DicomSeriesReader = o;
1407 this->m_Filters[ category ].insert( name );
1412 // -------------------------------------------------------------------------
1413 bool cpPlugins::Interface::Plugins::
1414 _InsertNewData( TDataObject* dobj, const std::string& parent )
1416 std::string name = dobj->GetName( );
1417 auto i = this->m_Objects.find( name );
1419 if( i == this->m_Objects.end( ) )
1423 auto j = this->m_Objects.find( parent );
1424 if( j != this->m_Objects.end( ) )
1425 this->m_Objects[ name ] = TTreeNode( parent, dobj );
1430 this->m_Objects[ name ] = TTreeNode( "", dobj );
1433 i->second.second = dobj;
1437 #ifdef cpPlugins_Interface_QT4
1438 if( this->m_Widget != NULL )
1439 QMessageBox::critical(
1441 QMessageBox::tr( "Error inserting data." ),
1442 QMessageBox::tr( "Given parent does not exists." )
1444 #else // cpPlugins_Interface_QT4
1446 << "Error inserting data: Given parent does not exists."
1448 #endif // cpPlugins_Interface_QT4