#include "ImageMPR.h" #include "ui_ImageMPR.h" #include #include #include #ifdef _WIN32 # define PLUGIN_EXT "dll" # define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)" #else # define PLUGIN_EXT "so" # define PLUGIN_REGEX "Plugins file (*.so);;All files (*)" #endif // _WIN32 // ------------------------------------------------------------------------- ImageMPR::ImageMPR( QWidget* parent ) : QMainWindow( parent ), m_UI( new Ui::ImageMPR ), m_InputImage( NULL ) { this->m_UI->setupUi( this ); // Create and associate renderers this->m_MPR = new TMPR( this->m_UI->m_XPlaneVTK->GetRenderWindow( ), this->m_UI->m_YPlaneVTK->GetRenderWindow( ), this->m_UI->m_ZPlaneVTK->GetRenderWindow( ), this->m_UI->m_3DVTK->GetRenderWindow( ) ); // signals <-> slots QObject::connect( this->m_UI->actionOpenPlugins, SIGNAL( triggered( ) ), this, SLOT( _triggered_actionOpenPlugins( ) ) ); QObject::connect( this->m_UI->actionOpenInputImage, SIGNAL( triggered( ) ), this, SLOT( _triggered_actionOpenInputImage( ) ) ); // Start: load all disponible plugins this->_triggered_actionOpenPlugins( ); } // ------------------------------------------------------------------------- ImageMPR:: ~ImageMPR( ) { // Close all connections this->m_Plugins.UnloadAll( ); // Delete objects delete this->m_UI; delete this->m_MPR; } // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionOpenPlugins( ) { // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFile ); dialog.setDirectory( "." ); dialog.setNameFilter( tr( PLUGIN_REGEX ) ); dialog.setDefaultSuffix( tr( PLUGIN_EXT ) ); if( !( dialog.exec( ) ) ) return; std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); this->m_Plugins.UnloadAll( ); if( !( this->m_Plugins.Load( fname ) ) ) { QMessageBox::critical( this, tr( "Ignoring plugin" ), tr( fname.c_str( ) ) ); this->m_Plugins.UnloadAll( ); return; } // fi this->m_BaseClasses[ "ImageReader" ] = "cpPlugins::Plugins::ImageReader"; this->m_BaseClasses[ "ImageSeriesReader" ] = "cpPlugins::Plugins::ImageSeriesReader"; } // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionOpenInputImage( ) { // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFiles ); dialog.setDirectory( tr( "." ) ); dialog.setNameFilter( tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) ); dialog.setDefaultSuffix( tr( "mhd" ) ); if( !( dialog.exec( ) ) ) return; this->m_InputImage = NULL; unsigned int nFiles = dialog.selectedFiles( ).size( ); if( nFiles == 1 ) { std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); TPlugin::Pointer reader = this->m_Plugins.CreateProcessObject( this->m_BaseClasses[ "ImageReader" ] ); TParameters reader_params = reader->GetDefaultParameters( ); reader_params.SetValueAsString( "FileName", fname ); reader_params.SetValueAsString( "PixelType", "short" ); reader_params.SetValueAsUint( "ImageDimension", 3 ); reader_params.SetValueAsUint( "IsColorImage", 0 ); reader->SetParameters( reader_params ); std::string err = reader->Update( ); if( err == "" ) { this->m_InputImage = dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) ); reader->DisconnectOutputs( ); } else QMessageBox::critical( this, tr( "Error reading single image" ), tr( err.c_str( ) ) ); } else if( nFiles > 1 ) { /* TODO if( this->m_ImageSeriesReaderClassName == "" ) { QMessageBox::critical( this, tr( "No plugin to read an image series found!" ), tr( "No plugin to read an image series found!" ) ); return( ret ); } // fi std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); this->m_LastOpenedFile = fname; return( ret ); */ } // fi if( this->m_InputImage.IsNotNull( ) ) this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); } // eof - $RCSfile$