#include #ifdef cpPlugins_Interface_QT4 #ifdef _WIN32 # define PLUGIN_PREFIX "" # define PLUGIN_EXT "dll" # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)" #else // Linux # define PLUGIN_PREFIX "lib" # define PLUGIN_EXT "so" # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)" #endif // _WIN32 #include #include #include #include // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWindow:: BaseMPRWindow( QWidget* parent ) : cpExtensions::QT::QuadSplitter( parent ), m_LastLoadedPlugin( "." ) { // Configure splitter this->m_XVTK = new QVTKWidget( this ); this->m_YVTK = new QVTKWidget( this ); this->m_ZVTK = new QVTKWidget( this ); this->m_WVTK = new QVTKWidget( this ); this->addWidgets( this->m_XVTK, this->m_YVTK, this->m_ZVTK, this->m_WVTK ); // Create and associate vtk renderers this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); this->m_MPRObjects->SetRenderWindows( this->m_XVTK->GetRenderWindow( ), this->m_YVTK->GetRenderWindow( ), this->m_ZVTK->GetRenderWindow( ), this->m_WVTK->GetRenderWindow( ) ); } // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWindow:: ~BaseMPRWindow( ) { if( this->m_WVTK != NULL ) delete this->m_WVTK; if( this->m_ZVTK != NULL ) delete this->m_ZVTK; if( this->m_YVTK != NULL ) delete this->m_YVTK; if( this->m_XVTK != NULL ) delete this->m_XVTK; } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: DialogLoadPlugins( ) { // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFile ); dialog.setDirectory( this->m_LastLoadedPlugin.c_str( ) ); dialog.setNameFilter( tr( PLUGIN_REGEX ) ); dialog.setDefaultSuffix( tr( PLUGIN_EXT ) ); if( !( dialog.exec( ) ) ) return; std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); if( !( this->LoadPlugins( fname ) ) ) QMessageBox::critical( this, tr( "Ignoring plugin" ), tr( fname.c_str( ) ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: AssociatePluginsToMenu( QMenu* menu, QObject* obj, const char* slot ) { std::map< std::string, std::set< std::string > >::const_iterator i; std::set< std::string >::const_iterator j; menu->clear( ); for( i = this->m_Filters.begin( ); i != this->m_Filters.end( ); i++ ) { QMenu* newMenu = menu->addMenu( i->first.c_str( ) ); for( j = i->second.begin( ); j != i->second.end( ); ++j ) { QAction* a = newMenu->addAction( j->c_str( ) ); QObject::connect( a, SIGNAL( triggered( ) ), obj, slot ); } // rof } // rof } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWindow:: LoadPlugins( const std::string& fname ) { this->Block( ); // Is it already loaded? if( this->m_LoadedPlugins.find( fname ) != this->m_LoadedPlugins.end( ) ) { this->Unblock( ); return( true ); } // fi // Was it succesfully loaded? if( !( this->m_Interface.Load( fname ) ) ) { this->Unblock( ); return( false ); } // fi // Update a simple track this->m_LoadedPlugins.insert( fname ); this->m_LastLoadedPlugin = fname; this->_UpdatePlugins( ); this->Unblock( ); return( true ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: LoadPlugins( ) { // Load file into a char buffer std::ifstream in( "Plugins.cfg", std::ios::in | std::ios::binary | std::ios::ate ); if( !in.is_open( ) ) return; std::streampos size = in.tellg( ); char* buffer = new char[ size ]; in.seekg( 0, std::ios::beg ); in.read( buffer, size ); in.close( ); // Read stream std::stringstream in_stream( buffer ); while( in_stream ) { char line[ 2048 ]; in_stream.getline( line, 2048 ); this->LoadPlugins( line ); } // elihw // Finish delete buffer; } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::BaseMPRWindow:: LoadImage( ) { std::string msg = ""; std::string ret = ""; if( this->m_ImageReader.IsNull( ) ) msg = "No valid image reader. Please load a valid plugin file."; if( this->m_ImageReader->ExecConfigurationDialog( this ) ) { this->Block( ); msg = this->m_ImageReader->Update( ); if( msg == "" ) { TImage::Pointer image = this->m_ImageReader->GetOutput< TImage >( "Output" ); if( this->m_Images.size( ) == 0 ) ret = image->GetName( ); else ret = "Segmentation"; this->m_Images[ ret ] = image; this->m_ImageReader->DisconnectOutputs( ); this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" ); vtkImageData* vtk_id = image->GetVTK< vtkImageData >( ); if( vtk_id != NULL ) { this->m_MPRObjects->AddImage( vtk_id ); /* MementoState(m_state, this->m_Image); this->m_state++; */ } else msg = "Read image does not have a valid VTK converter."; } else ret = ""; } // fi // Show errors and return this->Unblock( ); if( msg != "" ) QMessageBox::critical( this, tr( "Error reading image." ), tr( msg.c_str( ) ) ); return( ret ); } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::BaseMPRWindow:: LoadMesh( ) { return( "" ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: ExecuteFilter( const std::string& name, const std::string& input_id, const std::string& output_id ) { TProcessObject::Pointer filter = this->m_Interface.CreateProcessObject( name ); std::string category = filter->GetClassCategory( ); if( category == "ImageToBinaryImageFilter" ) { TImages::iterator iIt = this->m_Images.find( input_id ); if( iIt != this->m_Images.end( ) ) { filter->SetInput( "Input", this->m_Images[ input_id ] ); bool dlg_ok = filter->ExecConfigurationDialog( NULL ); if( !dlg_ok ) return; std::string err = filter->Update( ); std::cout << "ERR: " << err << std::endl; if( err == "" ) { this->m_Images[ "Segmentation" ] = filter->GetOutput< TImage >( "Output" ); filter->DisconnectOutputs( ); vtkImageData* vtk_id = this->m_Images[ "Segmentation" ]->GetVTK< vtkImageData >( ); if( vtk_id != NULL ) this->m_MPRObjects->AddImage( vtk_id ); } else QMessageBox::critical( this, tr( "Error with plugin" ), tr( err.c_str( ) ) ); } // fi } // fi } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: AddImage( const std::string& name, TImage* image ) { this->m_Images[ name ] = image; vtkImageData* vtk_id = this->m_Images[ name ]->GetVTK< vtkImageData >( ); if( vtk_id != NULL ) this->m_MPRObjects->AddImage( vtk_id ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: ClearAll( ) { this->m_MPRObjects->ClearAll( ); this->m_Images.clear( ); this->m_Meshes.clear( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWindow:: _UpdatePlugins( ) { typedef TInterface::TClasses _C; this->m_Filters.clear( ); _C& classes = this->m_Interface.GetClasses( ); for( _C::const_iterator i = classes.begin( ); i != classes.end( ); ++i ) { TProcessObject::Pointer o = this->m_Interface.CreateProcessObject( i->first ); std::string name = o->GetClassName( ); std::string category = o->GetClassCategory( ); if( category == "ImageReader" ) this->m_ImageReader = o; else if( category == "ImageWriter" ) this->m_ImageWriter = o; else if( category == "MeshReader" ) this->m_MeshReader = o; else if( category == "MeshWriter" ) this->m_MeshWriter = o; else this->m_Filters[ category ].insert( name ); /* if( category == "ImageReader" ) this->m_ImageReaderClass = name; else if( category == "ImageWriter" ) this->m_ImageWriterClass = name; else if( category == "MeshReader" ) this->m_MeshReaderClass = name; else if( category == "MeshWriter" ) this->m_MeshWriterClass = name; else if( category == "MeshToMeshFilter" ) { if( name.find_last_of( "Cutter" ) != std::string::npos ) this->m_MeshCutterClass = name; } else if( category == "ImageToImageFilter" ) { QAction* action = this->m_UI->MenuImageToImage->addAction( QString( name.c_str( ) ) ); QObject::connect( action, SIGNAL( triggered( ) ), this, SLOT( _triggered_actionImageToImage( ) ) ); } else if( category == "ImageToMeshFilter" ) { QAction* action = this->m_UI->MenuImageToMesh->addAction( QString( name.c_str( ) ) ); QObject::connect( action, SIGNAL( triggered( ) ), this, SLOT( _triggered_actionImageToMesh( ) ) ); } // fi */ } // rof } #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$