From: Leonardo Florez-Valencia Date: Tue, 3 Nov 2015 23:19:55 +0000 (-0500) Subject: Getting ready for interactive initialization. X-Git-Tag: v0.1~305^2~2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c0627ed97baf80b6751379801fc4d5c377b45467;hp=106a56bfe6a48067380089ffd61a518e40d77933;p=cpPlugins.git Getting ready for interactive initialization. --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index cc9a015..89af18d 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -57,20 +57,13 @@ ImageMPR:: void ImageMPR:: _aOpenImage( ) { - // Clear all, since we are loading the main image - if( this->m_Objects.size( ) > 0 ) - { - this->m_UI->MPR->ClearAll( ); - this->m_Objects.clear( ); - - } // fi - // Read and show image, if possible TPlugins::TImage::Pointer image; if( this->m_Plugins->ReadImage( image, true ) ) { vtkImageData* vimage = image->GetVTK< vtkImageData >( ); if( vimage == NULL ) + { QMessageBox::critical( this, QMessageBox::tr( "Error showing image." ), @@ -78,12 +71,21 @@ _aOpenImage( ) "Image was read, but no valid VTK conversion was found." ) ); + return; + } else - this->m_UI->MPR->ShowImage( vimage, image->GetName( ) ); + { + // Since we are opening an image, clear all + this->m_UI->MPR->DeleteAllData( ); + this->m_Objects.clear( ); - // Keep a track on a local data tree - this->m_Objects[ image->GetName( ) ] = - TTreeNode( "", image.GetPointer( ) ); + // Update references + std::string name = image->GetName( ); + this->m_Objects[ name ] = TTreeNode( "", image.GetPointer( ) ); + this->m_UI->MPR->AddImage( vimage, name ); + this->m_UI->MPR->ShowData( name ); + + } // fi } // fi } @@ -92,20 +94,13 @@ _aOpenImage( ) void ImageMPR:: _aOpenDICOMSeries( ) { - // Clear all, since we are loading the main image - if( this->m_Objects.size( ) > 0 ) - { - this->m_UI->MPR->ClearAll( ); - this->m_Objects.clear( ); - - } // fi - // Read and show image, if possible TPlugins::TImage::Pointer image; if( this->m_Plugins->ReadDicomSeries( image ) ) { vtkImageData* vimage = image->GetVTK< vtkImageData >( ); if( vimage == NULL ) + { QMessageBox::critical( this, QMessageBox::tr( "Error showing image." ), @@ -113,12 +108,21 @@ _aOpenDICOMSeries( ) "Image was read, but no valid VTK conversion was found." ) ); + return; + } else - this->m_UI->MPR->ShowImage( vimage, image->GetName( ) ); + { + // Since we are opening an image, clear all + this->m_UI->MPR->DeleteAllData( ); + this->m_Objects.clear( ); - // Keep a track on a local data tree - this->m_Objects[ image->GetName( ) ] = - TTreeNode( "", image.GetPointer( ) ); + // Update references + std::string name = image->GetName( ); + this->m_Objects[ name ] = TTreeNode( "", image.GetPointer( ) ); + this->m_UI->MPR->AddImage( vimage, name ); + this->m_UI->MPR->ShowData( name ); + + } // fi } // fi } @@ -203,7 +207,7 @@ _aShowPlugins( ) void ImageMPR:: _execPlugin( ) { - // Get filter name + // Get filter's name and category QAction* action = dynamic_cast< QAction* >( this->sender( ) ); if( action == NULL ) return; @@ -214,8 +218,7 @@ _execPlugin( ) std::string filter_name = action->text( ).toStdString( ); // Create filter - TPlugins::TProcessObject::Pointer filter; - if( !( this->m_Plugins->CreateFilter( filter, filter_name ) ) ) + if( !( this->m_Plugins->CreateFilter( this->m_ActiveFilter, filter_name ) ) ) { QMessageBox::critical( this, @@ -226,17 +229,30 @@ _execPlugin( ) std::string( "\"defined." ) ).c_str( ) ) ); + this->m_ActiveFilter = NULL; return; } // fi // Configure filter - if( !( filter->ExecConfigurationDialog( this ) ) ) + this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 0 ) ); + this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 1 ) ); + this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 2 ) ); + this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 3 ) ); + + TPlugins::TProcessObject::DialogResult res = + this->m_ActiveFilter->ExecConfigurationDialog( this ); + if( res == TPlugins::TProcessObject::DialogResult_Cancel ) + { + this->m_ActiveFilter = NULL; return; + } // fi + // Assign inputs std::string data_name = this->m_UI->MPR->GetSelectedData( ); - std::vector< std::string > inputs_names = filter->GetInputsNames( ); + std::vector< std::string > inputs_names = + this->m_ActiveFilter->GetInputsNames( ); if( inputs_names.size( ) == 1 ) { TTree::iterator iIt = this->m_Objects.find( data_name ); @@ -247,10 +263,11 @@ _execPlugin( ) tr( "Error configuring filter" ), tr( "No valid input found. Please select a valid input." ) ); + this->m_ActiveFilter = NULL; return; } //fi - filter->SetInput( inputs_names[ 0 ], iIt->second.second ); + this->m_ActiveFilter->SetInput( inputs_names[ 0 ], iIt->second.second ); } else if( inputs_names.size( ) > 1 ) { @@ -264,70 +281,81 @@ _execPlugin( ) } // fi // Execute filter - this->_Block( ); - std::string filter_err = filter->Update( ); - this->_Unblock( ); - if( filter_err != "" ) - { - QMessageBox::critical( - this, - tr( "Error executing" ), - tr( filter_err.c_str( ) ) - ); - return; - - } // fi + /* + if( res == TPlugins::TProcessObject::DialogResult_NoModal ) + { + this->_Block( ); + std::string filter_err = this->m_ActiveFilter->Update( ); + this->_Unblock( ); + if( filter_err != "" ) + { + QMessageBox::critical( + this, + tr( "Error executing" ), + tr( filter_err.c_str( ) ) + ); + this->m_ActiveFilter = NULL; + return; - // Get outputs - std::vector< std::string > outputs_names = filter->GetOutputsNames( ); - for( - auto oIt = outputs_names.begin( ); - oIt != outputs_names.end( ); - ++oIt - ) - { - std::string out_name = filter_name + "_" + *oIt; + } // fi - TPlugins::TImage* image = filter->GetOutput< TPlugins::TImage >( *oIt ); - if( image != NULL ) + // Get outputs + std::vector< std::string > outputs_names = filter->GetOutputsNames( ); + for( + auto oIt = outputs_names.begin( ); + oIt != outputs_names.end( ); + ++oIt + ) { - if( filter_cate == "ImageToBinaryImageFilter" ) - { - this->m_UI->MPR->ShowImage( - image->GetVTK< vtkImageData >( ), - out_name, - data_name, 1, 0, 0 - ); - } - else if( filter_cate == "ImageToImageFilter" ) + std::string out_name = filter_name + "_" + *oIt; + + TPlugins::TImage* image = + this->m_ActiveFilter->GetOutput< TPlugins::TImage >( *oIt ); + if( image != NULL ) { + if( filter_cate == "ImageToBinaryImageFilter" ) + { + this->m_UI->MPR->ShowImage( + image->GetVTK< vtkImageData >( ), + out_name, + data_name, 1, 0, 0 + ); + } + else if( filter_cate == "ImageToImageFilter" ) + { + } // fi + + // Keep a track on a local data tree and go to next output + this->m_Objects[ out_name ] = TTreeNode( data_name, image ); + continue; + } // fi - // Keep a track on a local data tree and go to next output - this->m_Objects[ out_name ] = TTreeNode( data_name, image ); - continue; + TPlugins::TMesh* mesh = filter->GetOutput< TPlugins::TMesh >( *oIt ); + if( mesh != NULL ) + { + // Show mesh + this->_Block( ); + this->m_UI->MPR->ShowMesh( + mesh->GetVTK< vtkPolyData >( ), + out_name, + data_name + ); + this->_Unblock( ); - } // fi + // Keep a track on a local data tree and go to next output + this->m_Objects[ out_name ] = TTreeNode( data_name, mesh ); + continue; - TPlugins::TMesh* mesh = filter->GetOutput< TPlugins::TMesh >( *oIt ); - if( mesh != NULL ) - { - // Show mesh - this->_Block( ); - this->m_UI->MPR->ShowMesh( - mesh->GetVTK< vtkPolyData >( ), - out_name, - data_name - ); - this->_Unblock( ); + } // fi - // Keep a track on a local data tree and go to next output - this->m_Objects[ out_name ] = TTreeNode( data_name, mesh ); - continue; + } // rof - } // fi + // No-modal filters just exists for one usage + this->m_ActiveFilter = NULL; - } // rof + } // fi + */ } // ------------------------------------------------------------------------- diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index c4d43e3..f5cb03d 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -180,6 +180,9 @@ private: typedef std::map< std::string, TTreeNode > TTree; TTree m_Objects; + // Active filter (for modal configuration) + TPlugins::TProcessObject::Pointer m_ActiveFilter; + // Plugins objects /* TPluginsInterface m_Plugins; diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx index bf82ba6..a23e374 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.cxx @@ -1,5 +1,6 @@ #include +#include #include #include #include @@ -85,6 +86,16 @@ SeedWidgetOff( ) } // fi } +// ------------------------------------------------------------------------- +void cpExtensions::Interaction::ImageInteractorStyle:: +SetSeedWidgetCommand( vtkCommand* cmd ) +{ + if( cmd == NULL || this->m_SeedWidget == NULL ) + return; + this->m_SeedWidget->Widget-> + AddObserver( vtkCommand::PlacePointEvent, cmd ); +} + // ------------------------------------------------------------------------- cpExtensions::Interaction::ImageInteractorStyle:: ImageInteractorStyle( ) diff --git a/lib/cpExtensions/Interaction/ImageInteractorStyle.h b/lib/cpExtensions/Interaction/ImageInteractorStyle.h index b63ca90..c18ab72 100644 --- a/lib/cpExtensions/Interaction/ImageInteractorStyle.h +++ b/lib/cpExtensions/Interaction/ImageInteractorStyle.h @@ -13,6 +13,7 @@ #include // Forward definitions +class vtkCommand; class vtkImageActor; namespace cpExtensions @@ -65,6 +66,7 @@ namespace cpExtensions // Widgets void SeedWidgetOn( ); void SeedWidgetOff( ); + void SetSeedWidgetCommand( vtkCommand* cmd ); protected: ImageInteractorStyle( ); diff --git a/lib/cpExtensions/Visualization/MPRObjects.cxx b/lib/cpExtensions/Visualization/MPRObjects.cxx index af0ad41..a0c1f3e 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.cxx +++ b/lib/cpExtensions/Visualization/MPRObjects.cxx @@ -68,6 +68,13 @@ AddImage( vtkImageData* image ) this->RenderAll( 1e-3 ); } +// ------------------------------------------------------------------------- +unsigned int cpExtensions::Visualization::MPRObjects:: +GetNumberOfImages( ) const +{ + return( this->m_MPRActors->GetNumberOfImages( ) ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRObjects:: ClearAll( ) diff --git a/lib/cpExtensions/Visualization/MPRObjects.h b/lib/cpExtensions/Visualization/MPRObjects.h index 8ac1cd2..c21fca6 100644 --- a/lib/cpExtensions/Visualization/MPRObjects.h +++ b/lib/cpExtensions/Visualization/MPRObjects.h @@ -45,6 +45,7 @@ namespace cpExtensions vtkRenderWindow* wz, vtkRenderWindow* w3D ); void AddImage( vtkImageData* image ); + unsigned int GetNumberOfImages( ) const; void ClearAll( ); void ResetCamera( const int& id ); diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.cxx b/lib/cpPlugins/Interface/BaseMPRWidget.cxx index 2017b17..ae56e07 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWidget.cxx @@ -10,7 +10,8 @@ cpPlugins::Interface::BaseMPRWidget:: BaseMPRWidget( QWidget* parent ) : QWidget( parent ), - m_UI( new Ui::BaseMPRWidget ) + m_UI( new Ui::BaseMPRWidget ), + m_MainImage( "" ) { this->m_UI->setupUi( this ); @@ -44,27 +45,194 @@ cpPlugins::Interface::BaseMPRWidget:: ~BaseMPRWidget( ) { delete this->m_UI; +} - // Delete polydata actors - std::map< std::string, PolyDataActor* >::iterator mIt = - this->m_Meshes.begin( ); - for( ; mIt != this->m_Meshes.end( ); ++mIt ) - delete mIt->second; - this->m_Meshes.clear( ); +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::BaseMPRWidget:: +AddImage( + vtkImageData* image, const std::string& name, const std::string& parent + ) +{ + if( name == "" ) + return( false ); + + if( parent == "" ) + this->DeleteAllData( ); + + auto iIt = this->m_Data.find( name ); + if( iIt == this->m_Data.end( ) ) + { + // Update tree + if( parent != "" ) + { + auto pIt = this->m_Data.find( parent ); + if( pIt != this->m_Data.end( ) ) + this->m_Tree[ name ] = parent; + else + return( false ); + } + else + this->m_MainImage = name; + + // Add new data + Data nd; + nd.Tag = Data::IMAGE; + nd.Image = image; + this->m_Data[ name ] = nd; + + // Add to tree view + this->_UpdateItem( name, parent ); + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: -ShowImage( +AddMesh( + vtkPolyData* mesh, const std::string& name, const std::string& parent + ) +{ + if( name == "" || parent == "" ) + return( false ); + + auto iIt = this->m_Data.find( name ); + if( iIt == this->m_Data.end( ) ) + { + // Add new data + Data nd; + nd.Tag = Data::MESH; + nd.Mesh.Configure( mesh ); + this->m_Data[ name ] = nd; + + // Update tree + auto pIt = this->m_Data.find( parent ); + if( pIt != this->m_Data.end( ) ) + this->m_Tree[ name ] = parent; + else + return( false ); + + // Add to tree view + this->_UpdateItem( name, parent ); + return( true ); + } + else + return( false ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget:: +DeleteData( const std::string& name ) +{ + auto iIt = this->m_Data.find( name ); + if( iIt != this->m_Data.end( ) ) + { + this->m_Data.erase( iIt ); + + // Get children + std::vector< std::string > to_erase; + auto tIt = this->m_Tree.begin( ); + for( ; tIt != this->m_Tree.end( ); ++tIt ) + if( tIt->second == name ) + to_erase.push_back( tIt->first ); + + // Delete from tree + tIt = this->m_Tree.find( name ); + if( tIt != this->m_Tree.end( ) ) + this->m_Tree.erase( tIt ); + + // Recursive erase + auto dIt = to_erase.begin( ); + for( ; dIt != to_erase.end( ); ++dIt ) + this->DeleteData( *dIt ); + + // Delete from tree widget + QTreeWidgetItem* item = this->_FindItem( name ); + if( item != NULL ) + this->m_UI->LoadedData->removeItemWidget( item, 0 ); + + // Reset main image, just in case + if( this->m_Data.size( ) == 0 ) + this->m_MainImage = ""; + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget:: +DeleteAllData( ) +{ + this->m_MPRObjects->ClearAll( ); + this->m_Data.clear( ); + this->m_Tree.clear( ); + this->m_UI->LoadedData->clear( ); + this->m_MainImage = ""; +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget:: +SetDataColor( + const std::string& name, const double& r, const double& g, const double& b + ) +{ + auto iIt = this->m_Data.find( name ); + if( iIt == this->m_Data.end( ) ) + return; + + if( iIt->second.Tag == Data::IMAGE ) + { + } + else if( iIt->second.Tag == Data::MESH ) + { + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget:: +ShowData( const std::string& name ) +{ + auto iIt = this->m_Data.find( name ); + if( iIt == this->m_Data.end( ) ) + return; + + if( iIt->second.Tag == Data::IMAGE ) + { + this->m_MPRObjects->AddImage( iIt->second.Image ); + } + else if( iIt->second.Tag == Data::MESH ) + { + } // fi +} + +// ------------------------------------------------------------------------- +vtkRenderWindowInteractor* cpPlugins::Interface::BaseMPRWidget:: +GetInteractor( unsigned int i ) +{ + if( i < 4 ) + { + if( this->m_VTK[ i ] != NULL ) + return( this->m_VTK[ i ]->GetInteractor( ) ); + else + return( NULL ); + } + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +/* + bool cpPlugins::Interface::BaseMPRWidget:: + ShowImage( vtkImageData* image, const std::string& name, const std::string& parent ) -{ + { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); if( new_item == NULL ) - return( false ); + return( false ); // Associate new data this->m_Images[ name ] = image; @@ -73,21 +241,21 @@ ShowImage( // Show image and return this->m_MPRObjects->AddImage( image ); return( true ); -} + } -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::BaseMPRWidget:: -ShowImage( + // ------------------------------------------------------------------------- + bool cpPlugins::Interface::BaseMPRWidget:: + ShowImage( vtkImageData* image, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ) -{ + { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); if( new_item == NULL ) - return( false ); + return( false ); // Associate new data this->m_Images[ name ] = image; @@ -96,20 +264,20 @@ ShowImage( // Show image and return this->m_MPRObjects->AddImage( image ); return( true ); -} + } -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::BaseMPRWidget:: -ShowMesh( + // ------------------------------------------------------------------------- + bool cpPlugins::Interface::BaseMPRWidget:: + ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent ) -{ + { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); if( new_item == NULL ) - return( false ); + return( false ); // Associate new data PolyDataActor* actor = new PolyDataActor( mesh ); @@ -119,30 +287,29 @@ ShowMesh( // Show mesh this->_Add3DActor( actor->Actor ); return( true ); -} + } -// ------------------------------------------------------------------------- -bool cpPlugins::Interface::BaseMPRWidget:: -ShowMesh( + // ------------------------------------------------------------------------- + bool cpPlugins::Interface::BaseMPRWidget:: + ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ) -{ + { return false; -} + } -// ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWidget:: -ClearAll( ) -{ - /* - this->m_MPRObjects->ClearAll( ); - this->m_Images.clear( ); - this->m_Meshes.clear( ); - */ -} + // ------------------------------------------------------------------------- + void cpPlugins::Interface::BaseMPRWidget:: + ClearAll( ) + { + this->m_MPRObjects->ClearAll( ); + this->m_Images.clear( ); + this->m_Meshes.clear( ); + } +*/ // ------------------------------------------------------------------------- std::string cpPlugins::Interface::BaseMPRWidget:: @@ -201,16 +368,18 @@ _UpdateItem( const std::string& name, const std::string& parent ) } // ------------------------------------------------------------------------- -void cpPlugins::Interface::BaseMPRWidget:: -_Add3DActor( vtkProp3D* prop ) -{ +/* + void cpPlugins::Interface::BaseMPRWidget:: + _Add3DActor( vtkProp3D* prop ) + { vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); + this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); if( ren == NULL ) - return; + return; ren->AddActor( prop ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); -} + } +*/ // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWidget:: @@ -227,8 +396,8 @@ _SyncTop( int a, int b ) } // ------------------------------------------------------------------------- -cpPlugins::Interface::BaseMPRWidget::PolyDataActor:: -PolyDataActor( vtkPolyData* pd ) +void cpPlugins::Interface::BaseMPRWidget::PolyDataActor:: +Configure( vtkPolyData* pd ) { if( pd == NULL ) return; @@ -241,6 +410,7 @@ PolyDataActor( vtkPolyData* pd ) this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( ); + this->Mesh = pd; this->Normals->SetInputData( pd ); this->Normals->SetFeatureAngle( 60.0 ); this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) ); diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.h b/lib/cpPlugins/Interface/BaseMPRWidget.h index 9ed62ce..0807a87 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.h +++ b/lib/cpPlugins/Interface/BaseMPRWidget.h @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -60,30 +61,56 @@ namespace cpPlugins explicit BaseMPRWidget( QWidget* parent = 0 ); virtual ~BaseMPRWidget( ); + // Data management + bool AddImage( + vtkImageData* image, + const std::string& name, + const std::string& parent = "" + ); + bool AddMesh( + vtkPolyData* mesh, + const std::string& name, + const std::string& parent + ); + void DeleteData( const std::string& name ); + void DeleteAllData( ); + // Some visualization accessors - bool ShowImage( + void SetDataColor( + const std::string& name, + const double& r, + const double& g, + const double& b + ); + void ShowData( const std::string& name ); + + vtkRenderWindowInteractor* GetInteractor( unsigned int i ); + + /* + bool ShowImage( vtkImageData* image, const std::string& name, const std::string& parent = "" ); - bool ShowImage( + bool ShowImage( vtkImageData* image, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ); - bool ShowMesh( + bool ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent ); - bool ShowMesh( + bool ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ); - void ClearAll( ); + void ClearAll( ); + */ // Visual objects accessors std::string GetSelectedData( ) const; @@ -94,8 +121,10 @@ namespace cpPlugins const std::string& name, const std::string& parent ); - - void _Add3DActor( vtkProp3D* prop ); + + /* TODO + void _Add3DActor( vtkProp3D* prop ); + */ private slots: void _SyncBottom( int a, int b ); @@ -104,22 +133,67 @@ namespace cpPlugins protected: Ui::BaseMPRWidget* m_UI; vtkSmartPointer< TMPRObjects > m_MPRObjects; + QVTKWidget* m_VTK[ 4 ]; struct PolyDataActor { + vtkSmartPointer< vtkPolyData > Mesh; vtkSmartPointer< vtkPolyDataNormals > Normals; vtkSmartPointer< vtkStripper > Stripper; vtkSmartPointer< vtkPolyDataMapper > Mapper; vtkSmartPointer< vtkQuadricLODActor > Actor; - PolyDataActor( vtkPolyData* pd ); + void Configure( vtkPolyData* pd ); }; - std::map< std::string, vtkImageData* > m_Images; - std::map< std::string, PolyDataActor* > m_Meshes; - std::map< std::string, std::string > m_Tree; + struct Data + { + enum { IMAGE, MESH } Tag; + union + { + vtkImageData* Image; + PolyDataActor Mesh; + }; + + Data( ) { } + virtual ~Data( ) { } + + inline Data& operator=( const Data& data ) + { + this->Tag = data.Tag; + if( this->Tag == Data::IMAGE ) + this->Image = data.Image; + else if( this->Tag == Data::MESH ) + this->Mesh = data.Mesh; + return( *this ); + } + + inline vtkImageData* GetImage( ) + { + if( this->Tag == Data::IMAGE ) + return( this->Image ); + else + return( NULL ); + } + inline vtkPolyData* GetMesh( ) + { + if( this->Tag == Data::MESH ) + return( this->Mesh.Mesh.GetPointer( ) ); + else + return( NULL ); + } + inline vtkProp* GetMeshActor( ) + { + if( this->Tag == Data::MESH ) + return( this->Mesh.Actor.GetPointer( ) ); + else + return( NULL ); + } + }; - QVTKWidget* m_VTK[ 4 ]; + std::string m_MainImage; + std::map< std::string, Data > m_Data; + std::map< std::string, std::string > m_Tree; }; } // ecapseman diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 3cea961..12cca5d 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -6,6 +6,7 @@ #include +#include #include #include @@ -15,6 +16,21 @@ #include #include +// ------------------------------------------------------------------------- +class SingleSeedCommand + : public vtkCommand +{ +public: + static SingleSeedCommand* New( ) + { return( new SingleSeedCommand ); } + virtual void Execute( vtkObject* caller, unsigned long eid, void* data ) + { + if( eid != vtkCommand::PlacePointEvent ) + return; +#error ACA VOY + } +}; + // ------------------------------------------------------------------------- cpPlugins::Interface::ParametersQtDialog:: ParametersQtDialog( QWidget* parent, Qt::WindowFlags f ) @@ -131,22 +147,23 @@ setParameters( Parameters* parameters ) } else if( pt == Parameters::Point || pt == Parameters::Index ) { + vtkSmartPointer< SingleSeedCommand > command = + vtkSmartPointer< SingleSeedCommand >::New( ); + auto iIt = this->m_Interactors.begin( ); for( ; iIt != this->m_Interactors.end( ); ++iIt ) { TStyle* style = dynamic_cast< TStyle* >( ( *iIt )->GetInteractorStyle( ) ); - std::cout << "ACA VOY --> " << style << std::endl; - - } // rof - this->m_IsModal = false; - - /* - if( this->m_Interactor != NULL ) + if( style != NULL ) { + style->SeedWidgetOn( ); + style->SetSeedWidgetCommand( command ); } // fi - */ + + } // rof + this->m_IsModal = false; } // fi diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index 45f5559..0e69212 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -271,10 +271,10 @@ ReadImage( TImage::Pointer& image, bool exec_qt ) if( ret == "" ) { - bool execute = true; + TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal; if( exec_qt ) - execute = this->m_ImageReader->ExecConfigurationDialog( this->m_Widget ); - if( execute ) + dret = this->m_ImageReader->ExecConfigurationDialog( this->m_Widget ); + if( dret != TProcessObject::DialogResult_Cancel ) { this->BlockWidget( ); ret = this->m_ImageReader->Update( ); @@ -319,7 +319,9 @@ ReadDicomSeries( TImage::Pointer& image ) if( ret == "" ) { - if( this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget ) ) + TProcessObject::DialogResult dret = + this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget ); + if( dret != TProcessObject::DialogResult_Cancel ) { this->BlockWidget( ); ret = this->m_DicomSeriesReader->Update( ); @@ -365,10 +367,10 @@ ReadMesh( TMesh::Pointer& mesh, bool exec_qt ) if( ret == "" ) { - bool execute = true; + TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal; if( exec_qt ) - execute = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget ); - if( execute ) + dret = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget ); + if( dret != TProcessObject::DialogResult_Cancel ) { this->BlockWidget( ); ret = this->m_MeshReader->Update( ); @@ -412,10 +414,10 @@ WriteImage( TImage* image, bool exec_qt ) if( ret == "" ) { - bool execute = true; + TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal; if( exec_qt ) - execute = this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget ); - if( execute ) + dret = this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget ); + if( dret != TProcessObject::DialogResult_Cancel ) { this->m_ImageWriter->SetInput( "Input", image ); this->BlockWidget( ); @@ -453,10 +455,10 @@ WriteMesh( TMesh* mesh, bool exec_qt ) if( ret == "" ) { - bool execute = true; + TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal; if( exec_qt ) - execute = this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget ); - if( execute ) + dret = this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget ); + if( dret != TProcessObject::DialogResult_Cancel ) { this->m_MeshWriter->SetInput( "Input", mesh ); this->BlockWidget( ); diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index f639d7f..9c3148d 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -4,6 +4,8 @@ #include #endif // cpPlugins_Interface_QT4 +#include + // ------------------------------------------------------------------------- void cpPlugins::Interface::ProcessObject:: Modified( ) const @@ -115,39 +117,39 @@ DisconnectOutputs( ) } // ------------------------------------------------------------------------- -bool cpPlugins::Interface::ProcessObject:: +void cpPlugins::Interface::ProcessObject:: +AddInteractor( vtkRenderWindowInteractor* interactor ) +{ +#ifdef cpPlugins_Interface_QT4 + this->m_ParametersDialog->addInteractor( interactor ); +#endif // cpPlugins_Interface_QT4 +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::ProcessObject:: +DialogResult cpPlugins::Interface::ProcessObject:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 - if( this->m_ParametersDialog == NULL ) - { - this->m_ParametersDialog = new ParametersQtDialog( parent ); - this->m_ParametersDialog->setTitle( - this->GetClassName( ) + std::string( " basic configuration" ) - ); - this->m_ParametersDialog->setParameters( this->m_Parameters ); - - } // fi + this->m_ParametersDialog->setParent( NULL ); + this->m_ParametersDialog->setParameters( this->m_Parameters ); if( !( this->m_ParametersDialog->IsModal( ) ) ) { this->m_ParametersDialog->show( ); - r = true; + r = Self::DialogResult_Modal; } else - r = ( this->m_ParametersDialog->exec( ) == 1 ); + { + if( this->m_ParametersDialog->exec( ) == 1 ) + r = Self::DialogResult_NoModal; + else + r = Self::DialogResult_Cancel; - /* - r = cpPlugins::Interface::ParametersQtDialog( - this->m_Parameters, - this->GetClassName( ) + std::string( " basic configuration" ), - parent - ); - if( r ) - */ + } // fi #endif // cpPlugins_Interface_QT4 @@ -159,18 +161,21 @@ cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), m_ITKObject( NULL ), - m_VTKObject( NULL ), - m_ParametersDialog( NULL ) + m_VTKObject( NULL ) { this->m_Parameters = TParameters::New( ); + + this->m_ParametersDialog = new ParametersQtDialog( ); + this->m_ParametersDialog->setTitle( + this->GetClassName( ) + std::string( " basic configuration" ) + ); } // ------------------------------------------------------------------------- cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { - if( this->m_ParametersDialog == NULL ) - delete this->m_ParametersDialog; + delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index 5fc98f3..6f38814 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -22,6 +22,8 @@ typedef char QWidget; #include #include +class vtkRenderWindowInteractor; + namespace cpPlugins { namespace Interface @@ -45,6 +47,13 @@ namespace cpPlugins typedef Parameters TParameters; + enum DialogResult + { + DialogResult_NoModal = 0, + DialogResult_Modal, + DialogResult_Cancel + }; + public: itkTypeMacro( ProcessObject, Object ); cpPlugins_Id_Macro( @@ -69,7 +78,8 @@ namespace cpPlugins virtual std::string Update( ); virtual void DisconnectOutputs( ); - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual void AddInteractor( vtkRenderWindowInteractor* interactor ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); template< class T > inline T* GetITK( ); diff --git a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx index e915fcf..e2aeb31 100644 --- a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx +++ b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.cxx @@ -20,10 +20,11 @@ #include // ------------------------------------------------------------------------- -bool cpPlugins::IO::DicomSeriesReader:: +cpPlugins::IO::DicomSeriesReader:: +DialogResult cpPlugins::IO::DicomSeriesReader:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 @@ -37,7 +38,7 @@ ExecConfigurationDialog( QWidget* parent ) dialog.setFileMode( QFileDialog::DirectoryOnly ); dialog.setDirectory( QFileDialog::tr( "." ) ); if( !dialog.exec( ) ) - return( false ); + return( Self::DialogResult_Cancel ); // Prepare dialog QApplication::setOverrideCursor( Qt::WaitCursor ); @@ -119,7 +120,7 @@ ExecConfigurationDialog( QWidget* parent ) { delete tree_widget; delete tree_dialog; - return( false ); + return( Self::DialogResult_Cancel ); } // fi @@ -149,7 +150,7 @@ ExecConfigurationDialog( QWidget* parent ) parent->setEnabled( true ); if( tree_dialog->exec( ) == 0 ) - return( false ); + return( Self::DialogResult_Cancel ); QTreeWidgetItem* item = tree_widget->currentItem( ); if( item != NULL ) @@ -169,7 +170,7 @@ ExecConfigurationDialog( QWidget* parent ) for( unsigned int f = 0; f < names.size( ); ++f ) this->m_Parameters->AddToStringList( "FileNames", names[ f ] ); - r = true; + r = Self::DialogResult_NoModal; QApplication::restoreOverrideCursor( ); if( parent != NULL ) diff --git a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h index 3bad459..c912476 100644 --- a/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h +++ b/lib/cpPlugins/Plugins/IO/DicomSeriesReader.h @@ -37,7 +37,7 @@ namespace cpPlugins ); public: - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); protected: DicomSeriesReader( ); diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.cxx b/lib/cpPlugins/Plugins/IO/ImageReader.cxx index fc747eb..a7c6687 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageReader.cxx @@ -9,10 +9,11 @@ #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -bool cpPlugins::IO::ImageReader:: +cpPlugins::IO::ImageReader:: +DialogResult cpPlugins::IO::ImageReader:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 @@ -40,7 +41,7 @@ ExecConfigurationDialog( QWidget* parent ) "FileNames", qIt->toStdString( ) ); this->m_Parameters->SetBool( "VectorType", false ); - r = true; + r = Self::DialogResult_NoModal; } // fi diff --git a/lib/cpPlugins/Plugins/IO/ImageReader.h b/lib/cpPlugins/Plugins/IO/ImageReader.h index 2f41e10..822c5fd 100644 --- a/lib/cpPlugins/Plugins/IO/ImageReader.h +++ b/lib/cpPlugins/Plugins/IO/ImageReader.h @@ -37,7 +37,7 @@ namespace cpPlugins ); public: - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); protected: ImageReader( ); diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx index 63080e2..519adb6 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.cxx @@ -8,10 +8,11 @@ #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -bool cpPlugins::IO::ImageWriter:: +cpPlugins::IO::ImageWriter:: +DialogResult cpPlugins::IO::ImageWriter:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 @@ -31,7 +32,7 @@ ExecConfigurationDialog( QWidget* parent ) if( name != "" ) { this->m_Parameters->SetString( "FileName", name ); - r = true; + r = Self::DialogResult_NoModal; } // fi diff --git a/lib/cpPlugins/Plugins/IO/ImageWriter.h b/lib/cpPlugins/Plugins/IO/ImageWriter.h index 849fc47..a9db113 100644 --- a/lib/cpPlugins/Plugins/IO/ImageWriter.h +++ b/lib/cpPlugins/Plugins/IO/ImageWriter.h @@ -27,7 +27,7 @@ namespace cpPlugins ); public: - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); protected: ImageWriter( ); diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.cxx b/lib/cpPlugins/Plugins/IO/MeshReader.cxx index 077b969..f8c3b84 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshReader.cxx @@ -9,10 +9,11 @@ #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -bool cpPlugins::IO::MeshReader:: +cpPlugins::IO::MeshReader:: +DialogResult cpPlugins::IO::MeshReader:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 @@ -28,7 +29,7 @@ ExecConfigurationDialog( QWidget* parent ) this->m_Parameters->SetSelectedChoice( "PixelType", "float" ); this->m_Parameters->SetUint( "Dimension", 3 ); - r = true; + r = Self::DialogResult_NoModal; } // fi diff --git a/lib/cpPlugins/Plugins/IO/MeshReader.h b/lib/cpPlugins/Plugins/IO/MeshReader.h index 7544a24..6724cd5 100644 --- a/lib/cpPlugins/Plugins/IO/MeshReader.h +++ b/lib/cpPlugins/Plugins/IO/MeshReader.h @@ -29,7 +29,7 @@ namespace cpPlugins ); public: - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); protected: MeshReader( ); diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx index 4aae3a3..13531a5 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.cxx +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.cxx @@ -10,10 +10,11 @@ #endif // cpPlugins_Interface_QT4 // ------------------------------------------------------------------------- -bool cpPlugins::IO::MeshWriter:: +cpPlugins::IO::MeshWriter:: +DialogResult cpPlugins::IO::MeshWriter:: ExecConfigurationDialog( QWidget* parent ) { - bool r = false; + DialogResult r = Self::DialogResult_Cancel; #ifdef cpPlugins_Interface_QT4 @@ -33,7 +34,7 @@ ExecConfigurationDialog( QWidget* parent ) if( name != "" ) { this->m_Parameters->SetString( "FileName", name ); - r = true; + r = Self::DialogResult_NoModal; } // fi diff --git a/lib/cpPlugins/Plugins/IO/MeshWriter.h b/lib/cpPlugins/Plugins/IO/MeshWriter.h index c97509d..3666864 100644 --- a/lib/cpPlugins/Plugins/IO/MeshWriter.h +++ b/lib/cpPlugins/Plugins/IO/MeshWriter.h @@ -29,7 +29,7 @@ namespace cpPlugins ); public: - virtual bool ExecConfigurationDialog( QWidget* parent ); + virtual DialogResult ExecConfigurationDialog( QWidget* parent ); protected: MeshWriter( );