From de28025e5f1835fba69cb0a6666d02f0b7daec0d Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 9 Dec 2014 18:46:07 +0100 Subject: [PATCH] Read/Write image plugin integration --- .../CMakeLists.txt | 8 +- .../MainWnd.cxx | 875 ++++++++++++------ .../MainWnd.h | 124 +-- .../MainWnd.ui | 45 +- .../idms.plugins | 1 + .../main.cxx | 2 + 6 files changed, 673 insertions(+), 382 deletions(-) diff --git a/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt b/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt index dfa2d8c..e360d5c 100644 --- a/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt +++ b/appli/InteractiveDeformableMeshSegmentation/CMakeLists.txt @@ -62,6 +62,7 @@ IF(BUILD_FINAL_APPLICATION) TARGET_LINK_LIBRARIES( ${App_NAME} cpm + ${cpPlugins_Interface_LIBRARIES} ${QT_LIBRARIES} ${ITK_LIBRARIES} ${VTK_LIBRARIES} @@ -70,7 +71,12 @@ IF(BUILD_FINAL_APPLICATION) CONFIGURE_FILE( idms.plugins ${PROJECT_BINARY_DIR}/idms.plugins - COPYONLY + @ONLY + ) + CONFIGURE_FILE( + idms.config + ${PROJECT_BINARY_DIR}/idms.config + @COPYONLY ) ENDIF(BUILD_FINAL_APPLICATION) diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx index 51c0ac1..bde4b4a 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx @@ -1,76 +1,41 @@ #include "MainWnd.h" #include "ui_MainWnd.h" +#include +#include #include -#include -#include -#include -#include - -#include -#include -#include + #include -#include -#include -#include #include -#include - -#include -#include -#include +#include +#include +#include +#include #include -/* - #include "ui_SegmentationParametersDlg.h" - - #include - - - #include - #include - #include - - #include - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - - #include -*/ +#include // ------------------------------------------------------------------------- -#define IDMS_QT_ACTION( action ) \ - QObject::connect( \ - this->m_UI->a##action, SIGNAL( triggered( ) ), \ - this, SLOT( triggered_a##action( ) ) \ +#define IDMS_QT_ACTION( name ) \ + QObject::connect( \ + this->m_UI->action##name, SIGNAL( triggered( ) ), \ + this, SLOT( _triggered_action##name( ) ) \ ) // ------------------------------------------------------------------------- MainWnd::MainWnd( QWidget* parent ) : QMainWindow( parent ), - m_UI( new Ui::MainWnd ) + m_UI( new Ui::MainWnd ), + m_InputImage( NULL ), + m_SegmentedImage( NULL ) { this->m_UI->setupUi( this ); - // Configure strings - this->m_LastOpenedFile = "."; + // Configuration files + this->m_ApplicationPreferencesFile = "idms.config"; this->m_PluginsConfigurationFile = "idms.plugins"; + this->_LoadApplicationPreferences( ); // Create and associate renderers this->m_3DRenderer = vtkSmartPointer< vtkRenderer >::New( ); @@ -111,76 +76,69 @@ MainWnd::MainWnd( QWidget* parent ) this->m_UI->m_ZPlaneVTK->GetInteractor( )-> SetInteractorStyle( this->m_ZStyle ); - /* - vtkSmartPointer< vtkCallbackCommand > z_callback = - vtkSmartPointer< vtkCallbackCommand >::New( ); - z_callback->SetCallback( MainWnd::_SliceEventCallback ); - z_callback->SetClientData( this ); - zstyle->AddObserver( idms::InteractorStyleImage::SliceEvent, z_callback ); - - // Orientation marks - vtkSmartPointer< vtkAnnotatedCubeActor > oCube = + // Orientation marks + vtkSmartPointer< vtkAnnotatedCubeActor > oCube = vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); - oCube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); - oCube->GetTextEdgesProperty( )->SetLineWidth( 1 ); - oCube->GetTextEdgesProperty( )->SetDiffuse( 0 ); - oCube->GetTextEdgesProperty( )->SetAmbient( 1 ); - oCube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); - oCube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); - oCube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); - oCube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); - oCube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); - oCube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); - oCube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); - oCube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); - oCube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); - - vtkSmartPointer< vtkAxesActor > oAxes = + oCube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); + oCube->GetTextEdgesProperty( )->SetLineWidth( 1 ); + oCube->GetTextEdgesProperty( )->SetDiffuse( 0 ); + oCube->GetTextEdgesProperty( )->SetAmbient( 1 ); + oCube->GetTextEdgesProperty( )->SetColor( 0.18, 0.28, 0.23 ); + oCube->GetXPlusFaceProperty( )->SetColor( 1, 0, 0 ); + oCube->GetXPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetXMinusFaceProperty( )->SetColor( 1, 0, 0 ); + oCube->GetXMinusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetYPlusFaceProperty( )->SetColor( 0, 1, 0 ); + oCube->GetYPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetYMinusFaceProperty( )->SetColor( 0, 1, 0 ); + oCube->GetYMinusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetZPlusFaceProperty( )->SetColor( 0, 0, 1 ); + oCube->GetZPlusFaceProperty( )->SetInterpolationToFlat( ); + oCube->GetZMinusFaceProperty( )->SetColor( 0, 0, 1 ); + oCube->GetZMinusFaceProperty( )->SetInterpolationToFlat( ); + + vtkSmartPointer< vtkAxesActor > oAxes = vtkSmartPointer< vtkAxesActor >::New( ); - oAxes->AxisLabelsOff( ); - oAxes->SetShaftTypeToCylinder( ); - oAxes->SetTotalLength( 2.5, 2.5, 2.5 ); + oAxes->AxisLabelsOff( ); + oAxes->SetShaftTypeToCylinder( ); + oAxes->SetTotalLength( 2.5, 2.5, 2.5 ); - vtkSmartPointer< vtkPropAssembly > oActors = + vtkSmartPointer< vtkPropAssembly > oActors = vtkSmartPointer< vtkPropAssembly >::New( ); - oActors->AddPart( oCube ); - oActors->AddPart( oAxes ); + oActors->AddPart( oCube ); + oActors->AddPart( oAxes ); - this->m_3DOrientationWidget = + this->m_3DOrientationWidget = vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); - this->m_3DOrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); - this->m_3DOrientationWidget->SetOrientationMarker( oActors ); - this->m_3DOrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); + this->m_3DOrientationWidget->SetOutlineColor( 0.93, 0.57, 0.13 ); + this->m_3DOrientationWidget->SetOrientationMarker( oActors ); + this->m_3DOrientationWidget->SetViewport( 0.0, 0.0, 0.2, 0.2 ); - // Add actors, widgets, stuff, ... - this->m_3DOrientationWidget-> + // Add actors, widgets, stuff, ... + this->m_3DOrientationWidget-> SetInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); - this->m_3DOrientationWidget->SetEnabled( 1 ); - this->m_3DOrientationWidget->InteractiveOff( ); + this->m_3DOrientationWidget->SetEnabled( 1 ); + this->m_3DOrientationWidget->InteractiveOff( ); - IDMS_QT_ACTION( aLoadInputImage ); - IDMS_QT_ACTION( aLoadSegmentedImage ); - */ // Qt signals <-> slots + IDMS_QT_ACTION( ReloadPlugins ); + IDMS_QT_ACTION( OpenInputImage ); + IDMS_QT_ACTION( OpenSegmentedImage ); QObject::connect( - this->m_UI->aNavigation, SIGNAL( triggered( ) ), - this, SLOT( triggered_aSwitchMode( ) ) + this->m_UI->actionNavigation, SIGNAL( triggered( ) ), + this, SLOT( _triggered_actionSwitchMode( ) ) ); QObject::connect( - this->m_UI->aSegmentationInteractiveDeformation, SIGNAL( triggered( ) ), - this, SLOT( triggered_aSwitchMode( ) ) + this->m_UI->actionSegmentationInteractiveDeformation, + SIGNAL( triggered( ) ), + this, SLOT( _triggered_actionSwitchMode( ) ) ); - IDMS_QT_ACTION( OpenInputImage ); - IDMS_QT_ACTION( OpenSegmentedImage ); - IDMS_QT_ACTION( ReloadPlugins ); + // Historic configuration + this->m_LastOpenedFile = "."; // Start: load all disponible plugins - this->triggered_aReloadPlugins( ); + this->_triggered_actionReloadPlugins( ); } // ------------------------------------------------------------------------- @@ -188,34 +146,463 @@ MainWnd:: ~MainWnd( ) { delete this->m_UI; + if( this->m_InputImage != NULL ) delete this->m_InputImage; + if( this->m_SegmentedImage != NULL ) delete this->m_SegmentedImage; +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_LoadApplicationPreferences( ) +{ + this->m_ApplicationPreferences.clear( ); + std::ifstream in( this->m_ApplicationPreferencesFile.c_str( ) ); + if( in ) + { + std::string line; + std::getline( in, line ); + while( !( in.eof( ) ) ) + { + long pos = line.find_last_of( "=" ); + std::string key = line.substr( 0, pos ); + std::string value = line.substr( pos + 1 ); + key.erase( + std::remove_if( key.begin( ), key.end( ), isspace ), key.end( ) + ); + value.erase( + std::remove_if( value.begin( ), value.end( ), isspace ), value.end( ) + ); + this->m_ApplicationPreferences[ key ] = value; + std::getline( in, line ); + + } // elihw + } + else + { + this->m_ApplicationPreferences[ "data_dimensions" ] = "3"; + this->m_ApplicationPreferences[ "input_image_type" ] = "short"; + this->m_ApplicationPreferences[ "segmented_image_type" ] = "uchar"; + this->m_ApplicationPreferences[ "mesh_type" ] = "double"; + + } // fi + in.close( ); +} + +// ------------------------------------------------------------------------- +MainWnd:: +TPluginData* MainWnd:: +_LoadImage( const std::string& image_type, const std::string& image_dim ) +{ + // Show dialog and check if it was accepted + QFileDialog dialog( this ); + dialog.setFileMode( QFileDialog::ExistingFiles ); + dialog.setDirectory( tr( this->m_LastOpenedFile.c_str( ) ) ); + dialog.setNameFilter( + tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) + ); + dialog.setDefaultSuffix( tr( "mhd" ) ); + if( !( dialog.exec( ) ) ) + return( NULL ); + + TPluginData* ret = NULL; + unsigned int nFiles = dialog.selectedFiles( ).size( ); + if( nFiles == 1 ) + { + if( this->m_ImageReaderClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No plugin to read a single image file found!" ), + tr( "No plugin to read a single image file found!" ) + ); + return( ret ); + + } // fi + + std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); + this->m_LastOpenedFile = fname; + + TPlugin* reader = + dynamic_cast< TPlugin* >( + this->m_Plugins.CreateObject( this->m_ImageReaderClassName ) + ); + + TParameters reader_params = reader->GetDefaultParameters( ); + reader_params[ "FileName" ].second = fname; + reader_params[ "PixelType" ].second = image_type; + reader_params[ "ImageDimension" ].second = image_dim; + reader_params[ "IsColorImage" ].second = "0"; + reader->SetParameters( reader_params ); + std::string err = reader->Update( ); + + if( err == "" ) + { + ret = reader->GetOutput( 0 ); + reader->DisconnectOutputs( ); + } + else + QMessageBox::critical( + this, + tr( "Error reading single image" ), + tr( err.c_str( ) ) + ); + delete reader; + return( ret ); + } + else if( nFiles > 1 ) + { + 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 + + /* TODO + std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( ); + this->m_LastOpenedFile = fname; + */ + return( ret ); + + } // fi + return( ret ); } // ------------------------------------------------------------------------- void MainWnd:: _UpdateEnabledFlags( ) { - bool img = this->m_Image.IsNotNull( ); + bool img = ( this->m_InputImage != NULL ); this->m_UI->menuSegmentInputImage->setEnabled( img ); - this->m_UI->aOpenSegmentedImage->setEnabled( img ); + this->m_UI->actionOpenSegmentedImage->setEnabled( img ); this->m_UI->m_3DVTK->setEnabled( img ); this->m_UI->m_XPlaneVTK->setEnabled( img ); this->m_UI->m_YPlaneVTK->setEnabled( img ); this->m_UI->m_ZPlaneVTK->setEnabled( img ); this->m_UI->m_AuxVTK->setEnabled( img ); - bool seg = this->m_Segmentation.IsNotNull( ); - this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); - this->m_UI->menuExtractMesh->setEnabled( seg ); - this->m_UI->aOpenMesh->setEnabled( seg ); + /* TODO + bool seg = this->m_Segmentation.IsNotNull( ); + this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); + this->m_UI->menuExtractMesh->setEnabled( seg ); + this->m_UI->actionOpenMesh->setEnabled( seg ); + + this->m_UI->actionNavigation->setEnabled( img && seg ); + this->m_UI->actionSegmentationInteractiveDeformation-> + setEnabled( img && seg ); + */ +} - this->m_UI->aNavigation->setEnabled( img && seg ); - this->m_UI->aSegmentationInteractiveDeformation->setEnabled( img && seg ); +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionReloadPlugins( ) +{ + this->m_Plugins.UnloadAll( ); + + this->m_ImageReaderClassName = ""; + this->m_ImageSeriesReaderClassName = ""; + this->m_ImageWriterClassName = ""; + + std::ifstream in( this->m_PluginsConfigurationFile.c_str( ) ); + if( in ) + { + std::string plugin; + std::getline( in, plugin ); + while( !( in.eof( ) ) ) + { + if( this->m_Plugins.Load( plugin ) ) + { + TPluginsInterface::TClassesIterator cIt = + this->m_Plugins.GetClasses( ).begin( ); + TPluginsInterface::TClassesIterator end_cIt = + this->m_Plugins.GetClasses( ).end( ); + for( ; cIt != end_cIt; ++cIt ) + { + std::string c_name = cIt->first; + c_name = c_name.substr( c_name.find_last_of( ":" ) + 1 ); + if( c_name == "ImageReader" ) + { + this->m_ImageReaderClassName = cIt->first; + } + else if( c_name == "ImageWriter" ) + { + this->m_ImageWriterClassName = cIt->first; + } + else + { + } // fi + + } // rof + + /* TODO + TFilterPlugins::TClassesIterator cIt = + this->m_Plugins.BeginClasses( ); + for( ; cIt != this->m_Plugins.EndClasses( ); ++cIt ) + { + TFilterObject* filter = + this->m_Plugins.CreateObject( cIt->first ); + if( filter == NULL ) + continue; + std::string cat = filter->GetCategory( ); + std::string catType = cat.substr( cat.find_last_of( ":" ) ); + if( catType == ":BinaryImageToBinaryImageFilter" ) + { + QAction* action = this->m_UI->menuFilterSegmentedImage-> + addAction( QString( cIt->first.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( triggered_aFilterSegmentedImage( ) ) + ); + } + else if( catType == ":ImageToMeshFilter" ) + { + QAction* action = this->m_UI->menuExtractMesh-> + addAction( QString( cIt->first.c_str( ) ) ); + QObject::connect( + action, SIGNAL( triggered( ) ), + this, SLOT( triggered_aSegmentedImageToMesh( ) ) + ); + + } // fi + delete filter; + } // rof + */ + } + else + { + QMessageBox::warning( + this, + tr( "Ignoring plugin" ), + tr( plugin.c_str( ) ) + ); + + } // fi + std::getline( in, plugin ); + + } // elihw + } + else + { + QMessageBox::critical( + this, + tr( "No plugins file loaded!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + in.close( ); + + if( this->m_ImageReaderClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No ImageReader found in plugins!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + + if( this->m_ImageWriterClassName == "" ) + { + QMessageBox::critical( + this, + tr( "No ImageWriter found in plugins!" ), + tr( this->m_PluginsConfigurationFile.c_str( ) ) + ); + + } // fi + this->_UpdateEnabledFlags( ); +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionOpenInputImage( ) +{ + if( this->m_InputImage != NULL ) + delete this->m_InputImage; + this->m_InputImage = + this->_LoadImage( + this->m_ApplicationPreferences[ "input_image_type" ], + this->m_ApplicationPreferences[ "data_dimensions" ] + ); + if( this->m_InputImage != NULL ) + { + cpPlugins::Interface::Image* img = + dynamic_cast< cpPlugins::Interface::Image* >( this->m_InputImage ); + this->m_ImageActors->Configure( + img->GetVTKImageData( ), + this->m_UI->m_XPlaneVTK->GetInteractor( ), + this->m_UI->m_YPlaneVTK->GetInteractor( ), + this->m_UI->m_ZPlaneVTK->GetInteractor( ) + ); + this->m_ImageActors-> + AddAuxiliaryInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); + + // Associate actors + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetImageOutlineActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetXBoundsActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetYBoundsActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetZBoundsActor( ) + ); + + // Reset all cameras + this->m_3DRenderer->ResetCamera( ); + this->m_ImageActors->ResetCameras( ); + + // Ok, start! + this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); + + // Update activations + this->_UpdateEnabledFlags( ); + this->m_UI->actionNavigation->setChecked( true ); + this->_triggered_actionSwitchMode( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionOpenSegmentedImage( ) +{ + if( this->m_SegmentedImage != NULL ) + delete this->m_SegmentedImage; + this->m_SegmentedImage = + this->_LoadImage( + this->m_ApplicationPreferences[ "segmented_image_type" ], + this->m_ApplicationPreferences[ "data_dimensions" ] + ); + if( this->m_SegmentedImage != NULL ) + { + cpPlugins::Interface::Image* img = + dynamic_cast< cpPlugins::Interface::Image* >( this->m_SegmentedImage ); + this->m_ImageActors->SetSegmentation( img->GetVTKImageData( ) ); + + // Ok, start! + this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); + this->_UpdateEnabledFlags( ); + + /* + this->m_ImageActors->Configure( + img->GetVTKImageData( ), + this->m_UI->m_XPlaneVTK->GetInteractor( ), + this->m_UI->m_YPlaneVTK->GetInteractor( ), + this->m_UI->m_ZPlaneVTK->GetInteractor( ) + ); + this->m_ImageActors-> + AddAuxiliaryInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); + + // Associate actors + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetImageOutlineActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetXBoundsActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetYBoundsActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetZBoundsActor( ) + ); + + // Reset all cameras + this->m_3DRenderer->ResetCamera( ); + this->m_ImageActors->ResetCameras( ); + + // Ok, start! + this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_XPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_YPlaneVTK->GetRenderWindow( )->Render( ); + this->m_UI->m_ZPlaneVTK->GetRenderWindow( )->Render( ); + + // Update activations + this->_UpdateEnabledFlags( ); + this->m_UI->actionNavigation->setChecked( true ); + this->_triggered_actionSwitchMode( ); + */ + + } // fi +} + +// ------------------------------------------------------------------------- +void MainWnd:: +_triggered_actionSwitchMode( ) +{ + QAction* snd = dynamic_cast< QAction* >( this->sender( ) ); + if( snd == this->m_UI->actionNavigation ) + { + this->m_UI->actionSegmentationInteractiveDeformation->setChecked( + !( this->m_UI->actionNavigation->isChecked( ) ) + ); + } + else if( snd == this->m_UI->actionSegmentationInteractiveDeformation ) + { + this->m_UI->actionNavigation->setChecked( + !( this->m_UI->actionSegmentationInteractiveDeformation->isChecked( ) ) + ); + } + else + { + this->m_UI->actionNavigation->setChecked( true ); + this->m_UI->actionSegmentationInteractiveDeformation->setChecked( false ); + + } // fi /* TODO - menuProcessMesh + if( this->m_UI->aNavigation->isChecked( ) ) + { + this->m_XStyle->SetModeToNavigation( ); + this->m_YStyle->SetModeToNavigation( ); + this->m_ZStyle->SetModeToNavigation( ); + this->m_ImageActors->HideRegion( 0 ); + this->m_ImageActors->HideRegion( 1 ); + this->m_ImageActors->HideRegion( 2 ); + this->m_3DRenderer->RemoveActor( + this->m_ImageActors->GetCursorActor( ) + ); + this->m_3DRenderer->RemoveActor( + this->m_ImageActors->GetRegionActor( ) + ); + this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + } + else if( this->m_UI->aSegmentationInteractiveDeformation->isChecked( ) ) + { + this->m_XStyle->SetModeToDeformation( ); + this->m_YStyle->SetModeToDeformation( ); + this->m_ZStyle->SetModeToDeformation( ); + this->m_ImageActors->ShowRegion( 0 ); + this->m_ImageActors->ShowRegion( 1 ); + this->m_ImageActors->ShowRegion( 2 ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetCursorActor( ) + ); + this->m_3DRenderer->AddActor( + this->m_ImageActors->GetRegionActor( ) + ); + this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + + } // fi */ } +// ------------------------------------------------------------------------- +/* TODO + // ------------------------------------------------------------------------- bool MainWnd:: _ParametersDialog( TParameters& parameters ) @@ -319,217 +706,94 @@ _ParametersDialog( TParameters& parameters ) return( true ); } return( false ); -} + } -// ------------------------------------------------------------------------- -template< class I > -bool MainWnd:: -_LoadImage( typename I::Pointer& image ) -{ + // ------------------------------------------------------------------------- + template< class I > + bool MainWnd:: + _LoadImage( typename I::Pointer& image ) + { QStringList qList = - QFileDialog::getOpenFileNames( - this, - tr( "Open an image" ), - tr( this->m_LastOpenedFile.c_str( ) ), - tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) - ); + QFileDialog::getOpenFileNames( + this, + tr( "Open an image" ), + tr( this->m_LastOpenedFile.c_str( ) ), + tr( "Medical image files (*.mhd *.bin *.dcm);;All files (*)" ) + ); if( qList.size( ) == 0 ) - return( false ); + return( false ); bool ret = true; QStringList::Iterator fIt = qList.begin( ); if( qList.size( ) == 1 ) { - // Read a single image - std::string fn = fIt->toStdString( ); - this->m_LastOpenedFile = fn; - - typename itk::ImageFileReader< I >::Pointer reader = - itk::ImageFileReader< I >::New( ); - reader->SetFileName( fn ); - try - { - reader->Update( ); - } - catch( itk::ExceptionObject& err ) - { - QMessageBox::critical( - this, - tr( "Error opening single image!" ), - tr( err.GetDescription( ) ) - ); - ret = false; - - } // yrt - image = reader->GetOutput( ); - image->DisconnectPipeline( ); + // Read a single image + std::string fn = fIt->toStdString( ); + this->m_LastOpenedFile = fn; + + typename itk::ImageFileReader< I >::Pointer reader = + itk::ImageFileReader< I >::New( ); + reader->SetFileName( fn ); + try + { + reader->Update( ); } - else if( qList.size( ) > 1 ) + catch( itk::ExceptionObject& err ) { - typedef std::set< std::string > _TOrderedStringList; - - // Read a slice set - _TOrderedStringList filenames; - for( ; fIt != qList.end( ); ++fIt ) - filenames.insert( fIt->toStdString( ) ); - typename itk::ImageSeriesReader< I >::Pointer reader = - itk::ImageSeriesReader< I >::New( ); - reader->SetImageIO( itk::GDCMImageIO::New( ) ); - _TOrderedStringList::const_iterator oIt = filenames.begin( ); - for( ; oIt != filenames.end( ); ++oIt ) - { - reader->AddFileName( *oIt ); - this->m_LastOpenedFile = *oIt; - - } // rof - try - { - reader->Update( ); - } - catch( itk::ExceptionObject& err ) - { - QMessageBox::critical( - this, - tr( "Error opening image series!" ), - tr( err.GetDescription( ) ) - ); - ret = false; - - } // yrt - image = reader->GetOutput( ); - image->DisconnectPipeline( ); - - } // fi - return( ret ); -} + QMessageBox::critical( + this, + tr( "Error opening single image!" ), + tr( err.GetDescription( ) ) + ); + ret = false; -// ------------------------------------------------------------------------- -void MainWnd:: -triggered_aSwitchMode( ) -{ - QAction* snd = dynamic_cast< QAction* >( this->sender( ) ); - if( snd == this->m_UI->aNavigation ) - { - this->m_UI->aSegmentationInteractiveDeformation->setChecked( - !( this->m_UI->aNavigation->isChecked( ) ) - ); + } // yrt + image = reader->GetOutput( ); + image->DisconnectPipeline( ); } - else if( snd == this->m_UI->aSegmentationInteractiveDeformation ) + else if( qList.size( ) > 1 ) { - this->m_UI->aNavigation->setChecked( - !( this->m_UI->aSegmentationInteractiveDeformation->isChecked( ) ) - ); - } - else + typedef std::set< std::string > _TOrderedStringList; + + // Read a slice set + _TOrderedStringList filenames; + for( ; fIt != qList.end( ); ++fIt ) + filenames.insert( fIt->toStdString( ) ); + typename itk::ImageSeriesReader< I >::Pointer reader = + itk::ImageSeriesReader< I >::New( ); + reader->SetImageIO( itk::GDCMImageIO::New( ) ); + _TOrderedStringList::const_iterator oIt = filenames.begin( ); + for( ; oIt != filenames.end( ); ++oIt ) { - this->m_UI->aNavigation->setChecked( true ); - this->m_UI->aSegmentationInteractiveDeformation->setChecked( false ); - - } // fi + reader->AddFileName( *oIt ); + this->m_LastOpenedFile = *oIt; - if( this->m_UI->aNavigation->isChecked( ) ) + } // rof + try { - this->m_XStyle->SetModeToNavigation( ); - this->m_YStyle->SetModeToNavigation( ); - this->m_ZStyle->SetModeToNavigation( ); - this->m_ImageActors->HideRegion( 0 ); - this->m_ImageActors->HideRegion( 1 ); - this->m_ImageActors->HideRegion( 2 ); - this->m_3DRenderer->RemoveActor( - this->m_ImageActors->GetCursorActor( ) - ); - this->m_3DRenderer->RemoveActor( - this->m_ImageActors->GetRegionActor( ) - ); - this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + reader->Update( ); } - else if( this->m_UI->aSegmentationInteractiveDeformation->isChecked( ) ) - { - this->m_XStyle->SetModeToDeformation( ); - this->m_YStyle->SetModeToDeformation( ); - this->m_ZStyle->SetModeToDeformation( ); - this->m_ImageActors->ShowRegion( 0 ); - this->m_ImageActors->ShowRegion( 1 ); - this->m_ImageActors->ShowRegion( 2 ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetCursorActor( ) - ); - this->m_3DRenderer->AddActor( - this->m_ImageActors->GetRegionActor( ) - ); - this->m_UI->m_3DVTK->GetRenderWindow( )->Render( ); + catch( itk::ExceptionObject& err ) + { + QMessageBox::critical( + this, + tr( "Error opening image series!" ), + tr( err.GetDescription( ) ) + ); + ret = false; + + } // yrt + image = reader->GetOutput( ); + image->DisconnectPipeline( ); } // fi -} + return( ret ); + } // ------------------------------------------------------------------------- void MainWnd:: triggered_aReloadPlugins( ) { - this->m_FilterPlugins.UnloadAll( ); - - std::ifstream in( this->m_PluginsConfigurationFile.c_str( ) ); - if( in ) - { - std::string plugin; - std::getline( in, plugin ); - while( !( in.eof( ) ) ) - { - if( this->m_FilterPlugins.Load( plugin ) ) - { - TFilterPlugins::TClassesIterator cIt = - this->m_FilterPlugins.BeginClasses( ); - for( ; cIt != this->m_FilterPlugins.EndClasses( ); ++cIt ) - { - TFilterObject* filter = - this->m_FilterPlugins.CreateObject( cIt->first ); - if( filter == NULL ) - continue; - std::string cat = filter->GetCategory( ); - std::string catType = cat.substr( cat.find_last_of( ":" ) ); - if( catType == ":BinaryImageToBinaryImageFilter" ) - { - QAction* action = this->m_UI->menuFilterSegmentedImage-> - addAction( QString( cIt->first.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( triggered_aFilterSegmentedImage( ) ) - ); - } - else if( catType == ":ImageToMeshFilter" ) - { - QAction* action = this->m_UI->menuExtractMesh-> - addAction( QString( cIt->first.c_str( ) ) ); - QObject::connect( - action, SIGNAL( triggered( ) ), - this, SLOT( triggered_aSegmentedImageToMesh( ) ) - ); - - } // fi - delete filter; - - } // rof - } - else - std::cerr - << std::endl - << "Ignoring \"" << plugin << "\"" - << std::endl; - std::getline( in, plugin ); - - } // elihw - } - else - { - QMessageBox::critical( - this, - tr( "No plugins file loaded!" ), - tr( "No plugins file loaded!" ) - ); - - } // fi - in.close( ); - this->_UpdateEnabledFlags( ); } // ------------------------------------------------------------------------- @@ -619,7 +883,7 @@ triggered_aFilterSegmentedImage( ) std::string filter_name = action->text( ).toStdString( ); // Create filter - TFilterObject* filter = this->m_FilterPlugins.CreateObject( filter_name ); + TFilterObject* filter = this->m_Plugins.CreateObject( filter_name ); if( filter == NULL ) return; @@ -631,14 +895,12 @@ triggered_aFilterSegmentedImage( ) std::string result = filter->Update( ); // Get modified segmentation - /* TODO this->m_Mesh = filter->GetCastedOutput< TMesh >( ); if( this->m_Mesh.IsNotNull( ) ) { this->m_Mesh->DisconnectPipeline( ); } // fi - */ // Ok, it seems to have runned fine delete filter; } @@ -656,7 +918,7 @@ triggered_aSegmentedImageToMesh( ) std::string filter_name = action->text( ).toStdString( ); // Create filter - TFilterObject* filter = this->m_FilterPlugins.CreateObject( filter_name ); + TFilterObject* filter = this->m_Plugins.CreateObject( filter_name ); if( filter == NULL ) return; @@ -678,6 +940,7 @@ triggered_aSegmentedImageToMesh( ) // Ok, it seems to have runned fine delete filter; } +*/ // ------------------------------------------------------------------------- /* diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.h b/appli/InteractiveDeformableMeshSegmentation/MainWnd.h index c1fe98f..d3bef88 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.h +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.h @@ -1,24 +1,34 @@ #ifndef __MAINWND__H__ #define __MAINWND__H__ -#include +// Standard stuff +#include +#include -#include -#include +// Qt stuff +#include +// vtk stuff #include #include #include -#include - -#include -#include +// Plugins interface +#include +#include +#include +// Local stuff #include "InteractorStyleImage.h" #include "VolumeActors.h" + /* + #include + #include + + #include + #include #include */ @@ -39,39 +49,26 @@ class MainWnd public: // Plugins types - typedef cpmPluginsInterface::FilterProvider TFilterProvider; - typedef cpmPluginsInterface::Filter TFilterObject; - typedef TFilterObject::TParameters TParameters; - typedef - cpmPluginsInterface::Interface< TFilterProvider, TFilterObject > - TFilterPlugins; - - // Data types - static const unsigned int Dimension = 3; - typedef short TPixel; - typedef double TScalar; - typedef itk::Image< TPixel, Dimension > TImage; - typedef itk::ImageToVTKImageFilter< TImage > TVTKImage; - - typedef cpm::DataStructures::QuadEdgeMesh< TScalar, Dimension > TMesh; - - /* - typedef cpm::VTK::MeshMapper< TTriangulation > TTriangulationMapper; - typedef - cpm::Algorithms::QuadEdge::MeshPlaneCutterFilter< TTriangulation > - TCutter; - */ + typedef cpPlugins::Interface::Interface TPluginsInterface; + typedef cpPlugins::Interface::DataObject TPluginData; + typedef cpPlugins::Interface::ProcessObject TPlugin; + typedef TPlugin::TParameters TParameters; public: explicit MainWnd( QWidget* parent = 0 ); virtual ~MainWnd( ); protected: + void _LoadApplicationPreferences( ); + TPluginData* _LoadImage( + const std::string& image_type, const std::string& image_dim + ); void _UpdateEnabledFlags( ); - bool _ParametersDialog( TParameters& parameters ); - template< class I > - bool _LoadImage( typename I::Pointer& image ); + /* TODO + bool _ParametersDialog( TParameters& parameters ); + template< class I > + */ /* void _SliceMesh( int axis ); @@ -83,33 +80,52 @@ protected: */ private slots: - void triggered_aSwitchMode( ); - void triggered_aReloadPlugins( ); - void triggered_aOpenInputImage( ); - void triggered_aOpenSegmentedImage( ); - void triggered_aFilterSegmentedImage( ); - void triggered_aSegmentedImageToMesh( ); - /* - void triggered_aLoadInputImage( ); - void triggered_aLoadSegmentedImage( ); + void _triggered_actionReloadPlugins( ); + void _triggered_actionOpenInputImage( ); + void _triggered_actionOpenSegmentedImage( ); + void _triggered_actionSwitchMode( ); + + /* TODO + void triggered_aOpenSegmentedImage( ); + void triggered_aFilterSegmentedImage( ); + void triggered_aSegmentedImageToMesh( ); + void triggered_aLoadInputImage( ); + void triggered_aLoadSegmentedImage( ); */ private: Ui::MainWnd* m_UI; + // Application preferences + std::string m_ApplicationPreferencesFile; + std::map< std::string, std::string > m_ApplicationPreferences; + // Plugins objects - std::string m_PluginsConfigurationFile; - TFilterPlugins m_FilterPlugins; - - // Inputs - std::string m_LastOpenedFile; - TImage::Pointer m_Image; - TImage::Pointer m_Segmentation; - TMesh::Pointer m_Mesh; - TVTKImage::Pointer m_VTKImage; - TVTKImage::Pointer m_VTKSegmentation; - - // Renderers + std::string m_PluginsConfigurationFile; + TPluginsInterface m_Plugins; + + // Needed object from plugins + std::string m_ImageReaderClassName; + std::string m_ImageSeriesReaderClassName; + std::string m_ImageWriterClassName; + + // Historic objects + std::string m_LastOpenedFile; + + // Real data + TPluginData* m_InputImage; + TPluginData* m_SegmentedImage; + + /* TODO + // Inputs + TImage::Pointer m_Image; + TImage::Pointer m_Segmentation; + TMesh::Pointer m_Mesh; + TVTKImage::Pointer m_VTKImage; + TVTKImage::Pointer m_VTKSegmentation; + */ + + // Visualization stuff vtkSmartPointer< vtkRenderer > m_3DRenderer; vtkSmartPointer< vtkRenderer > m_XPlaneRenderer; vtkSmartPointer< vtkRenderer > m_YPlaneRenderer; @@ -119,8 +135,8 @@ private: vtkSmartPointer< idms::InteractorStyleImage > m_XStyle; vtkSmartPointer< idms::InteractorStyleImage > m_YStyle; vtkSmartPointer< idms::InteractorStyleImage > m_ZStyle; - vtkSmartPointer< vtkOrientationMarkerWidget > m_3DOrientationWidget; + /* TTriangulation::Pointer m_Mesh; vtkSmartPointer< TTriangulationMapper > m_MeshMapper; diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.ui b/appli/InteractiveDeformableMeshSegmentation/MainWnd.ui index 9bea142..a533240 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.ui +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.ui @@ -117,10 +117,10 @@ &File - - + + - + @@ -139,7 +139,7 @@ Segment - + @@ -162,7 +162,7 @@ Extract mesh - + @@ -178,7 +178,7 @@ Process - + @@ -197,31 +197,34 @@ false - - + + - + + + true + Open - + - false + true Open - + - false + true Open - + true @@ -229,22 +232,22 @@ Open plugins - + Reload plugins - + Exit - + true - false + true @@ -254,12 +257,12 @@ Navigation - + true - false + true @@ -283,7 +286,7 @@ - aExit + actionExit triggered() MainWnd close() diff --git a/appli/InteractiveDeformableMeshSegmentation/idms.plugins b/appli/InteractiveDeformableMeshSegmentation/idms.plugins index e69de29..12e417d 100644 --- a/appli/InteractiveDeformableMeshSegmentation/idms.plugins +++ b/appli/InteractiveDeformableMeshSegmentation/idms.plugins @@ -0,0 +1 @@ +@cpPlugins_LIBRARY_NAME@ diff --git a/appli/InteractiveDeformableMeshSegmentation/main.cxx b/appli/InteractiveDeformableMeshSegmentation/main.cxx index 4a3fefe..5bede9d 100644 --- a/appli/InteractiveDeformableMeshSegmentation/main.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/main.cxx @@ -1,9 +1,11 @@ #include "MainWnd.h" +#include #include // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { + ::setenv( "LC_NUMERIC", "POSIX", 1 ); QApplication a( argc, argv ); MainWnd w; w.show( ); -- 2.47.1