From: Leonardo Florez-Valencia Date: Tue, 20 Oct 2015 21:03:43 +0000 (-0500) Subject: Widgets updated X-Git-Tag: v0.1~328 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=022d9ce59bfd6ab97517cba9440429750df6c442;p=cpPlugins.git Widgets updated --- diff --git a/appli/examples/example_HandleWidget.cxx b/appli/examples/example_HandleWidget.cxx index 193091c..2cce131 100644 --- a/appli/examples/example_HandleWidget.cxx +++ b/appli/examples/example_HandleWidget.cxx @@ -107,7 +107,7 @@ int main( int argc, char* argv[] ) vtkSmartPointer< vtkPointHandleRepresentation3D > rep = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); - rep->SetDisplayPosition( pos ); + rep->SetWorldPosition( pos ); rep->GetProperty( )->SetColor( 1, 0, 0 ); rep->ActiveRepresentationOff( ); rep->SetPointPlacer( placer ); diff --git a/appli/examples/example_SeedWidget.cxx b/appli/examples/example_SeedWidget.cxx index beac518..d1e776e 100644 --- a/appli/examples/example_SeedWidget.cxx +++ b/appli/examples/example_SeedWidget.cxx @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -98,10 +99,15 @@ int main( int argc, char* argv[] ) image_actors->AddInputData( image->GetVTK< vtkImageData >( ), 2 ); image_actors->PushActorsInto( window ); + vtkSmartPointer< vtkImageActorPointPlacer > placer = + vtkSmartPointer< vtkImageActorPointPlacer >::New( ); + placer->SetImageActor( image_actors->GetImageActor( 0 ) ); + // Create the widget and its representation vtkSmartPointer< vtkPointHandleRepresentation3D > handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); handle->GetProperty( )->SetColor( 1, 0, 0 ); + handle->SetPointPlacer( placer ); vtkSmartPointer< vtkSeedRepresentation > rep = vtkSmartPointer< vtkSeedRepresentation >::New( ); rep->SetHandleRepresentation( handle ); diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.cxx b/lib/cpExtensions/Visualization/ImageSliceActors.cxx index 17dc4c4..4bafde1 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.cxx +++ b/lib/cpExtensions/Visualization/ImageSliceActors.cxx @@ -264,6 +264,14 @@ Clear( ) this->AddItem( this->m_PlaneActor ); } +// ------------------------------------------------------------------------- +void cpExtensions::Visualization::ImageSliceActors:: +AssociateSlice( Self* slice ) +{ + this->m_AssociatedSlices.push_back( slice ); + this->Modified( ); +} + // ------------------------------------------------------------------------- vtkInteractorStyle* cpExtensions::Visualization::ImageSliceActors:: GetStyle( ) @@ -278,17 +286,40 @@ GetStyle( ) const return( this->m_Style.GetPointer( ) ); } +// ------------------------------------------------------------------------- +vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( unsigned int id ) +{ + vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( ); + vtkImageData* image = dynamic_cast< vtkImageData* >( + aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + ); + return( image ); +} + +// ------------------------------------------------------------------------- +const vtkImageData* cpExtensions::Visualization::ImageSliceActors:: +GetInputImage( unsigned int id ) const +{ + vtkAlgorithmOutput* aout = this->m_ImageMaps[ id ]->GetOutputPort( ); + const vtkImageData* image = dynamic_cast< const vtkImageData* >( + aout->GetProducer( )->GetOutputDataObject( aout->GetIndex( ) ) + ); + return( image ); +} + // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: PushActorsInto( vtkRenderWindow* window, bool force_style ) { + this->m_Window = window; if( window == NULL ) return; vtkRenderWindowInteractor* rwi = window->GetInteractor( ); vtkRenderer* renderer = window->GetRenderers( )->GetFirstRenderer( ); if( rwi == NULL || renderer == NULL ) return; - + // Update style if( this->m_Style.GetPointer( ) != NULL && force_style ) rwi->SetInteractorStyle( this->m_Style ); @@ -299,6 +330,12 @@ PushActorsInto( vtkRenderWindow* window, bool force_style ) while( prop = this->GetNextProp( ) ) renderer->AddViewProp( prop ); renderer->Modified( ); + if( !force_style ) + { + renderer->RemoveViewProp( this->m_CursorActor ); + renderer->RemoveViewProp( this->m_TextActor ); + + } // fi // Configure camera vtkCamera* camera = renderer->GetActiveCamera( ); @@ -859,6 +896,15 @@ SetSliceNumber( const int& slice ) d_ext[ axis << 1 ] = slice; d_ext[ ( axis << 1 ) + 1 ] = slice; + std::cout + << d_ext[ 0 ] << " " + << d_ext[ 1 ] << " " + << d_ext[ 2 ] << " " + << d_ext[ 3 ] << " " + << d_ext[ 4 ] << " " + << d_ext[ 5 ] << " : " + << axis << std::endl; + // Change visualization extent for( unsigned int i = 0; i < nImages; ++i ) { @@ -873,18 +919,18 @@ SetSliceNumber( const int& slice ) // Prevent obscuring voxels by offsetting the plane geometry double xbnds[ ] = { - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 0 ] ) ), - ori[ 0 ] + ( spac[ 0 ] * double( ext[ 1 ] ) ) + ori[ 0 ] + ( spac[ 0 ] * double( d_ext[ 0 ] ) ), + ori[ 0 ] + ( spac[ 0 ] * double( d_ext[ 1 ] ) ) }; double ybnds[ ] = { - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 2 ] ) ), - ori[ 1 ] + ( spac[ 1 ] * double( ext[ 3 ] ) ) + ori[ 1 ] + ( spac[ 1 ] * double( d_ext[ 2 ] ) ), + ori[ 1 ] + ( spac[ 1 ] * double( d_ext[ 3 ] ) ) }; double zbnds[ ] = { - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 4 ] ) ), - ori[ 2 ] + ( spac[ 2 ] * double( ext[ 5 ] ) ) + ori[ 2 ] + ( spac[ 2 ] * double( d_ext[ 4 ] ) ), + ori[ 2 ] + ( spac[ 2 ] * double( d_ext[ 5 ] ) ) }; if( spac[ 0 ] < double( 0 ) ) @@ -1084,28 +1130,18 @@ UpdateText( const double& w, const double& l ) void cpExtensions::Visualization::ImageSliceActors:: Render( ) { - vtkInteractorStyle* style = this->GetStyle( ); - if( style == NULL ) - return; - vtkRenderWindowInteractor* rwi = style->GetInteractor( ); - if( rwi != NULL ) - rwi->Render( ); + if( this->m_Window != NULL ) + this->m_Window->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::ImageSliceActors:: ResetCamera( ) { - vtkInteractorStyle* style = this->GetStyle( ); - if( style == NULL ) - return; - vtkRenderWindowInteractor* rwi = style->GetInteractor( ); - if( rwi == NULL ) - return; - vtkRenderWindow* rw = rwi->GetRenderWindow( ); - if( rw == NULL ) + if( this->m_Window == NULL ) return; - vtkRenderer* renderer = rw->GetRenderers( )->GetFirstRenderer( ); + vtkRenderer* renderer = + this->m_Window->GetRenderers( )->GetFirstRenderer( ); if( renderer != NULL ) renderer->ResetCamera( ); } @@ -1114,6 +1150,7 @@ ResetCamera( ) cpExtensions::Visualization::ImageSliceActors:: ImageSliceActors( ) : Superclass( ), + m_Window( NULL ), m_Interpolate( false ) { this->Clear( ); @@ -1313,8 +1350,16 @@ _MouseWheelCommand( if( slice > actors->GetSliceNumberMaxValue( ) ) slice = actors->GetSliceNumberMaxValue( ); actors->SetSliceNumber( slice ); - actors->Render( ); + auto a = actors->m_AssociatedSlices.begin( ); + for( ; a != actors->m_AssociatedSlices.end( ); ++a ) + { + ( *a )->SetSliceNumber( slice ); + ( *a )->Render( ); + + } // rof + actors->Render( ); + // Associate objects auto i = actors->m_RenderCommands.begin( ); for( ; i != actors->m_RenderCommands.end( ); ++i ) diff --git a/lib/cpExtensions/Visualization/ImageSliceActors.h b/lib/cpExtensions/Visualization/ImageSliceActors.h index 6c7d405..f24bc7e 100644 --- a/lib/cpExtensions/Visualization/ImageSliceActors.h +++ b/lib/cpExtensions/Visualization/ImageSliceActors.h @@ -23,6 +23,7 @@ class vtkAlgorithmOutput; class vtkImageData; class vtkLookupTable; +class vtkRenderer; // ------------------------------------------------------------------------- namespace cpExtensions @@ -65,6 +66,11 @@ namespace cpExtensions void AddInputData( vtkImageData* data, int axis = 2 ); void Clear( ); + void AssociateSlice( Self* slice ); + + vtkImageData* GetInputImage( unsigned int id ); + const vtkImageData* GetInputImage( unsigned int id ) const; + vtkInteractorStyle* GetStyle( ); const vtkInteractorStyle* GetStyle( ) const; @@ -159,6 +165,7 @@ namespace cpExtensions protected: vtkSmartPointer< TStyle > m_Style; + vtkRenderWindow* m_Window; // Multiple actors std::vector< vtkSmartPointer< vtkImageMapToColors > > m_ImageMaps; @@ -166,6 +173,9 @@ namespace cpExtensions std::vector< vtkSmartPointer< vtkImageActor > > m_ImageActors; bool m_Interpolate; + // Associated slices + std::vector< Self* > m_AssociatedSlices; + // Window-Level values double m_MinWindow, m_MaxWindow; double m_MinLevel, m_MaxLevel; diff --git a/lib/cpExtensions/Visualization/MPRActors.cxx b/lib/cpExtensions/Visualization/MPRActors.cxx index cff7a80..6419daa 100644 --- a/lib/cpExtensions/Visualization/MPRActors.cxx +++ b/lib/cpExtensions/Visualization/MPRActors.cxx @@ -211,52 +211,26 @@ PushActorsInto( this->Slices[ 0 ][ 0 ]->PushActorsInto( x, true ); this->Slices[ 0 ][ 1 ]->PushActorsInto( y, true ); this->Slices[ 0 ][ 2 ]->PushActorsInto( z, true ); + this->Slices[ 1 ][ 0 ]->PushActorsInto( w, false ); + this->Slices[ 1 ][ 1 ]->PushActorsInto( w, false ); + this->Slices[ 1 ][ 2 ]->PushActorsInto( w, false ); - vtkRenderer* wren = - ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; - vtkRenderer* rends[ ] = - { - ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL, - ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL, - ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL - }; - for( int i = 0; i < 3; ++i ) - { - if( rends[ i ] != NULL ) - for( int j = 0; j < 3; ++j ) - if( i != j ) - rends[ i ]->AddActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); - if( wren != NULL ) - { - for( - unsigned int k = 0; - k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); - ++k - ) - wren->AddActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); - wren->AddActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); + /* - } // fi + this->Slices[ 0 ][ 0 ]->PushActorsInto( y, false ); + this->Slices[ 0 ][ 0 ]->PushActorsInto( z, false ); - } // rof - if( wren != NULL ) - wren->AddActor( this->ImageOutlineActor ); + this->Slices[ 0 ][ 1 ]->PushActorsInto( x, false ); + this->Slices[ 0 ][ 1 ]->PushActorsInto( z, false ); - for( unsigned int j = 0; j < 3; ++j ) - { - /* TODO - ImageInteractorStyle* st = - dynamic_cast< ImageInteractorStyle* >( this->Slices[ 0 ][ j ]->GetStyle( ) ); - if( w != NULL ) - st->AssociateInteractor( w->GetInteractor( ) ); - for( unsigned int l = 0; l < 3; ++l ) - if( j != l ) - st->AssociateInteractor( - this->Slices[ 0 ][ l ]->GetStyle( )->GetInteractor( ) - ); - */ + this->Slices[ 0 ][ 2 ]->PushActorsInto( x, false ); + this->Slices[ 0 ][ 2 ]->PushActorsInto( y, false ); - } // rof + vtkRenderer* wren = + ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; + if( wren != NULL ) + wren->AddActor( this->ImageOutlineActor ); + */ } // ------------------------------------------------------------------------- @@ -269,34 +243,12 @@ PopActorsFrom( this->Slices[ 0 ][ 0 ]->PopActorsFrom( x ); this->Slices[ 0 ][ 1 ]->PopActorsFrom( y ); this->Slices[ 0 ][ 2 ]->PopActorsFrom( z ); + this->Slices[ 1 ][ 0 ]->PopActorsFrom( w ); + this->Slices[ 1 ][ 1 ]->PopActorsFrom( w ); + this->Slices[ 1 ][ 2 ]->PopActorsFrom( w ); vtkRenderer* wren = ( w != NULL )? w->GetRenderers( )->GetFirstRenderer( ): NULL; - vtkRenderer* rends[ ] = - { - ( x != NULL )? x->GetRenderers( )->GetFirstRenderer( ): NULL, - ( y != NULL )? y->GetRenderers( )->GetFirstRenderer( ): NULL, - ( z != NULL )? z->GetRenderers( )->GetFirstRenderer( ): NULL - }; - for( int i = 0; i < 3; ++i ) - { - if( rends[ i ] != NULL ) - for( int j = 0; j < 3; ++j ) - if( i != j ) - rends[ i ]->RemoveActor( this->Slices[ 0 ][ j ]->GetPlaneActor( ) ); - if( wren != NULL ) - { - for( - unsigned int k = 0; - k < this->Slices[ 1 ][ i ]->GetNumberOfImageActors( ); - ++k - ) - wren->RemoveActor( this->Slices[ 1 ][ i ]->GetImageActor( k ) ); - wren->RemoveActor( this->Slices[ 1 ][ i ]->GetPlaneActor( ) ); - - } // fi - - } // rof if( wren != NULL ) wren->RemoveActor( this->ImageOutlineActor ); @@ -360,7 +312,7 @@ GetSlice( const int& axis ) const void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const int& slice ) { - vtkImageData* image = this->_Image( 0 ); + vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 ); if( image == NULL ) return; @@ -385,7 +337,7 @@ SetSlice( const int& axis, const int& slice ) void cpExtensions::Visualization::MPRActors:: SetSlice( const int& axis, const double& slice ) { - vtkImageData* image = this->_Image( 0 ); + vtkImageData* image = this->Slices[ 0 ][ 0 ]->GetInputImage( 0 ); if( image == NULL ) return; @@ -419,105 +371,27 @@ MPRActors( ) for( unsigned int j = 0; j < 3; ++j ) this->Slices[ i ][ j ] = vtkSmartPointer< ImageSliceActors >::New( ); - /* - this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); - this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); - this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); - */ - /* - this->Slices[ 0 ][ 0 ]->AddSlicesCommand( TSlicesCommand command, void* data ); - AddWindowLevelCommand( TWindowLevelCommand command, void* data ); - AddRenderCommand - */ + this->Slices[ 0 ][ 0 ]->AssociateSlice( this->Slices[ 1 ][ 0 ] ); + this->Slices[ 0 ][ 1 ]->AssociateSlice( this->Slices[ 1 ][ 1 ] ); + this->Slices[ 0 ][ 2 ]->AssociateSlice( this->Slices[ 1 ][ 2 ] ); - /* TODO - this->Slices[ 0 ][ 0 ]->SetSlicesCommand( Self::_SetSlices, this ); - this->Slices[ 0 ][ 1 ]->SetSlicesCommand( Self::_SetSlices, this ); - this->Slices[ 0 ][ 2 ]->SetSlicesCommand( Self::_SetSlices, this ); - */ -} - -// ------------------------------------------------------------------------- -cpExtensions::Visualization::MPRActors:: -~MPRActors( ) -{ -} - -// ------------------------------------------------------------------------- -vtkImageData* cpExtensions::Visualization::MPRActors:: -_Image( unsigned int i ) const -{ - /* - if( i < this->ImageMaps.size( ) ) + for( unsigned int i = 0; i < 3; ++ i ) { - vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( ); - vtkInformation* info = algo->GetOutputInformation( 0 ); - return( - vtkImageData::SafeDownCast( - info->Get( vtkDataObject::DATA_OBJECT( ) ) - ) + this->Slices[ 0 ][ i ]->AddRenderCommand( + Self::_RenderCommand, this ); - } - else - */ - return( NULL ); + this->Slices[ 0 ][ i ]->AddWindowLevelCommand( + Self::_WindowLevelCommand, this + ); + // this->Slices[ 0 ][ i ]->AddSlicesCommand( Self::_SlicesCommand, this ); + + } // rof } // ------------------------------------------------------------------------- -void cpExtensions::Visualization::MPRActors:: -_Update( unsigned int i ) +cpExtensions::Visualization::MPRActors:: +~MPRActors( ) { - /* - // Check if the input has been configured - vtkImageData* image = this->_Image( i ); - if( image == NULL ) - return; - this->ImageMaps[ i ]->Update( ); - - for( int j = 0; j < 2; ++j ) - { - for( int k = 0; k < 3; ++k ) - { - this->Slices[ j ][ k ]->AddInputConnection( - this->ImageMaps[ i ]->GetOutputPort( ), k - ); - this->Slices[ j ][ k ]->UpdateText( ); - - // Add all of slice's props - this->Slices[ j ][ k ]->InitTraversal( ); - vtkProp* prop = this->Slices[ j ][ k ]->GetNextProp( ); - while( prop != NULL ) - { - this->AddItem( prop ); - prop = this->Slices[ j ][ k ]->GetNextProp( ); - - } // elihw - - } // rof - - } // rof - - if( i == 0 ) - { - // Create 3D outline - double bb[ 6 ]; - image->GetBounds( bb ); - - vtkSmartPointer< vtkOutlineSource > img_ol = - vtkSmartPointer< vtkOutlineSource >::New( ); - img_ol->SetBounds( bb ); - - vtkSmartPointer< vtkPolyDataMapper > img_ol_mapper = - vtkSmartPointer< vtkPolyDataMapper >::New( ); - img_ol_mapper->SetInputConnection( img_ol->GetOutputPort( ) ); - this->ImageOutlineActor->SetMapper( img_ol_mapper ); - this->ImageOutlineActor->GetProperty( )->SetColor( 1, 1, 1 ); - this->ImageOutlineActor->GetProperty( )->SetLineWidth( 1 ); - - this->AddItem( this->ImageOutlineActor ); - - } // fi - */ } // ------------------------------------------------------------------------- @@ -539,12 +413,30 @@ _SlicesCommand( double* pos, int axis, void* data ) void cpExtensions::Visualization::MPRActors:: _WindowLevelCommand( double window, double level, void* data ) { + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->Slices[ 0 ][ 0 ]->Render( ); + actors->Slices[ 0 ][ 1 ]->Render( ); + actors->Slices[ 0 ][ 2 ]->Render( ); + actors->Slices[ 1 ][ 0 ]->Render( ); + actors->Slices[ 1 ][ 1 ]->Render( ); + actors->Slices[ 1 ][ 2 ]->Render( ); } // ------------------------------------------------------------------------- void cpExtensions::Visualization::MPRActors:: _RenderCommand( void* data ) { + MPRActors* actors = reinterpret_cast< MPRActors* >( data ); + if( actors == NULL ) + return; + actors->Slices[ 0 ][ 0 ]->Render( ); + actors->Slices[ 0 ][ 1 ]->Render( ); + actors->Slices[ 0 ][ 2 ]->Render( ); + actors->Slices[ 1 ][ 0 ]->Render( ); + actors->Slices[ 1 ][ 1 ]->Render( ); + actors->Slices[ 1 ][ 2 ]->Render( ); } // eof - $RCSfile$ diff --git a/lib/cpExtensions/Visualization/MPRActors.h b/lib/cpExtensions/Visualization/MPRActors.h index f4283f4..01066b4 100644 --- a/lib/cpExtensions/Visualization/MPRActors.h +++ b/lib/cpExtensions/Visualization/MPRActors.h @@ -71,11 +71,10 @@ namespace cpExtensions MPRActors( ); virtual ~MPRActors( ); - vtkImageData* _Image( unsigned int i ) const; - void _Update( unsigned int i ); - static void _SlicesCommand( double* pos, int axis, void* data ); - static void _WindowLevelCommand( double window, double level, void* data ); + static void _WindowLevelCommand( + double window, double level, void* data + ); static void _RenderCommand( void* data ); private: diff --git a/lib/cpPlugins/Interface/CMakeLists.txt b/lib/cpPlugins/Interface/CMakeLists.txt index 83552b2..115cb44 100644 --- a/lib/cpPlugins/Interface/CMakeLists.txt +++ b/lib/cpPlugins/Interface/CMakeLists.txt @@ -25,11 +25,13 @@ IF(USE_QT4) SET( LIB_QT_Headers ParametersListWidget.h + ParametersQtDialog.h BaseMPRWindow.h ) SET( LIB_QT_Sources ParametersListWidget.cxx + ParametersQtDialog.cxx BaseMPRWindow.cxx ) SET( diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.cxx b/lib/cpPlugins/Interface/ParametersQtDialog.cxx index 9f6aadc..80d73a2 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.cxx +++ b/lib/cpPlugins/Interface/ParametersQtDialog.cxx @@ -3,48 +3,236 @@ #ifdef cpPlugins_Interface_QT4 #include -#include #include + +#include +#include +#include +#include +#include + #include -#include #include #include #include -#include #include #include // ------------------------------------------------------------------------- -bool cpPlugins::Interface:: -ParametersQtDialog( - Parameters* parameters, const std::string& title, QWidget* parent - ) +cpPlugins::Interface::ParametersQtDialog:: +ParametersQtDialog( QWidget* parent, Qt::WindowFlags f ) + : QDialog( parent, f ), + m_Parameters( NULL ), + m_IsModal( false ), + m_Interactor( NULL ) { - // Create dialog with a simple layout - QDialog* dlg = new QDialog( parent ); - dlg->setWindowFlags( Qt::FramelessWindowHint ); - dlg->setWindowFlags( Qt::WindowTitleHint ); - QGridLayout* gridLayout = new QGridLayout( dlg ); - QVBoxLayout* verticalLayout = new QVBoxLayout( ); + this->m_Title = new QLabel( this ); + this->m_Title->setText( "Parameters dialog title" ); - // Put a title - QLabel* dlg_title = new QLabel( dlg ); - dlg_title->setText( title.c_str( ) ); - verticalLayout->addWidget( dlg_title ); + 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::Interface::ParametersQtDialog:: +~ParametersQtDialog( ) +{ + delete this->m_Title; + delete this->m_MainLayout; + delete this->m_ToolsLayout; + + for( unsigned int i = 0; i < this->m_Widgets.size( ); ++i ) + this->m_Widgets[ i ]->Delete( ); +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ParametersQtDialog:: +IsModal( ) const +{ + return( this->m_IsModal ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +Parameters* cpPlugins::Interface::ParametersQtDialog:: +getParameters( ) const +{ + return( this->m_Parameters ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +setInteractor( vtkRenderWindowInteractor* interactor ) +{ + this->m_Interactor = interactor; +} + +// ------------------------------------------------------------------------- +bool cpPlugins::Interface::ParametersQtDialog:: +setParameters( Parameters* parameters ) +{ + this->m_IsModal = true; + this->m_Parameters = parameters; + if( this->m_Parameters == NULL ) + return( false ); // Put values std::vector< std::string > names; - parameters->GetNames( names ); + this->m_Parameters->GetNames( names ); std::vector< std::string >::const_iterator nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { - Parameters::Type pt = parameters->GetType( *nIt ); + Parameters::Type pt = this->m_Parameters->GetType( *nIt ); + + QWidget* w_input = NULL; + if( pt == Parameters::String ) + { + QLineEdit* v_string = new QLineEdit( this ); + v_string->setText( "Enter some text!!!" ); + w_input = v_string; + } + else if( pt == Parameters::Bool ) + { + QCheckBox* v_bool = new QCheckBox( this ); + v_bool->setText( "[ON/OFF]" ); + v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) ); + w_input = v_bool; + } + else if( pt == Parameters::Uint ) + { + QSpinBox* v_uint = new QSpinBox( this ); + v_uint->setMinimum( 0 ); + v_uint->setMaximum( std::numeric_limits< int >::max( ) ); + v_uint->setValue( this->m_Parameters->GetUint( *nIt ) ); + w_input = v_uint; + } + else if( pt == Parameters::Int ) + { + QSpinBox* v_int = new QSpinBox( this ); + v_int->setMinimum( -std::numeric_limits< int >::max( ) ); + v_int->setMaximum( std::numeric_limits< int >::max( ) ); + v_int->setValue( this->m_Parameters->GetInt( *nIt ) ); + w_input = v_int; + } + else if( pt == Parameters::Real ) + { + QDoubleSpinBox* v_double = new QDoubleSpinBox( this ); + v_double->setDecimals( 3 ); + v_double->setMinimum( -std::numeric_limits< double >::max( ) ); + v_double->setMaximum( std::numeric_limits< double >::max( ) ); + v_double->setValue( this->m_Parameters->GetReal( *nIt ) ); + w_input = v_double; + } + else if( + pt == Parameters::StringList || + pt == Parameters::IntList || + pt == Parameters::UintList || + pt == Parameters::RealList + ) + { + cpPlugins::Interface::ParametersListWidget* l_double = + new cpPlugins::Interface::ParametersListWidget( *nIt, this ); + w_input = l_double; + } + else if( pt == Parameters::Point || pt == Parameters::Index ) + { + if( this->m_Interactor != NULL ) + { + // Create a point widget and its representation + vtkSmartPointer< vtkPointHandleRepresentation3D > handle = + vtkSmartPointer< vtkPointHandleRepresentation3D >::New( ); + handle->GetProperty( )->SetColor( 1, 0, 0 ); + vtkSmartPointer< vtkSeedRepresentation > rep = + vtkSmartPointer< vtkSeedRepresentation >::New( ); + rep->SetHandleRepresentation( handle ); + + cpExtensions::Interaction::SeedWidget* widget = + cpExtensions::Interaction::SeedWidget::New( ); + widget->SetInteractor( this->m_Interactor ); + widget->SetRepresentation( rep ); + widget->On( ); + + this->m_Widgets.push_back( widget ); + this->m_IsModal = false; + + } // fi + + } // fi + + // Ok, a representation was created + if( w_input != NULL ) + { + w_input->setObjectName( QString( nIt->c_str( ) ) ); + + QHBoxLayout* new_layout = new QHBoxLayout( ); + QLabel* label = new QLabel( this ); + label->setText( QString( nIt->c_str( ) ) ); + new_layout->addWidget( label ); + new_layout->addWidget( w_input ); + this->m_ToolsLayout->addLayout( new_layout ); + + } // fi + + } // rof + return( this->m_IsModal ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +setTitle( const std::string& title ) +{ + this->m_Title->setText( title.c_str( ) ); +} + +// ------------------------------------------------------------------------- +int cpPlugins::Interface::ParametersQtDialog:: +exec( ) +{ + if( !this->m_IsModal ) + return( 0 ); + + // Add buttons + QDialogButtonBox* bb = new QDialogButtonBox( + QDialogButtonBox::Ok | QDialogButtonBox::Cancel + ); + QObject::connect( bb, SIGNAL( accepted( ) ), this, SLOT( accept( ) ) ); + QObject::connect( bb, SIGNAL( rejected( ) ), this, SLOT( reject( ) ) ); + this->m_ToolsLayout->addWidget( bb ); + + return( this->QDialog::exec( ) ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +show( ) +{ + if( this->m_IsModal ) + return; + + this->QDialog::show( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::ParametersQtDialog:: +syncParameters( ) +{ + std::cout << "TODO: SyncParameters" << std::endl; +} + + + + + + + + /* TODO enum Type { - Bool, Index, Point, StringList, @@ -53,9 +241,36 @@ ParametersQtDialog( UintList, IndexList, PointList, + Choices, NoType }; */ +/* +bool cpPlugins::Interface:: +ParametersQtDialog( + Parameters* parameters, const std::string& title, QWidget* parent + ) +{ + // Create dialog with a simple layout + QDialog* dlg = new QDialog( parent ); + dlg->setWindowFlags( Qt::FramelessWindowHint ); + dlg->setWindowFlags( Qt::WindowTitleHint ); + QGridLayout* gridLayout = new QGridLayout( dlg ); + QVBoxLayout* verticalLayout = new QVBoxLayout( ); + + // Put a title + QLabel* dlg_title = new QLabel( dlg ); + dlg_title->setText( title.c_str( ) ); + verticalLayout->addWidget( dlg_title ); + + // Put values + std::vector< std::string > names; + this->m_Parameters->GetNames( names ); + std::vector< std::string >::const_iterator nIt = names.begin( ); + for( ; nIt != names.end( ); ++nIt ) + { + Parameters::Type pt = this->m_Parameters->GetType( *nIt ); + QWidget* w_input = NULL; if( pt == Parameters::String ) { @@ -67,7 +282,7 @@ ParametersQtDialog( { QCheckBox* v_bool = new QCheckBox( dlg ); v_bool->setText( "[ON/OFF]" ); - v_bool->setChecked( parameters->GetBool( *nIt ) ); + v_bool->setChecked( this->m_Parameters->GetBool( *nIt ) ); w_input = v_bool; } else if( pt == Parameters::Uint ) @@ -75,7 +290,7 @@ ParametersQtDialog( QSpinBox* v_uint = new QSpinBox( dlg ); v_uint->setMinimum( 0 ); v_uint->setMaximum( std::numeric_limits< int >::max( ) ); - v_uint->setValue( parameters->GetUint( *nIt ) ); + v_uint->setValue( this->m_Parameters->GetUint( *nIt ) ); w_input = v_uint; } else if( pt == Parameters::Int ) @@ -83,7 +298,7 @@ ParametersQtDialog( QSpinBox* v_int = new QSpinBox( dlg ); v_int->setMinimum( -std::numeric_limits< int >::max( ) ); v_int->setMaximum( std::numeric_limits< int >::max( ) ); - v_int->setValue( parameters->GetInt( *nIt ) ); + v_int->setValue( this->m_Parameters->GetInt( *nIt ) ); w_input = v_int; } else if( pt == Parameters::Real ) @@ -92,7 +307,7 @@ ParametersQtDialog( v_double->setDecimals( 3 ); v_double->setMinimum( -std::numeric_limits< double >::max( ) ); v_double->setMaximum( std::numeric_limits< double >::max( ) ); - v_double->setValue( parameters->GetReal( *nIt ) ); + v_double->setValue( this->m_Parameters->GetReal( *nIt ) ); w_input = v_double; } else if( @@ -142,37 +357,37 @@ ParametersQtDialog( nIt = names.begin( ); for( ; nIt != names.end( ); ++nIt ) { - Parameters::Type pt = parameters->GetType( *nIt ); + Parameters::Type pt = this->m_Parameters->GetType( *nIt ); if( pt == Parameters::String ) { QLineEdit* v_string = dlg->findChild< QLineEdit* >( nIt->c_str( ) ); if( v_string != NULL ) - parameters->SetString( *nIt, v_string->text( ).toStdString( ) ); + this->m_Parameters->SetString( *nIt, v_string->text( ).toStdString( ) ); } else if( pt == Parameters::Bool ) { QCheckBox* v_bool = dlg->findChild< QCheckBox* >( nIt->c_str( ) ); if( v_bool != NULL ) - parameters->SetBool( *nIt, v_bool->isChecked( ) ); + this->m_Parameters->SetBool( *nIt, v_bool->isChecked( ) ); } else if( pt == Parameters::Uint ) { QSpinBox* v_uint = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); if( v_uint != NULL ) - parameters->SetUint( *nIt, v_uint->value( ) ); + this->m_Parameters->SetUint( *nIt, v_uint->value( ) ); } else if( pt == Parameters::Int ) { QSpinBox* v_int = dlg->findChild< QSpinBox* >( nIt->c_str( ) ); if( v_int != NULL ) - parameters->SetInt( *nIt, v_int->value( ) ); + this->m_Parameters->SetInt( *nIt, v_int->value( ) ); } else if( pt == Parameters::Real ) { QDoubleSpinBox* v_double = dlg->findChild< QDoubleSpinBox* >( nIt->c_str( ) ); if( v_double != NULL ) - parameters->SetReal( *nIt, v_double->value( ) ); + this->m_Parameters->SetReal( *nIt, v_double->value( ) ); } else if( pt == Parameters::StringList || @@ -191,25 +406,25 @@ ParametersQtDialog( { std::vector< std::string > values = l_double->GetStringValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToStringList( *nIt, values[ r ] ); + this->m_Parameters->AddToStringList( *nIt, values[ r ] ); } else if( pt == Parameters::IntList ) { std::vector< int > values = l_double->GetIntValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToIntList( *nIt, values[ r ] ); + this->m_Parameters->AddToIntList( *nIt, values[ r ] ); } else if( pt == Parameters::UintList ) { std::vector< unsigned int > values = l_double->GetUintValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToUintList( *nIt, values[ r ] ); + this->m_Parameters->AddToUintList( *nIt, values[ r ] ); } else if( pt == Parameters::RealList ) { std::vector< double > values = l_double->GetDoubleValues( ); for( int r = 0; r < values.size( ); ++r ) - parameters->AddToRealList( *nIt, values[ r ] ); + this->m_Parameters->AddToRealList( *nIt, values[ r ] ); } // fi @@ -220,6 +435,7 @@ ParametersQtDialog( } // rof return( true ); } +*/ #endif // cpPlugins_Interface_QT4 diff --git a/lib/cpPlugins/Interface/ParametersQtDialog.h b/lib/cpPlugins/Interface/ParametersQtDialog.h index ea9f84d..2dc62ed 100644 --- a/lib/cpPlugins/Interface/ParametersQtDialog.h +++ b/lib/cpPlugins/Interface/ParametersQtDialog.h @@ -8,17 +8,59 @@ #include #include -class QWidget; +#include + +#include +#include +#include +#include + +class vtkAbstractWidget; +class vtkRenderWindowInteractor; namespace cpPlugins { namespace Interface { - bool cpPlugins_Interface_EXPORT ParametersQtDialog( - Parameters* parameters, - const std::string& title, - QWidget* parent = NULL - ); + /** + */ + class cpPlugins_Interface_EXPORT ParametersQtDialog + : public QDialog + { + Q_OBJECT; + + public: + ParametersQtDialog( QWidget* parent = 0, Qt::WindowFlags f = 0 ); + virtual ~ParametersQtDialog( ); + + bool IsModal( ) const; + Parameters* getParameters( ) const; + void setInteractor( vtkRenderWindowInteractor* interactor ); + bool setParameters( Parameters* parameters ); + void setTitle( const std::string& title ); + + virtual int exec( ); + virtual void show( ); + void syncParameters( ); + + protected: + Parameters* m_Parameters; + QLabel* m_Title; + QGridLayout* m_MainLayout; + QVBoxLayout* m_ToolsLayout; + bool m_IsModal; + + vtkRenderWindowInteractor* m_Interactor; + std::vector< vtkAbstractWidget* > m_Widgets; + }; + + /* TODO + bool cpPlugins_Interface_EXPORT ParametersQtDialog( + Parameters* parameters, + const std::string& title, + QWidget* parent = NULL + ); + */ } // ecapseman diff --git a/lib/cpPlugins/Interface/ProcessObject.cxx b/lib/cpPlugins/Interface/ProcessObject.cxx index ae4a1d3..f0d8d52 100644 --- a/lib/cpPlugins/Interface/ProcessObject.cxx +++ b/lib/cpPlugins/Interface/ProcessObject.cxx @@ -100,12 +100,29 @@ ExecConfigurationDialog( QWidget* parent ) #ifdef cpPlugins_Interface_QT4 - r = cpPlugins::Interface::ParametersQtDialog( + if( this->m_ParametersDialog == NULL ) + { + this->m_ParametersDialog = new ParametersQtDialog( parent ); + this->m_ParametersDialog->setTitle( + this->GetClassName( ) + std::string( " basic configuration" ) + ); + this->m_ParametersDialog->setParameters( this->m_Parameters ); + + } // fi + + if( !( this->m_ParametersDialog->IsModal( ) ) ) + { + this->m_ParametersDialog->show( ); + r = true; + } + else + r = ( this->m_ParametersDialog->exec( ) == 1 ); + /* + r = cpPlugins::Interface::ParametersQtDialog( this->m_Parameters, this->GetClassName( ) + std::string( " basic configuration" ), parent ); - /* if( r ) // TODO: !!! this->m_Parameters = parameters; */ @@ -120,7 +137,8 @@ cpPlugins::Interface::ProcessObject:: ProcessObject( ) : Superclass( ), m_ITKObject( NULL ), - m_VTKObject( NULL ) + m_VTKObject( NULL ), + m_ParametersDialog( NULL ) { this->m_Parameters = TParameters::New( ); } @@ -129,6 +147,8 @@ ProcessObject( ) cpPlugins::Interface::ProcessObject:: ~ProcessObject( ) { + if( this->m_ParametersDialog == NULL ) + delete this->m_ParametersDialog; } // ------------------------------------------------------------------------- diff --git a/lib/cpPlugins/Interface/ProcessObject.h b/lib/cpPlugins/Interface/ProcessObject.h index 9548d48..53b784f 100644 --- a/lib/cpPlugins/Interface/ProcessObject.h +++ b/lib/cpPlugins/Interface/ProcessObject.h @@ -13,7 +13,7 @@ #ifdef cpPlugins_Interface_QT4 class QWidget; #else -typedef char QWidget +typedef char QWidget; #endif // cpPlugins_Interface_QT4 #include @@ -25,6 +25,12 @@ namespace cpPlugins { namespace Interface { +#ifdef cpPlugins_Interface_QT4 + class ParametersQtDialog; +#else + typedef char ParametersQtDialog; +#endif // cpPlugins_Interface_QT4 + /** */ class cpPlugins_Interface_EXPORT ProcessObject @@ -112,6 +118,7 @@ namespace cpPlugins vtkSmartPointer< vtkAlgorithm > m_VTKObject; Parameters::Pointer m_Parameters; + ParametersQtDialog* m_ParametersDialog; typedef std::map< std::string, DataObject::Pointer > _TDataContainer; _TDataContainer m_Inputs;