X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FQT%2FSimpleMPRWidget.cxx;h=7e338bc0b77c486e8f2c813f3f20383b838e0580;hb=f47059eb39b5c9eef5cd2ee1b6c013cd75eff97f;hp=ab47c28a32e0e354b1e4a0dafcd57ac0ad852c80;hpb=ebbbc4c90ed0e4814d360686e8d4b6aab509914c;p=cpPlugins.git diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index ab47c28..7e338bc 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,8 +3,31 @@ #ifdef cpExtensions_QT4 #include +#include #include +// ------------------------------------------------------------------------- +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle* +cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +New( ) +{ + return( new _3DInteractorStyle( ) ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle:: +OnKeyPress( ) +{ + vtkRenderWindowInteractor* i = this->Interactor; + std::string key = i->GetKeySym( ); + if( key == "r" || key == "R" ) + { + this->CurrentRenderer->ResetCamera( ); + i->Render( ); + + } // fi +} + // ------------------------------------------------------------------------- cpExtensions::QT::SimpleMPRWidget:: SimpleMPRWidget( QWidget* parent ) @@ -14,11 +37,10 @@ SimpleMPRWidget( QWidget* parent ) this->m_UI->setupUi( this ); // Configure VTK widgets - this->m_VTK[ 0 ] = this->m_UI->VTK01; - this->m_VTK[ 1 ] = this->m_UI->VTK00; - this->m_VTK[ 2 ] = this->m_UI->VTK10; - this->m_VTK[ 3 ] = this->m_UI->VTK11; - + this->m_VTK[ 0 ] = this->m_UI->VTK_X; + this->m_VTK[ 1 ] = this->m_UI->VTK_Y; + this->m_VTK[ 2 ] = this->m_UI->VTK_Z; + this->m_VTK[ 3 ] = this->m_UI->VTK_3D; for( unsigned int i = 0; i < 4; ++i ) { this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( ); @@ -26,6 +48,11 @@ SimpleMPRWidget( QWidget* parent ) AddRenderer( this->m_Renderers[ i ] ); } // rof + vtkSmartPointer< _3DInteractorStyle > style = + vtkSmartPointer< _3DInteractorStyle >::New( ); + this->m_VTK[ 3 ]->GetRenderWindow( )-> + GetInteractor( )->SetInteractorStyle( style ); + style->SetCurrentRenderer( this->m_Renderers[ 3 ] ); // Connect slots QObject::connect( @@ -42,6 +69,7 @@ SimpleMPRWidget( QWidget* parent ) cpExtensions::QT::SimpleMPRWidget:: ~SimpleMPRWidget( ) { + this->Clear( ); delete this->m_UI; } @@ -59,22 +87,23 @@ 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 ) { - this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( ); + this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); this->m_2DSlices[ i ]->SetInputData( image, i ); this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] ); this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )-> SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) ); - this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( ); + this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); this->m_3DSlices[ i ]->SetInputData( image, i ); this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] ); this->m_3DSlices[ i ]->SetStyle( @@ -84,59 +113,177 @@ 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, const std::string& name ) +{ + this->Clear( ); + vtkImageData* image = NULL; for( unsigned int i = 0; i < 3; ++i ) { - for( unsigned int j = 0; j < 3; ++j ) + this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); + if( i == 0 ) { - if( i != j ) - this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] ); - this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] ); + this->m_2DSlices[ i ]->SetInputActor( actor, i ); + image = this->m_2DSlices[ i ]->GetInputData( ); + } + else + this->m_2DSlices[ i ]->SetInputData( image, i ); + this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] ); + this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )-> + SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) ); - } // rof + this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( ); + this->m_3DSlices[ i ]->SetInputData( image, i ); + this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] ); + this->m_3DSlices[ i ]->SetStyle( + dynamic_cast< vtkInteractorStyle* >( + this->m_Renderers[ 3 ]->GetRenderWindow( )-> + GetInteractor( )->GetInteractorStyle( ) + ) + ); - } // rof - for( unsigned int i = 0; i < 3; ++i ) - { - this->m_2DSlices[ i ]->GetStyle( )-> - SetCurrentRenderer( this->m_Renderers[ i ] ); - this->m_Renderers[ i ]->ResetCamera( ); - this->m_VTK[ i ]->GetRenderWindow( )->Render( ); + this->m_NamedActors[ name ].insert( + this->m_2DSlices[ i ]->GetImageActor( ) + ); + this->m_NamedActors[ name ].insert( + this->m_3DSlices[ i ]->GetImageActor( ) + ); } // rof - this->m_Renderers[ 3 ]->ResetCamera( ); - this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + this->_AssociateSlices( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -AddMesh( vtkPolyData* mesh ) +AddImage( vtkImageData* image, const std::string& name ) { - PolyDataActor a; - a.Configure( mesh ); - this->m_PolyDatas[ mesh ] = a; - this->m_Renderers[ 3 ]->AddViewProp( a.Actor ); + std::cerr << "SimpleMPR: adding image" << std::endl; + std::exit( 1 ); +} - bool has_main_image = false; - for( unsigned int i = 0; i < 3; ++i ) +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget:: +AddImageActor( vtkImageActor* actor, const std::string& name ) +{ + unsigned int i = 0; + bool cont = true; + while( i < 3 && cont ) { if( this->m_2DSlices[ i ].GetPointer( ) != NULL ) { - if( this->m_2DSlices[ i ]->GetInputData( ) != NULL ) + if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL ) { - has_main_image = true; - this->m_2DSlices[ i ]->AddMesh( mesh ); - this->m_2DSlices[ i ]->Render( ); - - } // fi + // TODO: add image actor + } + else + cont = false; } // fi + i++; } // rof - if( !has_main_image ) - this->m_Renderers[ 3 ]->ResetCamera( ); - this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + + // Add if no actors were found + if( cont ) + this->SetMainActor( actor, name ); +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget:: +AddMesh( vtkPolyData* mesh, const std::string& name ) +{ + std::cerr << "SimpleMPR: adding mesh" << std::endl; + std::exit( 1 ); + /* TODO + PolyDataActor a; + a.Configure( mesh ); + this->m_PolyDatas[ mesh ] = a; + this->m_Renderers[ 3 ]->AddViewProp( a.Actor ); + + bool has_main_image = false; + for( unsigned int i = 0; i < 3; ++i ) + { + if( this->m_2DSlices[ i ].GetPointer( ) != NULL ) + { + if( this->m_2DSlices[ i ]->GetInputData( ) != NULL ) + { + has_main_image = true; + this->m_2DSlices[ i ]->AddMesh( mesh ); + this->m_2DSlices[ i ]->Render( ); + + } // fi + + } // fi + + } // rof + if( !has_main_image ) + this->m_Renderers[ 3 ]->ResetCamera( ); + this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + */ +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget:: +AddMeshActor( vtkProp3D* actor, const std::string& name ) +{ + if( actor != NULL ) + { + std::cout << name << " " << actor << std::endl; + + this->m_Renderers[ 3 ]->AddViewProp( actor ); + this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); + this->m_NamedActors[ name ].insert( actor ); + std::cout << "Size: " << this->m_NamedActors.size( ) << " " << this->m_NamedActors[ name ].size( ) << std::endl; + + + double bounds[ 6 ]; + this->m_Renderers[ 3 ]->ComputeVisiblePropBounds( bounds ); + std::cout + << bounds[ 0 ] << " " << bounds[ 1 ] << " " + << bounds[ 2 ] << " " << bounds[ 3 ] << " " + << bounds[ 4 ] << " " << bounds[ 5 ] << std::endl; + + } // fi +} + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget:: +AddActor( vtkProp* actor, const std::string& name ) +{ + auto ia = dynamic_cast< vtkImageActor* >( actor ); + if( ia == NULL ) + { + auto ma = dynamic_cast< vtkProp3D* >( actor ); + if( ma != NULL ) + this->AddMeshActor( ma, name ); + } + else + 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 ); } // ------------------------------------------------------------------------- @@ -160,39 +307,85 @@ GetRenderer( unsigned int i ) } // ------------------------------------------------------------------------- -std::vector< std::pair< vtkImageActor*, vtkRenderer* > > -cpExtensions::QT::SimpleMPRWidget:: -GetMainImageActors( ) +vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget:: +GetRenderWindow( unsigned int i ) { - std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors; - for( unsigned int i = 0; i < 3; ++i ) + if( i < 4 ) { - 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 ); + if( this->m_Renderers[ i ].GetPointer( ) != NULL ) + return( this->m_Renderers[ i ]->GetRenderWindow( ) ); + else + return( NULL ); + } + else + return( NULL ); } // ------------------------------------------------------------------------- -vtkActor* cpExtensions::QT::SimpleMPRWidget:: -GetActor( vtkPolyData* mesh ) +/* TODO + 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 ); + } +*/ + +// ------------------------------------------------------------------------- +/* TODO + vtkActor* cpExtensions::QT::SimpleMPRWidget:: + GetActor( vtkPolyData* mesh ) + { + auto i = this->m_PolyDatas.find( mesh ); + if( i != this->m_PolyDatas.end( ) ) + return( i->second.Actor.GetPointer( ) ); + else + return( NULL ); + } +*/ + +// ------------------------------------------------------------------------- +void cpExtensions::QT::SimpleMPRWidget:: +_AssociateSlices( ) { - auto i = this->m_PolyDatas.find( mesh ); - if( i != this->m_PolyDatas.end( ) ) - return( i->second.Actor.GetPointer( ) ); - else - return( NULL ); + for( unsigned int i = 0; i < 3; ++i ) + { + for( unsigned int j = 0; j < 3; ++j ) + { + if( i != j ) + this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] ); + this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] ); + + } // rof + + } // rof + for( unsigned int i = 0; i < 3; ++i ) + { + this->m_2DSlices[ i ]->GetStyle( )-> + SetCurrentRenderer( this->m_Renderers[ i ] ); + this->m_Renderers[ i ]->ResetCamera( ); + this->m_VTK[ i ]->GetRenderWindow( )->Render( ); + + } // rof + this->m_Renderers[ 3 ]->ResetCamera( ); + this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); } // -------------------------------------------------------------------------