X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=appli%2FInteractiveDeformableMeshSegmentation%2FMainWnd.cxx;h=548f87e5a9996f4f73464beb41a2735e1bc0f6a2;hb=93fb9ff2b54c04231a22d71ff71cab186d411900;hp=8e55c5a2815c320e3a6f69ef3f5f107c5e292049;hpb=6618a10363a5eb64022011925c86fa60a6c37e42;p=cpMesh.git diff --git a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx index 8e55c5a..548f87e 100644 --- a/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx +++ b/appli/InteractiveDeformableMeshSegmentation/MainWnd.cxx @@ -25,6 +25,8 @@ // ------------------------------------------------------------------------- MainWnd::MainWnd( QWidget* parent ) +{} + /* : QMainWindow( parent ), m_UI( new Ui::MainWnd ), m_InputImage( NULL ), @@ -53,10 +55,9 @@ MainWnd::MainWnd( QWidget* parent ) this->m_DoubleClickCommand = vtkSmartPointer< DoubleClickCommand >::New( ); this->m_DoubleClickCommand->SetMainWnd( this ); - this->m_MPR->AddDoubleClickObserver( this->m_DoubleClickCommand ); + // this->m_MPR->AddDoubleClickObserver( this->m_DoubleClickCommand ); // Orientation marks - /* TODO vtkSmartPointer< vtkAnnotatedCubeActor > oCube = vtkSmartPointer< vtkAnnotatedCubeActor >::New( ); oCube->GetCubeProperty( )->SetColor( 0.9, 0.7, 0.2 ); @@ -99,7 +100,6 @@ MainWnd::MainWnd( QWidget* parent ) SetInteractor( this->m_UI->m_3DVTK->GetInteractor( ) ); this->m_3DOrientationWidget->SetEnabled( 1 ); this->m_3DOrientationWidget->InteractiveOff( ); - */ // Qt signals <-> slots IDMS_QT_ACTION( ReloadPlugins ); @@ -121,63 +121,63 @@ MainWnd::MainWnd( QWidget* parent ) // Start: load all disponible plugins this->_triggered_actionReloadPlugins( ); } - +*/ // ------------------------------------------------------------------------- MainWnd:: ~MainWnd( ) { - // Close all connections - this->m_Plugins.UnloadAll( ); - - // Delete objects - delete this->m_UI; - delete this->m_MPR; - if( this->m_ActiveParameters != NULL ) - { - this->m_ActiveParameters->close( ); - delete this->m_ActiveParameters; - - } // fi - if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin; - if( this->m_InputImage != NULL ) delete this->m_InputImage; - if( this->m_SegmentedImage != NULL ) delete this->m_SegmentedImage; +// // Close all connections +// this->m_Plugins.UnloadAll( ); + +// // Delete objects +// delete this->m_UI; +// // delete this->m_MPR; +// if( this->m_ActiveParameters != NULL ) +// { +// this->m_ActiveParameters->close( ); +// delete this->m_ActiveParameters; + +// } // fi +// if( this->m_ActivePlugin != NULL ) delete this->m_ActivePlugin; +// 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( ); +// 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( ); } // ------------------------------------------------------------------------- @@ -185,235 +185,239 @@ MainWnd:: TPluginImage* 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 ); - - TPluginImage* ret = NULL; - unsigned int nFiles = dialog.selectedFiles( ).size( ); - if( nFiles == 1 ) - { - if( this->m_BaseClasses[ "ImageReader" ] == "" ) - { - 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_BaseClasses[ "ImageReader" ] ) - ); - - 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 = 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; - */ - - } // fi - return( ret ); +// // 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 ); + +// TPluginImage* ret = NULL; +// unsigned int nFiles = dialog.selectedFiles( ).size( ); +// if( nFiles == 1 ) +// { +// if( this->m_BaseClasses[ "ImageReader" ] == "" ) +// { +// 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_BaseClasses[ "ImageReader" ] ) +// ); + +// 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 = 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; +// */ + +// } // fi +// return( ret ); } // ------------------------------------------------------------------------- void MainWnd:: _UpdateEnabledFlags( ) { - bool img = ( this->m_InputImage != NULL ); - this->m_UI->menuSegmentInputImage->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_SegmentedImage != NULL ); - this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); - this->m_UI->menuExtractMesh->setEnabled( seg ); - this->m_UI->menuProcessMesh->setEnabled( seg ); - this->m_UI->actionOpenMesh->setEnabled( seg ); - - this->m_UI->actionNavigation->setEnabled( img && seg ); - this->m_UI->actionSegmentationInteractiveDeformation-> - setEnabled( img && seg ); +// bool img = ( this->m_InputImage != NULL ); +// this->m_UI->menuSegmentInputImage->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_SegmentedImage != NULL ); +// this->m_UI->menuFilterSegmentedImage->setEnabled( seg ); +// this->m_UI->menuExtractMesh->setEnabled( seg ); +// this->m_UI->menuProcessMesh->setEnabled( seg ); +// this->m_UI->actionOpenMesh->setEnabled( seg ); + +// this->m_UI->actionNavigation->setEnabled( img && seg ); +// this->m_UI->actionSegmentationInteractiveDeformation-> +// setEnabled( img && seg ); } // ------------------------------------------------------------------------- void MainWnd:: _triggered_actionReloadPlugins( ) { - if( !( this->_LoadPlugins( ) ) ) - { - QMessageBox::critical( - this, - tr( "Could not load plugins from given file." ), - tr( "Could not load plugins from given file." ) - ); - - } // fi - this->_UpdateEnabledFlags( ); +// if( !( this->_LoadPlugins( ) ) ) +// { +// QMessageBox::critical( +// this, +// tr( "Could not load plugins from given file." ), +// tr( "Could not load plugins from given file." ) +// ); + +// } // 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 ) - { - this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); - - // Update activations - this->_UpdateEnabledFlags( ); - this->m_UI->actionNavigation->setChecked( true ); - this->_triggered_actionSwitchMode( ); - - } // fi +// 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 ) +// { +// // this->m_MPR->SetImage( this->m_InputImage->GetVTKImageData( ) ); + +// // 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 ) - { - this->m_MPR->SetSegmentation( - this->m_SegmentedImage->GetVTKImageData( ) - ); - /* TODO - cpPlugins::Interface::Image* img = - dynamic_cast< cpPlugins::Interface::Image* >( this->m_SegmentedImage ); - this->m_ImageActors->SetSegmentation( img->GetVTKImageData( ) ); - */ - - // Ok, start! - this->m_MPR->Render( 0 ); - this->m_MPR->Render( 1 ); - this->m_MPR->Render( 2 ); - this->_UpdateEnabledFlags( ); - - } // fi +// 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 ) +// { +// /* +// this->m_MPR->SetSegmentation( +// this->m_SegmentedImage->GetVTKImageData( ) +// ); +// */ +// /* TODO +// cpPlugins::Interface::Image* img = +// dynamic_cast< cpPlugins::Interface::Image* >( this->m_SegmentedImage ); +// this->m_ImageActors->SetSegmentation( img->GetVTKImageData( ) ); +// */ + +// // Ok, start! +// /* +// this->m_MPR->Render( 0 ); +// this->m_MPR->Render( 1 ); +// this->m_MPR->Render( 2 ); +// */ +// this->_UpdateEnabledFlags( ); + +// } // 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 - 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 - */ +// 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 +// 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 +// */ } // -------------------------------------------------------------------------