From: Leonardo Florez-Valencia Date: Mon, 9 Nov 2015 22:53:44 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~303^2~1 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d5863750d8146d52ee20ce7835f5fb92e6d13fe9;p=cpPlugins.git ... --- diff --git a/appli/ImageMPR/ImageMPR.cxx b/appli/ImageMPR/ImageMPR.cxx index 5754e3d..70124e9 100644 --- a/appli/ImageMPR/ImageMPR.cxx +++ b/appli/ImageMPR/ImageMPR.cxx @@ -60,10 +60,25 @@ ImageMPR:: void ImageMPR:: UpdateActualFilter( ) { - /* TODO - if( !( this->m_Plugins->HasActiveFilter( ) ) ) - return; + if( !( this->m_Plugins.HasActiveFilter( ) ) ) + return; + + // Update filter + TPlugins::TStringContainer outputs; + if( + !( + this->m_Plugins.UpdateActiveFilter( + outputs, this->m_ActiveFilterMainInput + ) + ) + ) + return; + + // Show outputs + for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) + std::cout << *oIt << std::endl; + /* TODO std::vector< std::string > outputs; std::string err = this->m_Plugins->UpdateActiveFilter( outputs ); if( err == "" ) @@ -255,9 +270,8 @@ _execPlugin( ) return; // Get IO names - TPlugins::TStringContainer inputs, outputs; + TPlugins::TStringContainer inputs; this->m_Plugins.GetActiveFilterInputsNames( inputs ); - this->m_Plugins.GetActiveFilterOutputsNames( outputs ); // Configure inputs if( inputs.size( ) > 1 ) @@ -265,80 +279,29 @@ _execPlugin( ) // TODO } else if( inputs.size( ) == 1 ) + { + this->m_ActiveFilterMainInput = this->m_UI->MPR->GetSelectedData( ); this->m_Plugins.ConnectInputInActiveFilter( - this->m_UI->MPR->GetSelectedData( ), *( inputs.begin( ) ) + this->m_ActiveFilterMainInput, *( inputs.begin( ) ) ); - // Configure outputs - for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) - this->m_Plugins.SetOutputNameInActiveFilter( - filter_name + "_" + *oIt, *oIt - ); + } // fi // Configure paramereters auto dlg_res = this->m_Plugins.ConfigureActiveFilter( ); if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel ) { + // Just deactivate filter, since it was canceled this->m_Plugins.DeactivateFilter( ); - // TODO - } - - - /* - QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) ); - if( menu == NULL ) return; - std::string filter_cate = menu->title( ).toStdString( ); - - // Activate filter - if( !( this->m_Plugins->ActivateFilter( filter_name ) ) ) - return; - - // Associate inputs - std::vector< std::string > inputs = - this->m_Plugins->GetActiveFilterInputsNames( ); - if( inputs.size( ) == 1 ) - { - std::string data_name = this->m_UI->MPR->GetSelectedData( ); - this->m_Plugins->ConnectInputInActiveFilter( data_name, inputs[ 0 ] ); - } - else if( inputs.size( ) > 1 ) - { - QMessageBox::critical( - this, - tr( "Error executing" ), - tr( "Filter has multiple inputs: NOT YET IMPLEMENTED!!!" ) - ); - return; - - } // fi - - // Associate outputs - std::vector< std::string > outputs = - this->m_Plugins->GetActiveFilterOutputsNames( ); - for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt ) - this->m_Plugins->SetOutputNameInActiveFilter( - filter_name + "_" + *oIt, *oIt - ); - - // Configure filter - TPlugins::TProcessObject::DialogResult dlg_res = - this->m_Plugins->ConfigureActiveFilter( ); - if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel ) - { - this->m_Plugins->DeactivateFilter( ); - return; - - } // fi - - // Execute filter and associate outputs - if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal ) - { + } + else if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal ) + { + // Execute automatic filter and associate outputs this->UpdateActualFilter( ); - this->m_Plugins->DeactivateFilter( ); + this->m_Plugins.DeactivateFilter( ); - } // fi - */ + } // fi } // ------------------------------------------------------------------------- diff --git a/appli/ImageMPR/ImageMPR.h b/appli/ImageMPR/ImageMPR.h index 0a0199e..e11ec5d 100644 --- a/appli/ImageMPR/ImageMPR.h +++ b/appli/ImageMPR/ImageMPR.h @@ -182,6 +182,7 @@ private slots: private: Ui::ImageMPR* m_UI; TPlugins m_Plugins; + std::string m_ActiveFilterMainInput; // Objects /* diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index a389ddb..023d380 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -27,13 +27,13 @@ ENDFOREACH(prog) SET( EXAMPLES_PROGRAMS_WITH_PLUGINS example_ReadWriteImage + example_MarchingCubes #example_MPR example_View2DImage example_HandleWidget example_SeedWidget example_SphereWidget example_Test_Memento - ##example_MarchingCubes ##example_OtsuFilter ##example_RGBImageToHSVChannels ##example_RGBImageToYPbPrChannels diff --git a/appli/examples/example_MarchingCubes.cxx b/appli/examples/example_MarchingCubes.cxx index fbd43bb..a61a278 100644 --- a/appli/examples/example_MarchingCubes.cxx +++ b/appli/examples/example_MarchingCubes.cxx @@ -2,75 +2,89 @@ #include #include -#include -#include +#include +// ------------------------------------------------------------------------- +typedef cpPlugins::Interface::Plugins TPlugins; + +// ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { - if( argc < 5 ) + if( argc < 4 ) { std::cerr << "Usage: " << argv[ 0 ] << " plugins_file" - << " input_image value output_mesh" << std::endl; + << " input_image threshold output_image" << std::endl; return( 1 ); } // fi - // Create interface - typedef cpPlugins::Interface::Interface TInterface; - typedef TInterface::TClasses TClasses; - TInterface plugins; - if( !plugins.Load( argv[ 1 ] ) ) + // Load plugins + cpPlugins::Interface::Plugins plugins; + if( !plugins.LoadPluginsPath( argv[ 1 ] ) ) { std::cerr << "Failed to load plugins." << std::endl; return( 1 ); } // fi - // Create objects - typedef cpPlugins::Interface::ProcessObject TProcessObject; - typedef cpPlugins::Interface::DataObject TDataObject; - typedef cpPlugins::Interface::Parameters TParameters; - cpPlugins::Interface::ProcessObject::Pointer reader, writer, mc; - reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" ); - writer = plugins.CreateProcessObject( "cpPlugins::MeshWriter" ); - mc = plugins.CreateProcessObject( "cpPlugins::MarchingCubes" ); - if( reader.IsNull( ) || writer.IsNull( ) || mc.IsNull( ) ) + // Associate filenames + std::vector< std::string > fnames; + for( int i = 2; i < argc - 2; ++i ) + fnames.push_back( argv[ i ] ); + + // Read image + std::string filter = "cpPlugins::BasicFilters::MarchingCubes"; + try { - std::cerr << "No suitable objects found in plugins." << std::endl; - return( 1 ); + std::string name = plugins.ReadImage( fnames, "" ); - } // fi + if( !( plugins.ActivateFilter( filter ) ) ) + { + std::cerr << "Filter \"" << filter << "\" not found." << std::endl; + return( 1 ); - // Configure reader - TParameters reader_params = reader->GetDefaultParameters( ); - for( int i = 2; i < argc - 2; ++i ) - reader_params.AddValueToStringList( "FileNames", argv[ i ] ); - reader->SetParameters( reader_params ); - - // Configure marching cubes - TParameters mc_params = mc->GetDefaultParameters( ); - mc_params.AddValueToRealList( "Thresholds", std::atof( argv[ argc - 2 ] ) ); - mc->SetParameters( mc_params ); - - // Configure writer - TParameters writer_params = writer->GetDefaultParameters( ); - writer_params.SetValueAsString( "FileName", argv[ argc - 1 ] ); - writer->SetParameters( writer_params ); - - // Connect pipeline - mc->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) ); - writer->SetInput( 0, mc->GetOutput< TDataObject >( 0 ) ); - - // Execute pipeline - std::string err = writer->Update( ); - if( err != "" ) + } // fi + + // Connect IO objects + TPlugins::TStringContainer inputs, outputs; + plugins.GetActiveFilterInputsNames( inputs ); + plugins.GetActiveFilterOutputsNames( outputs ); + + plugins.ConnectInputInActiveFilter( name, *( inputs.begin( ) ) ); + //plugins.SetOutputNameInActiveFilter( "output_mesh", *( outputs.begin( ) ) ); + + // Configure filter + TPlugins::TParameters* params = plugins.GetActiveFilterParameters( ); + params->AddToRealList( "Thresholds", std::atof( argv[ argc - 2 ] ) ); + + // Execute filter + TPlugins::TStringContainer generated_outputs; + if( !( plugins.UpdateActiveFilter( generated_outputs, name ) ) ) + { + std::cerr << "Error using filter \"" << filter << "\"." << std::endl; + return( 1 ); + + } // fi + + // Save mesh + std::string outmesh_name = *( generated_outputs.begin( ) ); + if( !( plugins.WriteDataObject( argv[ argc - 1 ], outmesh_name ) ) ) + { + std::cerr + << "Error writing result into \"" << argv[ argc - 1 ] + << "\"" << std::endl; + return( 1 ); + + } // fi + } + catch( std::exception& err ) { - std::cerr << "ERROR: " << err << std::endl; + std::cerr << err.what( ) << std::endl; return( 1 ); - } // fi + } // yrt return( 0 ); } diff --git a/appli/examples/example_View2DImage.cxx b/appli/examples/example_View2DImage.cxx index 2778e88..5e83271 100644 --- a/appli/examples/example_View2DImage.cxx +++ b/appli/examples/example_View2DImage.cxx @@ -1,25 +1,20 @@ #include #include #include +#include #include #include #include -#include -#include +#include #include #include // ------------------------------------------------------------------------- -typedef cpPlugins::Interface::Interface TInterface; -typedef cpPlugins::Interface::ProcessObject TProcessObject; -typedef cpPlugins::Interface::DataObject TDataObject; -typedef cpPlugins::Interface::Image TImage; -typedef cpPlugins::Interface::Parameters TParameters; -typedef TInterface::TClasses TClasses; - +typedef cpPlugins::Interface::Plugins TPlugins; +typedef cpPlugins::Interface::Image TImage; typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; // ------------------------------------------------------------------------- @@ -29,53 +24,39 @@ int main( int argc, char* argv[] ) { std::cerr << "Usage: " << argv[ 0 ] - << " plugins_file input_image [widget]" + << " plugins_file input_image" << std::endl; return( 1 ); } // fi - // Create interface - TInterface plugins; - if( !plugins.Load( argv[ 1 ] ) ) + // Load plugins + cpPlugins::Interface::Plugins plugins; + if( !plugins.LoadPluginsPath( argv[ 1 ] ) ) { std::cerr << "Failed to load plugins." << std::endl; return( 1 ); } // fi - // Create objects - TProcessObject::Pointer reader; - reader = plugins.CreateObject( "cpPlugins::IO::ImageReader" ); - if( reader.IsNull( ) ) - { - std::cerr - << "No suitable reader found in plugins." << std::endl - << "Reader: " << reader.GetPointer( ) << std::endl - << std::endl; - return( 1 ); - - } // fi - - // Configure reader - TParameters* reader_params = reader->GetParameters( ); - if( argc > 4 ) + // Associate filenames + std::vector< std::string > fnames; + for( int i = 2; i < argc; ++i ) + fnames.push_back( argv[ i ] ); + + // Read image + std::string name = ""; + try { - for( int i = 2; i < argc; ++i ) - reader_params->AddToStringList( "FileNames", argv[ i ] ); + name = plugins.ReadImage( fnames, "" ); } - else - reader_params->AddToStringList( "FileNames", argv[ 2 ] ); - - // Execute pipeline - std::string err = reader->Update( ); - if( err != "" ) + catch( std::exception& err ) { - std::cerr << "ERROR: " << err << std::endl; + std::cerr << err.what( ) << std::endl; return( 1 ); - } // fi - TImage* image = reader->GetOutput< TImage >( "Output" ); + } // yrt + TImage* image = plugins.GetData< TImage >( name ); // Configure visualization objects vtkSmartPointer< vtkRenderer > renderer = diff --git a/lib/cpExtensions/Visualization/ImageBlender.cxx b/lib/cpExtensions/Visualization/ImageBlender.cxx index d5cbbd4..49292c8 100644 --- a/lib/cpExtensions/Visualization/ImageBlender.cxx +++ b/lib/cpExtensions/Visualization/ImageBlender.cxx @@ -25,8 +25,8 @@ PrintSelf( std::ostream& os, vtkIndent indent ) // Objects os << indent << "Colors: " << std::endl; - auto i = this->m_Colors.begin( ); - for( ; i != this->m_Colors.end( ); ++i ) + auto i = this->Colors.begin( ); + for( ; i != this->Colors.end( ); ++i ) os << indent << indent << i->first << " : [" << i->second.R << ", " @@ -39,73 +39,9 @@ PrintSelf( std::ostream& os, vtkIndent indent ) unsigned int cpExtensions::Visualization::ImageBlender:: GetNumberOfImages( ) const { - return( ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 ) ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetMaxWindow( ) const -{ - return( this->m_MaxWindow ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetMaxLevel( ) const -{ - return( this->m_MaxLevel ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetMinWindow( ) const -{ - return( this->m_MinWindow ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetMinLevel( ) const -{ - return( this->m_MinLevel ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetWindow( ) const -{ - return( this->m_Window ); -} - -// ------------------------------------------------------------------------- -const double& cpExtensions::Visualization::ImageBlender:: -GetLevel( ) const -{ - return( this->m_Level ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageBlender:: -SetWindow( const double& w ) -{ - if( this->m_Window != w ) - { - this->m_Window = w; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::Visualization::ImageBlender:: -SetLevel( const double& l ) -{ - if( this->m_Level != l ) - { - this->m_Level = l; - this->Modified( ); - - } // fi + return( + ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 ) + ); } // ------------------------------------------------------------------------- @@ -125,8 +61,8 @@ GetColor( double& b ) const { - auto c = this->m_Colors.find( i ); - if( c != this->m_Colors.end( ) ) + auto c = this->Colors.find( i ); + if( c != this->Colors.end( ) ) { r = c->second.R; g = c->second.G; @@ -151,7 +87,7 @@ SetColor( const double& b ) { - this->m_Colors[ i ] = TColor( r, g, b ); + this->Colors[ i ] = TColor( r, g, b ); this->Modified( ); } @@ -159,12 +95,12 @@ SetColor( cpExtensions::Visualization::ImageBlender:: ImageBlender( ) : Superclass( ), - m_MaxWindow( double( 0 ) ), - m_MaxLevel( double( 0 ) ), - m_MinWindow( double( 0 ) ), - m_MinLevel( double( 0 ) ), - m_Window( double( 0 ) ), - m_Level( double( 0 ) ) + MaxWindow( double( 1 ) ), + MaxLevel( double( 1 ) ), + MinWindow( double( 0 ) ), + MinLevel( double( 0 ) ), + Window( double( 1 ) ), + Level( double( 0.5 ) ) { this->SetNumberOfInputPorts( 1 ); } @@ -208,27 +144,13 @@ RequestInformation( this->m_Extent[ 5 ] += 1; // Configure window/level - double range[ 2 ]; - inData->GetScalarRange( range ); - this->m_MaxWindow = range[ 1 ] - range[ 0 ]; - this->m_MinWindow = this->m_MaxWindow * double( 1e-2 ); - this->m_MinLevel = range[ 0 ]; - this->m_MaxLevel = range[ 1 ]; - if( this->m_Window < this->m_MinWindow ) - this->m_Window = this->m_MinWindow; - if( this->m_Window > this->m_MaxWindow ) - this->m_Window = this->m_MaxWindow; - if( this->m_Level < this->m_MinLevel ) - this->m_Level = this->m_MinLevel; - if( this->m_Level > this->m_MaxLevel ) - this->m_Level = this->m_MaxLevel; - this->m_WLSlope = double( 1 ) / this->m_Window; - this->m_WLOffset = double( 0.5 ) - ( this->m_Level / this->m_Window ); + this->m_WLSlope = double( 1 ) / this->Window; + this->m_WLOffset = double( 0.5 ) - ( this->Level / this->Window ); // Configure output type vtkDataObject::SetPointDataActiveScalarInfo( outputVector->GetInformationObject( 0 ), - VTK_UNSIGNED_CHAR, 4 + VTK_UNSIGNED_CHAR, 3 ); return( 1 ); } @@ -337,7 +259,7 @@ _GenerateData( vtkImageData** inDatas, int numInputs, vtkImageData* outData, - int outExt[6], + int outExt[ 6 ], int id ) { @@ -352,7 +274,7 @@ _GenerateData( int mType = inDatas[ 0 ]->GetScalarType( ); int mSize = inDatas[ 0 ]->GetScalarSize( ); - double r, g, b, a; + double r, g, b; int e13 = this->m_Extent[ 1 ] * this->m_Extent[ 3 ]; for( int k = outExt[ 4 ]; k <= outExt[ 5 ]; ++k ) { @@ -375,7 +297,6 @@ _GenerateData( // Prepare color r = g = b = v; - a = _1; // Blend colors for( int i = 1; i < numInputs; ++i ) @@ -391,22 +312,20 @@ _GenerateData( ); if( c > double( 0 ) ) { - TColor rgb = this->m_Colors[ i ]; + TColor rgb = this->Colors[ i ]; r *= rgb.R * rgb.N; g *= rgb.G * rgb.N; b *= rgb.B * rgb.N; - a = _1; } // fi } // rof // Update color - int di4 = di << 2; - oBuffer[ di4 + 0 ] = static_cast< unsigned char >( r * _255 ); - oBuffer[ di4 + 1 ] = static_cast< unsigned char >( g * _255 ); - oBuffer[ di4 + 2 ] = static_cast< unsigned char >( b * _255 ); - oBuffer[ di4 + 3 ] = static_cast< unsigned char >( a * _255 ); + int di3 = di * 3; + oBuffer[ di3 + 0 ] = static_cast< unsigned char >( r * _255 ); + oBuffer[ di3 + 1 ] = static_cast< unsigned char >( g * _255 ); + oBuffer[ di3 + 2 ] = static_cast< unsigned char >( b * _255 ); } // rof diff --git a/lib/cpExtensions/Visualization/ImageBlender.h b/lib/cpExtensions/Visualization/ImageBlender.h index f122822..7ccc864 100644 --- a/lib/cpExtensions/Visualization/ImageBlender.h +++ b/lib/cpExtensions/Visualization/ImageBlender.h @@ -21,21 +21,25 @@ namespace cpExtensions typedef ImageBlender Self; vtkTypeMacro( ImageBlender, vtkThreadedImageAlgorithm ); + vtkGetMacro( MaxWindow, double ); + vtkGetMacro( MaxLevel, double ); + vtkGetMacro( MinWindow, double ); + vtkGetMacro( MinLevel, double ); + vtkGetMacro( Window, double ); + vtkGetMacro( Level, double ); + + vtkSetMacro( MaxWindow, double ); + vtkSetMacro( MaxLevel, double ); + vtkSetMacro( MinWindow, double ); + vtkSetMacro( MinLevel, double ); + vtkSetMacro( Window, double ); + vtkSetMacro( Level, double ); + public: static Self* New( ); void PrintSelf( std::ostream& os, vtkIndent indent ); unsigned int GetNumberOfImages( ) const; - - const double& GetMaxWindow( ) const; - const double& GetMaxLevel( ) const; - const double& GetMinWindow( ) const; - const double& GetMinLevel( ) const; - const double& GetWindow( ) const; - const double& GetLevel( ) const; - - void SetWindow( const double& w ); - void SetLevel( const double& l ); void SetWindowLevel( const double& w, const double& l ); void GetColor( @@ -74,7 +78,7 @@ namespace cpExtensions vtkImageData** inDatas, int numInputs, vtkImageData* outData, - int outExt[6], + int outExt[ 6 ], int id ); @@ -99,14 +103,14 @@ namespace cpExtensions this->N = std::sqrt( ( r * r ) + ( g * g ) + ( b * b ) ); } }; - mutable std::map< unsigned int, TColor > m_Colors; - - double m_MaxWindow; - double m_MaxLevel; - double m_MinWindow; - double m_MinLevel; - double m_Window; - double m_Level; + mutable std::map< unsigned int, TColor > Colors; + + double MaxWindow; + double MaxLevel; + double MinWindow; + double MinLevel; + double Window; + double Level; int m_Extent[ 6 ]; double m_WLSlope; diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.cxx b/lib/cpPlugins/Interface/BaseMPRWidget.cxx index e7f270c..4a03cd9 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWidget.cxx @@ -3,6 +3,9 @@ #ifdef cpPlugins_Interface_QT4 #include +#include +#include +#include #include #include @@ -49,39 +52,30 @@ cpPlugins::Interface::BaseMPRWidget:: // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: -AddImage( - vtkImageData* image, const std::string& name, const std::string& parent +AddData( + cpPlugins::Interface::DataObject* data, 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 + if( pIt == this->m_Data.end( ) ) return( false ); - } - else - this->m_MainImage = name; - + + } // fi + // Add new data - Data nd; - nd.Tag = Data::IMAGE; - nd.Image = image; - this->m_Data[ name ] = nd; + this->m_Data[ name ].SetSourceDataObject( data ); // Add to tree view - this->_UpdateItem( name, parent ); + this->_UpdateTreeItem( name, parent ); return( true ); } else @@ -90,32 +84,18 @@ AddImage( // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: -AddMesh( - vtkPolyData* mesh, const std::string& name, const std::string& parent - ) +SetMainImage( const std::string& name ) { - if( name == "" || parent == "" ) - return( false ); - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) + 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; + if( iIt->second.Tag == Data::IMAGE ) + { + this->m_MainImage = name; + return( true ); + } else return( false ); - - // Add to tree view - this->_UpdateItem( name, parent ); - return( true ); } else return( false ); @@ -148,14 +128,14 @@ DeleteData( const std::string& name ) this->DeleteData( *dIt ); // Delete from tree widget - QTreeWidgetItem* item = this->_FindItem( name ); + QTreeWidgetItem* item = this->_FindItemInTree( 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 } @@ -176,16 +156,18 @@ 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( ) ) + /* + 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 + if( iIt->second.Tag == Data::IMAGE ) + { + } + else if( iIt->second.Tag == Data::MESH ) + { + } // fi + */ } // ------------------------------------------------------------------------- @@ -196,20 +178,27 @@ ShowData( const std::string& name ) if( iIt == this->m_Data.end( ) ) return; - if( iIt->second.Tag == Data::IMAGE ) - { + /* + if( iIt->second.Tag == Data::IMAGE ) + { this->m_MPRObjects->AddImage( iIt->second.Image ); - } - else if( iIt->second.Tag == Data::MESH ) - { + } + else if( iIt->second.Tag == Data::MESH ) + { vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); + this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); if( ren == NULL ) - return; + return; ren->AddActor( iIt->second.GetMeshActor( ) ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + } // fi + */ +} - } // fi +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget:: +HideData( const std::string& name ) +{ } // ------------------------------------------------------------------------- @@ -237,7 +226,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -260,7 +249,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -282,7 +271,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -331,7 +320,7 @@ GetSelectedData( ) const // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: -_FindItem( const std::string& name ) const +_FindItemInTree( const std::string& name ) const { QList< QTreeWidgetItem* > items = this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly ); @@ -343,16 +332,16 @@ _FindItem( const std::string& name ) const // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: -_UpdateItem( const std::string& name, const std::string& parent ) +_UpdateTreeItem( const std::string& name, const std::string& parent ) { // Update tree view QTreeWidgetItem* new_item = NULL; if( parent != "" ) { - QTreeWidgetItem* parent_item = this->_FindItem( parent ); + QTreeWidgetItem* parent_item = this->_FindItemInTree( parent ); if( parent_item != NULL ) { - QTreeWidgetItem* old_item = this->_FindItem( name ); + QTreeWidgetItem* old_item = this->_FindItemInTree( name ); if( old_item == NULL ) { new_item = @@ -451,6 +440,107 @@ Configure( vtkPolyData* pd ) this->Actor->DeferLODConstructionOff( ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget::Data:: +Data( ) +{ + this->Tag = Data::IMAGE; + this->Source = NULL; + this->Image = NULL; +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget::Data:: +~Data( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget:: +Data& cpPlugins::Interface::BaseMPRWidget::Data:: +operator=( const Data& data ) +{ + this->Tag = data.Tag; + this->Source = data.Source; + if( this->Tag == Data::IMAGE ) + this->Image = data.Image; + else if( this->Tag == Data::MESH ) + this->Mesh = data.Mesh; + return( *this ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +DataObject* cpPlugins::Interface::BaseMPRWidget::Data:: +GetSourceDataObject( ) +{ + return( this->Source ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface:: +DataObject* cpPlugins::Interface::BaseMPRWidget::Data:: +GetSourceDataObject( ) const +{ + return( this->Source ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget::Data:: +SetSourceDataObject( cpPlugins::Interface::DataObject* dobj ) +{ + typedef cpPlugins::Interface::Image _TImage; + typedef cpPlugins::Interface::Mesh _TMesh; + + this->Source = dobj; + _TImage* image = dynamic_cast< _TImage* >( dobj ); + if( image != NULL ) + { + this->Tag = Data::IMAGE; + this->Image = image->GetVTK< vtkImageData >( ); + } + else + { + _TMesh* mesh = dynamic_cast< _TMesh* >( dobj ); + if( mesh == NULL ) + return; + + this->Tag = Data::MESH; + this->Mesh.Configure( mesh->GetVTK< vtkPolyData >( ) ); + + } // fi +} + +// ------------------------------------------------------------------------- +vtkImageData* cpPlugins::Interface::BaseMPRWidget::Data:: +GetImage( ) +{ + if( this->Tag == Data::IMAGE ) + return( this->Image ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +vtkPolyData* cpPlugins::Interface::BaseMPRWidget::Data:: +GetMesh( ) +{ + if( this->Tag == Data::MESH ) + return( this->Mesh.Mesh ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +vtkProp* cpPlugins::Interface::BaseMPRWidget::Data:: +GetMeshActor( ) +{ + if( this->Tag == Data::MESH ) + return( this->Mesh.Actor ); + else + return( NULL ); +} + #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$ diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.h b/lib/cpPlugins/Interface/BaseMPRWidget.h index 6cb89f3..cd269f4 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.h +++ b/lib/cpPlugins/Interface/BaseMPRWidget.h @@ -34,6 +34,9 @@ namespace cpPlugins { namespace Interface { + // Some forward declarations + class DataObject; + /** */ class cpPlugins_Interface_EXPORT BaseMPRWidget @@ -62,70 +65,34 @@ namespace cpPlugins virtual ~BaseMPRWidget( ); // Data management - bool AddImage( - vtkImageData* image, - const std::string& name, - const std::string& parent = "" - ); - bool AddMesh( - vtkPolyData* mesh, - const std::string& name, + bool AddData( + DataObject* data, const std::string& name, const std::string& parent ); + bool SetMainImage( const std::string& name ); void DeleteData( const std::string& name ); void DeleteAllData( ); // Some visualization accessors void SetDataColor( const std::string& name, - const double& r, - const double& g, - const double& b + const double& r, const double& g, const double& b ); void ShowData( const std::string& name ); + void HideData( const std::string& name ); vtkRenderWindowInteractor* GetInteractor( unsigned int i ); - /* - bool ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent = "" - ); - bool ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ); - bool ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent - ); - bool ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ); - void ClearAll( ); - */ - // Visual objects accessors std::string GetSelectedData( ) const; protected: - QTreeWidgetItem* _FindItem( const std::string& name ) const; - QTreeWidgetItem* _UpdateItem( + QTreeWidgetItem* _FindItemInTree( const std::string& name ) const; + QTreeWidgetItem* _UpdateTreeItem( const std::string& name, const std::string& parent ); - /* TODO - void _Add3DActor( vtkProp3D* prop ); - */ - private slots: void _SyncBottom( int a, int b ); void _SyncTop( int a, int b ); @@ -151,46 +118,25 @@ namespace cpPlugins struct Data { enum { IMAGE, MESH } Tag; + DataObject* Source; 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 ); - else - return( NULL ); - } - inline vtkProp* GetMeshActor( ) - { - if( this->Tag == Data::MESH ) - return( this->Mesh.Actor ); - else - return( NULL ); - } + Data( ); + virtual ~Data( ); + + Data& operator=( const Data& data ); + + DataObject* GetSourceDataObject( ); + const DataObject* GetSourceDataObject( ) const; + void SetSourceDataObject( DataObject* dobj ); + + vtkImageData* GetImage( ); + vtkPolyData* GetMesh( ); + vtkProp* GetMeshActor( ); }; std::string m_MainImage; diff --git a/lib/cpPlugins/Interface/Interface.cxx b/lib/cpPlugins/Interface/Interface.cxx index bb5b35c..494f189 100644 --- a/lib/cpPlugins/Interface/Interface.cxx +++ b/lib/cpPlugins/Interface/Interface.cxx @@ -43,7 +43,12 @@ CreateObject( const std::string& name ) const this->m_Providers[ cIt->second ] ); if( provider != NULL ) - return( provider->create( ) ); + { + cpPlugins::Interface::ProcessObject::Pointer po = provider->create( ); + po->SetName( name ); + return( po ); + + } // fi } // fi return( NULL ); diff --git a/lib/cpPlugins/Interface/Object.cxx b/lib/cpPlugins/Interface/Object.cxx index 474e031..85ef6a1 100644 --- a/lib/cpPlugins/Interface/Object.cxx +++ b/lib/cpPlugins/Interface/Object.cxx @@ -3,7 +3,8 @@ // ------------------------------------------------------------------------- cpPlugins::Interface::Object:: Object( ) - : Superclass( ) + : Superclass( ), + m_Name( "" ) { } diff --git a/lib/cpPlugins/Interface/Plugins.cxx b/lib/cpPlugins/Interface/Plugins.cxx index a5092cc..614fddb 100644 --- a/lib/cpPlugins/Interface/Plugins.cxx +++ b/lib/cpPlugins/Interface/Plugins.cxx @@ -676,6 +676,11 @@ UpdateActiveFilter( TStringContainer& outputs, const std::string& parent ) { TDataObject* dobj = this->m_ActiveFilter->GetOutput< TDataObject >( *oIt ); + + if( std::string( dobj->GetName( ) ) == std::string( "" ) ) + dobj->SetName( + this->m_ActiveFilter->GetName( ) + std::string( "_" ) + *oIt + ); this->_InsertNewData( dobj, parent ); outputs.insert( dobj->GetName( ) ); diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index 7d2a192..1e89c85 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -117,6 +117,8 @@ void cpPlugins::Interface::ProcessObject:: AddInteractor( vtkRenderWindowInteractor* interactor ) { #ifdef cpPlugins_Interface_QT4 + if( this->m_ParametersDialog == NULL ) + this->m_ParametersDialog = new ParametersQtDialog( ); this->m_ParametersDialog->addInteractor( interactor ); #endif // cpPlugins_Interface_QT4 }