From b9fd406b0196ce00c4152da45572b8be3cb3c805 Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Sun, 29 May 2016 20:01:01 -0500 Subject: [PATCH] Visual properties dialog finished. --- appli/PipelineEditor/PipelineEditor.cxx | 88 ++----- appli/PipelineEditor/PipelineEditor.h | 2 + .../example_MPRViewer/example_MPRViewer.cxx | 3 +- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 52 +++- lib/cpExtensions/QT/SimpleMPRWidget.h | 84 ++---- lib/cpPipelineEditor/BaseQtMainWindow.cxx | 129 ++++++++- lib/cpPipelineEditor/BaseQtMainWindow.h | 12 + lib/cpPipelineEditor/Port.cxx | 19 +- ...Dialog.cxx => ActorPropertiesQtDialog.cxx} | 246 +++++++++++------- ...onQtDialog.h => ActorPropertiesQtDialog.h} | 49 +++- lib/cpPlugins/CMakeLists.txt | 4 +- lib/cpPlugins/DataObject.cxx | 19 -- lib/cpPlugins/DataObject.h | 4 - plugins/cpPluginsWidgets/SeedWidget.cxx | 1 + 14 files changed, 418 insertions(+), 294 deletions(-) rename lib/cpPlugins/{DataObjectVisualizationQtDialog.cxx => ActorPropertiesQtDialog.cxx} (73%) rename lib/cpPlugins/{DataObjectVisualizationQtDialog.h => ActorPropertiesQtDialog.h} (55%) diff --git a/appli/PipelineEditor/PipelineEditor.cxx b/appli/PipelineEditor/PipelineEditor.cxx index 65fb82b..cd3876f 100644 --- a/appli/PipelineEditor/PipelineEditor.cxx +++ b/appli/PipelineEditor/PipelineEditor.cxx @@ -25,6 +25,14 @@ PipelineEditor( int argc, char* argv[], QApplication* app, QWidget* parent ) ); // Connect actions to slots + this->connect( + this->m_UI->ActionBackgroundMPR, SIGNAL( triggered( ) ), + this, SLOT( _ActionBackgroundMPR( ) ) + ); + this->connect( + this->m_UI->ActionBackground3D, SIGNAL( triggered( ) ), + this, SLOT( _ActionBackground3D( ) ) + ); this->connect( this->m_UI->ButtonLoadPluginsFile, SIGNAL( clicked( ) ), this, SLOT( _InteractiveLoadPlugins( ) ) @@ -74,32 +82,28 @@ PipelineEditor:: delete this->m_UI; } +// ------------------------------------------------------------------------- +void PipelineEditor:: +_ActionBackgroundMPR( ) +{ + this->_BackgroundProperties( 4 ); +} + +// ------------------------------------------------------------------------- +void PipelineEditor:: +_ActionBackground3D( ) +{ + this->_BackgroundProperties( 3 ); +} + // ------------------------------------------------------------------------- void PipelineEditor:: _ShowFilterOutput( const std::string& filter_name, const std::string& output_name ) { - // Update filter, if needed this->_ExecFilter( filter_name ); - - // Get output - auto output = this->m_Workspace.GetOutput( filter_name, output_name ); - if( output == NULL ) - { - QMessageBox::critical( - this, - QMessageBox::tr( "Error showing data" ), - QMessageBox::tr( "Unknown port name." ) - ); - return; - - } // fi - - // Create and associate actor - this->_Block( ); - this->m_UI->Viewer->AddActor( output->GetVTKActor( ) ); - this->_UnBlock( ); + this->_ShowData( filter_name, output_name ); } // ------------------------------------------------------------------------- @@ -108,21 +112,7 @@ _HideFilterOutput( const std::string& filter_name, const std::string& output_name ) { - // Get output - /* TODO - auto filter = this->m_Workspace.GetFilter( filter_name ); - if( filter != NULL ) - { - auto output = filter->GetOutputData( output_name ); - if( output != NULL ) - { - std::string data_name = output_name + "@" + filter_name; - this->m_UI->Viewer->HideData( data_name ); - - } // fi - - } // fi - */ + this->_HideData( filter_name, output_name ); } // ------------------------------------------------------------------------- @@ -131,35 +121,7 @@ _PropertiesFilterOutput( const std::string& filter_name, const std::string& output_name ) { - /* TODO - auto filter = this->m_Workspace.GetFilter( filter_name ); - if( filter != NULL ) - { - auto output = filter->GetOutputData< vtkPolyData >( output_name ); - if( output != NULL ) - { - auto actor = this->m_UI->Viewer->GetActor( output ); - if( actor != NULL ) - { - cpExtensions::QT::PropertyWidget* wdg = - new cpExtensions::QT::PropertyWidget( NULL ); - wdg->SetProp( actor ); - wdg->SetRenderWindow( - this->m_UI->Viewer->GetInteractor( 3 )->GetRenderWindow( ) - ); - wdg->show( ); - - } // fi - } - else - QMessageBox::critical( - this, - QMessageBox::tr( "Error showing data" ), - QMessageBox::tr( "No known VTK conversion!" ) - ); - - } // fi - */ + this->_DataProperties( filter_name, output_name ); } // eof - $RCSfile$ diff --git a/appli/PipelineEditor/PipelineEditor.h b/appli/PipelineEditor/PipelineEditor.h index 123f5e1..770c896 100644 --- a/appli/PipelineEditor/PipelineEditor.h +++ b/appli/PipelineEditor/PipelineEditor.h @@ -29,6 +29,8 @@ public: virtual ~PipelineEditor( ); protected slots: + void _ActionBackgroundMPR( ); + void _ActionBackground3D( ); void _ShowFilterOutput( const std::string& filter_name, const std::string& output_name ); diff --git a/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx index eb6daff..cfb33b4 100644 --- a/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx +++ b/appli/examples/plugins/QT/example_MPRViewer/example_MPRViewer.cxx @@ -66,7 +66,8 @@ example_MPRViewer( int argc, char* argv[], QWidget* parent ) } // yrt this->m_UI->Viewer->SetMainImage( - this->m_Reader->GetOutputData< vtkImageData >( "Output" ) + this->m_Reader->GetOutputData< vtkImageData >( "Output" ), + "MainImage" ); } diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index 836bd7b..a020fb9 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,6 +3,7 @@ #ifdef cpExtensions_QT4 #include +#include #include // ------------------------------------------------------------------------- @@ -42,6 +43,7 @@ SimpleMPRWidget( QWidget* parent ) cpExtensions::QT::SimpleMPRWidget:: ~SimpleMPRWidget( ) { + this->Clear( ); delete this->m_UI; } @@ -59,12 +61,12 @@ Clear( ) this->m_3DSlices[ i ]->Clear( ); } // rof - this->m_PolyDatas.clear( ); + this->m_NamedActors.clear( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -SetMainImage( vtkImageData* image ) +SetMainImage( vtkImageData* image, const std::string& name ) { this->Clear( ); for( unsigned int i = 0; i < 3; ++i ) @@ -85,13 +87,20 @@ SetMainImage( vtkImageData* image ) ) ); + this->m_NamedActors[ name ].insert( + this->m_2DSlices[ i ]->GetImageActor( ) + ); + this->m_NamedActors[ name ].insert( + this->m_3DSlices[ i ]->GetImageActor( ) + ); + } // rof this->_AssociateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -SetMainActor( vtkImageActor* actor ) +SetMainActor( vtkImageActor* actor, const std::string& name ) { this->Clear( ); vtkImageData* image = NULL; @@ -119,13 +128,20 @@ SetMainActor( vtkImageActor* actor ) ) ); + this->m_NamedActors[ name ].insert( + this->m_2DSlices[ i ]->GetImageActor( ) + ); + this->m_NamedActors[ name ].insert( + this->m_3DSlices[ i ]->GetImageActor( ) + ); + } // rof this->_AssociateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddImage( vtkImageData* image ) +AddImage( vtkImageData* image, const std::string& name ) { std::cerr << "SimpleMPR: adding image" << std::endl; std::exit( 1 ); @@ -133,7 +149,7 @@ AddImage( vtkImageData* image ) // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddImageActor( vtkImageActor* actor ) +AddImageActor( vtkImageActor* actor, const std::string& name ) { unsigned int i = 0; bool cont = true; @@ -155,12 +171,12 @@ AddImageActor( vtkImageActor* actor ) // Add if no actors were found if( cont ) - this->SetMainActor( actor ); + this->SetMainActor( actor, name ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddMesh( vtkPolyData* mesh ) +AddMesh( vtkPolyData* mesh, const std::string& name ) { std::cerr << "SimpleMPR: adding mesh" << std::endl; std::exit( 1 ); @@ -194,29 +210,43 @@ AddMesh( vtkPolyData* mesh ) // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddMeshActor( vtkProp3D* actor ) +AddMeshActor( vtkProp3D* actor, const std::string& name ) { if( actor != NULL ) { this->m_Renderers[ 3 ]->AddViewProp( actor ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + this->m_NamedActors[ name ].insert( actor ); } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddActor( vtkProp* actor ) +AddActor( vtkProp* actor, const std::string& name ) { auto ia = dynamic_cast< vtkImageActor* >( actor ); if( ia == NULL ) { auto ma = dynamic_cast< vtkActor* >( actor ); if( ma != NULL ) - this->AddMeshActor( ma ); + this->AddMeshActor( ma, name ); } else - this->AddImageActor( ia ); + this->AddImageActor( ia, name ); +} + +// ------------------------------------------------------------------------- +const cpExtensions::QT::SimpleMPRWidget:: +TActors& cpExtensions::QT::SimpleMPRWidget:: +GetActors( const std::string& name ) const +{ + static const TActors empty; + auto i = this->m_NamedActors.find( name ); + if( i != this->m_NamedActors.end( ) ) + return( i->second ); + else + return( empty ); } // ------------------------------------------------------------------------- diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.h b/lib/cpExtensions/QT/SimpleMPRWidget.h index fefe144..35307a4 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.h +++ b/lib/cpExtensions/QT/SimpleMPRWidget.h @@ -6,11 +6,9 @@ #ifdef cpExtensions_QT4 #include +#include #include -#include -#include -#include -#include +#include #include #include @@ -39,55 +37,17 @@ namespace cpExtensions public: typedef SimpleMPRWidget Self; - typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; - - /** - */ - struct PolyDataActor + struct TActorCmp { - vtkSmartPointer< vtkPolyData > Data; - vtkSmartPointer< vtkPolyDataNormals > Normals; - vtkSmartPointer< vtkStripper > Stripper; - vtkSmartPointer< vtkPolyDataMapper > Mapper; - vtkSmartPointer< vtkActor > Actor; - - void Configure( vtkPolyData* data ) - { - this->Data = data; - double r[ 2 ]; - this->Data->GetScalarRange( r ); - - this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( ); - this->Stripper = vtkSmartPointer< vtkStripper >::New( ); - this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); - this->Normals->SetInputData( this->Data ); - this->Normals->SetFeatureAngle( 60.0 ); - this->Stripper->SetInputConnection( - this->Normals->GetOutputPort( ) - ); - this->Mapper->SetInputConnection( - this->Stripper->GetOutputPort( ) - ); - this->Mapper->UseLookupTableScalarRangeOff( ); - this->Mapper->SetScalarRange( r[ 0 ], r[ 1 ] ); - - unsigned long nPolys = this->Data->GetNumberOfPolys( ); - if( nPolys < cpExtensions_MAX_POLYS ) - { - this->Actor = vtkSmartPointer< vtkActor >::New( ); - this->Actor->SetMapper( this->Mapper ); - } - else - { - vtkSmartPointer< vtkQuadricLODActor > actor = - vtkSmartPointer< vtkQuadricLODActor >::New( ); - actor->SetMapper( this->Mapper ); - actor->DeferLODConstructionOff( ); - this->Actor = actor.GetPointer( ); - - } // fi - } + bool operator()( + const vtkSmartPointer< vtkProp >& a, + const vtkSmartPointer< vtkProp >& b + ) const + { return( a.GetPointer( ) < b.GetPointer( ) ); } }; + typedef std::set< vtkSmartPointer< vtkProp >, TActorCmp > TActors; + typedef std::map< std::string, TActors > TNamedActors; + typedef cpExtensions::Visualization::ImageSliceActors TSliceActors; public: explicit SimpleMPRWidget( QWidget* parent = 0 ); @@ -95,23 +55,19 @@ namespace cpExtensions // Data management void Clear( ); - void SetMainImage( vtkImageData* image ); - void SetMainActor( vtkImageActor* actor ); - void AddImage( vtkImageData* image ); - void AddImageActor( vtkImageActor* actor ); - void AddMesh( vtkPolyData* mesh ); - void AddMeshActor( vtkProp3D* actor ); - void AddActor( vtkProp* actor ); + void SetMainImage( vtkImageData* image, const std::string& name ); + void SetMainActor( vtkImageActor* actor, const std::string& name ); + void AddImage( vtkImageData* image, const std::string& name ); + void AddImageActor( vtkImageActor* actor, const std::string& name ); + void AddMesh( vtkPolyData* mesh, const std::string& name ); + void AddMeshActor( vtkProp3D* actor, const std::string& name ); + void AddActor( vtkProp* actor, const std::string& name ); + const TActors& GetActors( const std::string& name ) const; // Visual objects vtkRenderWindowInteractor* GetInteractor( unsigned int i ); vtkRenderer* GetRenderer( unsigned int i ); vtkRenderWindow* GetRenderWindow( unsigned int i ); - /* TODO - std::vector< std::pair< vtkImageActor*, vtkRenderer* > > - GetMainImageActors( ); - vtkActor* GetActor( vtkPolyData* mesh ); - */ protected: void _AssociateSlices( ); @@ -128,7 +84,7 @@ namespace cpExtensions vtkSmartPointer< TSliceActors > m_2DSlices[ 3 ]; vtkSmartPointer< TSliceActors > m_3DSlices[ 3 ]; - std::map< vtkPolyData*, PolyDataActor > m_PolyDatas; + TNamedActors m_NamedActors; }; } // ecapseman diff --git a/lib/cpPipelineEditor/BaseQtMainWindow.cxx b/lib/cpPipelineEditor/BaseQtMainWindow.cxx index b423294..8d4a98b 100644 --- a/lib/cpPipelineEditor/BaseQtMainWindow.cxx +++ b/lib/cpPipelineEditor/BaseQtMainWindow.cxx @@ -1,8 +1,11 @@ #include #include +#include #include +#include #include +#include #include #include #include @@ -41,7 +44,8 @@ BaseQtMainWindow( m_Application( app ), m_PluginsPath( "." ), m_TreeWidget( NULL ), - m_Editor( NULL ) + m_Editor( NULL ), + m_MPR( NULL ) { this->m_Interface.GuessAccesiblePlugins( ); @@ -77,6 +81,7 @@ _Configure( this->m_Editor->setWorkspace( &( this->m_Workspace ) ); if( mpr != NULL ) this->m_Workspace.SetMPRViewer( mpr ); + this->m_MPR = mpr; } // ------------------------------------------------------------------------- @@ -236,6 +241,128 @@ _SaveWorkspace( const std::string& filename ) ); } +// ------------------------------------------------------------------------- +void cpPipelineEditor::BaseQtMainWindow:: +_ShowData( const std::string& filter_name, const std::string& output_name ) +{ + if( this->m_MPR == NULL ) + return; + auto output = this->m_Workspace.GetOutput( filter_name, output_name ); + if( output != NULL ) + { + this->_Block( ); + auto actor = output->GetVTKActor( ); + if( actor != NULL ) + { + this->m_MPR->AddActor( + actor, output_name + std::string( "@" ) + filter_name + ); + this->_UnBlock( ); + } + else + { + this->_UnBlock( ); + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing data" ), + QMessageBox::tr( "Unknown VTK conversion." ) + ); + + } // fi + } + else + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing data" ), + QMessageBox::tr( "Unknown port name." ) + ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::BaseQtMainWindow:: +_HideData( const std::string& filter, const std::string& output ) +{ +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::BaseQtMainWindow:: +_DataProperties( + const std::string& filter_name, const std::string& output_name + ) +{ + if( this->m_MPR == NULL ) + return; + auto output = this->m_Workspace.GetOutput( filter_name, output_name ); + if( output != NULL ) + { + this->_Block( ); + auto actors = this->m_MPR->GetActors( + output_name + std::string( "@" ) + filter_name + ); + auto dlg = new cpPlugins::ActorPropertiesQtDialog( NULL ); + for( auto i = actors.begin( ); i != actors.end( ); ++i ) + dlg->addActor( *i ); + dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 0 ) ); + dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 1 ) ); + dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 2 ) ); + dlg->addRenderWindow( this->m_MPR->GetRenderWindow( 3 ) ); + this->_UnBlock( ); + dlg->exec( ); + } + else + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing data" ), + QMessageBox::tr( "Unknown port name." ) + ); +} + +// ------------------------------------------------------------------------- +void cpPipelineEditor::BaseQtMainWindow:: +_BackgroundProperties( unsigned int i ) +{ + QColor color = + QColorDialog::getColor( + QColor( 0, 0, 0 ), + this, + "Select Color", + QColorDialog::DontUseNativeDialog + ); + if( color.isValid( ) ) + { + double r = double( color.red( ) ) / double( 255 ); + double g = double( color.green( ) ) / double( 255 ); + double b = double( color.blue( ) ) / double( 255 ); + if( i >= 4 ) + { + unsigned int maxId = ( i == 4 )? 3: 4; + for( unsigned int j = 0; j < maxId; ++j ) + { + auto ren = this->m_MPR->GetRenderer( j ); + if( ren != NULL ) + { + ren->SetBackground( r, g, b ); + ren->Render( ); + + } // fi + + } // rof + } + else + { + auto ren = this->m_MPR->GetRenderer( i ); + if( ren != NULL ) + { + ren->SetBackground( r, g, b ); + ren->Render( ); + + } // fi + + } // fi + + } // fi +} + // ------------------------------------------------------------------------- void cpPipelineEditor::BaseQtMainWindow:: _InteractiveLoadPlugins( ) diff --git a/lib/cpPipelineEditor/BaseQtMainWindow.h b/lib/cpPipelineEditor/BaseQtMainWindow.h index fbcde28..7b4837d 100644 --- a/lib/cpPipelineEditor/BaseQtMainWindow.h +++ b/lib/cpPipelineEditor/BaseQtMainWindow.h @@ -63,6 +63,17 @@ namespace cpPipelineEditor void _LoadWorkspace( const std::string& filename ); void _SaveWorkspace( const std::string& filename ); + void _ShowData( + const std::string& filter_name, const std::string& output_name + ); + void _HideData( + const std::string& filter_name, const std::string& output_name + ); + void _DataProperties( + const std::string& filter_name, const std::string& output_name + ); + void _BackgroundProperties( unsigned int i ); + protected slots: void _InteractiveLoadPlugins( ); void _InteractiveLoadPluginsFromPath( ); @@ -79,6 +90,7 @@ namespace cpPipelineEditor QTreeWidget* m_TreeWidget; Editor* m_Editor; + cpExtensions::QT::SimpleMPRWidget* m_MPR; }; } // ecapseman diff --git a/lib/cpPipelineEditor/Port.cxx b/lib/cpPipelineEditor/Port.cxx index b0278ea..1eb2c78 100644 --- a/lib/cpPipelineEditor/Port.cxx +++ b/lib/cpPipelineEditor/Port.cxx @@ -3,8 +3,6 @@ #include "Block.h" #include "Editor.h" -#include - #include #include #include @@ -296,19 +294,10 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) } else if( selectedAction == propertiesAction ) { - auto filter = this->m_Block->filter( ); - auto name = this->name( ).toStdString( ); - if( filter != NULL ) - { - auto output = filter->GetOutput( name ); - if( output != NULL ) - { - auto dlg = output->CreateQtDialog( ); - dlg->exec( ); - - } // fi - - } // fi + this->m_Block->editor( )->visualPropertiesOutputData( + this->m_Block->namePort( ).toStdString( ), + this->name( ).toStdString( ) + ); } // fi } diff --git a/lib/cpPlugins/DataObjectVisualizationQtDialog.cxx b/lib/cpPlugins/ActorPropertiesQtDialog.cxx similarity index 73% rename from lib/cpPlugins/DataObjectVisualizationQtDialog.cxx rename to lib/cpPlugins/ActorPropertiesQtDialog.cxx index 7494eed..eaed06a 100644 --- a/lib/cpPlugins/DataObjectVisualizationQtDialog.cxx +++ b/lib/cpPlugins/ActorPropertiesQtDialog.cxx @@ -1,14 +1,15 @@ -#include +#include +#ifdef cpPlugins_QT4 + +#include +#include #include #include #include #include -#include #include -#ifdef cpPlugins_QT4 - #include #include #include @@ -16,10 +17,9 @@ #include // ------------------------------------------------------------------------- -cpPlugins::DataObjectVisualizationQtDialog:: -DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f ) +cpPlugins::ActorPropertiesQtDialog:: +ActorPropertiesQtDialog( QWidget* parent, Qt::WindowFlags f ) : QDialog( parent, f ), - m_DataObject( NULL ), m_WidgetsUpdated( false ) { this->m_Title = new QLabel( this ); @@ -31,34 +31,52 @@ DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f ) } // ------------------------------------------------------------------------- -cpPlugins::DataObjectVisualizationQtDialog:: -~DataObjectVisualizationQtDialog( ) +cpPlugins::ActorPropertiesQtDialog:: +~ActorPropertiesQtDialog( ) { + this->m_Actors.clear( ); + this->m_Windows.clear( ); delete this->m_Title; delete this->m_ToolsLayout; delete this->m_MainLayout; } // ------------------------------------------------------------------------- -cpPlugins::DataObject* cpPlugins::DataObjectVisualizationQtDialog:: -getDataObject( ) const +bool cpPlugins::ActorPropertiesQtDialog:: +addActor( vtkProp* obj ) { - return( this->m_DataObject ); + if( obj == NULL ) + return( false ); + + if( this->m_Actors.size( ) > 0 ) + { + bool s = this->_addActor< vtkAxesActor >( obj ); + if( !s ) s = this->_addActor< vtkImageActor >( obj ); + if( !s ) s = this->_addActor< vtkActor >( obj ); + return( s ); + } + else + { + this->m_Actors.insert( obj ); + this->m_WidgetsUpdated = false; + return( true ); + + } // fi } // ------------------------------------------------------------------------- -bool cpPlugins::DataObjectVisualizationQtDialog:: -setDataObject( DataObject* obj ) +bool cpPlugins::ActorPropertiesQtDialog:: +addRenderWindow( vtkRenderWindow* win ) { - if( this->m_DataObject != NULL || obj == NULL ) + if( win == NULL ) return( false ); - this->m_DataObject = obj; + this->m_Windows.insert( win ); this->m_WidgetsUpdated = false; return( true ); } // ------------------------------------------------------------------------- -int cpPlugins::DataObjectVisualizationQtDialog:: +int cpPlugins::ActorPropertiesQtDialog:: exec( ) { this->_updateWidgets( ); @@ -73,7 +91,7 @@ exec( ) } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _addButtons( ) { // Add buttons @@ -85,54 +103,70 @@ _addButtons( ) this->m_Buttons, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); this->m_ToolsLayout->addWidget( this->m_Buttons ); - // TODO: this->updateView( ); this->m_WidgetsUpdated = true; } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _updateWidgets( ) { - if( this->m_WidgetsUpdated || this->m_DataObject == NULL ) + if( this->m_WidgetsUpdated || this->m_Actors.size( ) == 0 ) return; + bool s = this->_configureForAxes( ); + if( !s ) s = this->_configureForImage( ); + if( !s ) s = this->_configureForMesh( ); + this->_addButtons( ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::ActorPropertiesQtDialog:: +_configureForAxes( ) +{ + if( this->m_Actors.size( ) == 0 ) + return( false ); + auto actor = + dynamic_cast< vtkAxesActor* >( this->m_Actors.begin( )->GetPointer( ) ); + if( actor == NULL ) + return( false ); // Set dialog title std::stringstream title; - title - << "Parameters for an object of class \"" - << this->m_DataObject->GetClassName( ) - << "\""; + title << "Parameters for an object of class \"Axes\""; this->m_Title->setText( title.str( ).c_str( ) ); - // Configure particular objects - this->_configureForImage( ); - this->_configureForMesh( ); - - // Update values - this->_addButtons( ); + return( true ); } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +bool cpPlugins::ActorPropertiesQtDialog:: _configureForImage( ) { - /* TODO - auto image = this->m_DataObject->GetVTK< vtkImageData >( ); - auto aIt = this->m_DataObject->BeginVTKActors( ); - if( image == NULL || aIt == this->m_DataObject->EndVTKActors( ) ) - return; - auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + if( this->m_Actors.size( ) == 0 ) + return( false ); + auto actor = + dynamic_cast< vtkImageActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) - return; - + return( false ); + auto image = actor->GetInput( ); + if( image == NULL ) + return( false ); + + // Get properties + auto prop = actor->GetProperty( ); double r[ 2 ]; image->GetScalarRange( r ); double w = actor->GetProperty( )->GetColorWindow( ); double l = actor->GetProperty( )->GetColorLevel( ); double sw = double( 1000 ) * w / ( r[ 1 ] - r[ 0 ] ); double sl = double( 1000 ) * ( l - r[ 0 ] ) / ( r[ 1 ] - r[ 0 ] ); - double op = double( 10 ) * actor->GetProperty( )->GetOpacity( ); + double op = double( 10 ) * prop->GetOpacity( ); + + // Set dialog title + std::stringstream title; + title << "Parameters for an object of class \"Image\""; + this->m_Title->setText( title.str( ).c_str( ) ); + // Create widgets QDoubleSpinBox* win_box = new QDoubleSpinBox( this ); win_box->setObjectName( "win_box" ); win_box->setDecimals( 3 ); @@ -205,27 +239,33 @@ _configureForImage( ) op_layout->addWidget( op_label ); op_layout->addWidget( op_sld ); this->m_ToolsLayout->addLayout( op_layout ); -*/ + + return( true ); } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +bool cpPlugins::ActorPropertiesQtDialog:: _configureForMesh( ) { - /* TODO - auto mesh = this->m_DataObject->GetVTK< vtkPolyData >( ); - auto aIt = this->m_DataObject->BeginVTKActors( ); - if( mesh == NULL || aIt == this->m_DataObject->EndVTKActors( ) ) - return; - auto actor = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) ); + if( this->m_Actors.size( ) == 0 ) + return( false ); + auto actor = + dynamic_cast< vtkActor* >( this->m_Actors.begin( )->GetPointer( ) ); if( actor == NULL ) - return; + return( false ); + auto prop = actor->GetProperty( ); + // Set dialog title + std::stringstream title; + title << "Parameters for an object of class \"Mesh\""; + this->m_Title->setText( title.str( ).c_str( ) ); + + // Input boxes QSpinBox* ps_box = new QSpinBox( this ); ps_box->setObjectName( "ps_box" ); ps_box->setMinimum( 1 ); ps_box->setMaximum( 100 ); - ps_box->setValue( actor->GetProperty( )->GetPointSize( ) ); + ps_box->setValue( prop->GetPointSize( ) ); ps_box->connect( ps_box, SIGNAL( valueChanged( int ) ), this, SLOT( _boxPointSize( int ) ) @@ -242,7 +282,7 @@ _configureForMesh( ) lw_box->setObjectName( "lw_box" ); lw_box->setMinimum( 1 ); lw_box->setMaximum( 100 ); - lw_box->setValue( actor->GetProperty( )->GetLineWidth( ) ); + lw_box->setValue( prop->GetLineWidth( ) ); lw_box->connect( lw_box, SIGNAL( valueChanged( int ) ), this, SLOT( _boxLineWidth( int ) ) @@ -269,7 +309,7 @@ _configureForMesh( ) this->m_ToolsLayout->addLayout( sv_layout ); double cr, cg, cb; - actor->GetProperty( )->GetColor( cr, cg, cb ); + prop->GetColor( cr, cg, cb ); cr *= double( 255 ); cg *= double( 255 ); cb *= double( 255 ); @@ -295,7 +335,7 @@ _configureForMesh( ) op_sld->setObjectName( "op_sld" ); op_sld->setRange( 0, 10 ); op_sld->setValue( - ( unsigned int )( actor->GetProperty( )->GetOpacity( ) * double( 10 ) ) + ( unsigned int )( prop->GetOpacity( ) * double( 10 ) ) ); op_sld->connect( op_sld, SIGNAL( valueChanged( int ) ), @@ -308,20 +348,20 @@ _configureForMesh( ) op_layout->addWidget( op_label ); op_layout->addWidget( op_sld ); this->m_ToolsLayout->addLayout( op_layout ); -*/ + + return( true ); } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _setWindow( double w ) { - /* TODO - if( this->m_DataObject == NULL ) + if( this->m_Actors.size( ) == 0 ) return; - auto aIt = this->m_DataObject->BeginVTKActors( ); - for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) { - auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); if( actor != NULL ) { actor->GetProperty( )->SetColorWindow( w ); @@ -331,20 +371,18 @@ _setWindow( double w ) } // rof this->_render( ); -*/ } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _setLevel( double l ) { - /* TODO - if( this->m_DataObject == NULL ) + if( this->m_Actors.size( ) == 0 ) return; - auto aIt = this->m_DataObject->BeginVTKActors( ); - for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) { - auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + auto actor = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); if( actor != NULL ) { actor->GetProperty( )->SetColorLevel( l ); @@ -354,22 +392,36 @@ _setLevel( double l ) } // rof this->_render( ); -*/ } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _render( ) { - /* TODO - if( this->m_DataObject == NULL ) - return; - this->m_DataObject->RenderVTKActors( ); -*/ + for( auto i = this->m_Windows.begin( ); i != this->m_Windows.end( ); ++i ) + ( *i )->Render( ); +} + +// ------------------------------------------------------------------------- +template< class _TActor > +bool cpPlugins::ActorPropertiesQtDialog:: +_addActor( vtkProp* obj ) +{ + auto new_obj = dynamic_cast< _TActor* >( obj ); + auto pre_obj = + dynamic_cast< _TActor* >( this->m_Actors.begin( )->GetPointer( ) ); + if( new_obj != NULL && pre_obj != NULL ) + { + this->m_Actors.insert( obj ); + this->m_WidgetsUpdated = false; + return( true ); + } + else + return( false ); } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _boxWindow( double v ) { auto* box = this->findChild< QDoubleSpinBox* >( "win_box" ); @@ -391,7 +443,7 @@ _boxWindow( double v ) } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _sldWindow( int v ) { auto* box = this->findChild< QDoubleSpinBox* >( "win_box" ); @@ -413,7 +465,7 @@ _sldWindow( int v ) } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _boxLevel( double v ) { auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" ); @@ -435,7 +487,7 @@ _boxLevel( double v ) } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _sldLevel( int v ) { auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" ); @@ -457,11 +509,10 @@ _sldLevel( int v ) } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _sldOpacity( int v ) { - /* TODO - if( this->m_DataObject == NULL ) + if( this->m_Actors.size( ) == 0 ) return; auto* sld = this->findChild< QSlider* >( "op_sld" ); if( sld == NULL ) @@ -471,11 +522,11 @@ _sldOpacity( int v ) double max = double( sld->maximum( ) ); double s = ( double( v ) - min ) / ( max - min ); - auto aIt = this->m_DataObject->BeginVTKActors( ); - for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) { - auto ia = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); - auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) ); + auto ia = dynamic_cast< vtkImageActor* >( aIt->GetPointer( ) ); + auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) ); if( ia != NULL ) { ia->GetProperty( )->SetOpacity( s ); @@ -490,27 +541,25 @@ _sldOpacity( int v ) } // rof this->_render( ); -*/ } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _boxPointSize( int v ) { } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _boxLineWidth( int v ) { } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _scalarVisibility( int v ) { - /* TODO - if( this->m_DataObject == NULL ) + if( this->m_Actors.size( ) == 0 ) return; auto* btn = this->findChild< QPushButton* >( "color_button" ); auto* chk = this->findChild< QCheckBox* >( "sv_box" ); @@ -523,10 +572,10 @@ _scalarVisibility( int v ) rgb[ 1 ] = double( color.green( ) ) / double( 255 ); rgb[ 2 ] = double( color.blue( ) ) / double( 255 ); - auto aIt = this->m_DataObject->BeginVTKActors( ); - for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + auto aIt = this->m_Actors.begin( ); + for( ; aIt != this->m_Actors.end( ); ++aIt ) { - auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) ); + auto ma = dynamic_cast< vtkActor* >( aIt->GetPointer( ) ); if( ma != NULL ) { if( !( chk->isChecked( ) ) ) @@ -542,15 +591,13 @@ _scalarVisibility( int v ) } // rof this->_render( ); -*/ } // ------------------------------------------------------------------------- -void cpPlugins::DataObjectVisualizationQtDialog:: +void cpPlugins::ActorPropertiesQtDialog:: _color( ) { - /* TODO - if( this->m_DataObject == NULL ) + if( this->m_Actors.size( ) == 0 ) return; auto* btn = this->findChild< QPushButton* >( "color_button" ); auto* chk = this->findChild< QCheckBox* >( "sv_box" ); @@ -574,7 +621,6 @@ _color( ) this->_scalarVisibility( 0 ); } // fi -*/ } #endif // cpPlugins_QT4 diff --git a/lib/cpPlugins/DataObjectVisualizationQtDialog.h b/lib/cpPlugins/ActorPropertiesQtDialog.h similarity index 55% rename from lib/cpPlugins/DataObjectVisualizationQtDialog.h rename to lib/cpPlugins/ActorPropertiesQtDialog.h index a26b7ba..ca45b57 100644 --- a/lib/cpPlugins/DataObjectVisualizationQtDialog.h +++ b/lib/cpPlugins/ActorPropertiesQtDialog.h @@ -1,13 +1,14 @@ -#ifndef __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ -#define __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ +#ifndef __CPPLUGINS__ACTORPROPERTIESQTDIALOG__H__ +#define __CPPLUGINS__ACTORPROPERTIESQTDIALOG__H__ #include #ifdef cpPlugins_QT4 -#include - #include +#include +#include +#include #include #include @@ -16,37 +17,56 @@ #include #include +class vtkProp; + namespace cpPlugins { /** */ - class cpPlugins_EXPORT DataObjectVisualizationQtDialog + class cpPlugins_EXPORT ActorPropertiesQtDialog : public QDialog { Q_OBJECT; public: - DataObjectVisualizationQtDialog( + template< class _TObj > + struct TCmp + { + bool operator()( + const vtkSmartPointer< _TObj >& a, + const vtkSmartPointer< _TObj >& b ) const + { return( a.GetPointer( ) < b.GetPointer( ) ); } + }; + typedef vtkSmartPointer< vtkProp > TActor; + typedef vtkSmartPointer< vtkRenderWindow > TRenderWindow; + typedef std::set< TActor, TCmp< vtkProp > > TActors; + typedef std::set< TRenderWindow, TCmp< vtkRenderWindow > > TWindows; + + public: + ActorPropertiesQtDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 ); - virtual ~DataObjectVisualizationQtDialog( ); - - DataObject* getDataObject( ) const; - virtual bool setDataObject( DataObject* obj ); + virtual ~ActorPropertiesQtDialog( ); + virtual bool addActor( vtkProp* obj ); + virtual bool addRenderWindow( vtkRenderWindow* win ); virtual int exec( ); protected: virtual void _addButtons( ); virtual void _updateWidgets( ); - virtual void _configureForImage( ); - virtual void _configureForMesh( ); + virtual bool _configureForAxes( ); + virtual bool _configureForImage( ); + virtual bool _configureForMesh( ); void _setWindow( double w ); void _setLevel( double l ); void _render( ); + template< class _TActor > + inline bool _addActor( vtkProp* obj ); + protected slots: void _boxWindow( double v ); void _sldWindow( int v ); @@ -77,7 +97,8 @@ namespace cpPlugins */ protected: - DataObject* m_DataObject; + TActors m_Actors; + TWindows m_Windows; bool m_WidgetsUpdated; QLabel* m_Title; QGridLayout* m_MainLayout; @@ -89,6 +110,6 @@ namespace cpPlugins #endif // cpPlugins_QT4 -#endif // __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ +#endif // __CPPLUGINS__ACTORPROPERTIESQTDIALOG__H__ // eof - $RCSfile$ diff --git a/lib/cpPlugins/CMakeLists.txt b/lib/cpPlugins/CMakeLists.txt index 55ffd24..7817df1 100644 --- a/lib/cpPlugins/CMakeLists.txt +++ b/lib/cpPlugins/CMakeLists.txt @@ -32,12 +32,12 @@ IF(USE_QT4) ) SET( lib_QT_Headers - DataObjectVisualizationQtDialog.h + ActorPropertiesQtDialog.h ParametersQtDialog.h ) SET( lib_QT_Sources - DataObjectVisualizationQtDialog.cxx + ActorPropertiesQtDialog.cxx ParametersQtDialog.cxx ) SET( diff --git a/lib/cpPlugins/DataObject.cxx b/lib/cpPlugins/DataObject.cxx index e51ddaf..06806b5 100644 --- a/lib/cpPlugins/DataObject.cxx +++ b/lib/cpPlugins/DataObject.cxx @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -66,24 +65,6 @@ DisconnectFromPipeline( ) this->Modified( ); } -// ------------------------------------------------------------------------- -cpPlugins::DataObjectVisualizationQtDialog* cpPlugins::DataObject:: -CreateQtDialog( ) -{ -#ifdef cpPlugins_QT4 - DataObjectVisualizationQtDialog* dlg = NULL; - if( QApplication::instance( ) != NULL ) - { - dlg = new DataObjectVisualizationQtDialog( ); - dlg->setDataObject( this ); - - } // fi - return( dlg ); -#else // cpPlugins_QT4 - return( NULL ); -#endif // cpPlugins_QT4 -} - // ------------------------------------------------------------------------- vtkProp* cpPlugins::DataObject:: GetVTKActor( ) diff --git a/lib/cpPlugins/DataObject.h b/lib/cpPlugins/DataObject.h index ae98879..998a914 100644 --- a/lib/cpPlugins/DataObject.h +++ b/lib/cpPlugins/DataObject.h @@ -10,7 +10,6 @@ namespace cpPlugins { // Some forward declarations class ProcessObject; - class DataObjectVisualizationQtDialog; /** */ @@ -35,9 +34,6 @@ namespace cpPlugins void DisconnectFromPipeline( ); - // Qt dialog creation - virtual DataObjectVisualizationQtDialog* CreateQtDialog( ); - // VTK actors vtkProp* GetVTKActor( ); const vtkProp* GetVTKActor( ) const; diff --git a/plugins/cpPluginsWidgets/SeedWidget.cxx b/plugins/cpPluginsWidgets/SeedWidget.cxx index 18bcdeb..40b251b 100644 --- a/plugins/cpPluginsWidgets/SeedWidget.cxx +++ b/plugins/cpPluginsWidgets/SeedWidget.cxx @@ -2,6 +2,7 @@ #include #include +#include #include #include -- 2.45.1