#include "ImageMPR.h" #include "ui_ImageMPR.h" #include #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( ) ) ); QObject::connect( this->m_UI->actionOpenInputPolyData, SIGNAL( triggered( ) ), this, SLOT( _triggered_actionOpenInputPolyData( ) ) ); // 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[ "PolyDataReader" ] = "cpPlugins::Plugins::PolyDataReader"; } // ------------------------------------------------------------------------- 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; // Get a reader from plugins TPlugin::Pointer reader = this->m_Plugins.CreateProcessObject( this->m_BaseClasses[ "ImageReader" ] ); // Configure plugins TParameters reader_params = reader->GetDefaultParameters( ); // File names QStringList q_fnames = dialog.selectedFiles( ); QStringList::const_iterator qIt = q_fnames.begin( ); for( ; qIt != q_fnames.end( ); ++qIt ) reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) ); // Other parameters reader_params.SetValueAsString( "PixelType", "short" ); reader_params.SetValueAsUint( "ImageDimension", 3 ); reader_params.SetValueAsUint( "IsColorImage", 0 ); reader->SetParameters( reader_params ); // Execute and get error message, if any std::string err = reader->Update( ); // Assign fresh image, if any if( err == "" ) { this->m_InputImage = dynamic_cast< TPluginImage* >( reader->GetOutput( 0 ) ); reader->DisconnectOutputs( ); if( this->m_InputImage.IsNotNull( ) ) this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); } else QMessageBox::critical( this, tr( "Error reading single image" ), tr( err.c_str( ) ) ); } // ------------------------------------------------------------------------- void ImageMPR:: _triggered_actionOpenInputPolyData( ) { // Show dialog and check if it was accepted QFileDialog dialog( this ); dialog.setFileMode( QFileDialog::ExistingFile ); dialog.setDirectory( "." ); dialog.setNameFilter( tr( "VTK file (*.vtk);;All files (*)" ) ); dialog.setDefaultSuffix( tr( "vtk" ) ); if( !( dialog.exec( ) ) ) return; std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); this->m_InputPolyData = NULL; // Get a reader from plugins TPlugin::Pointer reader = this->m_Plugins.CreateProcessObject( this->m_BaseClasses[ "PolyDataReader" ] ); // Configure plugin TParameters reader_params = reader->GetDefaultParameters( ); reader_params.SetValueAsString( "FileName", fname ); reader->SetParameters( reader_params ); // Execute and get error message, if any std::string err = reader->Update( ); // Assign fresh image, if any if( err == "" ) { this->m_InputPolyData = dynamic_cast< TPluginPolyData* >( reader->GetOutput( 0 ) ); reader->DisconnectOutputs( ); if( this->m_InputPolyData.IsNotNull( ) ) { this->m_InputPolyData->GetActor( )->GetProperty( )->SetColor( 1, 0, 1 ); this->m_MPR->Add3DActor( this->m_InputPolyData->GetActor( ) ); } // fi } else QMessageBox::critical( this, tr( "Error reading polydata" ), tr( err.c_str( ) ) ); } // eof - $RCSfile$