#include "ImageMPR.h" #include "ui_ImageMPR.h" #include #include #include // ------------------------------------------------------------------------- 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; if( this->m_InputImage != NULL ) delete this->m_InputImage; } // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionOpenPlugins( ) { // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFile ); dialog.setDirectory( "." ); dialog.setNameFilter( tr( "Plugins file (*.so);;All files (*)" ) ); dialog.setDefaultSuffix( tr( "so" ) ); 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; if( this->m_InputImage != NULL ) delete this->m_InputImage; this->m_InputImage = NULL; unsigned int nFiles = dialog.selectedFiles( ).size( ); if( nFiles == 1 ) { std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); TPlugin* reader = dynamic_cast< TPlugin* >( this->m_Plugins.CreateObject( this->m_BaseClasses[ "ImageReader" ] ) ); TParameters reader_params = reader->GetDefaultParameters( ); reader_params[ "FileName" ].second = fname; reader_params[ "PixelType" ].second = "short"; reader_params[ "ImageDimension" ].second = "3"; reader_params[ "IsColorImage" ].second = "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( ) ) ); delete reader; } 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 != NULL ) this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); } // eof - $RCSfile$