From ebbbc4c90ed0e4814d360686e8d4b6aab509914c Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Mon, 23 May 2016 19:29:26 -0500 Subject: [PATCH] Windows compilation is broken. --- appli/PipelineEditor/PipelineEditor.cxx | 46 +- lib/cpExtensions/QT/SimpleMPRWidget.cxx | 35 ++ lib/cpExtensions/QT/SimpleMPRWidget.h | 4 +- .../Visualization/ImageSliceActors.cxx | 14 + .../Visualization/ImageSliceActors.h | 3 + lib/cpPipelineEditor/Block.cxx | 16 + lib/cpPipelineEditor/Block.h | 3 + lib/cpPipelineEditor/Port.cxx | 19 +- lib/cpPlugins/CMakeLists.txt | 2 + lib/cpPlugins/DataObject.cxx | 83 +++ lib/cpPlugins/DataObject.h | 26 + .../DataObjectVisualizationQtDialog.cxx | 566 ++++++++++++++++++ .../DataObjectVisualizationQtDialog.h | 94 +++ lib/cpPlugins/Mesh.cxx | 1 + 14 files changed, 893 insertions(+), 19 deletions(-) create mode 100644 lib/cpPlugins/DataObjectVisualizationQtDialog.cxx create mode 100644 lib/cpPlugins/DataObjectVisualizationQtDialog.h diff --git a/appli/PipelineEditor/PipelineEditor.cxx b/appli/PipelineEditor/PipelineEditor.cxx index b61cd14..a4cd75e 100644 --- a/appli/PipelineEditor/PipelineEditor.cxx +++ b/appli/PipelineEditor/PipelineEditor.cxx @@ -87,26 +87,44 @@ _ShowFilterOutput( auto filter = this->m_Workspace.GetFilter( filter_name ); if( filter != NULL ) { - auto id = filter->GetOutputData< vtkImageData >( output_name ); - auto md = filter->GetOutputData< vtkPolyData >( output_name ); - if( id != NULL ) + auto out = filter->GetOutput( output_name ); + if( out != NULL ) { - this->_Block( ); - this->m_UI->Viewer->Clear( ); - this->m_UI->Viewer->SetMainImage( id ); - this->_UnBlock( ); - } - else if( md != NULL ) - { - this->_Block( ); - this->m_UI->Viewer->AddMesh( md ); - this->_UnBlock( ); + auto id = out->GetVTK< vtkImageData >( ); + auto md = out->GetVTK< vtkPolyData >( ); + if( id != NULL ) + { + this->_Block( ); + this->m_UI->Viewer->Clear( ); + this->m_UI->Viewer->SetMainImage( id ); + auto actors = this->m_UI->Viewer->GetMainImageActors( ); + out->ClearVTKActors( ); + for( auto aIt = actors.begin( ); aIt != actors.end( ); ++aIt ) + out->AddVTKActor( aIt->first, aIt->second ); + this->_UnBlock( ); + } + else if( md != NULL ) + { + this->_Block( ); + this->m_UI->Viewer->AddMesh( md ); + out->AddVTKActor( + this->m_UI->Viewer->GetActor( md ), + this->m_UI->Viewer->GetRenderer( 3 ) + ); + this->_UnBlock( ); + } + else + QMessageBox::critical( + this, + QMessageBox::tr( "Error showing data" ), + QMessageBox::tr( "No known VTK conversion!" ) + ); } else QMessageBox::critical( this, QMessageBox::tr( "Error showing data" ), - QMessageBox::tr( "No known VTK conversion!" ) + QMessageBox::tr( "Unknown port name." ) ); } else diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index 0cede9d..ab47c28 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -149,6 +149,41 @@ GetInteractor( unsigned int i ) return( NULL ); } +// ------------------------------------------------------------------------- +vtkRenderer* cpExtensions::QT::SimpleMPRWidget:: +GetRenderer( unsigned int i ) +{ + if( i < 4 ) + return( this->m_Renderers[ i ] ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +std::vector< std::pair< vtkImageActor*, vtkRenderer* > > +cpExtensions::QT::SimpleMPRWidget:: +GetMainImageActors( ) +{ + std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors; + for( unsigned int i = 0; i < 3; ++i ) + { + actors.push_back( + std::pair< vtkImageActor*, vtkRenderer* >( + this->m_2DSlices[ i ]->GetImageActor( ), + this->m_Renderers[ i ] + ) + ); + actors.push_back( + std::pair< vtkImageActor*, vtkRenderer* >( + this->m_3DSlices[ i ]->GetImageActor( ), + this->m_Renderers[ 3 ] + ) + ); + + } // rof + return( actors ); +} + // ------------------------------------------------------------------------- vtkActor* cpExtensions::QT::SimpleMPRWidget:: GetActor( vtkPolyData* mesh ) diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.h b/lib/cpExtensions/QT/SimpleMPRWidget.h index f6d90f0..d5f3353 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.h +++ b/lib/cpExtensions/QT/SimpleMPRWidget.h @@ -100,7 +100,9 @@ namespace cpExtensions // Visual objects vtkRenderWindowInteractor* GetInteractor( unsigned int i ); - + vtkRenderer* GetRenderer( unsigned int i ); + std::vector< std::pair< vtkImageActor*, vtkRenderer* > > + GetMainImageActors( ); vtkActor* GetActor( vtkPolyData* mesh ); private slots: diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index d6542ef..2254ac9 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -92,6 +92,20 @@ GetInputData( ) return( NULL ); } +// ------------------------------------------------------------------------- +vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetImageActor( ) +{ + return( this->m_Actor.GetPointer( ) ); +} + +// ------------------------------------------------------------------------- +const vtkImageActor* cpExtensions::Visualization::ImageSliceActors:: +GetImageActor( ) const +{ + return( this->m_Actor.GetPointer( ) ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: AddMesh( vtkPolyData* mesh ) diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 7ff8838..075c6ec 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -85,6 +85,9 @@ namespace cpExtensions void SetInputData( vtkImageData* data, int orientation ); vtkImageData* GetInputData( ); + vtkImageActor* GetImageActor( ); + const vtkImageActor* GetImageActor( ) const; + void AddMesh( vtkPolyData* mesh ); void AssociateSlice( Self* slice ); diff --git a/lib/cpPipelineEditor/Block.cxx b/lib/cpPipelineEditor/Block.cxx index cd32453..07fdfb9 100644 --- a/lib/cpPipelineEditor/Block.cxx +++ b/lib/cpPipelineEditor/Block.cxx @@ -61,6 +61,22 @@ cpPipelineEditor::Block:: { } +// ------------------------------------------------------------------------- +cpPipelineEditor::Block:: +TFilter* cpPipelineEditor::Block:: +filter( ) +{ + return( this->m_Filter ); +} + +// ------------------------------------------------------------------------- +const cpPipelineEditor::Block:: +TFilter* cpPipelineEditor::Block:: +filter( ) const +{ + return( this->m_Filter ); +} + // ------------------------------------------------------------------------- cpPipelineEditor::Editor* cpPipelineEditor::Block:: editor( ) diff --git a/lib/cpPipelineEditor/Block.h b/lib/cpPipelineEditor/Block.h index 2ace7b7..6ee84f6 100644 --- a/lib/cpPipelineEditor/Block.h +++ b/lib/cpPipelineEditor/Block.h @@ -32,6 +32,9 @@ namespace cpPipelineEditor ); virtual ~Block( ); + TFilter* filter( ); + const TFilter* filter( ) const; + Editor* editor( ); const Editor* editor( ) const; void setEditor( Editor* editor ); diff --git a/lib/cpPipelineEditor/Port.cxx b/lib/cpPipelineEditor/Port.cxx index 1eb2c78..b0278ea 100644 --- a/lib/cpPipelineEditor/Port.cxx +++ b/lib/cpPipelineEditor/Port.cxx @@ -3,6 +3,8 @@ #include "Block.h" #include "Editor.h" +#include + #include #include #include @@ -294,10 +296,19 @@ contextMenuEvent( QGraphicsSceneContextMenuEvent* evt ) } else if( selectedAction == propertiesAction ) { - this->m_Block->editor( )->visualPropertiesOutputData( - this->m_Block->namePort( ).toStdString( ), - this->name( ).toStdString( ) - ); + 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 } // fi } diff --git a/lib/cpPlugins/CMakeLists.txt b/lib/cpPlugins/CMakeLists.txt index abf5082..55ffd24 100644 --- a/lib/cpPlugins/CMakeLists.txt +++ b/lib/cpPlugins/CMakeLists.txt @@ -32,10 +32,12 @@ IF(USE_QT4) ) SET( lib_QT_Headers + DataObjectVisualizationQtDialog.h ParametersQtDialog.h ) SET( lib_QT_Sources + DataObjectVisualizationQtDialog.cxx ParametersQtDialog.cxx ) SET( diff --git a/lib/cpPlugins/DataObject.cxx b/lib/cpPlugins/DataObject.cxx index 06c10df..ebfb8b2 100644 --- a/lib/cpPlugins/DataObject.cxx +++ b/lib/cpPlugins/DataObject.cxx @@ -1,9 +1,11 @@ #include #include +#include #include #include #include +#include // ------------------------------------------------------------------------- cpPlugins::ProcessObject* cpPlugins::DataObject:: @@ -64,6 +66,87 @@ 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 +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObject:: +AddVTKActor( vtkProp* actor, vtkRenderer* renderer ) +{ + if( actor != NULL && renderer != NULL ) + { + TDataView v; + v.Actor = actor; + v.Renderer = renderer; + this->m_Actors.insert( v ); + this->Modified( ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObject:: +ClearVTKActors( ) +{ + this->m_Actors.clear( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObject:: +RenderVTKActors( ) +{ + for( auto i = this->m_Actors.begin( ); i != this->m_Actors.end( ); ++i ) + i->Renderer->GetRenderWindow( )->Render( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject::TDataViews:: +iterator cpPlugins::DataObject:: +BeginVTKActors( ) +{ + return( this->m_Actors.begin( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject::TDataViews:: +iterator cpPlugins::DataObject:: +EndVTKActors( ) +{ + return( this->m_Actors.end( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject::TDataViews:: +const_iterator cpPlugins::DataObject:: +BeginVTKActors( ) const +{ + return( this->m_Actors.begin( ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject::TDataViews:: +const_iterator cpPlugins::DataObject:: +EndVTKActors( ) const +{ + return( this->m_Actors.end( ) ); +} + // ------------------------------------------------------------------------- cpPlugins::DataObject:: DataObject( ) diff --git a/lib/cpPlugins/DataObject.h b/lib/cpPlugins/DataObject.h index 279fe76..9ff55d8 100644 --- a/lib/cpPlugins/DataObject.h +++ b/lib/cpPlugins/DataObject.h @@ -2,11 +2,15 @@ #define __CPPLUGINS__DATAOBJECT__H__ #include +#include +#include +#include namespace cpPlugins { // Some forward declarations class ProcessObject; + class DataObjectVisualizationQtDialog; /** */ @@ -24,6 +28,15 @@ namespace cpPlugins itkTypeMacro( DataObject, Object ); cpPlugins_Id_Macro( DataObject, Object ); + struct TDataView + { + vtkSmartPointer< vtkProp > Actor; + vtkSmartPointer< vtkRenderer > Renderer; + bool operator<( const TDataView& b ) const + { return( this->Actor.GetPointer( ) < b.Actor.GetPointer( ) ); } + }; + typedef std::set< TDataView > TDataViews; + public: ProcessObject* GetSource( ); const ProcessObject* GetSource( ) const; @@ -31,6 +44,18 @@ namespace cpPlugins void DisconnectFromPipeline( ); + // Qt dialog creation + virtual DataObjectVisualizationQtDialog* CreateQtDialog( ); + + // VTK actors + virtual void AddVTKActor( vtkProp* actor, vtkRenderer* renderer ); + virtual void ClearVTKActors( ); + virtual void RenderVTKActors( ); + TDataViews::iterator BeginVTKActors( ); + TDataViews::iterator EndVTKActors( ); + TDataViews::const_iterator BeginVTKActors( ) const; + TDataViews::const_iterator EndVTKActors( ) const; + protected: DataObject( ); virtual ~DataObject( ); @@ -42,6 +67,7 @@ namespace cpPlugins protected: ProcessObject* m_Source; + TDataViews m_Actors; }; } // ecapseman diff --git a/lib/cpPlugins/DataObjectVisualizationQtDialog.cxx b/lib/cpPlugins/DataObjectVisualizationQtDialog.cxx new file mode 100644 index 0000000..cd6ca76 --- /dev/null +++ b/lib/cpPlugins/DataObjectVisualizationQtDialog.cxx @@ -0,0 +1,566 @@ +#include + +#include +#include +#include +#include +#include +#include + +#ifdef cpPlugins_QT4 + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +cpPlugins::DataObjectVisualizationQtDialog:: +DataObjectVisualizationQtDialog( QWidget* parent, Qt::WindowFlags f ) + : QDialog( parent, f ), + m_DataObject( NULL ), + m_WidgetsUpdated( false ) +{ + this->m_Title = new QLabel( this ); + this->m_Title->setText( "Visualization properties" ); + this->m_MainLayout = new QGridLayout( this ); + this->m_ToolsLayout = new QVBoxLayout( ); + this->m_ToolsLayout->addWidget( this->m_Title ); + this->m_MainLayout->addLayout( this->m_ToolsLayout, 0, 0, 1, 1 ); +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObjectVisualizationQtDialog:: +~DataObjectVisualizationQtDialog( ) +{ + delete this->m_Title; + delete this->m_ToolsLayout; + delete this->m_MainLayout; +} + +// ------------------------------------------------------------------------- +cpPlugins::DataObject* cpPlugins::DataObjectVisualizationQtDialog:: +getDataObject( ) const +{ + return( this->m_DataObject ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::DataObjectVisualizationQtDialog:: +setDataObject( DataObject* obj ) +{ + if( this->m_DataObject != NULL || obj == NULL ) + return( false ); + this->m_DataObject = obj; + this->m_WidgetsUpdated = false; + return( true ); +} + +// ------------------------------------------------------------------------- +int cpPlugins::DataObjectVisualizationQtDialog:: +exec( ) +{ + this->_updateWidgets( ); + int ret = this->QDialog::exec( ); + /* TODO + if( ret == 1 ) + this->updateParameters( ); + else + this->updateView( ); + */ + return( ret ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_addButtons( ) +{ + // Add buttons + this->m_Buttons = new QDialogButtonBox( QDialogButtonBox::Ok ); + this->connect( + this->m_Buttons, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) + ); + this->connect( + 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:: +_updateWidgets( ) +{ + if( this->m_WidgetsUpdated || this->m_DataObject == NULL ) + return; + + // Set dialog title + std::stringstream title; + title + << "Parameters for an object of class \"" + << this->m_DataObject->GetClassName( ) + << "\""; + this->m_Title->setText( title.str( ).c_str( ) ); + + // Configure particular objects + this->_configureForImage( ); + this->_configureForMesh( ); + + // Update values + this->_addButtons( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_configureForImage( ) +{ + 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( actor == NULL ) + return; + + 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( ); + + QDoubleSpinBox* win_box = new QDoubleSpinBox( this ); + win_box->setObjectName( "win_box" ); + win_box->setDecimals( 3 ); + win_box->setMinimum( 0 ); + win_box->setMaximum( r[ 1 ] - r[ 0 ] ); + win_box->setValue( w ); + win_box->connect( + win_box, SIGNAL( valueChanged( double ) ), + this, SLOT( _boxWindow( double ) ) + ); + + QSlider* win_sld = new QSlider( Qt::Horizontal, this ); + win_sld->setObjectName( "win_sld" ); + win_sld->setRange( 0, 1000 ); + win_sld->setValue( ( unsigned int )( sw ) ); + win_sld->connect( + win_sld, SIGNAL( valueChanged( int ) ), + this, SLOT( _sldWindow( int ) ) + ); + + QHBoxLayout* win_layout = new QHBoxLayout( ); + QLabel* win_label = new QLabel( this ); + win_label->setText( QString( "Window: " ) ); + win_layout->addWidget( win_label ); + win_layout->addWidget( win_box ); + win_layout->addWidget( win_sld ); + this->m_ToolsLayout->addLayout( win_layout ); + + QDoubleSpinBox* lev_box = new QDoubleSpinBox( this ); + lev_box->setObjectName( "lev_box" ); + lev_box->setDecimals( 3 ); + lev_box->setMinimum( r[ 0 ] ); + lev_box->setMaximum( r[ 1 ] ); + lev_box->setValue( l ); + lev_box->connect( + lev_box, SIGNAL( valueChanged( double ) ), + this, SLOT( _boxLevel( double ) ) + ); + + QSlider* lev_sld = new QSlider( Qt::Horizontal, this ); + lev_sld->setObjectName( "lev_sld" ); + lev_sld->setRange( 0, 1000 ); + lev_sld->setValue( ( unsigned int )( sl ) ); + lev_sld->connect( + lev_sld, SIGNAL( valueChanged( int ) ), + this, SLOT( _sldLevel( int ) ) + ); + + QHBoxLayout* lev_layout = new QHBoxLayout( ); + QLabel* lev_label = new QLabel( this ); + lev_label->setText( QString( "Level: " ) ); + lev_layout->addWidget( lev_label ); + lev_layout->addWidget( lev_box ); + lev_layout->addWidget( lev_sld ); + this->m_ToolsLayout->addLayout( lev_layout ); + + // Configure generic objects + QSlider* op_sld = new QSlider( Qt::Horizontal, this ); + op_sld->setObjectName( "op_sld" ); + op_sld->setRange( 0, 10 ); + op_sld->setValue( ( unsigned int )( op ) ); + op_sld->connect( + op_sld, SIGNAL( valueChanged( int ) ), + this, SLOT( _sldOpacity( int ) ) + ); + + QHBoxLayout* op_layout = new QHBoxLayout( ); + QLabel* op_label = new QLabel( this ); + op_label->setText( QString( "Opacity: " ) ); + op_layout->addWidget( op_label ); + op_layout->addWidget( op_sld ); + this->m_ToolsLayout->addLayout( op_layout ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_configureForMesh( ) +{ + 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( actor == NULL ) + return; + + 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->connect( + ps_box, SIGNAL( valueChanged( int ) ), + this, SLOT( _boxPointSize( int ) ) + ); + + QHBoxLayout* ps_layout = new QHBoxLayout( ); + QLabel* ps_label = new QLabel( this ); + ps_label->setText( QString( "Point size: " ) ); + ps_layout->addWidget( ps_label ); + ps_layout->addWidget( ps_box ); + this->m_ToolsLayout->addLayout( ps_layout ); + + QSpinBox* lw_box = new QSpinBox( this ); + lw_box->setObjectName( "lw_box" ); + lw_box->setMinimum( 1 ); + lw_box->setMaximum( 100 ); + lw_box->setValue( actor->GetProperty( )->GetLineWidth( ) ); + lw_box->connect( + lw_box, SIGNAL( valueChanged( int ) ), + this, SLOT( _boxLineWidth( int ) ) + ); + + QHBoxLayout* lw_layout = new QHBoxLayout( ); + QLabel* lw_label = new QLabel( this ); + lw_label->setText( QString( "Line width: " ) ); + lw_layout->addWidget( lw_label ); + lw_layout->addWidget( lw_box ); + this->m_ToolsLayout->addLayout( lw_layout ); + + QCheckBox* sv_box = new QCheckBox( this ); + sv_box->setObjectName( "sv_box" ); + sv_box->setText( "Scalar visibility: " ); + sv_box->setChecked( ( actor->GetMapper( )->GetScalarVisibility( ) == 1 ) ); + sv_box->connect( + sv_box, SIGNAL( stateChanged( int ) ), + this, SLOT( _scalarVisibility( int ) ) + ); + + QHBoxLayout* sv_layout = new QHBoxLayout( ); + sv_layout->addWidget( sv_box ); + this->m_ToolsLayout->addLayout( sv_layout ); + + double cr, cg, cb; + actor->GetProperty( )->GetColor( cr, cg, cb ); + cr *= double( 255 ); + cg *= double( 255 ); + cb *= double( 255 ); + + QPushButton* color_button = new QPushButton( "Color", this ); + color_button->setObjectName( "color_button" ); + QPalette color_palette = color_button->palette( ); + color_palette.setColor( QPalette::Button, QColor( cr, cg, cb ) ); + color_button->setAutoFillBackground( true ); + color_button->setPalette( color_palette ); + color_button->update( ); + color_button->connect( + color_button, SIGNAL( clicked( ) ), + this, SLOT( _color( ) ) + ); + + QHBoxLayout* color_layout = new QHBoxLayout( ); + color_layout->addWidget( color_button ); + this->m_ToolsLayout->addLayout( color_layout ); + + // Configure generic objects + QSlider* op_sld = new QSlider( Qt::Horizontal, this ); + op_sld->setObjectName( "op_sld" ); + op_sld->setRange( 0, 10 ); + op_sld->setValue( + ( unsigned int )( actor->GetProperty( )->GetOpacity( ) * double( 10 ) ) + ); + op_sld->connect( + op_sld, SIGNAL( valueChanged( int ) ), + this, SLOT( _sldOpacity( int ) ) + ); + + QHBoxLayout* op_layout = new QHBoxLayout( ); + QLabel* op_label = new QLabel( this ); + op_label->setText( QString( "Opacity: " ) ); + op_layout->addWidget( op_label ); + op_layout->addWidget( op_sld ); + this->m_ToolsLayout->addLayout( op_layout ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_setWindow( double w ) +{ + if( this->m_DataObject == NULL ) + return; + auto aIt = this->m_DataObject->BeginVTKActors( ); + for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + { + auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + if( actor != NULL ) + { + actor->GetProperty( )->SetColorWindow( w ); + actor->Modified( ); + + } // fi + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_setLevel( double l ) +{ + if( this->m_DataObject == NULL ) + return; + auto aIt = this->m_DataObject->BeginVTKActors( ); + for( ; aIt != this->m_DataObject->EndVTKActors( ); ++aIt ) + { + auto actor = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + if( actor != NULL ) + { + actor->GetProperty( )->SetColorLevel( l ); + actor->Modified( ); + + } // fi + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_render( ) +{ + if( this->m_DataObject == NULL ) + return; + this->m_DataObject->RenderVTKActors( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_boxWindow( double v ) +{ + auto* box = this->findChild< QDoubleSpinBox* >( "win_box" ); + auto* sld = this->findChild< QSlider* >( "win_sld" ); + if( box == NULL || sld == NULL ) + return; + + double min = double( sld->minimum( ) ); + double max = double( sld->maximum( ) ); + double vmin = box->minimum( ); + double vmax = box->maximum( ); + double s = ( v - vmin ) / ( vmax - vmin ); + s = ( ( max - min ) * s ) + min; + + bool o = sld->blockSignals( true ); + sld->setValue( ( unsigned int )( s ) ); + sld->blockSignals( o ); + this->_setWindow( v ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_sldWindow( int v ) +{ + auto* box = this->findChild< QDoubleSpinBox* >( "win_box" ); + auto* sld = this->findChild< QSlider* >( "win_sld" ); + if( box == NULL || sld == NULL ) + return; + + double min = double( sld->minimum( ) ); + double max = double( sld->maximum( ) ); + double vmin = box->minimum( ); + double vmax = box->maximum( ); + double s = ( double( v ) - min ) / ( max - min ); + s = ( ( vmax - vmin ) * s ) + vmin; + + bool o = box->blockSignals( true ); + box->setValue( s ); + box->blockSignals( o ); + this->_setWindow( s ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_boxLevel( double v ) +{ + auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" ); + auto* sld = this->findChild< QSlider* >( "lev_sld" ); + if( box == NULL || sld == NULL ) + return; + + double min = double( sld->minimum( ) ); + double max = double( sld->maximum( ) ); + double vmin = box->minimum( ); + double vmax = box->maximum( ); + double s = ( v - vmin ) / ( vmax - vmin ); + s = ( ( max - min ) * s ) + min; + + bool o = sld->blockSignals( true ); + sld->setValue( ( unsigned int )( s ) ); + sld->blockSignals( o ); + this->_setLevel( v ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_sldLevel( int v ) +{ + auto* box = this->findChild< QDoubleSpinBox* >( "lev_box" ); + auto* sld = this->findChild< QSlider* >( "lev_sld" ); + if( box == NULL || sld == NULL ) + return; + + double min = double( sld->minimum( ) ); + double max = double( sld->maximum( ) ); + double vmin = box->minimum( ); + double vmax = box->maximum( ); + double s = ( double( v ) - min ) / ( max - min ); + s = ( ( vmax - vmin ) * s ) + vmin; + + bool o = box->blockSignals( true ); + box->setValue( s ); + box->blockSignals( o ); + this->_setLevel( s ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_sldOpacity( int v ) +{ + if( this->m_DataObject == NULL ) + return; + auto* sld = this->findChild< QSlider* >( "op_sld" ); + if( sld == NULL ) + return; + + double min = double( sld->minimum( ) ); + 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 ia = dynamic_cast< vtkImageActor* >( aIt->Actor.GetPointer( ) ); + auto ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) ); + if( ia != NULL ) + { + ia->GetProperty( )->SetOpacity( s ); + ia->Modified( ); + } + else if( ma != NULL ) + { + ma->GetProperty( )->SetOpacity( s ); + ma->Modified( ); + + } // fi + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_boxPointSize( int v ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_boxLineWidth( int v ) +{ +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_scalarVisibility( int v ) +{ + if( this->m_DataObject == NULL ) + return; + auto* btn = this->findChild< QPushButton* >( "color_button" ); + auto* chk = this->findChild< QCheckBox* >( "sv_box" ); + if( btn == NULL || chk == NULL ) + return; + QPalette pal = btn->palette( ); + QColor color = pal.color( QPalette::Button ); + double rgb[ 3 ]; + rgb[ 0 ] = double( color.red( ) ) / double( 255 ); + 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 ma = dynamic_cast< vtkActor* >( aIt->Actor.GetPointer( ) ); + if( ma != NULL ) + { + if( !( chk->isChecked( ) ) ) + { + ma->GetMapper( )->ScalarVisibilityOff( ); + ma->GetProperty( )->SetColor( rgb ); + } + else + ma->GetMapper( )->ScalarVisibilityOn( ); + ma->Modified( ); + + } // fi + + } // rof + this->_render( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::DataObjectVisualizationQtDialog:: +_color( ) +{ + if( this->m_DataObject == NULL ) + return; + auto* btn = this->findChild< QPushButton* >( "color_button" ); + auto* chk = this->findChild< QCheckBox* >( "sv_box" ); + if( btn == NULL || chk == NULL ) + return; + + QPalette pal = btn->palette( ); + QColor color = + QColorDialog::getColor( + pal.color( QPalette::Button ), + this, + "Select Color", + QColorDialog::DontUseNativeDialog + ); + if( color.isValid( ) ) + { + pal.setColor( QPalette::Button, color ); + btn->setAutoFillBackground( true ); + btn->setPalette( pal ); + btn->update( ); + this->_scalarVisibility( 0 ); + + } // fi +} + +#endif // cpPlugins_QT4 + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/DataObjectVisualizationQtDialog.h b/lib/cpPlugins/DataObjectVisualizationQtDialog.h new file mode 100644 index 0000000..a26b7ba --- /dev/null +++ b/lib/cpPlugins/DataObjectVisualizationQtDialog.h @@ -0,0 +1,94 @@ +#ifndef __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ +#define __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ + +#include + +#ifdef cpPlugins_QT4 + +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace cpPlugins +{ + /** + */ + class cpPlugins_EXPORT DataObjectVisualizationQtDialog + : public QDialog + { + Q_OBJECT; + + public: + DataObjectVisualizationQtDialog( + QWidget* parent = 0, Qt::WindowFlags f = 0 + ); + virtual ~DataObjectVisualizationQtDialog( ); + + DataObject* getDataObject( ) const; + virtual bool setDataObject( DataObject* obj ); + + virtual int exec( ); + + protected: + virtual void _addButtons( ); + virtual void _updateWidgets( ); + + virtual void _configureForImage( ); + virtual void _configureForMesh( ); + + void _setWindow( double w ); + void _setLevel( double l ); + void _render( ); + + protected slots: + void _boxWindow( double v ); + void _sldWindow( int v ); + void _boxLevel( double v ); + void _sldLevel( int v ); + void _sldOpacity( int v ); + void _boxPointSize( int v ); + void _boxLineWidth( int v ); + void _scalarVisibility( int v ); + void _color( ); + + /* TODO + virtual void updateParameters( ); + virtual void updateView( ); + + protected: + virtual void _addButtons( ); + virtual void _updateWidgets( ); + + protected slots: + virtual void _dlg_OpenSingleFile( ); + virtual void _dlg_SaveSingleFile( ); + virtual void _dlg_OpenSinglePath( ); + virtual void _dlg_OpenMultipleFiles( ); + virtual void _dlg_AddInt( ); + virtual void _dlg_AddUint( ); + virtual void _dlg_AddReal( ); + */ + + protected: + DataObject* m_DataObject; + bool m_WidgetsUpdated; + QLabel* m_Title; + QGridLayout* m_MainLayout; + QVBoxLayout* m_ToolsLayout; + QDialogButtonBox* m_Buttons; + }; + +} // ecapseman + +#endif // cpPlugins_QT4 + +#endif // __CPPLUGINS__DATAOBJECTVISUALIZATIONQTDIALOG__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Mesh.cxx b/lib/cpPlugins/Mesh.cxx index 054b71a..071a51d 100644 --- a/lib/cpPlugins/Mesh.cxx +++ b/lib/cpPlugins/Mesh.cxx @@ -107,6 +107,7 @@ SetVTK( vtkObjectBase* o ) } // fi } + // ------------------------------------------------------------------------- cpPlugins::Mesh:: Mesh( ) -- 2.47.1